Beispiel #1
0
 private ReturnState UpdateContact(ContactType contactType, out Contact updatedContact)
 {
     return UpdateContact(contactType, WebServiceConstants.MessengerIndividualAddressBookId, null, out updatedContact);
 }
Beispiel #2
0
        /// <summary>
        /// Get the addressbook's owner contact.
        /// </summary>
        /// <param name="contactList"></param>
        /// <returns></returns>
        private ContactType SelectMeContactFromContactList(ContactType[] contactList)
        {
            if (contactList == null)
                return null;

            foreach (ContactType contact in contactList)
            {
                if (contact.contactInfo != null)
                {
                    if (contact.contactInfo.contactType == MessengerContactType.Me)
                        return contact;
                }
            }

            return null;
        }
Beispiel #3
0
        /// <summary>
        /// Get the owner of default addressbook in a certain addressbook page. This contact will used for exiting circle.
        /// </summary>
        /// <param name="contactList"></param>
        /// <param name="currentUserAccount"></param>
        /// <returns></returns>
        private ContactType SelectSelfContactFromContactList(ContactType[] contactList, string currentUserAccount)
        {
            if (contactList == null)
                return null;

            string lowerAccount = currentUserAccount.ToLowerInvariant();

            foreach (ContactType contact in contactList)
            {
                if (contact.contactInfo != null)
                {
                    if (contact.contactInfo.passportName.ToLowerInvariant() == lowerAccount)
                        return contact;
                }
            }

            return null;
        }
Beispiel #4
0
 private void UpdateContact(ContactType contact, string abId, ABContactUpdateCompletedEventHandler onSuccess)
 {
     UpdateContactAsync(contact, abId,
         delegate(object service, ABContactUpdateCompletedEventArgs e)
         {
             if (e.Error == null)
             {
                 abRequest(PartnerScenario.ContactSave, delegate
                 {
                     if (onSuccess != null)
                         onSuccess(service, e);
                 });
             }
         });
 }
Beispiel #5
0
        private void SaveContactTable(ContactType[] contacts)
        {
            if (contacts == null)
                return;

            lock (contactTable)
            {
                foreach (ContactType contact in contacts)
                {
                    if (contact.contactInfo != null)
                    {
                        contactTable[contact.contactInfo.CID] = contact;
                    }
                }
            }
        }
Beispiel #6
0
        /// <summary>
        /// Add or update a contact in the specific address book.
        /// </summary>
        /// <param name="abId">The identifier of addressbook.</param>
        /// <param name="contact">The contact to be added/updated.</param>
        /// <returns>If the contact added to the addressbook, returen true, if the contact is updated (not add), return false.</returns>
        internal bool SetContactToAddressBookContactPage(string abId, ContactType contact)
        {
            lock (SyncObject)
            {
                string lowerId = abId.ToLowerInvariant();
                bool returnval = false;

                lock (AddressbookContacts)
                {
                    if (!AddressbookContacts.ContainsKey(lowerId))
                    {
                        AddressbookContacts.Add(lowerId, new SerializableDictionary<Guid, ContactType>());
                        returnval = true;
                    }

                    AddressbookContacts[lowerId][new Guid(contact.contactId)] = contact;
                }

                return returnval;
            }
        }
Beispiel #7
0
        /// <summary>
        /// Create a circle.
        /// </summary>
        /// <param name="me"></param>
        /// <param name="inverseInfo"></param>
        /// <returns></returns>
        private Contact CreateCircle(ContactType me, CircleInverseInfoType inverseInfo)
        {
            if (me == null || me.contactInfo == null)
            {
                Trace.WriteLineIf(Settings.TraceSwitch.TraceVerbose, "[CreateCircle] Cannot create circle since Me not found in addressbook.");
                return null;
            }

            if (inverseInfo == null || inverseInfo.PersonalInfo == null ||
                inverseInfo.Content == null || inverseInfo.Content.Info == null || inverseInfo.Content.Handle == null)
            {
                Trace.WriteLineIf(Settings.TraceSwitch.TraceVerbose, "[CreateCircle] Cannot create circle since inverse info not found in circle result list.");
                return null;
            }

            string circleMail = inverseInfo.Content.Handle.Id.ToLowerInvariant() + "@" + inverseInfo.Content.Info.HostedDomain.ToLowerInvariant();
            Contact circle = NSMessageHandler.ContactList.GetContactWithCreate(circleMail, IMAddressInfoType.Circle);

            circle.SetCircleInfo(inverseInfo, me);

            return circle;
        }
