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)); }
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)); }
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)); }
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)); }
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)); }
/// <summary> /// Get a circle addressbook by addressbook identifier. /// </summary> /// <param name="abId"></param> /// <param name="state"></param> /// <param name="scene"></param> /// <returns></returns> private bool RequestAddressBookByABId(string abId, RelationshipState state, Scenario scene) { Trace.WriteLineIf(Settings.TraceSwitch.TraceVerbose, "Requesting AddressBook by ABId: " + abId + ", Scenario: " + scene.ToString()); abId = abId.ToLowerInvariant(); abHandleType individualAB = new abHandleType(); individualAB.ABId = abId; individualAB.Cid = 0; individualAB.Puid = 0; switch (state) { case RelationshipState.Accepted: requestCircleCount++; try { NSMessageHandler.ContactService.abRequest(PartnerScenario.Initial, individualAB, null); } catch (Exception ex1) { requestCircleCount--; Trace.WriteLineIf(Settings.TraceSwitch.TraceError, "[RequestAddressBookByABId] Error: " + ex1.Message); } break; case RelationshipState.WaitingResponse: try { NSMessageHandler.ContactService.abRequest(PartnerScenario.Initial, individualAB, null); } catch (Exception ex2) { Trace.WriteLineIf(Settings.TraceSwitch.TraceError, "[RequestAddressBookByABId] Error: " + ex2.Message); } break; } return true; }
/// <summary> /// Async Address book request /// </summary> /// <param name="partnerScenario"></param> /// <param name="abHandle">The specified addressbook to retrieve.</param> /// <param name="onSuccess">The delegate to be executed after async ab request completed successfuly</param> internal void abRequest(string partnerScenario, abHandleType abHandle, ABFindContactsPagedCompletedEventHandler onSuccess) { if (NSMessageHandler.MSNTicket == MSNTicket.Empty || AddressBook == null) { OnServiceOperationFailed(this, new ServiceOperationFailedEventArgs("ABFindContactsPaged", new MSNPSharpException("You don't have access right on this action anymore."))); return; } ABFindContactsPagedAsync(partnerScenario, abHandle, // Register callback for success/error. e.Cancelled handled by ABFindContactsPagedAsync. delegate(object sender, ABFindContactsPagedCompletedEventArgs abfcpcea) { if (abfcpcea.Error == null /* No error */) { BinarySemaphore.WaitOne(); // Addressbook re-defined here, because the reference can be changed. // ABFindContactsPagedAsync can delete addressbook if addressbook sync is required. XMLContactList xmlcl; ABFindContactsPagedResultType forwardList; String circleResult = null; if ((null != (xmlcl = AddressBook)) && (null != (forwardList = abfcpcea.Result.ABFindContactsPagedResult))) { // Following line is horrible for semaphore usage... xmlcl .Merge(forwardList) .Save(); if (forwardList.CircleResult != null) { circleResult = forwardList.CircleResult.CircleTicket; } } BinarySemaphore.Release(); if (!String.IsNullOrEmpty(circleResult)) { NSMessageHandler.SendSHAAMessage(circleResult); } if (onSuccess != null) { onSuccess(sender, abfcpcea); } } else { // Error handler BinarySemaphore.WaitOne(); if (AddressBook == null && Deltas == null && AddressBookSynchronized == false) { BinarySemaphore.Release(); // This means before the webservice returned the connection had broken. OnServiceOperationFailed(this, new ServiceOperationFailedEventArgs("ABFindContactsPaged", new MSNPSharpException("Addressbook and Deltas have been reset."))); return; } BinarySemaphore.Release(); } }); }
internal void ServerNotificationRequest(string scene, object[] parameters, ABFindContactsPagedCompletedEventHandler onSuccess) { Trace.WriteLineIf(Settings.TraceSwitch.TraceVerbose, "Executing notify addressbook request, PartnerScenario: " + scene); switch (scene) { case PartnerScenario.ABChangeNotifyAlert: msRequest(scene, delegate { ABNotifyChangedSaveReuqest(scene, onSuccess); } ); break; case PartnerScenario.CircleIdAlert: abHandleType abHandler = new abHandleType(); abHandler.Puid = 0; abHandler.Cid = 0; abHandler.ABId = parameters[0].ToString(); msRequest(PartnerScenario.MessengerPendingList, delegate { ABNotifyChangedSaveReuqest(scene, onSuccess); } ); break; } }