Пример #1
0
        private void FindFriendsInCommonAsync(Guid abId, long cid, int count,
                                              FindFriendsInCommonCompletedEventHandler callback)
        {
            if (NSMessageHandler.MSNTicket == MSNTicket.Empty || AddressBook == null)
            {
                OnServiceOperationFailed(this, new ServiceOperationFailedEventArgs("FindFriendsInCommon", new MSNPSharpException("You don't have access right on this action anymore.")));
                return;
            }

            if (cid == NSMessageHandler.Owner.CID)
            {
                return;
            }

            abHandleType abHandle = new abHandleType();

            abHandle.Puid = 0;

            if (abId != Guid.Empty)
            {
                // Find in circle
                abHandle.ABId = abId.ToString("D").ToLowerInvariant();
            }
            else if (cid != 0)
            {
                // Find by CID
                abHandle.Cid = cid;
            }

            FindFriendsInCommonRequestType request = new FindFriendsInCommonRequestType();

            request.domainID   = DomainIds.WindowsLiveDomain;
            request.maxResults = count;
            request.options    = "List Count Matched Unmatched "; // IncludeInfo

            request.targetAB = abHandle;

            MsnServiceState  findFriendsInCommonObject = new MsnServiceState(PartnerScenario.Timer, "FindFriendsInCommon", true);
            ABServiceBinding abService = (ABServiceBinding)CreateService(MsnServiceType.AB, findFriendsInCommonObject);

            abService.FindFriendsInCommonCompleted += delegate(object service, FindFriendsInCommonCompletedEventArgs e)
            {
                OnAfterCompleted(new ServiceOperationEventArgs(abService, MsnServiceType.AB, e));

                if (e.Cancelled || NSMessageHandler.MSNTicket == MSNTicket.Empty)
                {
                    return;
                }

                if (callback != null)
                {
                    callback(service, e);
                }
            };

            RunAsyncMethod(new BeforeRunAsyncMethodEventArgs(abService, MsnServiceType.AB, findFriendsInCommonObject, request));
        }
Пример #2
0
        private void ManageWLConnectionAsync(Guid contactGuid, Guid abID, string inviteMessage,
                                             bool connection, bool presence, int action, int relType, int relRole,
                                             ManageWLConnectionCompletedEventHandler callback)
        {
            ManageWLConnectionRequestType wlconnectionRequest = new ManageWLConnectionRequestType();

            wlconnectionRequest.contactId  = contactGuid.ToString("D");
            wlconnectionRequest.connection = connection;
            wlconnectionRequest.presence   = presence;
            wlconnectionRequest.action     = action;

            wlconnectionRequest.relationshipType = relType;
            wlconnectionRequest.relationshipRole = relRole;

            if (!String.IsNullOrEmpty(inviteMessage))
            {
                Annotation anno = new Annotation();
                anno.Name  = AnnotationNames.MSN_IM_InviteMessage;
                anno.Value = inviteMessage;

                wlconnectionRequest.annotations = new Annotation[] { anno };
            }

            if (abID != Guid.Empty)
            {
                abHandleType abHandle = new abHandleType();
                abHandle.ABId = abID.ToString("D").ToLowerInvariant();
                abHandle.Puid = 0;
                abHandle.Cid  = 0;

                wlconnectionRequest.abHandle = abHandle;
            }

            MsnServiceState  manageWLConnectionObject = new MsnServiceState(abID == Guid.Empty ? PartnerScenario.ContactSave : PartnerScenario.CircleInvite, "ManageWLConnection", true);
            ABServiceBinding abServiceBinding         = (ABServiceBinding)CreateService(MsnServiceType.AB, manageWLConnectionObject);

            abServiceBinding.ManageWLConnectionCompleted += delegate(object wlcSender, ManageWLConnectionCompletedEventArgs e)
            {
                OnAfterCompleted(new ServiceOperationEventArgs(abServiceBinding, MsnServiceType.AB, e));

                if (e.Cancelled || NSMessageHandler.MSNTicket == MSNTicket.Empty)
                {
                    return;
                }

                if (callback != null)
                {
                    callback(wlcSender, e);
                }
            };

            RunAsyncMethod(new BeforeRunAsyncMethodEventArgs(abServiceBinding, MsnServiceType.AB, manageWLConnectionObject, wlconnectionRequest));
        }