Beispiel #8
0
        /// <summary>
        /// Get a contact's nick name from it's Annotations.
        /// </summary>
        /// <param name="contact"></param>
        /// <returns></returns>
        private string GetContactNickName(ContactType contact)
        {
            if (contact.contactInfo == null)
                return string.Empty;

            if (contact.contactInfo.annotations == null)
                return string.Empty;

            foreach (Annotation anno in contact.contactInfo.annotations)
            {
                if (anno.Name == AnnotationNames.AB_NickName)
                {
                    return anno.Value;
                }
            }

            return string.Empty;
        }
Beispiel #9
0
        /// <summary>
        /// Get the domain tage of circle's hidden repersentative.
        /// </summary>
        /// <param name="contact"></param>
        /// <returns></returns>
        private string GetHiddenRepresentativeDomainTag(ContactType contact)
        {
            if (contact.contactInfo == null)
                return string.Empty;

            if (contact.contactInfo.contactType != MessengerContactType.Circle)
                return string.Empty;

            return GetDomainTagFromNetworkInfo(contact.contactInfo.NetworkInfoList, DomainIds.WindowsLiveDomain);
        }
Beispiel #10
0
 /// <summary>
 /// Use to create a facebook contact from an individual <see cref="ShellContact"/>.
 /// </summary>
 /// <param name="individualShellContact"></param>
 /// <returns></returns>
 private Contact CreateFaceBookContactFromShellContact(ContactType individualShellContact)
 {
     return CreateFaceBookContactFromShellContact(null, individualShellContact, true);
 }
Beispiel #11
0
        private Contact CreateFaceBookContactFromShellContact(Contact coreContact, ContactType shellContact, bool isIndividualShellContact)
        {
            Contact facebookGatewayContact = NSMessageHandler.ContactList.GetContactWithCreate(
                                            RemoteNetworkGateways.FaceBookGatewayAccount,
                                            IMAddressInfoType.RemoteNetwork);
            Contact facebookContact = null;

            if (shellContact.contactInfo.NetworkInfoList != null)
            {
                foreach (NetworkInfoType networkInfo in shellContact.contactInfo.NetworkInfoList)
                {
                    if (!String.IsNullOrEmpty(networkInfo.DomainTag) &&
                        networkInfo.DomainTag != WebServiceConstants.NullDomainTag)
                    {
                        if (networkInfo.SourceId == SourceId.FaceBook && networkInfo.DomainId == DomainIds.FaceBookDomain)
                        {
                            facebookContact = facebookGatewayContact.ContactList.CreateShellContact(
                                coreContact, IMAddressInfoType.Connect, networkInfo.DomainTag);

                            if (!String.IsNullOrEmpty(networkInfo.UserTileURL))
                            {
                                facebookContact.UserTileURL = new Uri(networkInfo.UserTileURL);
                            }
                            return facebookContact;
                        }
                    }
                }
            }
            else
            {
                facebookContact = facebookGatewayContact.ContactList.CreateShellContact(coreContact, IMAddressInfoType.Connect, shellContact.contactInfo.SourceHandle.ObjectID);

                if (shellContact.contactInfo.URLs != null)
                {
                    foreach (ContactURLType contactURL in shellContact.contactInfo.URLs)
                    {
                        if (String.IsNullOrEmpty(contactURL.URL) == false &&
                            contactURL.URLType == URLType.Other && contactURL.URLName == URLName.UserTileXL)
                        {
                            facebookContact.UserTileURL = new Uri(contactURL.URL);
                        }
                    }
                }
            }

            if (isIndividualShellContact)
            {
                facebookContact.SetName(shellContact.contactInfo.firstName + " " + shellContact.contactInfo.lastName);
            }

            return facebookContact;
        }
