Beispiel #1
0
        public ShellContact(Contact coreContact, IMAddressInfoType type, string objectID, NSMessageHandler handler)
            : base(coreContact.AddressBookId, objectID, type, 0, handler)
        {
            CoreContact = coreContact;
            SetName(CoreContact.Name);
            SetNickName(CoreContact.NickName);
            SetList(RoleLists.Forward);
            PersonalMessage = CoreContact.PersonalMessage;

            CoreContact.ScreenNameChanged += new EventHandler<EventArgs>(CoreContact_ScreenNameChanged);
            CoreContact.PersonalMessageChanged += new EventHandler<EventArgs>(CoreContact_PersonalMessageChanged);
        }
Beispiel #2
0
        /// <summary>
        /// Remove a contact with specified account and client type.
        /// </summary>
        /// <param name="account"></param>
        /// <param name="type"></param>
        public bool Remove(string account, IMAddressInfoType type)
        {
            bool removed = false;

            if (type != IMAddressInfoType.None)
            {
                string hash = Contact.MakeHash(account, type);

                lock (SyncRoot)
                {
                    removed = base[type].Remove(hash);

                    if (removed)
                    {
                        bool found = false;

                        foreach (IMAddressInfoType deleteList in addressTypes)
                        {
                            if (deleteList != IMAddressInfoType.None)
                            {
                                if (base[deleteList].ContainsKey(hash))
                                {
                                    found = true; // Can't be deleted...
                                    break;
                                }
                            }
                        }

                        // None found. It is time to remove from none list, too.
                        if (!found)
                        {
                            base[IMAddressInfoType.None].Remove(hash);
                        }
                    }
                }
            }

            return(removed);
        }
Beispiel #3
0
 protected internal Contact(string abId, string account, IMAddressInfoType cliType, long cid, NSMessageHandler handler)
     : this(new Guid(abId), account, cliType, cid, handler)
 {
 }
Beispiel #4
0
 protected internal Contact(string account, IMAddressInfoType cliType, NSMessageHandler handler)
     : this(Guid.Empty, account, cliType, 0, handler)
 {
 }
Beispiel #5
0
        internal static bool ParseFullAccount(
            string fullAccount,
            out IMAddressInfoType accountAddressType, out string account,
            out IMAddressInfoType viaAccountAddressType, out string viaAccount)
        {
            accountAddressType = viaAccountAddressType = IMAddressInfoType.None;
            account = viaAccount = String.Empty;

            string[] memberAndNetwork = fullAccount.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);

            if (memberAndNetwork.Length > 0)
            {
                if (memberAndNetwork.Length > 1)
                {
                    // via=;
                    if (memberAndNetwork[1].Contains("via="))
                    {
                        string via = memberAndNetwork[1].Replace("via=", String.Empty);

                        string[] viaNetwork = via.Split(new char[] { ':' }, 2, StringSplitOptions.RemoveEmptyEntries);
                        if (viaNetwork.Length > 1)
                        {
                            viaAccountAddressType = (IMAddressInfoType)Enum.Parse(typeof(IMAddressInfoType), viaNetwork[0].ToString());
                            viaAccount = viaNetwork[1].ToLowerInvariant();

                            if (viaAccountAddressType == IMAddressInfoType.Telephone)
                                viaAccount = viaAccount.Replace("tel:", String.Empty);
                        }
                        else
                        {
                            // Assume windows live account
                            viaAccountAddressType = IMAddressInfoType.WindowsLive;
                            viaAccount = viaNetwork[0].ToLowerInvariant();
                        }
                    }
                }

                string[] member = memberAndNetwork[0].Split(new char[] { ':' }, 2, StringSplitOptions.RemoveEmptyEntries);

                if (member.Length > 1)
                {
                    accountAddressType = (IMAddressInfoType)Enum.Parse(typeof(IMAddressInfoType), member[0].ToString());
                    account = member[1].ToLowerInvariant();

                    if (accountAddressType == IMAddressInfoType.Telephone)
                        account = viaAccount.Replace("tel:", String.Empty);
                }
                else
                {
                    // Assume windows live account
                    accountAddressType = IMAddressInfoType.WindowsLive;
                    account = member[0].ToString().ToLowerInvariant();
                }

                return true;
            }

            return false;
        }
