public override IEnumerable <Rule> GetRules(int pageID) { PageData page = PageEngine.GetPage(pageID); if (page != null) { string pageTypeName = HttpUtility.UrlEncode(page.PageTypeName); var pageTypeQuery = (from rules in RuleDataStore.Items <Rule>() where rules.PageTypeLeft.ToLower().Contains(pageTypeName.ToLower()) || rules.PageTypeRight.ToLower().Contains(pageTypeName.ToLower()) select rules); List <Rule> allRules = pageTypeQuery.ToList(); List <Rule> relevantRules = new List <Rule>(); foreach (Rule rule in allRules) { int startPage = (RuleEngine.Instance.IsLeftRule(pageID, rule) ? rule.RelationHierarchyStartLeft : rule.RelationHierarchyStartRight); if (startPage < 1 || IsDescendent(pageID, startPage)) { relevantRules.Add(rule); } } return(relevantRules); } return(new List <Rule>()); }
/* * public static PageDataCollection GetRelatedPagesRoundTripHierarchy(Rule rule, Relation relation, int pageID) * { * PageReference pr = new PageReference(pageID); * PageData origPage = DataFactory.Instance.GetPage(pr); * List<int> relationPages = RelationEngine.GetRelationsForPageRoundTripHierarchy(pageID, rule, relation); * return PageIDListToPages(relationPages); * }*/ /// <summary> /// Helper method for page relation getters to convert relations to pages. /// </summary> /// <param name="pageIDList">Collection of page IDs</param> /// <returns>Collection of pages</returns> public static PageDataCollection PageIDListToPages(List <int> pageIDList) { PageDataCollection pages = new PageDataCollection(); foreach (int pgid in pageIDList) { PageData pd = PageEngine.GetPage(pgid); if (pd != null && !pages.Contains(pd)) { pages.Add(pd); } } return(pages); }
protected override IEnumerable <IContent> GetContent(ContentQueryParameters parameters) { if (HttpContext.Current.Session != null) { HttpContext.Current.Session["ValidationResult"] = ""; } bool isLeftRule = (HttpUtility.HtmlDecode(parameters.AllParameters["direction"]) == "left"); var queryText = HttpUtility.HtmlDecode(parameters.AllParameters["queryText"]); var relationPageLeft = HttpUtility.HtmlDecode(parameters.AllParameters["relationPageLeft"]); string relationPageRightUrl = HttpUtility.HtmlDecode(parameters.AllParameters["relationPageRight"]); //string relationPageRight = ""; /* * if (!string.IsNullOrEmpty(relationPageRightUrl)) { * * Match match = regex.Match(HttpUtility.HtmlDecode(parameters.AllParameters["relationPageRight"])); * if (match.Success) * { * relationPageRight = (match.Groups[1].Value); * } * }*/ var relationRule = HttpUtility.HtmlDecode(parameters.AllParameters["relationRule"]); var action = HttpUtility.HtmlDecode(parameters.AllParameters["action"]); PageReference contextPage = (relationPageLeft != null) ? new PageReference(relationPageLeft) : null; PageDataCollection result = new PageDataCollection(); if (contextPage != null && relationPageLeft != null) { try { List <int> relations = new List <int>(); if (RuleEngine.Instance.GetRule(relationRule).RuleTextLeft == RuleEngine.Instance.GetRule(relationRule).RuleTextRight) { relations = RelationEngine.Instance.GetRelationPagesForPage(contextPage.ID, RuleEngine.Instance.GetRule(relationRule)); } else { relations = isLeftRule ? RelationEngine.Instance.GetRelationPagesForPage(contextPage.ID, RuleEngine.Instance.GetRule(relationRule), Rule.Direction.Left).Distinct <int>().ToList <int>() : RelationEngine.Instance.GetRelationPagesForPage(contextPage.ID, RuleEngine.Instance.GetRule(relationRule), Rule.Direction.Right).Distinct <int>().ToList <int>(); } foreach (int pageid in relations) { try { result.Add(PageEngine.GetPage(pageid)); } catch { Logging.Warning(string.Format("Error fetching page {0} related to {1}", pageid, contextPage.ID)); } } } catch { Logging.Warning(string.Format("Error fetching relations from page {0}", contextPage.ID)); } } return(result); }