コード例 #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);
        }
コード例 #2
0
        private bool CreateRelationshipsSync(string scenario, string expressionProfileResourceId, string documentResourceId)
        {
            if (string.IsNullOrEmpty(expressionProfileResourceId) || string.IsNullOrEmpty(documentResourceId))
            {
                Trace.WriteLineIf(Settings.TraceSwitch.TraceError, "CreateRelationships error: expression profile Id or document resource Id is empty.");
                return(false);
            }

            MsnServiceState serviceState   = new MsnServiceState(scenario, "CreateRelationships", false);
            StorageService  storageService = (StorageService)CreateService(MsnServiceType.Storage, serviceState);

            CreateRelationshipsRequestType createRelationshipRequest = new CreateRelationshipsRequestType();
            Relationship relationship = new Relationship();

            relationship.RelationshipName = "ProfilePhoto";
            relationship.SourceType       = "SubProfile";                //From SubProfile
            relationship.TargetType       = "Photo";                     //To Photo
            relationship.SourceID         = expressionProfileResourceId; //From Expression profile
            relationship.TargetID         = documentResourceId;          //To Document

            createRelationshipRequest.relationships = new Relationship[] { relationship };
            try
            {
                ChangeCacheKeyAndPreferredHostForSpecifiedMethod(storageService, MsnServiceType.Storage, serviceState, createRelationshipRequest);
                storageService.CreateRelationships(createRelationshipRequest);
            }
            catch (Exception ex)
            {
                OnServiceOperationFailed(storageService, new ServiceOperationFailedEventArgs("CreateRelationships", ex));
                Trace.WriteLineIf(Settings.TraceSwitch.TraceError, "CreateRelationships error: " + ex.Message, GetType().Name);
                return(false);
            }

            return(true);
        }
コード例 #3
0
        private bool CreateProfileSync(string scenario, out string profileResourceId)
        {
            //1. CreateProfile, create a new profile and return its resource id.
            MsnServiceState serviceState   = new MsnServiceState(scenario, "CreateProfile", false);
            StorageService  storageService = (StorageService)CreateService(MsnServiceType.Storage, serviceState);

            CreateProfileRequestType createRequest = new CreateProfileRequestType();

            createRequest.profile = new CreateProfileRequestTypeProfile();
            createRequest.profile.ExpressionProfile = new ExpressionProfile();
            createRequest.profile.ExpressionProfile.PersonalStatus     = "";
            createRequest.profile.ExpressionProfile.RoleDefinitionName = "ExpressionProfileDefault";

            try
            {
                ChangeCacheKeyAndPreferredHostForSpecifiedMethod(storageService, MsnServiceType.Storage, serviceState, createRequest);
                CreateProfileResponse createResponse = storageService.CreateProfile(createRequest);
                profileResourceId = createResponse.CreateProfileResult;
                NSMessageHandler.ContactService.Deltas.Profile.ResourceID = profileResourceId;
                NSMessageHandler.ContactService.Deltas.Save(true);
            }
            catch (Exception ex)
            {
                OnServiceOperationFailed(storageService, new ServiceOperationFailedEventArgs("CreateProfile", ex));
                Trace.WriteLineIf(Settings.TraceSwitch.TraceError, "CreateProfile error: " + ex.Message, GetType().Name);
                profileResourceId = string.Empty;

                return(false);
            }

            return(true);
        }
コード例 #4
0
        private bool DeleteRelationshipByResourceIdSync(string scenario, string sourceHandlerResourceId, string targetHandlerResourceId)
        {
            if (string.IsNullOrEmpty(sourceHandlerResourceId) || string.IsNullOrEmpty(targetHandlerResourceId))
            {
                return(false);
            }

            MsnServiceState serviceState   = new MsnServiceState(scenario, "DeleteRelationships", false);
            StorageService  storageService = (StorageService)CreateService(MsnServiceType.Storage, serviceState);

            //3.2 Profile -> Photo
            DeleteRelationshipsRequestType request = new DeleteRelationshipsRequestType();

            request.sourceHandle                = new Handle();
            request.sourceHandle.ResourceID     = sourceHandlerResourceId;
            request.targetHandles               = new Handle[] { new Handle() };
            request.targetHandles[0].ResourceID = targetHandlerResourceId;
            try
            {
                ChangeCacheKeyAndPreferredHostForSpecifiedMethod(storageService, MsnServiceType.Storage, serviceState, request);
                storageService.DeleteRelationships(request);
            }
            catch (Exception ex)
            {
                OnServiceOperationFailed(storageService, new ServiceOperationFailedEventArgs("DeleteRelationships", ex));
                Trace.WriteLineIf(Settings.TraceSwitch.TraceError, ex.Message, GetType().Name);
                return(false);
            }

            return(true);
        }
コード例 #5
0
        private bool DeleteRelationshipByNameSync(string scenario, string relationshipName, string targetHandlerResourceId)
        {
            MsnServiceState serviceState   = new MsnServiceState(scenario, "DeleteRelationships", false);
            StorageService  storageService = (StorageService)CreateService(MsnServiceType.Storage, serviceState);

            Alias mycidAlias = new Alias();

            mycidAlias.Name      = Convert.ToString(NSMessageHandler.Owner.CID);
            mycidAlias.NameSpace = "MyCidStuff";

            // 3. DeleteRelationships. If an error occurs, don't return, continue...

            // 3.1 UserTiles -> Photo
            DeleteRelationshipsRequestType request = new DeleteRelationshipsRequestType();

            request.sourceHandle = new Handle();
            request.sourceHandle.RelationshipName = relationshipName; //"/UserTiles";
            request.sourceHandle.Alias            = mycidAlias;
            request.targetHandles = new Handle[] { new Handle() };
            request.targetHandles[0].ResourceID = targetHandlerResourceId;
            try
            {
                ChangeCacheKeyAndPreferredHostForSpecifiedMethod(storageService, MsnServiceType.Storage, serviceState, request);
                storageService.DeleteRelationships(request);
            }
            catch (Exception ex)
            {
                OnServiceOperationFailed(storageService, new ServiceOperationFailedEventArgs("DeleteRelationships", ex));
                Trace.WriteLineIf(Settings.TraceSwitch.TraceError, ex.Message, GetType().Name);
                return(false);
            }

            return(true);
        }
コード例 #6
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));
        }
コード例 #7
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));
        }
コード例 #8
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));
        }