Beispiel #6
0
        public static string[] GenerateMailListForAdl(Dictionary <string, RoleLists> contacts, bool initial)
        {
            List <string> mls       = new List <string>();
            XmlDocument   xmlDoc    = new XmlDocument();
            XmlElement    mlElement = xmlDoc.CreateElement("ml");

            if (initial)
            {
                mlElement.SetAttribute("l", "1");
            }

            if (contacts == null || contacts.Count == 0)
            {
                mls.Add(mlElement.OuterXml);
                return(mls.ToArray());
            }

            List <string> sortedContacts = new List <string>(contacts.Keys);

            sortedContacts.Sort(CompareContactsHash);

            int        domaincontactcount = 0;
            string     currentDomain      = null;
            XmlElement domtelElement      = null;

            foreach (string contact_hash in sortedContacts)
            {
                String   name;
                String   domain;
                string[] arr  = contact_hash.Split(new string[] { ":", ";via=" }, StringSplitOptions.RemoveEmptyEntries);
                String   type = IMAddressInfoType.Yahoo.ToString();
                if (arr.Length > 0)
                {
                    type = arr[0];
                }

                IMAddressInfoType clitype = (IMAddressInfoType)Enum.Parse(typeof(IMAddressInfoType), type);
                type = ((int)clitype).ToString();
                RoleLists imlist = contacts[contact_hash];
                RoleLists pelist = imlist;
                pelist &= ~RoleLists.Hide; // Remove Hide role from PE service

                if (clitype == IMAddressInfoType.Telephone)
                {
                    if (!arr[1].StartsWith("+"))
                    {
                        continue;
                    }

                    domain = String.Empty;
                    name   = "tel:" + arr[1];
                }
                else if (clitype == IMAddressInfoType.RemoteNetwork)
                {
                    domain = String.Empty;
                    name   = arr[1];
                }
                else
                {
                    String[] usernameanddomain = arr[1].Split('@');
                    domain = usernameanddomain[1];
                    name   = usernameanddomain[0];
                }

                if (imlist != RoleLists.None)
                {
                    if (currentDomain != domain)
                    {
                        currentDomain      = domain;
                        domaincontactcount = 0;

                        if (clitype == IMAddressInfoType.Telephone)
                        {
                            domtelElement = xmlDoc.CreateElement("t");
                        }
                        else if (clitype == IMAddressInfoType.RemoteNetwork)
                        {
                            domtelElement = xmlDoc.CreateElement("n");
                        }
                        else
                        {
                            domtelElement = xmlDoc.CreateElement("d");
                            domtelElement.SetAttribute("n", currentDomain);
                        }
                        mlElement.AppendChild(domtelElement);
                    }

                    XmlElement contactElement = xmlDoc.CreateElement("c");
                    contactElement.SetAttribute("n", name);

                    if (clitype != IMAddressInfoType.Telephone && clitype != IMAddressInfoType.RemoteNetwork)
                    {
                        contactElement.SetAttribute("t", type);
                    }

                    // IM
                    XmlElement IMservice = xmlDoc.CreateElement("s");
                    IMservice.SetAttribute("l", ((int)imlist).ToString());
                    IMservice.SetAttribute("n", ServiceShortNames.IM.ToString());
                    contactElement.AppendChild(IMservice);

                    // PE
                    if (pelist != RoleLists.None)
                    {
                        XmlElement PEservice = xmlDoc.CreateElement("s");
                        PEservice.SetAttribute("l", ((int)pelist).ToString());
                        PEservice.SetAttribute("n", ServiceShortNames.PE.ToString());
                        contactElement.AppendChild(PEservice);
                    }

                    domtelElement.AppendChild(contactElement);
                    domaincontactcount++;
                }

                if (mlElement.OuterXml.Length > 7300)
                {
                    mlElement.AppendChild(domtelElement);
                    mls.Add(mlElement.OuterXml);

                    mlElement = xmlDoc.CreateElement("ml");
                    if (initial)
                    {
                        mlElement.SetAttribute("l", "1");
                    }

                    currentDomain      = null;
                    domaincontactcount = 0;
                }
            }

            if (domaincontactcount > 0 && domtelElement != null)
            {
                mlElement.AppendChild(domtelElement);
            }

            mls.Add(mlElement.OuterXml);
            return(mls.ToArray());
        }
