Пример #1
0
        private void ABFindContactsPagedAsync(string partnerScenario, abHandleType abHandle, ABFindContactsPagedCompletedEventHandler abFindContactsPagedCallback)
        {
            if (NSMessageHandler.MSNTicket == MSNTicket.Empty || AddressBook == null)
            {
                OnServiceOperationFailed(this, new ServiceOperationFailedEventArgs("ABFindContactsPaged", new MSNPSharpException("You don't have access right on this action anymore.")));
                return;
            }

            bool deltasOnly = false;
            ABFindContactsPagedRequestType request = new ABFindContactsPagedRequestType();
            request.abView = "MessengerClient8";  //NO default!

            if (abHandle == null ||
                abHandle.ABId == WebServiceConstants.MessengerIndividualAddressBookId)
            {
                request.extendedContent = "AB AllGroups CircleResult";

                request.filterOptions = new filterOptionsType();
                request.filterOptions.ContactFilter = new ContactFilterType();

                if (DateTime.MinValue != WebServiceDateTimeConverter.ConvertToDateTime(AddressBook.GetAddressBookLastChange(WebServiceConstants.MessengerIndividualAddressBookId)))
                {
                    deltasOnly = true;
                    request.filterOptions.LastChanged = AddressBook.GetAddressBookLastChange(WebServiceConstants.MessengerIndividualAddressBookId);
                }

                request.filterOptions.DeltasOnly = deltasOnly;
                request.filterOptions.ContactFilter.IncludeHiddenContacts = true;

                // Without these two lines we cannot get the Connect contacts correctly.
                request.filterOptions.ContactFilter.IncludeShellContactsSpecified = true;
                request.filterOptions.ContactFilter.IncludeShellContacts = true;
            }
            else
            {
                request.extendedContent = "AB";
                request.abHandle = abHandle;
            }

            MsnServiceState ABFindContactsPagedObject = new MsnServiceState(partnerScenario, "ABFindContactsPaged", true);
            ABServiceBinding abService = (ABServiceBinding)CreateService(MsnServiceType.AB, ABFindContactsPagedObject);
            abService.ABFindContactsPagedCompleted += delegate(object sender, ABFindContactsPagedCompletedEventArgs e)
            {
                OnAfterCompleted(new ServiceOperationEventArgs(abService, MsnServiceType.AB, e));

                // Cancelled or signed off
                if (e.Cancelled || NSMessageHandler.MSNTicket == MSNTicket.Empty)
                    return;

                if (e.Error != null)
                {
                    // Handle errors and recall this method if necesarry.

                    if ((e.Error.Message.ToLowerInvariant().Contains("need to do full sync")
                         || e.Error.Message.ToLowerInvariant().Contains("full sync required")))
                    {
                        if (abHandle == null ||
                            abHandle.ABId == WebServiceConstants.MessengerIndividualAddressBookId)
                        {
                            // Default addressbook
                            DeleteRecordFile(true);
                        }
                        else
                        {
                            // Circle addressbook
                            AddressBook.RemoveCircle(new Guid(abHandle.ABId).ToString("D").ToLowerInvariant(), false);
                        }

                        // recursive Call -----------------------------
                        ABFindContactsPagedAsync(partnerScenario, abHandle, abFindContactsPagedCallback);
                    }
                    else
                    {
                        Trace.WriteLineIf(Settings.TraceSwitch.TraceVerbose,
                            "UNHANDLED ERROR: " + e.Error.Message.ToString(), GetType().Name);

                        // Pass to the callback
                        if (abFindContactsPagedCallback != null)
                        {
                            abFindContactsPagedCallback(sender, e);
                        }
                    }
                }
                else
                {
                    // No error, fire event handler.
                    if (abFindContactsPagedCallback != null)
                    {
                        abFindContactsPagedCallback(sender, e);
                    }
                }
            };

            RunAsyncMethod(new BeforeRunAsyncMethodEventArgs(abService, MsnServiceType.AB, ABFindContactsPagedObject, request));
        }