コード例 #9
0
ファイル: MSNService.cs プロジェクト: supercoeus/msnp-sharp
 /// <summary>
 /// Construct a <see cref="BeforeRunAsyncMethodEventArgs"/> object.
 /// </summary>
 /// <param name="ws">Webservice binding to call.</param>
 /// <param name="st">Service type.</param>
 /// <param name="ss">Service state object.</param>
 /// <param name="r">Webservice requst parameter.</param>
 public BeforeRunAsyncMethodEventArgs(SoapHttpClientProtocol ws, MsnServiceType st, MsnServiceState ss, object r)
 {
     webService   = ws;
     serviceType  = st;
     serviceState = ss;
     request      = r;
 }
コード例 #10
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));
        }
コード例 #11
0
        /// <summary>
        /// Get the recent activities of your contacts.
        /// </summary>
        /// <param name="count">Max activity count, must be larger than zero and less than 200.</param>
        public void GetWhatsUp(int count)
        {
            if (count > 200)
            {
                count = 200;
            }
            else if (count < 0)
            {
                count = 50;
            }

            if (NSMessageHandler.MSNTicket != MSNTicket.Empty)
            {
                MsnServiceState       getContactsRecentActivityObject = new MsnServiceState(PartnerScenario.None, "GetContactsRecentActivity", true);
                WhatsUpServiceBinding wuService = (WhatsUpServiceBinding)CreateService(MsnServiceType.WhatsUp, getContactsRecentActivityObject);
                wuService.GetContactsRecentActivityCompleted += delegate(object sender, GetContactsRecentActivityCompletedEventArgs e)
                {
                    OnAfterCompleted(new ServiceOperationEventArgs(wuService, MsnServiceType.WhatsUp, e));

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

                    if (e.Cancelled)
                    {
                        return;
                    }

                    if (e.Error != null)
                    {
                        OnGetWhatsUpCompleted(this, new GetWhatsUpCompletedEventArgs(e.Error, null));
                        Trace.WriteLineIf(Settings.TraceSwitch.TraceError, e.Error.Message, GetType().Name);
                        return;
                    }

                    if (e.Result.GetContactsRecentActivityResult != null)
                    {
                        feedUrl = e.Result.GetContactsRecentActivityResult.FeedUrl;
                        OnGetWhatsUpCompleted(this, new GetWhatsUpCompletedEventArgs(null, e.Result.GetContactsRecentActivityResult));
                    }
                    else
                    {
                        OnGetWhatsUpCompleted(this, new GetWhatsUpCompletedEventArgs(null, null));
                    }
                };

                GetContactsRecentActivityRequestType request = new GetContactsRecentActivityRequestType();
                request.entityHandle     = new entityHandle();
                request.entityHandle.Cid = Convert.ToInt64(NSMessageHandler.Owner.CID);
                request.locales          = new string[] { System.Globalization.CultureInfo.CurrentCulture.Name };
                request.count            = count;

                RunAsyncMethod(new BeforeRunAsyncMethodEventArgs(wuService, MsnServiceType.WhatsUp, getContactsRecentActivityObject, request));
            }
        }
コード例 #12
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));
        }
コード例 #13
0
        private bool UpdatePhotoDocumentSync(string scenario, string photoName, string documentResourceId, byte[] photoData)
        {
            if (string.IsNullOrEmpty(documentResourceId) || photoData == null)
            {
                return(false);
            }

            MsnServiceState serviceState   = new MsnServiceState(scenario, "UpdateDocument", false);
            StorageService  storageService = (StorageService)CreateService(MsnServiceType.Storage, serviceState);

            UpdateDocumentRequestType request = new UpdateDocumentRequestType();

            request.document = new Photo();

            if (!string.IsNullOrEmpty(photoName))
            {
                request.document.Name = photoName;
            }
            else
            {
                request.document.Name = "?";
            }


            request.document.ResourceID                            = documentResourceId;
            request.document.DocumentStreams                       = new PhotoStream[] { new PhotoStream() };
            request.document.DocumentStreams[0].DataSize           = 0;
            request.document.DocumentStreams[0].MimeType           = "image/png";
            request.document.DocumentStreams[0].DocumentStreamType = "UserTileStatic";
            request.document.DocumentStreams[0].Data               = photoData;

            try
            {
                ChangeCacheKeyAndPreferredHostForSpecifiedMethod(storageService, MsnServiceType.Storage, serviceState, request);
                storageService.UpdateDocument(request);
            }
            catch (Exception ex)
            {
                OnServiceOperationFailed(storageService, new ServiceOperationFailedEventArgs("UpdateDocument", ex));
                Trace.WriteLineIf(Settings.TraceSwitch.TraceError, ex.Message, GetType().Name);
                return(false);
            }

            NSMessageHandler.ContactService.Deltas.Profile.Photo.Name         = photoName;
            NSMessageHandler.ContactService.Deltas.Profile.Photo.DisplayImage = new SerializableMemoryStream();
            NSMessageHandler.ContactService.Deltas.Profile.Photo.DisplayImage.Write(photoData, 0, photoData.Length);
            NSMessageHandler.ContactService.Deltas.Save(true);

            return(true);
        }
コード例 #14
0
        private bool AddProfileExpressionRoleMemberSync(string scenario)
        {
            HandleType srvHandle = new HandleType();

            srvHandle.ForeignId = "MyProfile";
            srvHandle.Id        = "0";
            srvHandle.Type      = ServiceName.Profile;
            if (NSMessageHandler.MSNTicket != MSNTicket.Empty)
            {
                MsnServiceState       serviceState   = new MsnServiceState(scenario, "AddMember", false);
                SharingServiceBinding sharingService = (SharingServiceBinding)CreateService(MsnServiceType.Sharing, serviceState);

                AddMemberRequestType addMemberRequest = new AddMemberRequestType();

                addMemberRequest.serviceHandle = srvHandle;

                Membership memberShip = new Membership();
                memberShip.MemberRole = RoleId.ProfileExpression;
                RoleMember roleMember = new RoleMember();
                roleMember.Type  = "Role";
                roleMember.Id    = RoleId.Allow;
                roleMember.State = MemberState.Accepted;
                roleMember.MaxRoleRecursionDepth = "0";
                roleMember.MaxDegreesSeparation  = "0";

                HandleType defService = new HandleType();
                defService.ForeignId = "";
                defService.Id        = "0";
                defService.Type      = ServiceName.Messenger;

                roleMember.DefiningService   = defService;
                memberShip.Members           = new RoleMember[] { roleMember };
                addMemberRequest.memberships = new Membership[] { memberShip };
                try
                {
                    ChangeCacheKeyAndPreferredHostForSpecifiedMethod(sharingService, MsnServiceType.Sharing, serviceState, addMemberRequest);
                    sharingService.AddMember(addMemberRequest);
                }
                catch (Exception ex)
                {
                    OnServiceOperationFailed(sharingService, new ServiceOperationFailedEventArgs("ShareItem", ex));
                    Trace.WriteLineIf(Settings.TraceSwitch.TraceError, "AddMember error: " + ex.Message, GetType().Name);
                    return(false);
                }

                return(true);
            }

            return(false);
        }