Beispiel #7
0
        private static Contact GetGateway(string gatewayAccount, IMAddressInfoType gatewayType, NSMessageHandler nsMessageHandler)
        {
            Contact gateWay = null;

            if (gatewayType == IMAddressInfoType.Circle)
            {
                gateWay = nsMessageHandler.ContactList.GetCircle(gatewayAccount);
            }
            else if (gatewayType == IMAddressInfoType.TemporaryGroup)
            {
                gateWay = nsMessageHandler.GetMultiparty(gatewayAccount);
            }
            else
            {
                gateWay = nsMessageHandler.ContactList.GetContact(gatewayAccount, gatewayType);
            }

            return gateWay;
        }
Beispiel #8
0
        /// <summary>
        /// Add a member to the underlying membership data structure.
        /// </summary>
        /// <param name="servicetype"></param>
        /// <param name="account"></param>
        /// <param name="type"></param>
        /// <param name="memberrole"></param>
        /// <param name="member"></param>
        internal void AddMemberhip(ServiceName servicetype, string account, IMAddressInfoType type, RoleId memberrole, BaseMember member)
        {
            lock (SyncObject)
            {
                SerializableDictionary<RoleId, SerializableDictionary<string, BaseMember>> ms = SelectTargetMemberships(servicetype);
                if (ms != null)
                {
                    if (!ms.ContainsKey(memberrole))
                        ms.Add(memberrole, new SerializableDictionary<string, BaseMember>(0));

                    ms[memberrole][Contact.MakeHash(account, type)] = member;
                }
            }
        }
Beispiel #9
0
 private bool HasMemberhip(ServiceName servicetype, string account, IMAddressInfoType type, RoleId memberrole)
 {
     SerializableDictionary<RoleId, SerializableDictionary<string, BaseMember>> ms = SelectTargetMemberships(servicetype);
     return (ms != null) && ms.ContainsKey(memberrole) && ms[memberrole].ContainsKey(Contact.MakeHash(account, type));
 }
Beispiel #10
0
 public ShellContact(Guid addressBookID, string objectID, IMAddressInfoType type, NSMessageHandler handler)
     : base(addressBookID, objectID, type, 0, handler)
 {
     SetList(RoleLists.Forward);
 }
Beispiel #11
0
        internal void AddNewContact(string account, IMAddressInfoType network, string invitation)
        {
            if (NSMessageHandler.MSNTicket == MSNTicket.Empty || AddressBook == null)
            {
                OnServiceOperationFailed(this, new ServiceOperationFailedEventArgs("AddContact", new MSNPSharpException("You don't have access right on this action anymore.")));
                return;
            }

            CreateContactAndManageWLConnection(account, network, invitation);
        }