Пример #2
0
        private void ABFindContactsPagedAsync(string partnerScenario, abHandleType abHandle, ABFindContactsPagedCompletedEventHandler abFindContactsPagedCallback)
        {
            if (NSMessageHandler.MSNTicket == MSNTicket.Empty || AddressBook == null)
            {
                OnServiceOperationFailed(this, new ServiceOperationFailedEventArgs("ABFindContactsPaged", new MSNPSharpException("You don't have access right on this action anymore.")));
                return;
            }

            bool deltasOnly = false;
            ABFindContactsPagedRequestType request = new ABFindContactsPagedRequestType();

            request.abView = "MessengerClient8";  //NO default!

            if (abHandle == null ||
                abHandle.ABId == WebServiceConstants.MessengerIndividualAddressBookId)
            {
                request.extendedContent = "AB AllGroups CircleResult";

                request.filterOptions = new filterOptionsType();
                request.filterOptions.ContactFilter = new ContactFilterType();

                if (DateTime.MinValue != WebServiceDateTimeConverter.ConvertToDateTime(AddressBook.GetAddressBookLastChange(WebServiceConstants.MessengerIndividualAddressBookId)))
                {
                    deltasOnly = true;
                    request.filterOptions.LastChanged = AddressBook.GetAddressBookLastChange(WebServiceConstants.MessengerIndividualAddressBookId);
                }

                request.filterOptions.DeltasOnly = deltasOnly;
                request.filterOptions.ContactFilter.IncludeHiddenContacts = true;

                // Without these two lines we cannot get the Connect contacts correctly.
                request.filterOptions.ContactFilter.IncludeShellContactsSpecified = true;
                request.filterOptions.ContactFilter.IncludeShellContacts          = true;
            }
            else
            {
                request.extendedContent = "AB";
                request.abHandle        = abHandle;
            }

            MsnServiceState  ABFindContactsPagedObject = new MsnServiceState(partnerScenario, "ABFindContactsPaged", true);
            ABServiceBinding abService = (ABServiceBinding)CreateService(MsnServiceType.AB, ABFindContactsPagedObject);

            abService.ABFindContactsPagedCompleted += delegate(object sender, ABFindContactsPagedCompletedEventArgs e)
            {
                OnAfterCompleted(new ServiceOperationEventArgs(abService, MsnServiceType.AB, e));

                // Cancelled or signed off
                if (e.Cancelled || NSMessageHandler.MSNTicket == MSNTicket.Empty)
                {
                    return;
                }

                if (e.Error != null)
                {
                    // Handle errors and recall this method if necesarry.

                    if ((e.Error.Message.ToLowerInvariant().Contains("need to do full sync") ||
                         e.Error.Message.ToLowerInvariant().Contains("full sync required")))
                    {
                        if (abHandle == null ||
                            abHandle.ABId == WebServiceConstants.MessengerIndividualAddressBookId)
                        {
                            // Default addressbook
                            DeleteRecordFile(true);
                        }
                        else
                        {
                            // Circle addressbook
                            AddressBook.RemoveCircle(new Guid(abHandle.ABId).ToString("D").ToLowerInvariant(), false);
                        }

                        // recursive Call -----------------------------
                        ABFindContactsPagedAsync(partnerScenario, abHandle, abFindContactsPagedCallback);
                    }
                    else
                    {
                        Trace.WriteLineIf(Settings.TraceSwitch.TraceVerbose,
                                          "UNHANDLED ERROR: " + e.Error.Message.ToString(), GetType().Name);

                        // Pass to the callback
                        if (abFindContactsPagedCallback != null)
                        {
                            abFindContactsPagedCallback(sender, e);
                        }
                    }
                }
                else
                {
                    // No error, fire event handler.
                    if (abFindContactsPagedCallback != null)
                    {
                        abFindContactsPagedCallback(sender, e);
                    }
                }
            };

            RunAsyncMethod(new BeforeRunAsyncMethodEventArgs(abService, MsnServiceType.AB, ABFindContactsPagedObject, request));
        }