コード例 #15
0
        private void AddServiceAsync(ServiceName serviceName, AddServiceCompletedEventHandler callback)
        {
            if (NSMessageHandler.MSNTicket == MSNTicket.Empty || AddressBook == null)
            {
                OnServiceOperationFailed(this, new ServiceOperationFailedEventArgs("AddService", new MSNPSharpException("You don't have access right on this action anymore.")));
            }
            else
            {
                AddServiceRequestType r = new AddServiceRequestType();
                r.serviceInfo                  = new InfoType();
                r.serviceInfo.Handle           = new HandleType();
                r.serviceInfo.Handle.Type      = serviceName;
                r.serviceInfo.Handle.ForeignId = String.Empty;
                r.serviceInfo.InverseRequired  = true;

                MsnServiceState       addServiceObject = new MsnServiceState(PartnerScenario.CircleSave, "AddService", true);
                SharingServiceBinding abService        = (SharingServiceBinding)CreateService(MsnServiceType.Sharing, addServiceObject);
                abService.AddServiceCompleted += delegate(object service, AddServiceCompletedEventArgs e)
                {
                    OnAfterCompleted(new ServiceOperationEventArgs(abService, MsnServiceType.Sharing, e));

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

                    if (e.Error == null)
                    {
                        Trace.WriteLineIf(Settings.TraceSwitch.TraceInfo,
                                          serviceName + "=" + e.Result.AddServiceResult + " created...");

                        // Update service membership...
                        msRequest(PartnerScenario.BlockUnblock,
                                  delegate
                        {
                            if (callback != null)
                            {
                                callback(abService, e);
                            }
                        });
                    }
                };

                RunAsyncMethod(new BeforeRunAsyncMethodEventArgs(abService, MsnServiceType.Sharing, addServiceObject, r));
            }
        }
コード例 #16
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));
        }
コード例 #17
0
        private bool UpdateProfileLiteSync(string scenario, string profileResourceId, string displayName, string personalStatus, string freeText, int flag)
        {
            MsnServiceState serviceState   = new MsnServiceState(scenario, "UpdateProfile", false);
            StorageService  storageService = (StorageService)CreateService(MsnServiceType.Storage, serviceState);

            UpdateProfileRequestType updateProfileRequest = new UpdateProfileRequestType();

            updateProfileRequest.profile            = new UpdateProfileRequestTypeProfile();
            updateProfileRequest.profile.ResourceID = profileResourceId;
            ExpressionProfile expProf = new ExpressionProfile();

            expProf.FreeText       = freeText;
            expProf.DisplayName    = displayName;
            expProf.Flags          = flag;
            expProf.FlagsSpecified = true;

            if (!string.IsNullOrEmpty(personalStatus))
            {
                expProf.PersonalStatus = personalStatus == null ? string.Empty : personalStatus;
            }
            updateProfileRequest.profile.ExpressionProfile = expProf;

            NSMessageHandler.ContactService.Deltas.Profile.DisplayName     = displayName;
            NSMessageHandler.ContactService.Deltas.Profile.PersonalMessage = personalStatus;
            NSMessageHandler.ContactService.Deltas.Save(true);  //Save no matter the request succeed or fail.

            try
            {
                ChangeCacheKeyAndPreferredHostForSpecifiedMethod(storageService, MsnServiceType.Storage, serviceState, updateProfileRequest);
                storageService.UpdateProfile(updateProfileRequest);
            }
            catch (Exception ex)
            {
                OnServiceOperationFailed(storageService, new ServiceOperationFailedEventArgs("UpdateProfile", ex));
                Trace.WriteLineIf(Settings.TraceSwitch.TraceError, "UpdateProfile error: " + ex.Message, GetType().Name);
                return(false);
            }

            return(true);
        }
コード例 #18
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));
        }
コード例 #19
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));
        }
コード例 #20
0
        private void CreateCircleAsync(string circleName, CreateCircleCompletedEventHandler callback)
        {
            //This is M$ style, you will never guess out the meaning of these numbers.
            ContentInfoType properties = new ContentInfoType();

            properties.Domain                  = 1;
            properties.HostedDomain            = Contact.DefaultHostDomain;
            properties.Type                    = 2;
            properties.MembershipAccess        = 0;
            properties.IsPresenceEnabled       = true;
            properties.RequestMembershipOption = 2;
            properties.DisplayName             = circleName;

            CreateCircleRequestType request = new CreateCircleRequestType();

            request.properties = properties;
            request.callerInfo = new callerInfoType();
            request.callerInfo.PublicDisplayName = NSMessageHandler.Owner.Name == string.Empty ? NSMessageHandler.Owner.Account : NSMessageHandler.Owner.Name;

            MsnServiceState       createCircleObject = new MsnServiceState(PartnerScenario.CircleSave, "CreateCircle", true);
            SharingServiceBinding sharingService     = (SharingServiceBinding)CreateService(MsnServiceType.Sharing, createCircleObject);

            sharingService.CreateCircleCompleted += delegate(object sender, CreateCircleCompletedEventArgs e)
            {
                OnAfterCompleted(new ServiceOperationEventArgs(sharingService, MsnServiceType.Sharing, e));

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

                if (callback != null)
                {
                    callback(sender, e);
                }
            };

            RunAsyncMethod(new BeforeRunAsyncMethodEventArgs(sharingService, MsnServiceType.Sharing, createCircleObject, request));
        }
コード例 #21
0
        private bool ShareItemSync(string scenario, string profileResourceId)
        {
            MsnServiceState serviceState   = new MsnServiceState(scenario, "ShareItem", false);
            StorageService  storageService = (StorageService)CreateService(MsnServiceType.Storage, serviceState);

            ShareItemRequestType shareItemRequest = new ShareItemRequestType();

            shareItemRequest.resourceID  = profileResourceId;
            shareItemRequest.displayName = "Messenger Roaming Identity";
            try
            {
                ChangeCacheKeyAndPreferredHostForSpecifiedMethod(storageService, MsnServiceType.Storage, serviceState, shareItemRequest);
                storageService.ShareItem(shareItemRequest);
            }
            catch (Exception ex)
            {
                OnServiceOperationFailed(storageService, new ServiceOperationFailedEventArgs("ShareItem", ex));
                Trace.WriteLineIf(Settings.TraceSwitch.TraceError, "ShareItem error: " + ex.Message, GetType().Name); //Item already shared.
                return(false);
            }

            return(true);
        }