Beispiel #12
0
        private void CreateContactsFromLinkedShellContact(ContactType contactType)
        {
            if (contactType.contactInfo.LinkInfo != null)
            {
                Guid persionID = new Guid(contactType.contactInfo.LinkInfo.PersonID);

                CreateContactFromLinkedShellContact(persionID, SourceId.FaceBook);
                CreateContactFromLinkedShellContact(persionID, SourceId.LinkedIn);
                CreateContactFromLinkedShellContact(persionID, SourceId.MySpace);
            }
        }
Beispiel #13
0
        private Contact CreateContactFromIndividualShellContact(ContactType individualShellContact)
        {
            if (individualShellContact.contactInfo == null)
            {
                Trace.WriteLineIf(Settings.TraceSwitch.TraceError,
                            "Create Contact from ShellContact error. Try to create shell contact from individualShellContact, but contactInfo is null.");
                return null;
            }

            if (individualShellContact.contactInfo.SourceHandle == null)
            {
                Trace.WriteLineIf(Settings.TraceSwitch.TraceError,
                            "Create Contact from ShellContact error. Try to create shell contact from individualShellContact, but individualShellContact.contactInfo.SourceHandle is null.");
                return null;
            }

            switch (individualShellContact.contactInfo.SourceHandle.SourceID)
            {
                case SourceId.FaceBook:
                    Contact facebookContact = CreateFaceBookContactFromShellContact(individualShellContact);
                    Trace.WriteLineIf(Settings.TraceSwitch.TraceVerbose, facebookContact + ":" + facebookContact.Name + " added to connect contacts", GetType().Name);

                    return facebookContact;
                case SourceId.LinkedIn:
                    break;
                case SourceId.MySpace:
                    break;
            }

            return null;
        }
Beispiel #14
0
        protected internal void SetCircleInfo(CircleInverseInfoType circleInfo, ContactType me)
        {
            MeContact = me;
            CID = me.contactInfo.CID;

            this.circleInfo = circleInfo;

            HostDomain = circleInfo.Content.Info.HostedDomain.ToLowerInvariant();
            CircleRole = circleInfo.PersonalInfo.MembershipInfo.CirclePersonalMembership.Role;

            SetName(circleInfo.Content.Info.DisplayName);
            SetNickName(Name);

            contactList = new ContactList(AddressBookId, new Owner(AddressBookId, me.contactInfo.passportName, me.contactInfo.CID, NSMessageHandler), this, NSMessageHandler);
            Lists = RoleLists.Allow | RoleLists.Forward;
        }
