Exemplo n.º 1
0
        private bool AddDynamicItemSync(string scenario)
        {
            if (NSMessageHandler.MSNTicket != MSNTicket.Empty)
            {
                MsnServiceState  serviceState = new MsnServiceState(scenario, "AddDynamicItem", false);
                ABServiceBinding abService    = (ABServiceBinding)CreateService(MsnServiceType.AB, serviceState);

                PassportDynamicItem newDynamicItem = new PassportDynamicItem();
                newDynamicItem.Type         = "Passport";
                newDynamicItem.PassportName = NSMessageHandler.Owner.Account;

                AddDynamicItemRequestType addDynamicItemRequest = new AddDynamicItemRequestType();
                addDynamicItemRequest.abId         = WebServiceConstants.MessengerIndividualAddressBookId;
                addDynamicItemRequest.dynamicItems = new BaseDynamicItemType[] { newDynamicItem };

                try
                {
                    ChangeCacheKeyAndPreferredHostForSpecifiedMethod(abService, MsnServiceType.AB, serviceState, addDynamicItemRequest);
                    abService.AddDynamicItem(addDynamicItemRequest);
                }
                catch (Exception ex)
                {
                    OnServiceOperationFailed(abService, new ServiceOperationFailedEventArgs("AddDynamicItem", ex));
                    Trace.WriteLineIf(Settings.TraceSwitch.TraceError, "AddDynamicItem error: " + ex.Message, GetType().Name);
                    return(false);
                }
                return(true);
            }

            return(false);
        }
Exemplo n.º 2
0
        private void UpdateContactAsync(ContactType contact, string abId, ABContactUpdateCompletedEventHandler callback)
        {
            ABContactUpdateRequestType request = new ABContactUpdateRequestType();

            request.abId     = abId;
            request.contacts = new ContactType[] { contact };
            request.options  = new ABContactUpdateRequestTypeOptions();
            request.options.EnableAllowListManagementSpecified = true;
            request.options.EnableAllowListManagement          = true;

            MsnServiceState  ABContactUpdateObject = new MsnServiceState(contact.contactInfo.isMessengerUser ? PartnerScenario.ContactSave : PartnerScenario.Timer, "ABContactUpdate", true);
            ABServiceBinding abService             = (ABServiceBinding)CreateService(MsnServiceType.AB, ABContactUpdateObject);

            abService.ABContactUpdateCompleted += delegate(object service, ABContactUpdateCompletedEventArgs 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, ABContactUpdateObject, request));
        }
Exemplo n.º 3
0
        private void ABGroupDeleteAsync(ContactGroup contactGroup, ABGroupDeleteCompletedEventHandler callback)
        {
            if (NSMessageHandler.MSNTicket == MSNTicket.Empty || AddressBook == null)
            {
                OnServiceOperationFailed(this, new ServiceOperationFailedEventArgs("ABGroupDelete", new MSNPSharpException("You don't have access right on this action anymore.")));
                return;
            }

            ABGroupDeleteRequestType request = new ABGroupDeleteRequestType();

            request.abId                 = WebServiceConstants.MessengerIndividualAddressBookId;
            request.groupFilter          = new groupFilterType();
            request.groupFilter.groupIds = new string[] { contactGroup.Guid };

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

            abService.ABGroupDeleteCompleted += delegate(object service, ABGroupDeleteCompletedEventArgs 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, ABGroupDeleteObject, request));
        }
Exemplo n.º 4
0
        private void DeleteContactAsync(Contact contact,
                                        DeleteContactCompletedEventHandler callback)
        {
            if (NSMessageHandler.MSNTicket == MSNTicket.Empty || AddressBook == null)
            {
                OnServiceOperationFailed(this, new ServiceOperationFailedEventArgs("DeleteContact", new MSNPSharpException("You don't have access right on this action anymore.")));
                return;
            }

            DeleteContactRequestType request = new DeleteContactRequestType();

            request.contactId = contact.Guid.ToString("D").ToLowerInvariant();

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

            abService.DeleteContactCompleted += delegate(object service, DeleteContactCompletedEventArgs 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, deleteContactObject, request));
        }
Exemplo n.º 5
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));
        }
Exemplo n.º 6
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));
        }