Пример #3
0
        /// <summary>
        /// Async Address book request
        /// </summary>
        /// <param name="partnerScenario"></param>
        /// <param name="abHandle">The specified addressbook to retrieve.</param>
        /// <param name="onSuccess">The delegate to be executed after async ab request completed successfuly</param>
        internal void abRequest(string partnerScenario, abHandleType abHandle, ABFindContactsPagedCompletedEventHandler onSuccess)
        {
            if (NSMessageHandler.MSNTicket == MSNTicket.Empty || AddressBook == null)
            {
                OnServiceOperationFailed(this, new ServiceOperationFailedEventArgs("ABFindContactsPaged", new MSNPSharpException("You don't have access right on this action anymore.")));
                return;
            }

            ABFindContactsPagedAsync(partnerScenario, abHandle,
                // Register callback for success/error. e.Cancelled handled by ABFindContactsPagedAsync.
                delegate(object sender, ABFindContactsPagedCompletedEventArgs abfcpcea)
                {
                    if (abfcpcea.Error == null /* No error */)
                    {
                        BinarySemaphore.WaitOne();

                        // Addressbook re-defined here, because the reference can be changed.
                        // ABFindContactsPagedAsync can delete addressbook if addressbook sync is required.
                        XMLContactList xmlcl;
                        ABFindContactsPagedResultType forwardList;
                        String circleResult = null;

                        if ((null != (xmlcl = AddressBook)) &&
                            (null != (forwardList = abfcpcea.Result.ABFindContactsPagedResult)))
                        {
                            // Following line is horrible for semaphore usage...
                            xmlcl
                                .Merge(forwardList)
                                .Save();

                            if (forwardList.CircleResult != null)
                            {
                                circleResult = forwardList.CircleResult.CircleTicket;
                            }
                        }

                        BinarySemaphore.Release();

                        if (!String.IsNullOrEmpty(circleResult))
                        {
                            NSMessageHandler.SendSHAAMessage(circleResult);
                        }

                        if (onSuccess != null)
                        {
                            onSuccess(sender, abfcpcea);
                        }
                    }
                    else
                    {
                        // Error handler

                        BinarySemaphore.WaitOne();
                        if (AddressBook == null && Deltas == null && AddressBookSynchronized == false)
                        {
                            BinarySemaphore.Release();
                            // This means before the webservice returned the connection had broken.
                            OnServiceOperationFailed(this, new ServiceOperationFailedEventArgs("ABFindContactsPaged",
                                    new MSNPSharpException("Addressbook and Deltas have been reset.")));
                            return;
                        }
                        BinarySemaphore.Release();
                    }
                });
        }
Пример #4
0
 /// <summary>
 /// Async Address book request
 /// </summary>
 /// <param name="partnerScenario"></param>
 /// <param name="onSuccess">The delegate to be executed after async ab request completed successfuly</param>
 internal void abRequest(string partnerScenario, ABFindContactsPagedCompletedEventHandler onSuccess)
 {
     try
     {
         abRequest(partnerScenario, null, onSuccess);
     }
     catch (Exception ex)
     {
         OnServiceOperationFailed(this, new ServiceOperationFailedEventArgs("ABFindContactsPaged",
            new MSNPSharpException(ex.Message, ex)));
         return;
     }
 }
Пример #5
0
        private void ABNotifyChangedSaveReuqest(string scene, ABFindContactsPagedCompletedEventHandler onSuccess)
        {
            abRequest(scene,
                      delegate(object sender, ABFindContactsPagedCompletedEventArgs e)
                      {
                          if (e.Cancelled || e.Error != null)
                          {
                              return;
                          }

                          if (e.Result.ABFindContactsPagedResult.Contacts == null
                              && e.Result.ABFindContactsPagedResult.Groups == null)
                          {
                              if (e.Result.ABFindContactsPagedResult.CircleResult == null
                                  || e.Result.ABFindContactsPagedResult.CircleResult.Circles == null)
                              {
                                  return;
                              }
                          }

                          AddressBook.Save();

                          if (onSuccess != null)
                              onSuccess(sender, e);
                      }
                      );
        }
Пример #6
0
        internal void ServerNotificationRequest(string scene, object[] parameters, ABFindContactsPagedCompletedEventHandler onSuccess)
        {
            Trace.WriteLineIf(Settings.TraceSwitch.TraceVerbose, "Executing notify addressbook request, PartnerScenario: " + scene);

            switch (scene)
            {
                case PartnerScenario.ABChangeNotifyAlert:
                    msRequest(scene,
                        delegate
                        {
                            ABNotifyChangedSaveReuqest(scene, onSuccess);
                        }
                    );
                    break;

                case PartnerScenario.CircleIdAlert:
                    abHandleType abHandler = new abHandleType();
                    abHandler.Puid = 0;
                    abHandler.Cid = 0;
                    abHandler.ABId = parameters[0].ToString();

                    msRequest(PartnerScenario.MessengerPendingList,
                        delegate
                        {
                            ABNotifyChangedSaveReuqest(scene, onSuccess);
                        }
                    );
                    break;
            }
        }