Пример #1
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));
        }
Пример #2
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));
        }