Beispiel #12
0
        private void CreateContactAndManageWLConnection(string account, IMAddressInfoType network, string invitation)
        {
            CreateContactAsync(
                account,
                network,
                Guid.Empty,
                delegate(object service, CreateContactCompletedEventArgs cce)
                {
                    if (cce.Error == null)
                    {
                        // Get windows live contact (yes)
                        Contact contact = NSMessageHandler.ContactList.GetContactWithCreate(account, IMAddressInfoType.WindowsLive);
                        contact.Guid = new Guid(cce.Result.CreateContactResult.contactId);

                        if (network == IMAddressInfoType.Telephone)
                            return;

                        ManageWLConnectionAsync(
                            contact.Guid, Guid.Empty, invitation,
                            true, true, 1, RelationshipTypes.IndividualAddressBook, (int)RelationshipState.None,
                            delegate(object wlcSender, ManageWLConnectionCompletedEventArgs mwlce)
                            {
                                string payload = ContactList.GenerateMailListForAdl(contact, RoleLists.Allow | RoleLists.Forward, false);
                                NSMessageHandler.MessageProcessor.SendMessage(new NSPayLoadMessage("ADL", payload));

                                // Get all contacts and send ADL for each contact... Yahoo, Facebook etc.
                                abRequest(PartnerScenario.ContactSave,
                                    delegate
                                    {
                                        msRequest(PartnerScenario.ContactSave,
                                            delegate
                                            {
                                                List<IMAddressInfoType> typesFound = new List<IMAddressInfoType>();
                                                IMAddressInfoType[] addressTypes = (IMAddressInfoType[])Enum.GetValues(typeof(IMAddressInfoType));

                                                foreach (IMAddressInfoType at in addressTypes)
                                                {
                                                    if (NSMessageHandler.ContactList.HasContact(account, at))
                                                    {
                                                        typesFound.Add(at);
                                                    }
                                                }

                                                if (typesFound.Count > 0)
                                                {
                                                    Dictionary<string, RoleLists> hashlist = new Dictionary<string, RoleLists>(2);

                                                    foreach (IMAddressInfoType im in typesFound)
                                                    {
                                                        hashlist.Add(Contact.MakeHash(account, im), RoleLists.Allow | RoleLists.Forward);
                                                    }

                                                    payload = ContactList.GenerateMailListForAdl(hashlist, false)[0];
                                                    NSMessageHandler.MessageProcessor.SendMessage(new NSPayLoadMessage("ADL", payload));
                                                }
                                            });
                                    });
                            });
                    }
                });
        }
Beispiel #13
0
 public ShellContact(Guid addressBookID, string objectID, IMAddressInfoType type, NSMessageHandler handler)
     : base(addressBookID, objectID, type, 0, handler)
 {
     SetList(RoleLists.Forward);
 }
Beispiel #14
0
 internal ShellContact CreateShellContact(string objectID, IMAddressInfoType type)
 {
     return(CreateShellContact(null, type, objectID));
 }
Beispiel #15
0
        protected internal Contact(Guid abId, string acc, IMAddressInfoType cliType, long cid, NSMessageHandler handler)
        {
            GenerateNewDCKeys();

            NSMessageHandler = handler;
            addressBookId = abId;
            account = acc.ToLowerInvariant();
            clientType = cliType;
            cId = cid;

            SetName(account);
            siblingString = ClientType.ToString() + ":" + account;
            hash = MakeHash(Account, ClientType);

            if (NSMessageHandler != null)
            {
                NSMessageHandler.ContactManager.Add(this);
            }

            displayImage = DisplayImage.CreateDefaultImage(Account);
            sceneImage = SceneImage.CreateDefaultImage(Account);
            personalMessage = new PersonalMessage();

            if (Account == RemoteNetworkGateways.FaceBookGatewayAccount ||
                Account == RemoteNetworkGateways.LinkedInGateway)
            {
                IsHiddenContact = true;
            }
        }