コード例 #22
0
ファイル: MSNService.cs プロジェクト: supercoeus/msnp-sharp
        protected void ChangeCacheKeyAndPreferredHostForSpecifiedMethod(SoapHttpClientProtocol ws, MsnServiceType st, MsnServiceState ss, object request)
        {
            if (st == MsnServiceType.AB ||
                st == MsnServiceType.Sharing ||
                st == MsnServiceType.Storage)
            {
                DeltasList deltas = NSMessageHandler.ContactService.Deltas;
                if (deltas == null)
                {
                    throw new MSNPSharpException("Deltas is null.");
                }

                string       methodName       = ss.MethodName;
                string       preferredHostKey = ws.ToString() + "." + methodName;
                CacheKeyType keyType          = (st == MsnServiceType.Storage) ? CacheKeyType.StorageServiceCacheKey : CacheKeyType.OmegaContactServiceCacheKey;

                string originalUrl  = ws.Url;
                string originalHost = FetchHost(ws.Url);
                bool   needRequest  = false;

                lock (deltas.SyncObject)
                {
                    needRequest = (deltas.CacheKeys.ContainsKey(keyType) == false ||
                                   deltas.CacheKeys[keyType] == string.Empty ||
                                   (deltas.CacheKeys[keyType] != string.Empty &&
                                    (deltas.PreferredHosts.ContainsKey(preferredHostKey) == false ||
                                     deltas.PreferredHosts[preferredHostKey] == String.Empty)));
                }

                if (needRequest)
                {
                    try
                    {
                        Trace.WriteLineIf(Settings.TraceSwitch.TraceInfo, ws.GetType().ToString() + " is requesting a cachekey and preferred host for calling " + methodName);

                        switch (keyType)
                        {
                        case CacheKeyType.OmegaContactServiceCacheKey:
                            ws.Url = ws.Url.Replace(originalHost, MSNService.ContactServiceRedirectionHost);
                            break;

                        case CacheKeyType.StorageServiceCacheKey:
                            ws.Url = ws.Url.Replace(originalHost, MSNService.StorageServiceRedirectionHost);
                            break;
                        }

                        ws.GetType().InvokeMember(methodName, System.Reflection.BindingFlags.InvokeMethod,
                                                  null, ws,
                                                  new object[] { request });
                    }
                    catch (Exception ex)
                    {
                        bool getHost = false;
                        if (ex.InnerException is WebException && ex.InnerException != null)
                        {
                            WebException    webException = ex.InnerException as WebException;
                            HttpWebResponse webResponse  = webException.Response as HttpWebResponse;

                            if (webResponse != null)
                            {
                                if (webResponse.StatusCode == HttpStatusCode.Moved ||
                                    webResponse.StatusCode == HttpStatusCode.MovedPermanently ||
                                    webResponse.StatusCode == HttpStatusCode.Redirect ||
                                    webResponse.StatusCode == HttpStatusCode.RedirectKeepVerb)
                                {
                                    string redirectUrl = webResponse.Headers[HttpResponseHeader.Location];

                                    if (!string.IsNullOrEmpty(redirectUrl))
                                    {
                                        getHost = true;

                                        lock (deltas.SyncObject)
                                            deltas.PreferredHosts[preferredHostKey] = FetchHost(redirectUrl);

                                        Trace.WriteLineIf(Settings.TraceSwitch.TraceVerbose, "Get redirect URL by HTTP error succeed, method " + methodName + ":\r\n " +
                                                          "Original: " + FetchHost(ws.Url) + "\r\n " +
                                                          "Redirect: " + FetchHost(redirectUrl) + "\r\n");
                                    }

                                    #region Fetch CacheKey

                                    try
                                    {
                                        XmlDocument errdoc       = new XmlDocument();
                                        string      errorMessage = ex.InnerException.Message;
                                        string      xmlstr       = errorMessage.Substring(errorMessage.IndexOf("<?xml"));
                                        xmlstr = xmlstr.Substring(0, xmlstr.IndexOf("</soap:envelope>", StringComparison.InvariantCultureIgnoreCase) + "</soap:envelope>".Length);

                                        //I think the xml parser microsoft used internally is just a super parser, it can ignore everything.
                                        xmlstr = xmlstr.Replace("&amp;", "&");
                                        xmlstr = xmlstr.Replace("&", "&amp;");

                                        errdoc.LoadXml(xmlstr);

                                        XmlNodeList findnodelist = errdoc.GetElementsByTagName("CacheKey");
                                        if (findnodelist.Count > 0 && !String.IsNullOrEmpty(findnodelist[0].InnerText))
                                        {
                                            deltas.CacheKeys[keyType] = findnodelist[0].InnerText;
                                        }
                                    }
                                    catch (Exception exc)
                                    {
                                        Trace.WriteLineIf(Settings.TraceSwitch.TraceError,
                                                          "An error occured while getting CacheKey:\r\n" +
                                                          "Service:    " + ws.GetType().ToString() + "\r\n" +
                                                          "MethodName: " + methodName + "\r\n" +
                                                          "Message:    " + exc.Message);
                                    }

                                    #endregion
                                }
                            }
                        }

                        if (!getHost)
                        {
                            Trace.WriteLineIf(Settings.TraceSwitch.TraceError,
                                              "An error occured while getting CacheKey and Preferred host:\r\n" +
                                              "Service:    " + ws.GetType().ToString() + "\r\n" +
                                              "MethodName: " + methodName + "\r\n" +
                                              "Message:    " + ex.Message);

                            lock (deltas.SyncObject)
                                deltas.PreferredHosts[preferredHostKey] = originalHost; //If there's an error, we must set the host back to its original value.
                        }
                    }
                    deltas.Save();
                }

                lock (deltas.SyncObject)
                {
                    if (originalHost != null && originalHost != String.Empty)
                    {
                        if (deltas.PreferredHosts.ContainsKey(preferredHostKey))
                        {
                            ws.Url = originalUrl.Replace(originalHost, FetchHost(deltas.PreferredHosts[preferredHostKey]));
                        }
                        else
                        {
                            //This means the redirection URL returns respond content.
                            lock (deltas.SyncObject)
                            {
                                deltas.PreferredHosts[preferredHostKey] = ws.Url;
                                deltas.Save();
                            }

                            Trace.WriteLineIf(Settings.TraceSwitch.TraceInfo, "The redirect URL returns correct result, use " + ws.Url + " for " + preferredHostKey);
                        }
                    }

                    // Set cache key
                    if (st == MsnServiceType.AB)
                    {
                        ((ABServiceBinding)ws).ABApplicationHeaderValue.CacheKey = deltas.CacheKeys[keyType];
                    }
                    else if (st == MsnServiceType.Sharing)
                    {
                        ((SharingServiceBinding)ws).ABApplicationHeaderValue.CacheKey = deltas.CacheKeys[keyType];
                    }
                    else if (st == MsnServiceType.Storage)
                    {
                        ((StorageService)ws).AffinityCacheHeaderValue.CacheKey = deltas.CacheKeys[keyType];
                    }
                }
            }
        }
