private List <ContactCandidate> ToContactCandidates(IList <User> users)
        {
            List <ContactCandidate> candidates = new List <ContactCandidate>();

            if (users == null)
            {
                return(candidates);
            }

            foreach (User user in users)
            {
                if (FilterDisplayName(user.DisplayName))
                {
                    ContactCandidate candidate = new ContactCandidate();
                    candidate.Name = user.DisplayName;

                    if (!string.IsNullOrEmpty(user.Id))
                    {
                        candidate.CorrespondingId = user.Id;
                    }

                    if (!string.IsNullOrEmpty(user.MobilePhone))
                    {
                        candidate.PhoneNumbers.Add(MakePhoneNumber(user.MobilePhone, PhoneNumberType.StandardType.MOBILE));
                    }

                    AddRange(candidate.PhoneNumbers, MakePhoneNumbers(user.BusinessPhones, PhoneNumberType.StandardType.BUSINESS));

                    candidates.Add(candidate);
                }
            }

            return(candidates);
        }
 private ContactFields ExtractContactFields(ContactCandidate contact)
 {
     return(new ContactFields
     {
         Name = contact.Name,
     });
 }
Example #3
0
        private IList <ContactCandidate> ToContactCandidates(IList <Person> people)
        {
            List <ContactCandidate> result = new List <ContactCandidate>();

            foreach (Person person in people)
            {
                if (person.Names != null && person.Names.Count != 0 && !string.IsNullOrEmpty(person.Names[0].DisplayName))
                {
                    ContactCandidate contact = new ContactCandidate();
                    contact.Name = person.Names[0].DisplayName;

                    if (person.PhoneNumbers != null)
                    {
                        foreach (GooglePhoneNumber googlePhoneNumber in person.PhoneNumbers)
                        {
                            if (!string.IsNullOrEmpty(googlePhoneNumber.Value))
                            {
                                PhoneNumber phoneNumber = new PhoneNumber();
                                phoneNumber.Number = googlePhoneNumber.Value;

                                if (!string.IsNullOrEmpty(googlePhoneNumber.Type))
                                {
                                    phoneNumber.Type = MapPhoneNumberType(googlePhoneNumber.Type);
                                }

                                contact.PhoneNumbers.Add(phoneNumber);
                            }
                        }
                    }

                    result.Add(contact);
                }
            }

            return(result);
        }
        private List <ContactCandidate> ToContactCandidates(IList <Contact> contacts)
        {
            List <ContactCandidate> candidates = new List <ContactCandidate>();

            if (contacts == null)
            {
                return(candidates);
            }

            foreach (Contact contact in contacts)
            {
                if (FilterDisplayName(contact.DisplayName))
                {
                    ContactCandidate candidate = new ContactCandidate();
                    candidate.Name = contact.DisplayName;

                    if (!string.IsNullOrEmpty(contact.Id))
                    {
                        candidate.CorrespondingId = contact.Id;
                    }

                    AddRange(candidate.PhoneNumbers, MakePhoneNumbers(contact.HomePhones, PhoneNumberType.StandardType.HOME));

                    if (!string.IsNullOrEmpty(contact.MobilePhone))
                    {
                        candidate.PhoneNumbers.Add(MakePhoneNumber(contact.MobilePhone, PhoneNumberType.StandardType.MOBILE));
                    }

                    AddRange(candidate.PhoneNumbers, MakePhoneNumbers(contact.BusinessPhones, PhoneNumberType.StandardType.BUSINESS));

                    candidates.Add(candidate);
                }
            }

            return(candidates);
        }
        public void Test_DeduplicateByPhoneNumbers()
        {
            var contacts = new List <ContactCandidate>();

            var andrew = new ContactCandidate();

            andrew.Name = "Andrew";
            var andrewHome = new PhoneNumber();

            andrewHome.Number            = "555 111 1111";
            andrewHome.Type.Standardized = PhoneNumberType.StandardType.HOME;
            andrew.PhoneNumbers.Add(andrewHome);
            var andrewBusiness = new PhoneNumber();

            andrewBusiness.Number            = "555 222 2222";
            andrewBusiness.Type.Standardized = PhoneNumberType.StandardType.BUSINESS;
            andrew.PhoneNumbers.Add(andrewBusiness);
            var andrewMobile = new PhoneNumber();

            andrewMobile.Number            = "555 333 3333";
            andrewMobile.Type.Standardized = PhoneNumberType.StandardType.MOBILE;
            andrew.PhoneNumbers.Add(andrewMobile);
            contacts.Add(andrew);

            var bob = new ContactCandidate();

            bob.Name = "Bob";
            var bobHome = new PhoneNumber();

            bobHome.Number            = "555 444 4444";
            bobHome.Type.Standardized = PhoneNumberType.StandardType.HOME;
            bob.PhoneNumbers.Add(bobHome);
            contacts.Add(bob);

            var chris = new ContactCandidate();

            chris.Name = "Chris";
            var chrisMobile = new PhoneNumber();

            chrisMobile.Number            = "555 222 2222";
            chrisMobile.Type.Standardized = PhoneNumberType.StandardType.MOBILE;
            chris.PhoneNumbers.Add(chrisMobile);
            var chrisHome = new PhoneNumber();

            chrisHome.Number            = "555 555 5555";
            chrisHome.Type.Standardized = PhoneNumberType.StandardType.HOME;
            chris.PhoneNumbers.Add(chrisHome);
            contacts.Add(chris);

            var delilah = new ContactCandidate();

            delilah.Name = "Delilah";
            var delilahHome = new PhoneNumber();

            delilahHome.Number            = "555 555 5555";
            delilahHome.Type.Standardized = PhoneNumberType.StandardType.HOME;
            delilah.PhoneNumbers.Add(delilahHome);
            var delilahBusiness = new PhoneNumber();

            delilahBusiness.Number            = "555 666 6666";
            delilahBusiness.Type.Standardized = PhoneNumberType.StandardType.BUSINESS;
            delilah.PhoneNumbers.Add(delilahBusiness);
            contacts.Add(delilah);

            var dedupedContacts = ContactDeduplicator.DeduplicateByPhoneNumbers(contacts);

            CheckThatPhoneNumbersAreUnique(dedupedContacts);

            var expectedContacts = new List <ContactCandidate>();

            var expectedAndrew = new ContactCandidate();

            expectedAndrew.Name = "Andrew";
            var expectedAndrewHome = new PhoneNumber();

            expectedAndrewHome.Number            = "555 111 1111";
            expectedAndrewHome.Type.Standardized = PhoneNumberType.StandardType.HOME;
            expectedAndrew.PhoneNumbers.Add(expectedAndrewHome);
            var expectedAndrewBusiness = new PhoneNumber();

            expectedAndrewBusiness.Number            = "555 222 2222";
            expectedAndrewBusiness.Type.Standardized = PhoneNumberType.StandardType.BUSINESS;
            expectedAndrew.PhoneNumbers.Add(expectedAndrewBusiness);
            var expectedAndrewMobile = new PhoneNumber();

            expectedAndrewMobile.Number            = "555 333 3333";
            expectedAndrewMobile.Type.Standardized = PhoneNumberType.StandardType.MOBILE;
            expectedAndrew.PhoneNumbers.Add(expectedAndrewMobile);
            var expectedChrisHome = new PhoneNumber();

            expectedChrisHome.Number            = "555 555 5555";
            expectedChrisHome.Type.Standardized = PhoneNumberType.StandardType.HOME;
            expectedAndrew.PhoneNumbers.Add(expectedChrisHome);
            var expectedDelilahBusiness = new PhoneNumber();

            expectedDelilahBusiness.Number            = "555 666 6666";
            expectedDelilahBusiness.Type.Standardized = PhoneNumberType.StandardType.BUSINESS;
            expectedAndrew.PhoneNumbers.Add(expectedDelilahBusiness);
            expectedContacts.Add(expectedAndrew);

            var expectedBob = new ContactCandidate();

            expectedBob.Name = "Bob";
            var expectedBobHome = new PhoneNumber();

            expectedBobHome.Number            = "555 444 4444";
            expectedBobHome.Type.Standardized = PhoneNumberType.StandardType.HOME;
            expectedBob.PhoneNumbers.Add(expectedBobHome);
            expectedContacts.Add(expectedBob);

            CheckContacts(expectedContacts, dedupedContacts);
        }
        private List <ContactCandidate> ToContactCandidates(IList <Person> people)
        {
            List <ContactCandidate> candidates = new List <ContactCandidate>();

            if (people == null)
            {
                return(candidates);
            }

            foreach (Person person in people)
            {
                if (FilterDisplayName(person.DisplayName))
                {
                    ContactCandidate candidate = new ContactCandidate();
                    candidate.Name = person.DisplayName;

                    if (!string.IsNullOrEmpty(person.Id))
                    {
                        candidate.CorrespondingId = person.Id;
                    }

                    if (person.Phones != null)
                    {
                        foreach (Phone phone in person.Phones)
                        {
                            if (!string.IsNullOrEmpty(phone.Number))
                            {
                                PhoneNumber phoneNumber = new PhoneNumber();
                                phoneNumber.Number = phone.Number;

                                if (phone.Type != null)
                                {
                                    switch (phone.Type)
                                    {
                                    case PhoneType.Home:
                                        phoneNumber.Type.Standardized = PhoneNumberType.StandardType.HOME;
                                        break;

                                    case PhoneType.Mobile:
                                        phoneNumber.Type.Standardized = PhoneNumberType.StandardType.MOBILE;
                                        break;

                                    case PhoneType.Business:
                                        phoneNumber.Type.Standardized = PhoneNumberType.StandardType.BUSINESS;
                                        break;

                                    default:
                                        phoneNumber.Type.FreeForm = phone.Type.ToString();
                                        break;
                                    }
                                }

                                candidate.PhoneNumbers.Add(phoneNumber);
                            }
                        }
                    }

                    candidates.Add(candidate);
                }
            }

            return(candidates);
        }