Beispiel #16
0
        private bool DetectBaseMember(BaseMember bm,
            out string account, out IMAddressInfoType type, out long cid, out string displayname)
        {
            bool ret = false;

            account = string.Empty;
            displayname = string.Empty;
            type = IMAddressInfoType.None;
            cid = 0;

            switch (bm.Type)
            {
                case MembershipType.Passport:
                    PassportMember pm = bm as PassportMember;

                    type = IMAddressInfoType.WindowsLive;
                    cid = pm.CID;

                    if (!pm.IsPassportNameHidden)
                    {
                        account = pm.PassportName;
                    }

                    break;

                case MembershipType.Email:

                    type = IMAddressInfoType.Yahoo;
                    account = ((EmailMember)bm).Email;

                    if (bm.Annotations != null)
                    {
                        foreach (Annotation anno in bm.Annotations)
                        {
                            switch (anno.Name)
                            {
                                case AnnotationNames.MSN_IM_BuddyType:
                                    if (!String.IsNullOrEmpty(anno.Value) && anno.Value.Contains(":"))
                                    {
                                        type = (IMAddressInfoType)int.Parse(anno.Value.Split(':')[0]);
                                    }
                                    break;
                            }
                        }
                    }

                    break;

                case MembershipType.Phone:
                    type = IMAddressInfoType.Telephone;
                    account = ((PhoneMember)bm).PhoneNumber;
                    break;

                case MembershipType.ExternalID:
                    type = IMAddressInfoType.RemoteNetwork;
                    account = ((ExternalIDMember)bm).SourceID;
                    break;

                case MembershipType.Domain:
                    account = ((DomainMember)bm).DomainName;
                    break;

                case MembershipType.Circle:
                    type = IMAddressInfoType.Circle;
                    account = ((CircleMember)bm).CircleId + "@" + Contact.DefaultHostDomain;
                    break;

                case MembershipType.Role:
                case MembershipType.Service:
                case MembershipType.Everyone:
                case MembershipType.Partner:
                    type = IMAddressInfoType.None;
                    account = bm.Type + "/" + bm.MembershipId;
                    break;
            }

            if (!String.IsNullOrEmpty(account) && type != IMAddressInfoType.None)
            {
                account = account.ToLowerInvariant();
                displayname = (bm.DisplayName == null) ? account : bm.DisplayName;
                ret = true;
            }

            return ret;
        }