Exemplo n.º 7
0
        private void ABGroupAddAsync(string groupName, ABGroupAddCompletedEventHandler callback)
        {
            if (NSMessageHandler.MSNTicket == MSNTicket.Empty || AddressBook == null)
            {
                OnServiceOperationFailed(this, new ServiceOperationFailedEventArgs("ABGroupAdd", new MSNPSharpException("You don't have access right on this action anymore.")));
                return;
            }

            ABGroupAddRequestType request = new ABGroupAddRequestType();

            request.abId            = WebServiceConstants.MessengerIndividualAddressBookId;
            request.groupAddOptions = new ABGroupAddRequestTypeGroupAddOptions();
            request.groupAddOptions.fRenameOnMsgrConflict          = false;
            request.groupAddOptions.fRenameOnMsgrConflictSpecified = true;
            request.groupInfo                                = new ABGroupAddRequestTypeGroupInfo();
            request.groupInfo.GroupInfo                      = new groupInfoType();
            request.groupInfo.GroupInfo.name                 = groupName;
            request.groupInfo.GroupInfo.fMessenger           = false;
            request.groupInfo.GroupInfo.fMessengerSpecified  = true;
            request.groupInfo.GroupInfo.groupType            = WebServiceConstants.MessengerGroupType;
            request.groupInfo.GroupInfo.annotations          = new Annotation[] { new Annotation() };
            request.groupInfo.GroupInfo.annotations[0].Name  = AnnotationNames.MSN_IM_Display;
            request.groupInfo.GroupInfo.annotations[0].Value = "1";

            MsnServiceState  ABGroupAddObject = new MsnServiceState(PartnerScenario.GroupSave, "ABGroupAdd", true);
            ABServiceBinding abService        = (ABServiceBinding)CreateService(MsnServiceType.AB, ABGroupAddObject);

            abService.ABGroupAddCompleted += delegate(object service, ABGroupAddCompletedEventArgs 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, ABGroupAddObject, request));
        }
Exemplo n.º 8
0
        private void ABGroupUpdateAsync(ContactGroup group, string newGroupName, ABGroupUpdateCompletedEventHandler callback)
        {
            if (NSMessageHandler.MSNTicket == MSNTicket.Empty || AddressBook == null)
            {
                OnServiceOperationFailed(this, new ServiceOperationFailedEventArgs("ABGroupUpdate", new MSNPSharpException("You don't have access right on this action anymore.")));
                return;
            }

            ABGroupUpdateRequestType request = new ABGroupUpdateRequestType();

            request.abId   = WebServiceConstants.MessengerIndividualAddressBookId;
            request.groups = new GroupType[1] {
                new GroupType()
            };
            request.groups[0].groupId           = group.Guid;
            request.groups[0].propertiesChanged = PropertyString.GroupName; //"GroupName";
            request.groups[0].groupInfo         = new groupInfoType();
            request.groups[0].groupInfo.name    = newGroupName;

            MsnServiceState  ABGroupUpdateObject = new MsnServiceState(PartnerScenario.GroupSave, "ABGroupUpdate", true);
            ABServiceBinding abService           = (ABServiceBinding)CreateService(MsnServiceType.AB, ABGroupUpdateObject);

            abService.ABGroupUpdateCompleted += delegate(object service, ABGroupUpdateCompletedEventArgs 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, ABGroupUpdateObject, request));
        }
Exemplo n.º 9
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));
        }
Exemplo n.º 10
0
        private bool UpdateDynamicItemSync(string scenario)
        {
            if (NSMessageHandler.MSNTicket != MSNTicket.Empty)
            {
                //9. UpdateDynamicItem
                MsnServiceState  serviceState = new MsnServiceState(scenario, "UpdateDynamicItem", false);
                ABServiceBinding abService    = (ABServiceBinding)CreateService(MsnServiceType.AB, serviceState);

                UpdateDynamicItemRequestType updateDyItemRequest = new UpdateDynamicItemRequestType();
                updateDyItemRequest.abId = Guid.Empty.ToString();

                PassportDynamicItem passportDyItem = new PassportDynamicItem();
                passportDyItem.Type         = "Passport";
                passportDyItem.PassportName = NSMessageHandler.Owner.Account;
                passportDyItem.Changes      = "Notifications";

                NotificationDataType notification = new NotificationDataType();
                notification.Status      = "Exist Access";
                notification.InstanceId  = "0";
                notification.Gleam       = false;
                notification.LastChanged = NSMessageHandler.ContactService.Deltas.Profile.DateModified;

                ServiceType srvInfo = new ServiceType();
                srvInfo.Changes = "";

                HandleType srvHandle = new HandleType();
                srvHandle.ForeignId = "MyProfile";
                srvHandle.Id        = "0";
                srvHandle.Type      = ServiceName.Profile;

                InfoType info = new InfoType();
                info.Handle          = srvHandle;
                info.IsBot           = false;
                info.InverseRequired = false;

                srvInfo.Info = info;
                notification.StoreService        = srvInfo;
                passportDyItem.Notifications     = new NotificationDataType[] { notification };
                updateDyItemRequest.dynamicItems = new PassportDynamicItem[] { passportDyItem };
                try
                {
                    ChangeCacheKeyAndPreferredHostForSpecifiedMethod(abService, MsnServiceType.AB, serviceState, updateDyItemRequest);
                    abService.UpdateDynamicItem(updateDyItemRequest);
                }
                catch (Exception ex)
                {
                    OnServiceOperationFailed(abService, new ServiceOperationFailedEventArgs("UpdateDynamicItem", ex));
                    Trace.WriteLineIf(Settings.TraceSwitch.TraceError, "UpdateDynamicItem error: You don't receive any contact updates, vice versa! " + ex.Message, GetType().Name);

                    AddDynamicItemRequestType addDynamicItemRequest = new AddDynamicItemRequestType();
                    addDynamicItemRequest.abId         = updateDyItemRequest.abId;
                    addDynamicItemRequest.dynamicItems = updateDyItemRequest.dynamicItems;
                    foreach (BaseDynamicItemType dynamicItem in addDynamicItemRequest.dynamicItems)
                    {
                        dynamicItem.Notifications = null;
                        dynamicItem.Changes       = null;
                        dynamicItem.LastChanged   = null;
                    }

                    try
                    {
                        ChangeCacheKeyAndPreferredHostForSpecifiedMethod(abService, MsnServiceType.AB, serviceState, addDynamicItemRequest);
                        abService.AddDynamicItem(addDynamicItemRequest);
                    }
                    catch (Exception exAddDynamicItem)
                    {
                        OnServiceOperationFailed(abService, new ServiceOperationFailedEventArgs("AddDynamicItem", exAddDynamicItem));
                        Trace.WriteLineIf(Settings.TraceSwitch.TraceError, "AddDynamicItem error: You don't receive any contact updates, vice versa! " + exAddDynamicItem.Message, GetType().Name);
                        return(false);
                    }
                    return(true);
                }
                return(true);
            }

            return(false);
        }