コード例 #23
0
        private void AddMemberAsync(Contact contact, ServiceName serviceName, RoleLists list, AddMemberCompletedEventHandler callback)
        {
            if (NSMessageHandler.MSNTicket == MSNTicket.Empty || AddressBook == null)
            {
                OnServiceOperationFailed(this, new ServiceOperationFailedEventArgs("AddMember", new MSNPSharpException("You don't have access right on this action anymore.")));
                return;
            }

            // check whether the update is necessary
            if (contact.HasLists(list))
            {
                return;
            }

            RoleId memberRole = ContactList.GetMemberRole(list);

            if (memberRole == RoleId.None)
            {
                return;
            }

            Service service = AddressBook.SelectTargetService(serviceName);

            if (service == null)
            {
                AddServiceAsync(serviceName,
                                delegate
                {
                    // RESURSIVE CALL
                    AddMemberAsync(contact, serviceName, list, callback);
                });
                return;
            }


            AddMemberRequestType addMemberRequest = new AddMemberRequestType();

            addMemberRequest.serviceHandle      = new HandleType();
            addMemberRequest.serviceHandle.Id   = service.Id.ToString();
            addMemberRequest.serviceHandle.Type = serviceName;

            Membership memberShip = new Membership();

            memberShip.MemberRole = memberRole;
            BaseMember member = null; // Abstract

            if (contact.ClientType == IMAddressInfoType.WindowsLive)
            {
                member = new PassportMember();
                PassportMember passportMember = member as PassportMember;
                passportMember.PassportName = contact.Account;
                passportMember.State        = MemberState.Accepted;
                passportMember.Type         = MembershipType.Passport;
            }
            else if (contact.ClientType == IMAddressInfoType.Yahoo ||
                     contact.ClientType == IMAddressInfoType.OfficeCommunicator)
            {
                member = new EmailMember();
                EmailMember emailMember = member as EmailMember;
                emailMember.State                = MemberState.Accepted;
                emailMember.Type                 = MembershipType.Email;
                emailMember.Email                = contact.Account;
                emailMember.Annotations          = new Annotation[] { new Annotation() };
                emailMember.Annotations[0].Name  = AnnotationNames.MSN_IM_BuddyType;
                emailMember.Annotations[0].Value = (contact.ClientType == IMAddressInfoType.Yahoo) ?
                                                   "32:" : "02:";
            }
            else if (contact.ClientType == IMAddressInfoType.Telephone)
            {
                member = new PhoneMember();
                PhoneMember phoneMember = member as PhoneMember;
                phoneMember.State       = MemberState.Accepted;
                phoneMember.Type        = MembershipType.Phone;
                phoneMember.PhoneNumber = contact.Account;
            }
            else if (contact.ClientType == IMAddressInfoType.Circle)
            {
                member = new CircleMember();
                CircleMember circleMember = member as CircleMember;
                circleMember.Type     = MembershipType.Circle;
                circleMember.State    = MemberState.Accepted;
                circleMember.CircleId = contact.AddressBookId.ToString("D").ToLowerInvariant();
            }

            if (member == null)
            {
                return;
            }

            memberShip.Members           = new BaseMember[] { member };
            addMemberRequest.memberships = new Membership[] { memberShip };

            MsnServiceState       AddMemberObject = new MsnServiceState(PartnerScenario.ContactMsgrAPI, "AddMember", true);
            SharingServiceBinding sharingService  = (SharingServiceBinding)CreateService(MsnServiceType.Sharing, AddMemberObject);

            sharingService.AddMemberCompleted += delegate(object srv, AddMemberCompletedEventArgs e)
            {
                OnAfterCompleted(new ServiceOperationEventArgs(sharingService, MsnServiceType.Sharing, e));

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

                // Update AB
                AddressBook.AddMemberhip(serviceName, contact.Account, contact.ClientType, memberRole, member);

                if (callback != null)
                {
                    callback(srv, e);
                }
            };

            RunAsyncMethod(new BeforeRunAsyncMethodEventArgs(sharingService, MsnServiceType.Sharing, AddMemberObject, addMemberRequest));
        }
コード例 #24
0
ファイル: MSNService.cs プロジェクト: supercoeus/msnp-sharp
        private void HandleServiceHeader(SoapHttpClientProtocol ws, MsnServiceType st, MsnServiceState ss)
        {
            ServiceHeader sh = (st == MsnServiceType.AB) ?
                               ((ABServiceBinding)ws).ServiceHeaderValue :
                               ((SharingServiceBinding)ws).ServiceHeaderValue;

            if (null != sh &&
                NSMessageHandler.ContactService != null &&
                NSMessageHandler.ContactService.Deltas != null)
            {
                if (sh.CacheKeyChanged)
                {
                    NSMessageHandler.ContactService.Deltas.CacheKeys[CacheKeyType.OmegaContactServiceCacheKey] = sh.CacheKey;
                }

                lock (NSMessageHandler.ContactService.Deltas.SyncObject)
                {
                    /*
                     * // The implementation here is incorrect, we should only believe in the Location header
                     * // from the http response.
                     * if (!String.IsNullOrEmpty(sh.PreferredHostName))
                     * {
                     *  string methodKey = ws.ToString() + "." + ss.MethodName;
                     *  string preferredHost = FetchHost(sh.PreferredHostName);
                     *  if (NSMessageHandler.ContactService.Deltas.PreferredHosts[methodKey] == preferredHost)
                     *      return;
                     *
                     *  Trace.WriteLineIf(Settings.TraceSwitch.TraceVerbose, "Update redirect URL by response succeed, method " + ss.MethodName + ":\r\n " +
                     *                  "Original: " + FetchHost(ws.Url) + "\r\n " +
                     *                  "Redirect: " + preferredHost + "\r\n");
                     *
                     *  NSMessageHandler.ContactService.Deltas.PreferredHosts[methodKey] = preferredHost;
                     * }
                     */

                    NSMessageHandler.ContactService.Deltas.Save();
                }
            }
        }
コード例 #25
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));
        }
