Beispiel #1
0
        private static MatchedUrl GetUrlMatch(string relativeUrl, string cultureCode, DataTable possibleUrls = null)
        {
            var PossibleUrlPatterns = new DataTable();

            PossibleUrlPatterns.Columns.Add("possibleUrl", typeof(string));
            PossibleUrlPatterns.Columns.Add("UrlSlugNodeId", typeof(int));
            PossibleUrlPatterns.Columns.Add("ClassName", typeof(string));
            DataRow row1 = PossibleUrlPatterns.NewRow();

            row1["possibleUrl"]   = "/wills-and-probate/help-and-advice/{item1?}";
            row1["UrlSlugNodeId"] = 443;
            row1["ClassName"]     = "TheLawSuperStore.HelpAndAdviceHub";
            PossibleUrlPatterns.Rows.Add(row1);
            var urlMatchup = new UrlByWildcardCollection();

            if (PossibleUrlPatterns.Rows.Count > 0)
            {
                foreach (DataRow dr in PossibleUrlPatterns.Rows)
                {
                    int    documentID = dr.Field <int>("UrlSlugNodeId");
                    string urlPattern = dr.Field <string>("possibleUrl");
                    string className  = dr.Field <string>("ClassName");
                    urlMatchup.AddUrl(urlPattern, new KenticoData(documentID, className));
                }

                var matchedUrl = urlMatchup.FindBaseUrl(relativeUrl);
                if (matchedUrl.UrlBreakdown == null || !matchedUrl.HasMatch)
                {
                    return(null);
                }
                return(matchedUrl);
            }
            return(null);
        }
Beispiel #2
0
        private static MatchedUrl GetUrlMatch(string relativeUrl, string cultureCode, DataTable possibleUrls = null)
        {
            var PossibleUrlPatterns = possibleUrls ?? GetPossibleUrls(relativeUrl, cultureCode);
            var urlMatchup          = new UrlByWildcardCollection();

            if (PossibleUrlPatterns.Rows.Count > 0)
            {
                foreach (DataRow dr in PossibleUrlPatterns.Rows)
                {
                    int    documentID = ValidationHelper.GetInteger(dr["UrlSlugNodeId"], 0);
                    string urlPattern = ValidationHelper.GetString(dr["possibleUrl"], "");
                    string className  = ValidationHelper.GetString(dr["ClassName"], "");
                    urlMatchup.AddUrl(urlPattern, new KenticoData(documentID, className));
                }

                var matchedUrl = urlMatchup.FindBaseUrl(relativeUrl);
                if (matchedUrl.UrlBreakdown == null || !matchedUrl.HasMatch)
                {
                    return(null);
                }
                return(matchedUrl);
            }
            return(null);
        }