Exemplo n.º 11
0
        private void FindMembershipAsync(string partnerScenario, FindMembershipCompletedEventHandler findMembershipCallback)
        {
            if (NSMessageHandler.MSNTicket == MSNTicket.Empty || AddressBook == null)
            {
                OnServiceOperationFailed(this, new ServiceOperationFailedEventArgs("FindMembership", new MSNPSharpException("You don't have access right on this action anymore.")));
                return;
            }

            bool     msdeltasOnly      = false;
            DateTime serviceLastChange = WebServiceDateTimeConverter.ConvertToDateTime(WebServiceConstants.ZeroTime);
            DateTime msLastChange      = WebServiceDateTimeConverter.ConvertToDateTime(AddressBook.MembershipLastChange);
            string   strLastChange     = WebServiceConstants.ZeroTime;

            if (msLastChange != serviceLastChange)
            {
                msdeltasOnly  = true;
                strLastChange = AddressBook.MembershipLastChange;
            }

            FindMembershipRequestType request = new FindMembershipRequestType();

            request.view                = "Full"; // NO default!
            request.deltasOnly          = msdeltasOnly;
            request.lastChange          = strLastChange;
            request.serviceFilter       = new ServiceFilter();
            request.serviceFilter.Types = new ServiceName[]
            {
                ServiceName.Messenger,
                ServiceName.IMAvailability,
                ServiceName.SocialNetwork
            };

            MsnServiceState       FindMembershipObject = new MsnServiceState(partnerScenario, "FindMembership", true);
            SharingServiceBinding sharingService       = (SharingServiceBinding)CreateService(MsnServiceType.Sharing, FindMembershipObject);

            sharingService.FindMembershipCompleted += delegate(object sender, FindMembershipCompletedEventArgs e)
            {
                OnAfterCompleted(new ServiceOperationEventArgs(sharingService, MsnServiceType.Sharing, 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"))
                    {
                        // recursive Call -----------------------------
                        DeleteRecordFile(true);
                        FindMembershipAsync(partnerScenario, findMembershipCallback);
                    }
                    else if (e.Error.Message.ToLowerInvariant().Contains("address book does not exist"))
                    {
                        ABAddRequestType abAddRequest = new ABAddRequestType();
                        abAddRequest.abInfo            = new abInfoType();
                        abAddRequest.abInfo.ownerEmail = NSMessageHandler.Owner.Account;
                        abAddRequest.abInfo.ownerPuid  = 0;
                        abAddRequest.abInfo.fDefault   = true;

                        MsnServiceState  ABAddObject = new MsnServiceState(partnerScenario, "ABAdd", true);
                        ABServiceBinding abservice   = (ABServiceBinding)CreateService(MsnServiceType.AB, ABAddObject);
                        abservice.ABAddCompleted += delegate(object srv, ABAddCompletedEventArgs abadd_e)
                        {
                            OnAfterCompleted(new ServiceOperationEventArgs(abservice, MsnServiceType.AB, abadd_e));

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

                            if (abadd_e.Error == null)
                            {
                                // recursive Call -----------------------------
                                DeleteRecordFile(true);
                                FindMembershipAsync(partnerScenario, findMembershipCallback);
                            }
                        };
                        RunAsyncMethod(new BeforeRunAsyncMethodEventArgs(abservice, MsnServiceType.AB, ABAddObject, abAddRequest));
                    }
                    else
                    {
                        Trace.WriteLineIf(Settings.TraceSwitch.TraceVerbose,
                                          "UNHANDLED ERROR: " + e.Error.Message.ToString(), GetType().Name);

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

            RunAsyncMethod(new BeforeRunAsyncMethodEventArgs(sharingService, MsnServiceType.Sharing, FindMembershipObject, request));
        }
Exemplo n.º 12
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));
        }
Exemplo n.º 13
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));
        }