Beispiel #15
0
        private ReturnState UpdateContact(ContactType contactType, string abId, Contact circle, out Contact updatedContact)
        {
            if (contactType.contactInfo == null)
            {
                Trace.WriteLineIf(Settings.TraceSwitch.TraceError, "Cannot update contact, contact info is null.");
                updatedContact = null;
                return ReturnState.UpdateError;
            }

            contactInfoType contactInfo = contactType.contactInfo;
            IMAddressInfoType type = IMAddressInfoType.WindowsLive;
            string account = contactInfo.passportName;
            string displayName = contactInfo.displayName;
            string nickName = GetContactNickName(contactType);
            Uri userTileURL = GetUserTileURLFromWindowsLiveNetworkInfo(contactType);
            bool isMessengerUser = contactInfo.isMessengerUser;
            string lowerId = abId.ToLowerInvariant();
            ReturnState returnValue = ReturnState.ProcessNextContact;
            ContactList contactList = null;
            bool isDefaultAddressBook = (lowerId == null || lowerId == WebServiceConstants.MessengerIndividualAddressBookId);
            bool isHidden = contactType.contactInfo.IsHiddenSpecified ? contactType.contactInfo.IsHidden : false;
            bool isShellContact = contactType.contactInfo.IsShellContactSpecified ? contactType.contactInfo.IsShellContact : false;

            if (isShellContact)
            {
                if (contactInfo.LinkInfo != null)
                {
                    Guid persionID = new Guid(contactInfo.LinkInfo.PersonID);
                    lock (ShellContactLink)
                    {
                        if (!ShellContactLink.ContainsKey(persionID))
                        {
                            ShellContactLink[persionID] = new List<ContactType>(0);
                        }

                        ShellContactLink[persionID].Add(contactType);
                    }
                    updatedContact = null;
                    return ReturnState.ProcessNextContact;
                }
                else
                {
                    lock (IndividualShellContacts)
                    {
                        IndividualShellContacts.Add(contactType);
                        updatedContact = null;
                        return ReturnState.ProcessNextContact;
                    }
                }
            }

            if (contactInfo.emails != null && account == null && contactInfo != null)
            {
                foreach (contactEmailType cet in contactInfo.emails)
                {
                    if (cet.isMessengerEnabled)
                    {
                        type = (IMAddressInfoType)Enum.Parse(typeof(IMAddressInfoType), cet.Capability);
                        account = cet.email;
                        isMessengerUser |= cet.isMessengerEnabled;
                        displayName = account;
                        break;
                    }
                }
            }

            if (contactInfo.phones != null && account == null)
            {
                foreach (contactPhoneType cpt in contactInfo.phones)
                {
                    if (cpt.isMessengerEnabled)
                    {
                        type = IMAddressInfoType.Telephone;
                        account = cpt.number;
                        isMessengerUser |= cpt.isMessengerEnabled;
                        displayName = account;
                        break;
                    }
                }
            }

            if (account != null)
            {
                account = account.ToLowerInvariant();
                if (contactInfo.contactType != MessengerContactType.Me)
                {
                    #region Contacts other than owner

                    Contact contact = null;

                    if (isDefaultAddressBook)
                    {
                        contact = NSMessageHandler.ContactList.GetContactWithCreate(account, type);
                        contactList = NSMessageHandler.ContactList;
                        if (contact == null)
                        {
                            updatedContact = null;
                            return ReturnState.UpdateError;
                        }

                        if (contactInfo.LinkInfo != null && isMessengerUser)
                        {
                            lock (MessengerContactLink)
                            {
                                // There might be shell contact connect with this contact.
                                // Add it to link info.
                                Guid persionID = new Guid(contactInfo.LinkInfo.PersonID);
                                MessengerContactLink[persionID] = new KeyValuePair<Contact, ContactType>(contact, contactType);
                            }
                        }
                    }
                    else
                    {
                        if (circle == null)
                        {
                            Trace.WriteLineIf(Settings.TraceSwitch.TraceError, "Cannot update contact: " + account + " in addressbook: " + abId);

                            //This means we are restoring contacts from mcl file.
                            //We need to retore the circle first, then initialize this contact again.
                            updatedContact = null;
                            return ReturnState.UpdateError;
                        }

                        RoleId membershipRole = GetCircleMemberRoleFromNetworkInfo(contactInfo.NetworkInfoList);
                        contact = circle.ContactList.GetContactWithCreate(account, type);
                        contactList = circle.ContactList;
                        contact.CircleRole = membershipRole;
                        string tempName = GetCircleMemberDisplayNameFromNetworkInfo(contactInfo.NetworkInfoList);
                        if (!string.IsNullOrEmpty(tempName))
                            displayName = tempName;
                    }

                    contact.Guid = new Guid(contactType.contactId);
                    contact.CID = Convert.ToInt64(contactInfo.CID);
                    contact.ContactType = contactInfo.contactType;
                    contact.SetHasSpace(contactInfo.hasSpace);
                    contact.SetComment(contactInfo.comment);
                    contact.SetIsMessengerUser(isMessengerUser);
                    contact.SetMobileAccess(contactInfo.isMobileIMEnabled);
                    contact.UserTileURL = userTileURL;
                    SetContactPhones(contact, contactInfo);

                    if (!string.IsNullOrEmpty(nickName) && string.IsNullOrEmpty(contact.NickName))
                    {
                        contact.SetNickName(nickName);
                    }

                    if (contact.IsMessengerUser)
                    {
                        contact.AddToList(RoleLists.Forward); //IsMessengerUser is only valid in AddressBook member
                    }

                    if (!string.IsNullOrEmpty(displayName))
                    {
                        if ((contact.Name == contact.Account && displayName != contact.Account) ||
                            string.IsNullOrEmpty(contact.Name))
                        {
                            contact.SetName(displayName);
                        }
                    }

                    if (contactInfo.groupIds != null)
                    {
                        foreach (string groupId in contactInfo.groupIds)
                        {
                            contact.ContactGroups.Add(NSMessageHandler.ContactGroups[groupId]);
                        }
                    }

                    if (contactInfo.groupIdsDeleted != null)
                    {
                        foreach (string groupId in contactInfo.groupIdsDeleted)
                        {
                            contact.ContactGroups.Remove(NSMessageHandler.ContactGroups[groupId]);
                        }
                    }

                    #endregion

                    #region Filter yourself and members who alrealy left this circle.
                    bool needsDelete = false;

                    RelationshipState relationshipState = GetCircleMemberRelationshipStateFromNetworkInfo(contactInfo.NetworkInfoList);
                    if (((relationshipState & RelationshipState.Rejected) != RelationshipState.None ||
                        relationshipState == RelationshipState.None) &&
                        isDefaultAddressBook == false)
                    {
                        //Members who already left.
                        needsDelete |= true;
                    }

                    if (isHidden && !isShellContact)
                    {
                        needsDelete |= true;
                    }

                    if (account == NSMessageHandler.Owner.Account.ToLowerInvariant() &&
                        contactInfo.NetworkInfoList != null &&
                        type == NSMessageHandler.Owner.ClientType &&
                        isDefaultAddressBook == false)
                    {
                        //This is a self contact. If we need to left a circle, we need its contactId.
                        //The exit circle operation just delete this contact from addressbook.
                        needsDelete |= true;
                    }

                    if (contactType.fDeleted)
                    {
                        needsDelete |= true;
                    }

                    if (needsDelete && contact.Lists == RoleLists.None && contact.FriendshipStatus == RoleId.None)
                    {
                        contactList.Remove(account, type);
                    }

                    #endregion

                    updatedContact = contact;
                }
                else
                {
                    #region Update owner and Me contact

                    Owner owner = null;

                    if (lowerId == WebServiceConstants.MessengerIndividualAddressBookId)
                    {
                        owner = NSMessageHandler.Owner;
                        if (owner == null)
                        {
                            owner = new Owner(abId, contactInfo.passportName, Convert.ToInt64(contactInfo.CID), NSMessageHandler);
                            NSMessageHandler.ContactList.SetOwner(owner);
                        }
                    }
                    else
                    {
                        if (circle == null)
                        {
                            Trace.WriteLineIf(Settings.TraceSwitch.TraceError, "Cannot update owner: " + account + " in addressbook: " + abId);
                            updatedContact = null;
                            return ReturnState.UpdateError;
                        }

                        owner = circle.ContactList.Owner;
                    }

                    if (displayName == owner.Account && !String.IsNullOrEmpty(owner.Name))
                    {
                        displayName = owner.Name;
                    }

                    owner.Guid = new Guid(contactType.contactId);
                    owner.CID = Convert.ToInt64(contactInfo.CID);
                    owner.ContactType = contactInfo.contactType;

                    if (!string.IsNullOrEmpty(displayName) && string.IsNullOrEmpty(owner.Name))
                    {
                        //We set display name by the addressbook information only if it's initially empty.
                        owner.SetName(displayName);
                    }

                    if (!string.IsNullOrEmpty(nickName) && string.IsNullOrEmpty(owner.NickName))
                    {
                        owner.SetNickName(nickName);
                    }

                    owner.UserTileURL = userTileURL;
                    SetContactPhones(owner, contactInfo);

                    #endregion

                    // Networks...
                    if (contactInfo.NetworkInfoList != null)
                    {
                        foreach (NetworkInfoType networkInfo in contactInfo.NetworkInfoList)
                        {
                            if (!String.IsNullOrEmpty(networkInfo.DomainTag) &&
                                networkInfo.DomainTag != WebServiceConstants.NullDomainTag &&
                                networkInfo.SourceId == SourceId.FaceBook &&
                                networkInfo.DomainId == DomainIds.FaceBookDomain)
                            {
                                CreateGatewayContact(networkInfo);
                            }
                        }
                    }

                    updatedContact = owner;
                }
            }
            else
            {
                updatedContact = null;
            }

            return returnValue;
        }
