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)); }
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); } }