Beispiel #17
0
        private void CreateContactAsync(string account, IMAddressInfoType network, Guid abId,
                                        CreateContactCompletedEventHandler callback)
        {
            if (NSMessageHandler.MSNTicket == MSNTicket.Empty || AddressBook == null)
            {
                OnServiceOperationFailed(this, new ServiceOperationFailedEventArgs("CreateContact", new MSNPSharpException("You don't have access right on this action anymore.")));
                return;
            }

            CreateContactType request = new CreateContactType();

            if (network == IMAddressInfoType.Telephone)
            {
                contactInfoType contactInfo = new contactInfoType();

                contactPhoneType cpt = new contactPhoneType();
                cpt.contactPhoneType1 = ContactPhoneTypes.ContactPhoneMobile;
                cpt.number            = account;

                contactInfo.phones  = new contactPhoneType[] { cpt };
                request.contactInfo = contactInfo;
            }
            else
            {
                contactHandleType contactHandle = new contactHandleType();
                contactHandle.Email    = account;
                contactHandle.Cid      = 0;
                contactHandle.Puid     = 0;
                contactHandle.CircleId = WebServiceConstants.MessengerIndividualAddressBookId;
                request.contactHandle  = contactHandle;
            }

            if (abId != Guid.Empty)
            {
                abHandleType abHandle = new abHandleType();
                abHandle.ABId = abId.ToString("D").ToLowerInvariant();
                abHandle.Puid = 0;
                abHandle.Cid  = 0;

                request.abHandle = abHandle;
            }

            MsnServiceState  createContactObject = new MsnServiceState(abId == Guid.Empty ? PartnerScenario.ContactSave : PartnerScenario.CircleSave, "CreateContact", true);
            ABServiceBinding abService           = (ABServiceBinding)CreateService(MsnServiceType.AB, createContactObject);

            abService.CreateContactCompleted += delegate(object service, CreateContactCompletedEventArgs e)
            {
                OnAfterCompleted(new ServiceOperationEventArgs(abService, MsnServiceType.AB, e));

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

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

            RunAsyncMethod(new BeforeRunAsyncMethodEventArgs(abService, MsnServiceType.AB, createContactObject, request));
        }
Beispiel #18
0
 /// <summary>
 /// Get a basemember from membership list.
 /// </summary>
 /// <param name="servicetype"></param>
 /// <param name="account"></param>
 /// <param name="type"></param>
 /// <param name="memberrole"></param>
 /// <returns>If the member not exist, return null.</returns>
 public BaseMember SelectBaseMember(ServiceName servicetype, string account, IMAddressInfoType type, RoleId memberrole)
 {
     SerializableDictionary<RoleId, SerializableDictionary<string, BaseMember>> ms = SelectTargetMemberships(servicetype);
     if ((ms != null) && ms.ContainsKey(memberrole))
     {
         string hash = Contact.MakeHash(account, type);
         if (ms[memberrole].ContainsKey(hash))
             return ms[memberrole][hash];
     }
     return null;
 }
Beispiel #19
0
        internal static bool IsSpecialGatewayType(IMAddressInfoType type)
        {
            if (type == IMAddressInfoType.Circle || type == IMAddressInfoType.TemporaryGroup)
                return true;

            if (type == IMAddressInfoType.RemoteNetwork)
                return true;

            return false;
        }
Beispiel #20
0
 internal void RemoveMemberhip(ServiceName servicetype, string account, IMAddressInfoType type, RoleId memberrole)
 {
     lock (SyncObject)
     {
         SerializableDictionary<RoleId, SerializableDictionary<string, BaseMember>> ms = SelectTargetMemberships(servicetype);
         if (ms != null && ms.ContainsKey(memberrole))
         {
             string hash = Contact.MakeHash(account, type);
             if (ms[memberrole].ContainsKey(hash))
             {
                 ms[memberrole].Remove(hash);
             }
         }
     }
 }
Beispiel #21
0
        internal static string MakeHash(string account, IMAddressInfoType type)
        {
            if (account == null)
                throw new ArgumentNullException("account");

            return type.ToString() + ":" + account.ToLowerInvariant();
        }
        private void CreateContactAsync(string account, IMAddressInfoType network, Guid abId,
            CreateContactCompletedEventHandler callback)
        {
            if (NSMessageHandler.MSNTicket == MSNTicket.Empty || AddressBook == null)
            {
                OnServiceOperationFailed(this, new ServiceOperationFailedEventArgs("CreateContact", new MSNPSharpException("You don't have access right on this action anymore.")));
                return;
            }

            CreateContactType request = new CreateContactType();

            if (network == IMAddressInfoType.Telephone)
            {
                contactInfoType contactInfo = new contactInfoType();

                contactPhoneType cpt = new contactPhoneType();
                cpt.contactPhoneType1 = ContactPhoneTypes.ContactPhoneMobile;
                cpt.number = account;

                contactInfo.phones = new contactPhoneType[] { cpt };
                request.contactInfo = contactInfo;
            }
            else
            {
                contactHandleType contactHandle = new contactHandleType();
                contactHandle.Email = account;
                contactHandle.Cid = 0;
                contactHandle.Puid = 0;
                contactHandle.CircleId = WebServiceConstants.MessengerIndividualAddressBookId;
                request.contactHandle = contactHandle;
            }

            if (abId != Guid.Empty)
            {
                abHandleType abHandle = new abHandleType();
                abHandle.ABId = abId.ToString("D").ToLowerInvariant();
                abHandle.Puid = 0;
                abHandle.Cid = 0;

                request.abHandle = abHandle;
            }

            MsnServiceState createContactObject = new MsnServiceState(abId == Guid.Empty ? PartnerScenario.ContactSave : PartnerScenario.CircleSave, "CreateContact", true);
            ABServiceBinding abService = (ABServiceBinding)CreateService(MsnServiceType.AB, createContactObject);
            abService.CreateContactCompleted += delegate(object service, CreateContactCompletedEventArgs e)
            {
                OnAfterCompleted(new ServiceOperationEventArgs(abService, MsnServiceType.AB, e));

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

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

            RunAsyncMethod(new BeforeRunAsyncMethodEventArgs(abService, MsnServiceType.AB, createContactObject, request));
        }
Beispiel #23
0
 internal static bool ParseFullAccount(
     string fullAccount,
     out IMAddressInfoType accountAddressType,
     out string account)
 {
     IMAddressInfoType viaAccountAddressType = IMAddressInfoType.None;
     string viaAccount = string.Empty;
     return ParseFullAccount(fullAccount, out accountAddressType, out account, out viaAccountAddressType, out viaAccount);
 }