Adjust NotifyHandshake to adapter changes sync
authorThomas
Wed, 24 Apr 2019 16:55:52 +0200
branchsync
changeset 2620055a316b8ff8
parent 2619 05d5e378d011
child 2621 04d3ed8778d1
Adjust NotifyHandshake to adapter changes
AdapterCallbacks.cs
     1.1 --- a/AdapterCallbacks.cs	Tue Apr 23 13:29:30 2019 +0200
     1.2 +++ b/AdapterCallbacks.cs	Wed Apr 24 16:55:52 2019 +0200
     1.3 @@ -25,14 +25,10 @@
     1.4          /// <param name="own">The personal identity for the handshake.</param>
     1.5          /// <param name="partner">The communication partner identity for the handshake.</param>
     1.6          /// <param name="signal">The reason for the handshake notification.</param>
     1.7 -        /// <returns>The user selected result.</returns>
     1.8 -        public SyncHandshakeResult NotifyHandshake(ref pEpIdentity own,
     1.9 -                                                   ref pEpIdentity partner,
    1.10 -                                                   SyncHandshakeSignal signal)
    1.11 +        public void NotifyHandshake(ref pEpIdentity own,
    1.12 +                                    ref pEpIdentity partner,
    1.13 +                                    SyncHandshakeSignal signal)
    1.14          {
    1.15 -            bool? dialogResult = null;
    1.16 -            SyncHandshakeResult handshakeResult = SyncHandshakeResult.SyncHandshakeCancel;
    1.17 -
    1.18              Log.Verbose("NotifyHandshake: Started with signal " + signal.ToString());
    1.19  
    1.20              /* Close handshake dialog if it was still open and the signal type
    1.21 @@ -62,7 +58,6 @@
    1.22                  // No action necessary
    1.23                  case SyncHandshakeSignal.SyncNotifyUndefined:
    1.24                      {
    1.25 -                        handshakeResult = SyncHandshakeResult.SyncHandshakeCancel;
    1.26                          break;
    1.27                      }
    1.28                  /* Currently, all of the following signals trigger showing the handshake dialog.
    1.29 @@ -74,11 +69,11 @@
    1.30                          // Syncronize engine with settings just in case (should already be synced)
    1.31                          Globals.ThisAddIn.SyncWithSettings(true);
    1.32  
    1.33 -                        // If sync is disabled, return cancel
    1.34 +                        // If sync is disabled, cancel
    1.35                          if (own.Flags.HasFlag(pEpIdentityFlags.pEpIdfNotForSync))
    1.36                          {
    1.37                              Log.Warning("NotifyHandshake: callback received for account with NotForSync flag. Ignoring request.");
    1.38 -                            return handshakeResult;
    1.39 +                            return;
    1.40                          }
    1.41  
    1.42                          // Close handshake dialog if necessary
    1.43 @@ -88,43 +83,18 @@
    1.44                          }
    1.45  
    1.46                          // Show handshake dialog in new STA thread
    1.47 -                        dialogResult = this.ShowHandshakeDialog(new PEPIdentity(own), new PEPIdentity(partner));
    1.48 -
    1.49 -                        AdapterCallbacks.handshakeDialog = null;
    1.50 -
    1.51 -                        // Send result back to the engine
    1.52 -                        switch (dialogResult)
    1.53 -                        {
    1.54 -                            case true:
    1.55 -                                {
    1.56 -                                    handshakeResult = SyncHandshakeResult.SyncHandshakeAccepted;
    1.57 -                                    break;
    1.58 -                                }
    1.59 -                            case false:
    1.60 -                                {
    1.61 -                                    handshakeResult = SyncHandshakeResult.SyncHandshakeRejected;
    1.62 -                                    break;
    1.63 -                                }
    1.64 -                            case null:
    1.65 -                            default: // this should never happen if we cover all enums
    1.66 -                                {
    1.67 -                                    handshakeResult = SyncHandshakeResult.SyncHandshakeCancel;
    1.68 -                                    break;
    1.69 -                                }
    1.70 -                        }
    1.71 +                        this.ShowHandshakeDialog(own, partner);
    1.72  
    1.73                          break;
    1.74                      }
    1.75                  // In case of timeout, the handshake gets cancelled (dialog is already closed at this point)
    1.76                  case SyncHandshakeSignal.SyncNotifyTimeout:
    1.77                      {
    1.78 -                        handshakeResult = SyncHandshakeResult.SyncHandshakeCancel;
    1.79                          break;
    1.80                      }
    1.81                  // Signal to close the dialog (actually, it is already closed at this point)
    1.82                  case SyncHandshakeSignal.SyncNotifyOvertaken:
    1.83                      {
    1.84 -                        handshakeResult = SyncHandshakeResult.SyncHandshakeCancel;
    1.85                          break;
    1.86                      }
    1.87                  // Currently, there is no action defined for the next three signals
    1.88 @@ -132,14 +102,11 @@
    1.89                  case SyncHandshakeSignal.SyncNotifyAcceptedGroupCreated:
    1.90                  default:
    1.91                      {
    1.92 -                        handshakeResult = SyncHandshakeResult.SyncHandshakeCancel;
    1.93                          break;
    1.94                      }
    1.95              }
    1.96  
    1.97 -            Log.Verbose("NotifyHandshake: Completed, " + handshakeResult.ToString());
    1.98 -
    1.99 -            return handshakeResult;
   1.100 +            Log.Verbose("NotifyHandshake: Completed.");
   1.101          }
   1.102  
   1.103          /// <summary>
   1.104 @@ -251,21 +218,45 @@
   1.105          /// <param name="own">The personal identity for the handshake.</param>
   1.106          /// <param name="partner">The communication partner identity for the handshake.</param>
   1.107          /// <param name="signal">The reason for the handshake notification.</param>
   1.108 -        /// <returns>The user selected result.</returns>
   1.109 -        public bool? ShowHandshakeDialog(PEPIdentity own, PEPIdentity partner)
   1.110 +        public void ShowHandshakeDialog(pEpIdentity own, pEpIdentity partner)
   1.111          {
   1.112              // Show the dialog
   1.113              Task<bool?> task = this.ShowHandshakeDialogAsync(own, partner);
   1.114 +            bool? result = task.Result;
   1.115  
   1.116 -            // Check for exceptions and return result
   1.117 +            // At this point, the handshake dialog is already closed
   1.118 +            AdapterCallbacks.handshakeDialog = null;
   1.119 +
   1.120 +            // Check for exceptions
   1.121              if (task.Exception != null)
   1.122              {
   1.123                  Log.Error("ShowHandshakeDialog: Error occured. " + task.Exception);
   1.124 -                return null;
   1.125              }
   1.126              else
   1.127              {
   1.128 -                return task.Result;
   1.129 +                SyncHandshakeResult handshakeResult = SyncHandshakeResult.SyncHandshakeCancel;
   1.130 +
   1.131 +                switch (result)
   1.132 +                {
   1.133 +                    case true:
   1.134 +                        {
   1.135 +                            handshakeResult = SyncHandshakeResult.SyncHandshakeAccepted;
   1.136 +                            break;
   1.137 +                        }
   1.138 +                    case false:
   1.139 +                        {
   1.140 +                            handshakeResult = SyncHandshakeResult.SyncHandshakeRejected;
   1.141 +                            break;
   1.142 +                        }
   1.143 +                    case null:
   1.144 +                    default:
   1.145 +                        {
   1.146 +                            handshakeResult = SyncHandshakeResult.SyncHandshakeCancel;
   1.147 +                            break;
   1.148 +                        }
   1.149 +                }
   1.150 +
   1.151 +                ThisAddIn.PEPEngine.DeliverHandshakeResult(handshakeResult, new pEpIdentity[] { partner });
   1.152              }
   1.153          }
   1.154  
   1.155 @@ -276,14 +267,14 @@
   1.156          /// <param name="partner">The communication partner identity for the handshake.</param>
   1.157          /// <param name="signal">The reason for the handshake notification.</param>
   1.158          /// <returns>The user selected result.</returns>
   1.159 -        public async Task<bool?> ShowHandshakeDialogAsync(PEPIdentity own, PEPIdentity partner)
   1.160 +        public async Task<bool?> ShowHandshakeDialogAsync(pEpIdentity own, pEpIdentity partner)
   1.161          {
   1.162              // Create a new STA thread and show dialog on it
   1.163              return await AdapterCallbacks.StartSTATask<bool?>(() =>
   1.164              {
   1.165                  // Create the handshake dialog
   1.166 -                AdapterCallbacks.handshakeDialog = new HandshakeDialog(own,
   1.167 -                                                                       partner,
   1.168 +                AdapterCallbacks.handshakeDialog = new HandshakeDialog(new PEPIdentity(own),
   1.169 +                                                                       new PEPIdentity(partner),
   1.170                                                                         HandshakeDialog.HandshakeMode.SyncTypeA);
   1.171  
   1.172