Satrabel.OpenUrlRewriter.Components.CacheController.GetLanguageRule C# (CSharp) Method

GetLanguageRule() public method

public GetLanguageRule ( string Url ) : Satrabel.HttpModules.Provider.UrlRule
Url string
return Satrabel.HttpModules.Provider.UrlRule
        public UrlRule GetLanguageRule(string Url)
        {
            var rule = _rules.FirstOrDefault(r => r.RuleType == UrlRuleType.Culture && r.Url == Url);
            return rule;
        }

Usage Example

        private static void GetCulture(CacheController cacheCtrl, Dictionary<string, Locale> dicLocales, RewriterAction action, int portalID)
        {
            string cultureCode = string.Empty;
            //cultureUrl = string.Empty;
            // check if multi language site
            if (dicLocales.Count > 1)
            {
                String[] splitUrl = action.WorkUrl.TrimStart('/').Split('/');
                // asume culture is always first part of url afetr alias
                string culturePart = splitUrl[0];
                // try to find UrlRule
                var ruleL = cacheCtrl.GetLanguageRule(culturePart.ToLower());
                if (ruleL != null)
                {
                    if (ruleL.Action == UrlRuleAction.Redirect)
                    {
                        //action.RedirectUrl = redirect.RedirectUrl.Replace("/" + culturePart + "/", "/" + ruleL.RedirectDestination + "/");
                        action.RedirectCulture = ruleL.RedirectDestination;
                        action.Status = ruleL.RedirectStatus;
                        action.DoRedirect = true;
                        action.Raison += "+Culture:" + ruleL.Url + ">" + ruleL.RedirectDestination;
                    }
                    else if (culturePart != ruleL.Url) // because different case
                    {
                        action.RedirectCulture = ruleL.Url;
                        action.DoRedirect = true;
                        action.Raison += "+Culture Wrong case";
                    }
                    culturePart = ruleL.CultureCode;
                }

                foreach (KeyValuePair<string, Locale> key in dicLocales)
                {
                    if (key.Key.ToLower().Equals(culturePart.ToLower()))
                    {
                        action.CultureCode = key.Value.Code;
                        action.CultureUrl = splitUrl[0];
                        action.WorkUrl = action.WorkUrl.Substring(action.CultureUrl.Length + 1);
                        break;
                    }
                }
                if (string.IsNullOrEmpty(action.CultureUrl))
                {
                    Locale DefaultLocale = LocaleController.Instance.GetDefaultLocale(portalID);
                    action.RedirectCulture = DefaultLocale.Code;
                    var ruleD = cacheCtrl.GetLanguageRule(culturePart.ToLower());
                    if (ruleD != null && ruleL.Action == UrlRuleAction.Redirect)
                    {
                        action.RedirectCulture = ruleD.RedirectDestination;
                        action.Status = ruleD.RedirectStatus;
                    }
                    action.DoRedirect = true;
                    action.Raison += "+Language empty";
                }

            }
        }