예제 #1
0
        private static void GetNamesByAnrFromContacts(UserContext userContext, AnrManager.NameParsingResult parsingResult, AnrManager.Options options, List <RecipientAddress> addresses)
        {
            if (string.IsNullOrEmpty(parsingResult.Name))
            {
                return;
            }
            if (userContext.TryGetMyDefaultFolderId(DefaultFolderType.Contacts) == null)
            {
                return;
            }
            string ambiguousName = parsingResult.ParsedSuccessfully ? parsingResult.RoutingAddress : parsingResult.Name;

            using (ContactsFolder contactsFolder = ContactsFolder.Bind(userContext.MailboxSession, DefaultFolderType.Contacts))
            {
                if (contactsFolder.IsValidAmbiguousName(ambiguousName))
                {
                    PropertyDefinition[] array;
                    object[][]           results;
                    if (AnrManager.IsMobileNumberInput(parsingResult, options))
                    {
                        array   = AnrManager.AnrProperties.Get(AnrManager.AnrProperties.PropertiesType.ContactFindSomeone, options);
                        results = contactsFolder.FindNamesView(new Dictionary <PropertyDefinition, object>
                        {
                            {
                                ContactSchema.MobilePhone,
                                parsingResult.Name
                            }
                        }, AnrManager.nameLimit, null, array);
                    }
                    else if (options.ResolveAgainstAllContacts || options.IsDefaultRoutingType("MOBILE"))
                    {
                        array   = AnrManager.AnrProperties.Get(AnrManager.AnrProperties.PropertiesType.ContactFindSomeone, options);
                        results = contactsFolder.FindSomeoneView(ambiguousName, AnrManager.nameLimit, null, array);
                    }
                    else
                    {
                        array   = AnrManager.AnrProperties.Get(AnrManager.AnrProperties.PropertiesType.ContactAnr, options);
                        results = contactsFolder.ResolveAmbiguousNameView(ambiguousName, AnrManager.nameLimit, null, array);
                    }
                    AnrManager.AddContacts(userContext, options, array, results, addresses);
                }
            }
        }