private void SetParentIndex(List <IndexName> indexList, List <UsersConfigMapConfigElement> languages, string primaryLanguage)
        {
            UsersConfigMapConfigElement primaryLanguageConfig = languages.Where(l => l.PrimaryLanguage.ToLower() == primaryLanguage.ToLower()).FirstOrDefault();

            if (primaryLanguageConfig != null)
            {
                if (!string.IsNullOrEmpty(primaryLanguageConfig.ParentIndex) && !string.IsNullOrEmpty(primaryLanguageConfig.ParentLanguage))
                {
                    throw new InvalidConfigurationException("Both ParentIndex and ParentLanguage cannot be set for " + primaryLanguage);
                }
                if (!string.IsNullOrEmpty(primaryLanguageConfig.ParentIndex) && (null != indexList.Where(i => i.name == primaryLanguageConfig.ParentIndex).FirstOrDefault()))
                {
                    //Set parentIndex to the value of @parentindex.
                    this.parentIndexClient = CreateSearchIndexClient(primaryLanguageConfig.ParentIndex);
                    this.parentLanguage    = primaryLanguageConfig.PrimaryLanguage;
                }
                if (!string.IsNullOrEmpty(primaryLanguageConfig.ParentLanguage))
                {
                    //Set the parentIndex to the value of @parentindex from the first ancestor that has @parentindex set.
                    string ancestorLanguageWithParentIndex = GetAncestorWithParentIndexLanguage(languages, primaryLanguageConfig.ParentLanguage);
                    if (!string.IsNullOrEmpty(ancestorLanguageWithParentIndex))
                    {
                        UsersConfigMapConfigElement ancestorLanguageConfig = languages.Where(l => l.PrimaryLanguage.ToLower() == ancestorLanguageWithParentIndex.ToLower()).FirstOrDefault();
                        if (ancestorLanguageConfig != null && !string.IsNullOrEmpty(ancestorLanguageConfig.ParentIndex))
                        {
                            this.parentIndexClient = CreateSearchIndexClient(ancestorLanguageConfig.ParentIndex);
                            this.parentLanguage    = ancestorLanguageConfig.PrimaryLanguage;
                        }
                    }
                }
            }
        }
        public static string GetParentLanguage(string primaryLanguage)
        {
            UsersConfigMapSection config = UsersConfigMapSection.Config;

            if (config != null)
            {
                List <UsersConfigMapConfigElement> languages             = config.SettingsList.ToList <UsersConfigMapConfigElement>();
                UsersConfigMapConfigElement        primaryLanguageConfig = languages.Where(l => l.PrimaryLanguage.ToLower() == primaryLanguage.ToLower()).FirstOrDefault();
                if (primaryLanguageConfig != null)
                {
                    if (!string.IsNullOrEmpty(primaryLanguageConfig.ParentLanguage) && !string.IsNullOrEmpty(primaryLanguageConfig.ParentIndex))
                    {
                        //Invalid config. @parentlanguage and @parentindex cannot both be set for @language.
                        return(string.Empty);
                    }
                    if (!string.IsNullOrEmpty(primaryLanguageConfig.ParentLanguage))
                    {
                        try
                        {
                            return(GetAncestorWithParentIndexLanguage(languages, primaryLanguageConfig.ParentLanguage));
                        }
                        catch (InvalidConfigurationException)
                        {
                            return(string.Empty);
                        }
                    }
                }
            }
            return(string.Empty);
        }
        private static string GetAncestorWithParentIndexLanguage(List <UsersConfigMapConfigElement> languages, string parentLanguage)
        {
            UsersConfigMapConfigElement currentParentLanguageConfig = languages.Where(l => l.PrimaryLanguage.ToLower() == parentLanguage.ToLower()).FirstOrDefault();

            if (currentParentLanguageConfig != null)
            {
                if (!string.IsNullOrEmpty(currentParentLanguageConfig.ParentLanguage) && !string.IsNullOrEmpty(currentParentLanguageConfig.ParentIndex))
                {
                    //Invalid config. @parentlanguage and @parentindex cannot both be set for @language.
                    throw new InvalidConfigurationException("Both ParentIndex and ParentLanguage cannot be set for " + parentLanguage);
                }
                if (!string.IsNullOrEmpty(currentParentLanguageConfig.ParentLanguage))
                {
                    //Look at the next ancestor.
                    return(GetAncestorWithParentIndexLanguage(languages, currentParentLanguageConfig.ParentLanguage));
                }
                if (!string.IsNullOrEmpty(currentParentLanguageConfig.ParentIndex))
                {
                    //We've found an ancestor that has a ParentIndex set so return the language.
                    return(currentParentLanguageConfig.PrimaryLanguage);
                }
                //Invalid config. @parentlanguage has been set, but an ancestor with a @parentindex cannot be found.
                throw new InvalidConfigurationException("parentlanguage has been set, but an ancestor with a parentindex cannot be found");
            }
            throw new InvalidConfigurationException("Invalid configuration for " + parentLanguage);
        }
        private void SetUltimateIndex(List <IndexName> indexList, List <UsersConfigMapConfigElement> languages)
        {
            UsersConfigMapConfigElement ultimateLanguageConfig = languages.Where(l => l.UltimateIndex != string.Empty).FirstOrDefault();

            if (ultimateLanguageConfig != null && (null != indexList.Where(i => i.name == ultimateLanguageConfig.UltimateIndex).FirstOrDefault()))
            {
                this.ultimateIndexClient = CreateSearchIndexClient(ultimateLanguageConfig.UltimateIndex);
                this.ultimateLanguage    = ultimateLanguageConfig.PrimaryLanguage;
            }
        }
        private void SetPrimaryIndex(List <IndexName> indexList, List <UsersConfigMapConfigElement> languages, string primaryLanguage)
        {
            UsersConfigMapConfigElement primaryLanguageConfig = languages.Where(l => l.PrimaryLanguage.ToLower() == primaryLanguage.ToLower()).FirstOrDefault();

            if (primaryLanguageConfig != null)
            {
                if (!string.IsNullOrEmpty(primaryLanguageConfig.Index) && (null != indexList.Where(i => i.name == primaryLanguageConfig.Index).FirstOrDefault()))
                {
                    //Set primaryIndex to the value of @index
                    this.primaryIndexClient = CreateSearchIndexClient(primaryLanguageConfig.Index);
                }
            }
        }
        public static string GetUltimateLanguage()
        {
            UsersConfigMapSection config = UsersConfigMapSection.Config;

            if (config != null)
            {
                List <UsersConfigMapConfigElement> languages = config.SettingsList.ToList <UsersConfigMapConfigElement>();
                UsersConfigMapConfigElement        ultimateLanguageConfig = languages.Where(l => l.UltimateIndex != string.Empty).FirstOrDefault();
                if (ultimateLanguageConfig != null)
                {
                    return(ultimateLanguageConfig.PrimaryLanguage);
                }
            }
            return(string.Empty);
        }