public int CompareTo(Service other) { if (other == null) { return(1); } return(DateTime.Compare(WebServiceDateTimeConverter.ConvertToDateTime(LastChange), WebServiceDateTimeConverter.ConvertToDateTime(other.LastChange))); }
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)); }
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)); }