Beispiel #16
0
        /// <summary>
        /// Get user title url.
        /// </summary>
        /// <param name="contact"></param>
        /// <param name="domainId"></param>
        /// <returns></returns>
        private string GetUserTileURLByDomainIdFromNetworkInfo(ContactType contact, int domainId)
        {
            if (contact.contactInfo == null || contact.contactInfo.NetworkInfoList == null)
                return string.Empty;

            foreach (NetworkInfoType info in contact.contactInfo.NetworkInfoList)
            {
                if (info.DomainId != 0 && info.DomainId == domainId)
                {
                    if (!string.IsNullOrEmpty(info.UserTileURL))
                    {
                        return info.UserTileURL;
                    }
                }
            }

            return string.Empty;
        }
Beispiel #17
0
        /// <summary>
        /// Initialize contacts from mcl file. Creates contacts based on MemberShipList, Groups, CircleResults and AddressbookContacts.
        /// MemberShipList, Groups, CircleResults and AddressbookContacts is pure clean and no contains DELTAS...
        /// So, member.Deleted is not valid here...
        /// </summary>
        internal void Initialize()
        {
            if (initialized)
                return;

            initialized = true;

            #region Restore Memberships

            SerializableDictionary<RoleId, SerializableDictionary<string, BaseMember>> ms =
                SelectTargetMemberships(ServiceName.Messenger);

            if (ms != null)
            {
                foreach (RoleId role in ms.Keys)
                {
                    RoleLists msnlist = ContactList.GetMSNList(role);

                    if (msnlist != RoleLists.None)
                    {
                        foreach (BaseMember bm in ms[role].Values)
                        {
                            long cid;
                            string account;
                            IMAddressInfoType type;
                            string displayname;

                            if (DetectBaseMember(bm, out account, out type, out cid, out displayname))
                            {
                                Contact contact = NSMessageHandler.ContactList.GetContact(account, displayname, type);
                                contact.Lists |= msnlist;

                                if (cid != 0)
                                    contact.CID = cid;
                            }
                        }
                    }
                }
            }

            #endregion

            #region Restore Friendship status

            SerializableDictionary<RoleId, SerializableDictionary<string, BaseMember>> fs =
               SelectTargetMemberships(ServiceName.SocialNetwork);

            if (fs != null)
            {
                foreach (RoleId role in fs.Keys)
                {
                    foreach (BaseMember bm in fs[role].Values)
                    {
                        long cid;
                        string account;
                        IMAddressInfoType type;
                        string displayname;

                        if (DetectBaseMember(bm, out account, out type, out cid, out displayname))
                        {
                            Contact contact = NSMessageHandler.ContactList.GetContact(account, displayname, type);

                            if (cid != 0)
                                contact.CID = cid;

                            contact.SetFriendshipStatus(role, false);
                        }
                    }
                }
            }

            #endregion

            #region IMAvailability

            SerializableDictionary<RoleId, SerializableDictionary<string, BaseMember>> hd =
              SelectTargetMemberships(ServiceName.IMAvailability);

            if (hd != null && hd.ContainsKey(RoleId.Hide))
            {
                foreach (BaseMember bm in hd[RoleId.Hide].Values)
                {
                    long cid;
                    string account;
                    IMAddressInfoType type;
                    string displayname;

                    if (DetectBaseMember(bm, out account, out type, out cid, out displayname))
                    {
                        Contact contact = NSMessageHandler.ContactList.GetContact(account, displayname, type);
                        contact.Lists |= RoleLists.Hide;

                        if (cid != 0)
                            contact.CID = cid;
                    }
                }
            }

            #endregion

            #region Restore Groups

            foreach (GroupType group in Groups.Values)
            {
                NSMessageHandler.ContactGroups.AddGroup(new ContactGroup(group.groupInfo.name, group.groupId, NSMessageHandler, group.groupInfo.IsFavorite));
            }

            #endregion

            #region Restore CID contact table

            foreach (string abId in AddressbookContacts.Keys)
            {
                ContactType[] contactList = new ContactType[AddressbookContacts[abId].Count];

                AddressbookContacts[abId].Values.CopyTo(contactList, 0);
                SaveContactTable(contactList);
            }

            #endregion

            #region Restore Circles

            string[] abIds = FilterWLConnections(new List<string>(CircleResults.Keys), RelationshipState.Accepted);
            RestoreCircles(abIds, RelationshipState.Accepted);
            abIds = FilterWLConnections(new List<string>(CircleResults.Keys), RelationshipState.WaitingResponse);
            RestoreCircles(abIds, RelationshipState.WaitingResponse);

            #endregion

            #region Restore default addressbook

            if (AddressbookContacts.ContainsKey(WebServiceConstants.MessengerIndividualAddressBookId))
            {
                SerializableDictionary<Guid, ContactType> defaultPage = AddressbookContacts[WebServiceConstants.MessengerIndividualAddressBookId];
                foreach (ContactType contactType in defaultPage.Values)
                {
                    Contact tmpContact;
                    ReturnState updateResult = UpdateContact(contactType, out tmpContact); //Restore contacts.
                    if ((updateResult & ReturnState.UpdateError) != ReturnState.None)
                    {
                        Trace.WriteLineIf(Settings.TraceSwitch.TraceError, "[Initialize Error]: update contact error.");
                    }
                }

                // Get all remote network contacts
                CreateContactsFromShellContact();
            }

            #endregion
        }