コード例 #26
0
        private void DeleteMemberAsync(Contact contact, ServiceName serviceName, RoleLists list, DeleteMemberCompletedEventHandler callback)
        {
            if (NSMessageHandler.MSNTicket == MSNTicket.Empty || AddressBook == null)
            {
                OnServiceOperationFailed(this, new ServiceOperationFailedEventArgs("DeleteMember", new MSNPSharpException("You don't have access right on this action anymore.")));
                return;
            }

            // check whether the update is necessary
            if (!contact.HasLists(list))
            {
                return;
            }

            RoleId memberRole = ContactList.GetMemberRole(list);

            if (memberRole == RoleId.None)
            {
                return;
            }

            Service service = AddressBook.SelectTargetService(serviceName);

            if (service == null)
            {
                AddServiceAsync(serviceName,
                                delegate
                {
                    // RESURSIVE CALL
                    DeleteMemberAsync(contact, serviceName, list, callback);
                });
                return;
            }


            DeleteMemberRequestType deleteMemberRequest = new DeleteMemberRequestType();

            deleteMemberRequest.serviceHandle      = new HandleType();
            deleteMemberRequest.serviceHandle.Id   = service.Id.ToString();
            deleteMemberRequest.serviceHandle.Type = serviceName;

            Membership memberShip = new Membership();

            memberShip.MemberRole = memberRole;

            BaseMember deleteMember = null; // BaseMember is an abstract type, so we cannot create a new instance.
            // If we have a MembershipId different from 0, just use it. Otherwise, use email or phone number.
            BaseMember baseMember   = AddressBook.SelectBaseMember(serviceName, contact.Account, contact.ClientType, memberRole);
            int        membershipId = (baseMember == null) ? 0 : baseMember.MembershipId;

            switch (contact.ClientType)
            {
            case IMAddressInfoType.WindowsLive:

                deleteMember       = new PassportMember();
                deleteMember.Type  = (baseMember == null) ? MembershipType.Passport : baseMember.Type;
                deleteMember.State = (baseMember == null) ? MemberState.Accepted : baseMember.State;
                if (membershipId == 0)
                {
                    (deleteMember as PassportMember).PassportName = contact.Account;
                }
                else
                {
                    deleteMember.MembershipId          = membershipId;
                    deleteMember.MembershipIdSpecified = true;
                }
                break;

            case IMAddressInfoType.Yahoo:
            case IMAddressInfoType.OfficeCommunicator:

                deleteMember       = new EmailMember();
                deleteMember.Type  = MembershipType.Email;
                deleteMember.State = (baseMember == null) ? MemberState.Accepted : baseMember.State;
                if (membershipId == 0)
                {
                    (deleteMember as EmailMember).Email = contact.Account;
                }
                else
                {
                    deleteMember.MembershipId          = membershipId;
                    deleteMember.MembershipIdSpecified = true;
                }
                break;

            case IMAddressInfoType.Telephone:

                deleteMember       = new PhoneMember();
                deleteMember.Type  = MembershipType.Phone;
                deleteMember.State = (baseMember == null) ? MemberState.Accepted : baseMember.State;
                if (membershipId == 0)
                {
                    (deleteMember as PhoneMember).PhoneNumber = contact.Account;
                }
                else
                {
                    deleteMember.MembershipId          = membershipId;
                    deleteMember.MembershipIdSpecified = true;
                }
                break;

            case IMAddressInfoType.Circle:
                deleteMember       = new CircleMember();
                deleteMember.Type  = MembershipType.Circle;
                deleteMember.State = (baseMember == null) ? MemberState.Accepted : baseMember.State;
                (deleteMember as CircleMember).CircleId = contact.AddressBookId.ToString("D").ToLowerInvariant();
                break;
            }

            memberShip.Members = new BaseMember[] { deleteMember };
            deleteMemberRequest.memberships = new Membership[] { memberShip };

            MsnServiceState       DeleteMemberObject = new MsnServiceState(PartnerScenario.ContactMsgrAPI, "DeleteMember", true);
            SharingServiceBinding sharingService     = (SharingServiceBinding)CreateService(MsnServiceType.Sharing, DeleteMemberObject);

            sharingService.DeleteMemberCompleted += delegate(object srv, DeleteMemberCompletedEventArgs e)
            {
                OnAfterCompleted(new ServiceOperationEventArgs(sharingService, MsnServiceType.Sharing, e));

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

                // Update AB
                AddressBook.RemoveMemberhip(serviceName, contact.Account, contact.ClientType, memberRole);

                if (callback != null)
                {
                    callback(srv, e);
                }
            };

            RunAsyncMethod(new BeforeRunAsyncMethodEventArgs(sharingService, MsnServiceType.Sharing, DeleteMemberObject, deleteMemberRequest));
        }
コード例 #27
0
        private bool CreatePhotoDocumentSync(string scenario, out string documentResourceId, string photoName, byte[] photoData)
        {
            if (photoData == null)
            {
                documentResourceId = string.Empty;
                return(false);
            }

            MsnServiceState serviceState   = new MsnServiceState(scenario, "CreateDocument", false);
            StorageService  storageService = (StorageService)CreateService(MsnServiceType.Storage, serviceState);

            CreateDocumentRequestType createDocRequest = new CreateDocumentRequestType();

            createDocRequest.relationshipName = "ProfilePhoto";

            Handle parenthandle = new Handle();

            parenthandle.RelationshipName = @"/MyProfile/ExpressionProfile";

            Alias alias = new Alias();

            alias.NameSpace = "MyCidStuff";
            alias.Name      = Convert.ToString(NSMessageHandler.Owner.CID);

            parenthandle.Alias             = alias;
            createDocRequest.parentHandle  = parenthandle;
            createDocRequest.document      = new Photo();
            createDocRequest.document.Name = photoName;

            PhotoStream photoStream = new PhotoStream();

            photoStream.DataSize           = 0;
            photoStream.MimeType           = @"image/png";
            photoStream.DocumentStreamType = "UserTileStatic";
            photoStream.Data = photoData;
            createDocRequest.document.DocumentStreams = new PhotoStream[] { photoStream };

            DisplayImage displayImage = new DisplayImage(NSMessageHandler.Owner.Account.ToLowerInvariant(), new MemoryStream(photoData));

            NSMessageHandler.Owner.DisplayImage = displayImage;

            try
            {
                ChangeCacheKeyAndPreferredHostForSpecifiedMethod(storageService, MsnServiceType.Storage, serviceState, createDocRequest);
                CreateDocumentResponseType createDocResponse = storageService.CreateDocument(createDocRequest);
                documentResourceId = createDocResponse.CreateDocumentResult;
            }
            catch (Exception ex)
            {
                OnServiceOperationFailed(storageService, new ServiceOperationFailedEventArgs("CreateDocument", ex));
                Trace.WriteLineIf(Settings.TraceSwitch.TraceError, "CreateDocument error: " + ex.Message, GetType().Name);
                documentResourceId = string.Empty;
                return(false);
            }

            NSMessageHandler.ContactService.Deltas.Profile.Photo.Name         = photoName;
            NSMessageHandler.ContactService.Deltas.Profile.Photo.DisplayImage = new SerializableMemoryStream();
            NSMessageHandler.ContactService.Deltas.Profile.Photo.DisplayImage.Write(photoData, 0, photoData.Length);
            NSMessageHandler.ContactService.Deltas.Save(true);

            return(true);
        }