Пример #3
0
        private void BreakConnectionAsync(Guid contactGuid, Guid abID, bool block, bool delete,
                                          BreakConnectionCompletedEventHandler callback)
        {
            BreakConnectionRequestType breakconnRequest = new BreakConnectionRequestType();

            breakconnRequest.contactId     = contactGuid.ToString("D");
            breakconnRequest.blockContact  = block;
            breakconnRequest.deleteContact = delete;

            if (abID != Guid.Empty)
            {
                abHandleType handler = new abHandleType();
                handler.ABId = abID.ToString("D");
                handler.Cid  = 0;
                handler.Puid = 0;

                breakconnRequest.abHandle = handler;
            }

            MsnServiceState  breakConnectionObject = new MsnServiceState(PartnerScenario.BlockUnblock, "BreakConnection", true);
            ABServiceBinding abService             = (ABServiceBinding)CreateService(MsnServiceType.AB, breakConnectionObject);

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

                if (e.Cancelled || NSMessageHandler.MSNTicket == MSNTicket.Empty)
                {
                    return;
                }

                if (callback != null)
                {
                    callback(sender, e);
                }
            };

            RunAsyncMethod(new BeforeRunAsyncMethodEventArgs(abService, MsnServiceType.AB, breakConnectionObject, breakconnRequest));
        }
Пример #4
0
        private void CreateContactAsync(string account, IMAddressInfoType network, Guid abId,
                                        CreateContactCompletedEventHandler callback)
        {
            if (NSMessageHandler.MSNTicket == MSNTicket.Empty || AddressBook == null)
            {
                OnServiceOperationFailed(this, new ServiceOperationFailedEventArgs("CreateContact", new MSNPSharpException("You don't have access right on this action anymore.")));
                return;
            }

            CreateContactType request = new CreateContactType();

            if (network == IMAddressInfoType.Telephone)
            {
                contactInfoType contactInfo = new contactInfoType();

                contactPhoneType cpt = new contactPhoneType();
                cpt.contactPhoneType1 = ContactPhoneTypes.ContactPhoneMobile;
                cpt.number            = account;

                contactInfo.phones  = new contactPhoneType[] { cpt };
                request.contactInfo = contactInfo;
            }
            else
            {
                contactHandleType contactHandle = new contactHandleType();
                contactHandle.Email    = account;
                contactHandle.Cid      = 0;
                contactHandle.Puid     = 0;
                contactHandle.CircleId = WebServiceConstants.MessengerIndividualAddressBookId;
                request.contactHandle  = contactHandle;
            }

            if (abId != Guid.Empty)
            {
                abHandleType abHandle = new abHandleType();
                abHandle.ABId = abId.ToString("D").ToLowerInvariant();
                abHandle.Puid = 0;
                abHandle.Cid  = 0;

                request.abHandle = abHandle;
            }

            MsnServiceState  createContactObject = new MsnServiceState(abId == Guid.Empty ? PartnerScenario.ContactSave : PartnerScenario.CircleSave, "CreateContact", true);
            ABServiceBinding abService           = (ABServiceBinding)CreateService(MsnServiceType.AB, createContactObject);

            abService.CreateContactCompleted += delegate(object service, CreateContactCompletedEventArgs e)
            {
                OnAfterCompleted(new ServiceOperationEventArgs(abService, MsnServiceType.AB, e));

                if (e.Cancelled || NSMessageHandler.MSNTicket == MSNTicket.Empty)
                {
                    return;
                }

                if (callback != null)
                {
                    callback(service, e);
                }
            };

            RunAsyncMethod(new BeforeRunAsyncMethodEventArgs(abService, MsnServiceType.AB, createContactObject, request));
        }
Пример #5
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));
        }