Beispiel #18
0
        /// <summary>
        /// Get windows live user title url.
        /// </summary>
        /// <param name="contact"></param>
        /// <returns></returns>
        private Uri GetUserTileURLFromWindowsLiveNetworkInfo(ContactType contact)
        {
            string returnURL = GetUserTileURLByDomainIdFromNetworkInfo(contact, DomainIds.WindowsLiveDomain);
            try
            {
                Uri urlResult = null;
                if (Uri.TryCreate(returnURL, UriKind.Absolute, out urlResult))
                    return urlResult;
            }
            catch (Exception)
            {

            }

            return null;
        }
Beispiel #19
0
        private bool AddToContactTable(long CID, ContactType contact)
        {
            if (contact.contactInfo == null)
                return false;

            lock (contactTable)
                contactTable[CID] = contact;
            return true;
        }
Beispiel #20
0
        private bool SaveAddressBookContactPage(string abId, ContactType[] contacts)
        {
            if (contacts == null)
                return false;

            lock (AddressbookContacts)
            {
                SerializableDictionary<Guid, ContactType> page = new SerializableDictionary<Guid, ContactType>(0);
                AddressbookContacts[abId.ToLowerInvariant()] = page;
                foreach (ContactType contact in contacts)
                {
                    page[new Guid(contact.contactId)] = contact;
                }
            }

            return true;
        }
        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));
        }