コード例 #28
0
        private InternalOperationReturnValues GetProfileLiteSync(string scenario, out string profileResourceId, out string expressionProfileResourceId, bool syncToOwner)
        {
            MsnServiceState serviceState   = new MsnServiceState(scenario, "GetProfile", false);
            StorageService  storageService = (StorageService)CreateService(MsnServiceType.Storage, serviceState);

            GetProfileRequestType getprofileRequest = new GetProfileRequestType();

            Alias alias = new Alias();

            alias.NameSpace = "MyCidStuff";
            alias.Name      = Convert.ToString(NSMessageHandler.Owner.CID);

            Handle pHandle = new Handle();

            pHandle.RelationshipName = "MyProfile";
            pHandle.Alias            = alias;

            getprofileRequest.profileHandle     = pHandle;
            getprofileRequest.profileAttributes = new profileAttributes();

            ExpressionProfileAttributesType expAttrib = CreateFullExpressionProfileAttributes();

            getprofileRequest.profileAttributes.ExpressionProfileAttributes = expAttrib;

            try
            {
                ChangeCacheKeyAndPreferredHostForSpecifiedMethod(storageService, MsnServiceType.Storage, serviceState, getprofileRequest);
                GetProfileResponse response = storageService.GetProfile(getprofileRequest);

                #region Process Profile
                profileResourceId = response.GetProfileResult.ResourceID;

                if (response.GetProfileResult.ExpressionProfile == null)
                {
                    Trace.WriteLineIf(Settings.TraceSwitch.TraceInfo, "Get profile cannot get expression profile of this owner.");
                    NSMessageHandler.ContactService.Deltas.Profile.HasExpressionProfile = false;
                    NSMessageHandler.ContactService.Deltas.Profile.DisplayName          = NSMessageHandler.Owner.Name;

                    expressionProfileResourceId = string.Empty;
                    return(InternalOperationReturnValues.NoExpressionProfile);
                }
                else
                {
                    NSMessageHandler.ContactService.Deltas.Profile.HasExpressionProfile           = true;
                    NSMessageHandler.ContactService.Deltas.Profile.ExpressionProfile.ResourceID   = response.GetProfileResult.ExpressionProfile.ResourceID;
                    NSMessageHandler.ContactService.Deltas.Profile.ExpressionProfile.DateModified = response.GetProfileResult.ExpressionProfile.DateModified;

                    expressionProfileResourceId = response.GetProfileResult.ExpressionProfile.ResourceID;
                }

                NSMessageHandler.ContactService.Deltas.Profile.DateModified = response.GetProfileResult.DateModified;
                NSMessageHandler.ContactService.Deltas.Profile.ResourceID   = response.GetProfileResult.ResourceID;

                // Display name
                NSMessageHandler.ContactService.Deltas.Profile.DisplayName = response.GetProfileResult.ExpressionProfile.DisplayName;

                // Personal status
                if (response.GetProfileResult.ExpressionProfile.PersonalStatus != null)
                {
                    NSMessageHandler.ContactService.Deltas.Profile.PersonalMessage = response.GetProfileResult.ExpressionProfile.PersonalStatus;
                }

                NSMessageHandler.ContactService.Deltas.Save(true);

                // Display photo
                if (null != response.GetProfileResult.ExpressionProfile.Photo)
                {
                    foreach (DocumentStream docStream in response.GetProfileResult.ExpressionProfile.Photo.DocumentStreams)
                    {
                        if (docStream.DocumentStreamType != "UserTileStatic")
                        {
                            continue;
                        }

                        if (NSMessageHandler.ContactService.Deltas.Profile.Photo.PreAthURL == docStream.PreAuthURL)
                        {
                            if (syncToOwner)
                            {
                                DisplayImage newDisplayImage = new DisplayImage(NSMessageHandler.Owner.Account.ToLowerInvariant(), NSMessageHandler.ContactService.Deltas.Profile.Photo.DisplayImage);

                                NSMessageHandler.Owner.DisplayImage = newDisplayImage;
                            }
                        }
                        else
                        {
                            string requesturi = docStream.PreAuthURL;
                            if (requesturi.StartsWith("/"))
                            {
                                requesturi = "http://blufiles.storage.msn.com" + requesturi;  //I found it http://byfiles.storage.msn.com is also ok
                            }

                            // Don't urlencode t= :))
                            string usertitleURL = requesturi + "?t=" + System.Web.HttpUtility.UrlEncode(NSMessageHandler.MSNTicket.SSOTickets[SSOTicketType.Storage].Ticket.Substring(2));
                            SyncUserTile(usertitleURL,
                                         syncToOwner,
                                         delegate(object imageStream)
                            {
                                SerializableMemoryStream ms = imageStream as SerializableMemoryStream;
                                NSMessageHandler.ContactService.Deltas.Profile.Photo.Name         = response.GetProfileResult.ExpressionProfile.Photo.Name;
                                NSMessageHandler.ContactService.Deltas.Profile.Photo.DateModified = response.GetProfileResult.ExpressionProfile.Photo.DateModified;
                                NSMessageHandler.ContactService.Deltas.Profile.Photo.ResourceID   = response.GetProfileResult.ExpressionProfile.Photo.ResourceID;
                                NSMessageHandler.ContactService.Deltas.Profile.Photo.PreAthURL    = docStream.PreAuthURL;
                                if (ms != null)
                                {
                                    NSMessageHandler.ContactService.Deltas.Profile.Photo.DisplayImage = ms;
                                }

                                NSMessageHandler.ContactService.Deltas.Save(true);
                            },
                                         delegate(object param)
                            {
                                Exception ex = param as Exception;
                                Trace.WriteLineIf(Settings.TraceSwitch.TraceError, "Get DisplayImage error: " + ex.Message, GetType().Name);
                                if (NSMessageHandler.Owner.UserTileURL != null)
                                {
                                    SyncUserTile(NSMessageHandler.Owner.UserTileURL.AbsoluteUri, syncToOwner, null, null);
                                }
                            });
                        }
                    }
                }

                #endregion
            }
            catch (Exception ex)
            {
                OnServiceOperationFailed(storageService, new ServiceOperationFailedEventArgs("GetProfile", ex));
                Trace.WriteLineIf(Settings.TraceSwitch.TraceError, "GetProfile error: " + ex.Message, GetType().FullName);
                expressionProfileResourceId = string.Empty;
                profileResourceId           = string.Empty;

                if (ex.Message.ToLowerInvariant().Contains("does not exist"))
                {
                    return(InternalOperationReturnValues.ProfileNotExist);
                }


                return(InternalOperationReturnValues.RequestFailed);
            }

            return(InternalOperationReturnValues.Succeed);
        }
