Esempio n. 1
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));
        }
Esempio n. 2
0
 /// <remarks/>
 public void AddMemberAsync(AddMemberRequestType AddMember1) {
     this.AddMemberAsync(AddMember1, null);
 }
Esempio n. 3
0
 /// <remarks/>
 public void AddMemberAsync(AddMemberRequestType AddMember1, object userState) {
     if ((this.AddMemberOperationCompleted == null)) {
         this.AddMemberOperationCompleted = new System.Threading.SendOrPostCallback(this.OnAddMemberOperationCompleted);
     }
     this.InvokeAsync("AddMember", new object[] {
                 AddMember1}, this.AddMemberOperationCompleted, userState);
 }
Esempio n. 4
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;
        }