Beispiel #22
0
        internal void UpdateContact(Contact contact, string abId, ABContactUpdateCompletedEventHandler onSuccess)
        {
            if (NSMessageHandler.MSNTicket == MSNTicket.Empty || AddressBook == null)
            {
                OnServiceOperationFailed(this, new ServiceOperationFailedEventArgs("ABContactUpdate", new MSNPSharpException("You don't have access right on this action anymore.")));
                return;
            }

            if (contact.Guid == Guid.Empty)
                throw new InvalidOperationException("This is not a valid Messenger contact.");

            string lowerId = abId.ToLowerInvariant();

            if (!AddressBook.HasContact(lowerId, contact.Guid))
                return;

            ContactType abContactType = AddressBook.SelectContactFromAddressBook(lowerId, contact.Guid);
            ContactType contactToChange = new ContactType();

            List<string> propertiesChanged = new List<string>();

            contactToChange.contactId = contact.Guid.ToString();
            contactToChange.contactInfo = new contactInfoType();

            // Comment
            if (abContactType.contactInfo.comment != contact.Comment)
            {
                propertiesChanged.Add(PropertyString.Comment);
                contactToChange.contactInfo.comment = contact.Comment;
            }

            // DisplayName
            if (abContactType.contactInfo.displayName != contact.Name)
            {
                propertiesChanged.Add(PropertyString.DisplayName);
                contactToChange.contactInfo.displayName = contact.Name;
            }

            //HasSpace
            if (abContactType.contactInfo.hasSpace != contact.HasSpace && abContactType.contactInfo.hasSpaceSpecified)
            {
                propertiesChanged.Add(PropertyString.HasSpace);
                contactToChange.contactInfo.hasSpace = contact.HasSpace;
            }

            // Annotations
            List<Annotation> annotationsChanged = new List<Annotation>();
            Dictionary<string, string> oldAnnotations = new Dictionary<string, string>();
            if (abContactType.contactInfo.annotations != null)
            {
                foreach (Annotation anno in abContactType.contactInfo.annotations)
                {
                    oldAnnotations[anno.Name] = anno.Value;
                }
            }

            // Annotations: AB.NickName
            string oldNickName = oldAnnotations.ContainsKey(AnnotationNames.AB_NickName) ? oldAnnotations[AnnotationNames.AB_NickName] : String.Empty;
            if (oldNickName != contact.NickName)
            {
                Annotation anno = new Annotation();
                anno.Name = AnnotationNames.AB_NickName;
                anno.Value = contact.NickName;
                annotationsChanged.Add(anno);
            }

            if (annotationsChanged.Count > 0)
            {
                propertiesChanged.Add(PropertyString.Annotation);
                contactToChange.contactInfo.annotations = annotationsChanged.ToArray();
            }

            // ClientType changes
            switch (contact.ClientType)
            {
                case IMAddressInfoType.WindowsLive:
                    {
                        // IsMessengerUser
                        if (abContactType.contactInfo.isMessengerUser != contact.IsMessengerUser)
                        {
                            propertiesChanged.Add(PropertyString.IsMessengerUser);
                            contactToChange.contactInfo.isMessengerUser = contact.IsMessengerUser;
                            contactToChange.contactInfo.isMessengerUserSpecified = true;
                            propertiesChanged.Add(PropertyString.MessengerMemberInfo); // Pang found WLM2009 add this.
                            contactToChange.contactInfo.MessengerMemberInfo = new MessengerMemberInfo(); // But forgot to add this...
                            contactToChange.contactInfo.MessengerMemberInfo.DisplayName = NSMessageHandler.Owner.Name; // and also this :)
                        }

                        // ContactType
                        if (abContactType.contactInfo.contactType != contact.ContactType)
                        {
                            propertiesChanged.Add(PropertyString.ContactType);
                            contactToChange.contactInfo.contactType = contact.ContactType;
                        }
                    }
                    break;

                case IMAddressInfoType.Yahoo:
                    {
                        if (abContactType.contactInfo.emails != null)
                        {
                            foreach (contactEmailType em in abContactType.contactInfo.emails)
                            {
                                if (em.email.ToLowerInvariant() == contact.Account.ToLowerInvariant() && em.isMessengerEnabled != contact.IsMessengerUser)
                                {
                                    propertiesChanged.Add(PropertyString.ContactEmail);
                                    contactToChange.contactInfo.emails = new contactEmailType[] { new contactEmailType() };
                                    contactToChange.contactInfo.emails[0].contactEmailType1 = ContactEmailTypeType.Messenger2;
                                    contactToChange.contactInfo.emails[0].isMessengerEnabled = contact.IsMessengerUser;
                                    contactToChange.contactInfo.emails[0].propertiesChanged = PropertyString.IsMessengerEnabled; //"IsMessengerEnabled";
                                    break;
                                }
                            }
                        }
                    }
                    break;

                case IMAddressInfoType.Telephone:
                    {
                        if (abContactType.contactInfo.phones != null)
                        {
                            foreach (contactPhoneType ph in abContactType.contactInfo.phones)
                            {
                                if (ph.number == contact.Account && ph.isMessengerEnabled != contact.IsMessengerUser)
                                {
                                    propertiesChanged.Add(PropertyString.ContactPhone);
                                    contactToChange.contactInfo.phones = new contactPhoneType[] { new contactPhoneType() };
                                    contactToChange.contactInfo.phones[0].contactPhoneType1 = ContactPhoneTypes.ContactPhoneMobile;
                                    contactToChange.contactInfo.phones[0].isMessengerEnabled = contact.IsMessengerUser;
                                    contactToChange.contactInfo.phones[0].propertiesChanged = PropertyString.IsMessengerEnabled; //"IsMessengerEnabled";
                                    break;
                                }
                            }
                        }
                    }
                    break;
            }

            if (propertiesChanged.Count > 0)
            {
                contactToChange.propertiesChanged = String.Join(PropertyString.propertySeparator, propertiesChanged.ToArray());
                UpdateContact(contactToChange, WebServiceConstants.MessengerIndividualAddressBookId, onSuccess);
            }
        }