コード例 #29
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);
        }
コード例 #30
0
ファイル: MSNService.cs プロジェクト: supercoeus/msnp-sharp
        protected internal SoapHttpClientProtocol CreateService(MsnServiceType serviceType, MsnServiceState asyncObject)
        {
            SoapHttpClientProtocol service = null;

            switch (serviceType)
            {
            case MsnServiceType.AB:

                ABServiceBinding abService = new ABServiceBindingWrapper(NSMessageHandler);
                abService.Timeout   = Int32.MaxValue;
                abService.UserAgent = Properties.Resources.WebServiceUserAgent;
                abService.ABApplicationHeaderValue = new ABApplicationHeader();
                abService.ABApplicationHeaderValue.ApplicationId   = NSMessageHandler.Credentials.ClientInfo.ApplicationId;
                abService.ABApplicationHeaderValue.IsMigration     = false;
                abService.ABApplicationHeaderValue.PartnerScenario = Convert.ToString(asyncObject.PartnerScenario);
                abService.ABApplicationHeaderValue.CacheKey        = NSMessageHandler.ContactService.Deltas.CacheKeys[CacheKeyType.OmegaContactServiceCacheKey];
                abService.ABAuthHeaderValue                     = new ABAuthHeader();
                abService.ABAuthHeaderValue.TicketToken         = NSMessageHandler.MSNTicket.SSOTickets[SSOTicketType.Contact].Ticket;
                abService.ABAuthHeaderValue.ManagedGroupRequest = false;

                service = abService;
                break;

            case MsnServiceType.Sharing:

                SharingServiceBinding sharingService = new SharingServiceBindingWrapper(NSMessageHandler);
                sharingService.Timeout   = Int32.MaxValue;
                sharingService.UserAgent = Properties.Resources.WebServiceUserAgent;
                sharingService.ABApplicationHeaderValue = new ABApplicationHeader();
                sharingService.ABApplicationHeaderValue.ApplicationId   = NSMessageHandler.Credentials.ClientInfo.ApplicationId;
                sharingService.ABApplicationHeaderValue.IsMigration     = false;
                sharingService.ABApplicationHeaderValue.PartnerScenario = Convert.ToString(asyncObject.PartnerScenario);
                sharingService.ABApplicationHeaderValue.BrandId         = NSMessageHandler.MSNTicket.MainBrandID;
                sharingService.ABApplicationHeaderValue.CacheKey        = NSMessageHandler.ContactService.Deltas.CacheKeys[CacheKeyType.OmegaContactServiceCacheKey];
                sharingService.ABAuthHeaderValue                     = new ABAuthHeader();
                sharingService.ABAuthHeaderValue.TicketToken         = NSMessageHandler.MSNTicket.SSOTickets[SSOTicketType.Contact].Ticket;
                sharingService.ABAuthHeaderValue.ManagedGroupRequest = false;

                service = sharingService;
                break;

            case MsnServiceType.Storage:

                StorageService storageService = new StorageServiceWrapper(NSMessageHandler);
                storageService.StorageApplicationHeaderValue = new StorageApplicationHeader();
                storageService.StorageApplicationHeaderValue.ApplicationID = Properties.Resources.ApplicationStrId;
                storageService.StorageApplicationHeaderValue.Scenario      = Convert.ToString(asyncObject.PartnerScenario);
                storageService.StorageUserHeaderValue             = new StorageUserHeader();
                storageService.StorageUserHeaderValue.Puid        = 0;
                storageService.StorageUserHeaderValue.TicketToken = NSMessageHandler.MSNTicket.SSOTickets[SSOTicketType.Storage].Ticket;
                storageService.AffinityCacheHeaderValue           = new AffinityCacheHeader();
                storageService.AffinityCacheHeaderValue.CacheKey  = NSMessageHandler.ContactService.Deltas.CacheKeys[CacheKeyType.StorageServiceCacheKey];

                service = storageService;
                break;

            case MsnServiceType.WhatsUp:

                WhatsUpServiceBinding wuService = new WhatsUpServiceBindingWrapper(NSMessageHandler);
                wuService.Timeout             = 60000;
                wuService.UserAgent           = Properties.Resources.WebServiceUserAgent;
                wuService.WNApplicationHeader = new WNApplicationHeaderType();
                wuService.WNApplicationHeader.ApplicationId = Properties.Resources.WhatsupServiceAppID;
                wuService.WNAuthHeader             = new WNAuthHeaderType();
                wuService.WNAuthHeader.TicketToken = NSMessageHandler.MSNTicket.SSOTickets[SSOTicketType.WhatsUp].Ticket;

                service = wuService;
                break;

            case MsnServiceType.Directory:

                DirectoryService dirService = new DirectoryServiceWrapper(NSMessageHandler);
                dirService.Timeout = Int32.MaxValue;
                dirService.SOAPApplicationHeaderValue = new SOAPApplicationHeader();
                dirService.SOAPApplicationHeaderValue.ApplicationId = Properties.Resources.DirectoryServiceAppID;
                dirService.SOAPApplicationHeaderValue.Scenario      = Convert.ToString(asyncObject.PartnerScenario);
                dirService.SOAPUserHeaderValue             = new SOAPUserHeader();
                dirService.SOAPUserHeaderValue.TicketToken = NSMessageHandler.MSNTicket.SSOTickets[SSOTicketType.Directory].Ticket;

                service = dirService;
                break;
            }

            if (service != null)
            {
                service.EnableDecompression = Settings.EnableGzipCompressionForWebServices;

                if (asyncObject != null && asyncObject.AddToAsyncList)
                {
                    lock (asyncStates)
                    {
                        asyncStates[asyncObject] = service;
                    }
                }
            }

            return(service);
        }