コード例 #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            ErrorMessageContainer.Visible = false;
            ScriptManager.GetCurrent(this.Page).RegisterAsyncPostBackControl(Button1);
            if (CurrentRule != null)
            {
                RuleName.Text             = CurrentRule.RuleName;
                IsLeftRule                = (CurrentRule.RuleDirection == Rule.Direction.Left);
                RuleDirectionLiteral.Text = _ruleDirection.ToString();
            }
            else if (!string.IsNullOrEmpty(RuleName.Text))
            {
                CurrentRule    = RuleEngine.Instance.GetRule(RuleName.Text);
                _ruleDirection = (Rule.Direction)Enum.Parse(typeof(Rule.Direction), RuleDirectionLiteral.Text);
            }

            if (_ruleDirection == Rule.Direction.Both)
            {
                // Rule direction not set - check page against rule
                IsLeftRule = RuleEngine.Instance.IsLeftRule(CurrentPage.PageLink.ID, CurrentRule);
            }

            if (IsLeftRule && !CurrentRule.RuleVisibleLeft || !IsLeftRule && !CurrentRule.RuleVisibleRight)
            {
                this.Visible = false;
                return;
            }

            if (!IsPostBack)
            {
                PerformSearch_Click(null, null);
            }

            string pageTypes = "";

            if (IsLeftRule)
            {
                pageTypes = HttpUtility.UrlDecode(CurrentRule.PageTypeRight);
            }
            else
            {
                pageTypes = HttpUtility.UrlDecode(CurrentRule.PageTypeLeft);
            }

            if (!IsPostBack)
            {
                if (pageTypes.Split(';').Length > 2)
                {
                    PageTypesDropDown.DataSource = pageTypes.Split(';');
                    PageTypesDropDown.DataBind();
                    PageTypesContainer.Visible      = true;
                    PageTypesDropDown.SelectedIndex = PageTypesDropDown.Items.Count - 1;
                }
            }

            RelatedRelations.DataSource = GetRelationsForPage(CurrentPage.PageLink.ID, CurrentRule);
            RelatedRelations.DataBind();
        }
コード例 #2
0
        public static PageDataCollection GetRelatedPages(this PageReference pageReference, string firstRuleName, string firstRuleDirection, string secondRuleName, string secondRuleDirection)
        {
            try
            {
                Rule.Direction firstDir  = (Rule.Direction)Enum.Parse(typeof(Rule.Direction), firstRuleDirection);
                Rule.Direction secondDir = (Rule.Direction)Enum.Parse(typeof(Rule.Direction), secondRuleDirection);

                return(Helpers.PageHelper.GetPagesRelated(pageReference, firstRuleName, firstDir, secondRuleName, secondDir));
            }
            catch (Exception e) {
                throw new Exception("Could not parse rule direction. Should be Left, Right or Both - " + e.Message);
            }
        }
コード例 #3
0
        public override List <int> GetRelationPagesForPage(int pageID, Rule rule, Rule.Direction direction)
        {
            string     cacheKey            = GetCacheKey(pageID, rule.RuleName + "Int", direction);
            List <int> relationsForPageInt = (GetFromCache(cacheKey)) as List <int>;

            if (relationsForPageInt != null)
            {
                return(relationsForPageInt);
            }

            List <Relation> relationsForPage = new List <Relation>();
            List <int>      result           = new List <int>();

            relationsForPage = GetRelationsForPage(pageID, rule, direction);
            foreach (Relation relation in relationsForPage)
            {
                result.Add((direction == Rule.Direction.Left) ? relation.PageIDRight : relation.PageIDLeft);
            }
            StoreInCache(cacheKey, result);
            return(result);
        }
コード例 #4
0
        /// <summary>
        /// Returns a PageDataCollection with a distinct list of pages related through the given rule. Number of relations are added to PageName.
        /// </summary>
        /// <param name="allPages">PageDataCollection to create facets from</param>
        /// <param name="ruleName">Rule used for facet relations</param>
        /// <param name="direction">Direction of facet relations</param>
        /// <returns></returns>
        public static PageDataCollection FacetList(PageDataCollection allPages, string ruleName,
                                                   Rule.Direction direction)
        {
            List <Relation> relations = RelationEngine.Instance.GetAllRelations(ruleName);

            List <int> facets;

            if (direction == Rule.Direction.Right)
            {
                facets = (from id in relations select id.PageIDRight).Distinct().ToList();
            }
            else
            {
                facets = (from id in relations select id.PageIDLeft).Distinct().ToList();
            }

            PageDataCollection facetPages      = PageHelper.PageIDListToPages(facets);
            PageDataCollection facetsWithCount = new PageDataCollection();

            foreach (PageData facetPage in facetPages)
            {
                PageData writableFacet = facetPage.CreateWritableClone();
                if (direction == Rule.Direction.Right)
                {
                    writableFacet.PageName = writableFacet.PageName + " (" +
                                             (from id in relations where id.PageIDRight == facetPage.PageLink.ID select id)
                                             .Count() + ")";
                }
                else
                {
                    writableFacet.PageName = writableFacet.PageName + " (" +
                                             (from id in relations where id.PageIDLeft == facetPage.PageLink.ID select id)
                                             .Count() + ")";
                }
                facetsWithCount.Add(writableFacet);
            }
            new EPiServer.Filters.FilterSort(FilterSortOrder.Alphabetical).Sort(facetsWithCount);
            return(facetsWithCount);
        }
コード例 #5
0
        public override List <Relation> GetRelationsForPage(int pageID, Rule rule, Rule.Direction direction)
        {
            List <Relation> allRelations = GetAllRelations();

            string          cacheKey         = GetCacheKey(pageID, rule.RuleName, direction);
            List <Relation> relationsForPage = (GetFromCache(cacheKey)) as List <Relation>;

            if (relationsForPage != null)
            {
                return(relationsForPage);
            }
            Timer timer = new Timer("Query GetRelatedRelations for rule '" + rule.RuleName + "' with page " + pageID);

            switch (direction)
            {
            case Rule.Direction.Both:
                return(GetRelationsForPage(pageID, rule));

            case Rule.Direction.Left:
                var pageTypeQueryLeft = (from relations in allRelations
                                         where (relations.RuleName == rule.RuleName && (relations.PageIDLeft == pageID))
                                         select relations);
                relationsForPage = pageTypeQueryLeft.ToList();
                break;

            case Rule.Direction.Right:
                var pageTypeQueryRight = (from relations in allRelations
                                          where (relations.RuleName == rule.RuleName && (relations.PageIDRight == pageID))
                                          select relations);
                relationsForPage = pageTypeQueryRight.ToList();
                break;
            }

            timer.Stop();
            ValidationFilter(relationsForPage);
            StoreInCache(cacheKey, relationsForPage);
            return(relationsForPage);
        }
コード例 #6
0
        /*
         * public static List<int> GetRelationsForPageRoundTripHierarchy(int pageID, Rule rule, Relation relation)
         * {
         *  Timer timer = new Timer("Starting query GetRelatedRelations for rule '" + rule.RuleName + "' with page " + pageID);
         *  List<int> pages = new List<int>();
         *  PageDataCollection descendents = PageEngine.GetDescendents(pageID, rule, relation);
         *  foreach (PageData pd in descendents)
         *  {
         *      pages.Add(pd.PageLink.ID);
         *  }
         *  var pageTypeQuery = (from relations in RelationDataStore.Items<Relation>()
         *                       where (relations.RuleName == rule.RuleName && (pages.Contains(relations.PageIDLeft) || pages.Contains(relations.PageIDRight)))
         *                       select relations);
         *
         *  List<Relation> relationsForPage = pageTypeQuery.ToList();
         *  ValidationFilter(relationsForPage);
         *  List<int> result = new List<int>();
         *  foreach (Relation pageRelations in relationsForPage)
         *      result.Add(pageRelations.PageIDLeft == pageID ? pageRelations.PageIDRight : pageRelations.PageIDLeft);
         *  timer.Stop();
         *  return result;
         * }
         */

        public override List <int> GetRelationsForPageTwoHop(int pageID, Rule firstRule, Rule.Direction firstDirection, Rule secondRule, Rule.Direction secondDirection)
        {
            List <int> primaryRelations   = Instance.GetRelationPagesForPage(pageID, firstRule, firstDirection);
            List <int> secondaryRelations = new List <int>();

            foreach (int secondary in primaryRelations)
            {
                secondaryRelations.AddRange(Instance.GetRelationPagesForPage(secondary, secondRule, secondDirection));
            }
            return(secondaryRelations.ToList());
        }
コード例 #7
0
 private static bool IsValidDirection(bool fromClient, Rule.Direction direction)
 => direction.HasFlag(fromClient ? Rule.Direction.ToServer : Rule.Direction.ToClient);
コード例 #8
0
ファイル: PageHelper.cs プロジェクト: dsshan/Relations
 public static PageDataCollection GetPagesRelated(PageReference page, string firstRuleName, string secondRuleName)
 {
     Rule.Direction firstDirection  = (RuleEngine.Instance.IsLeftRule(page.ID, RuleEngine.Instance.GetRule(firstRuleName))) ? Rule.Direction.Left : Rule.Direction.Right;
     Rule.Direction secondDirection = (RuleEngine.Instance.IsLeftRule(page.ID, RuleEngine.Instance.GetRule(secondRuleName))) ? Rule.Direction.Left : Rule.Direction.Right;
     return(GetPagesRelated(page, firstRuleName, firstDirection, secondRuleName, secondDirection));
 }
コード例 #9
0
ファイル: PageHelper.cs プロジェクト: dsshan/Relations
        /// <summary>
        /// Getting related pages through two rules.
        /// </summary>
        /// <param name="page">Page to find relations to</param>
        /// <param name="firstRuleName">The first relation rule to search through</param>
        /// <param name="secondRuleName">The second relation rule to search through</param>
        /// <returns>All related pages</returns>
        public static PageDataCollection GetPagesRelated(PageReference page, string firstRuleName, Rule.Direction firstRuleDirection, string secondRuleName, Rule.Direction secondRuleDirection)
        {
            List <int> relations = RelationEngine.Instance.GetRelationsForPageTwoHop(page.ID, RuleEngine.Instance.GetRule(firstRuleName), firstRuleDirection, RuleEngine.Instance.GetRule(secondRuleName), secondRuleDirection);

            return(PageIDListToPages(relations));
        }
コード例 #10
0
ファイル: PageHelper.cs プロジェクト: dsshan/Relations
        public static PageDataCollection GetPagesRelated(PageReference page, string ruleName, Rule.Direction direction)
        {
            Rule currentRule = RuleEngine.Instance.GetRule(ruleName);

            List <int> relations = new List <int>();

            switch (direction)
            {
            case Rule.Direction.Both:
                relations = RelationEngine.Instance.GetRelationPagesForPage(page.ID, currentRule);
                break;

            case Rule.Direction.Left:
            case Rule.Direction.Right:
                relations = RelationEngine.Instance.GetRelationPagesForPage(page.ID, currentRule, direction);
                break;
            }
            FilterSortOrder    sortOrder;
            PageDataCollection result = PageIDListToPages(relations);

            sortOrder = (FilterSortOrder)((direction == Rule.Direction.Left)
                ? currentRule.SortOrderLeft
                : currentRule.SortOrderRight);
            new EPiServer.Filters.FilterSort(sortOrder).Sort(result);

            return(result);
        }
コード例 #11
0
 /// <summary>
 /// Get a list of all related pages through one direction of two given rules
 /// </summary>
 /// <param name="pageID"></param>
 /// <param name="firstRule"></param>
 /// <param name="firstDirection"></param>
 /// <param name="secondRule"></param>
 /// <param name="secondDirection"></param>
 /// <returns></returns>
 public abstract List <int> GetRelationsForPageTwoHop(int pageID, Rule firstRule, Rule.Direction firstDirection, Rule secondRule, Rule.Direction secondDirection);
コード例 #12
0
 private static string GetCacheKey(int pageid, string rule, Rule.Direction direction)
 {
     return("Relations-" + pageid + "-" + rule + "-" + direction.ToString());
 }
コード例 #13
0
 /// <summary>
 /// Get a list of all related pages through one direction of a given rule
 /// </summary>
 /// <param name="pageID">Page ID to get relations from</param>
 /// <param name="rule">Rule to get relations through</param>
 /// <param name="direction">Direction to search through</param>
 /// <returns></returns>
 public abstract List <int> GetRelationPagesForPage(int pageID, Rule rule, Rule.Direction direction);
コード例 #14
0
 /// <summary>
 /// Get all page relations for the rule through a specific direction
 /// </summary>
 /// <param name="pageID">Page ID to get relations from</param>
 /// <param name="rule">Rule to get relations through</param>
 /// <returns></returns>
 public abstract List <Relation> GetRelationsForPage(int pageID, Rule rule, Rule.Direction dir);
コード例 #15
0
 public override List <int> GetRelationPagesForPage(int pageID, Rule rule, Rule.Direction direction)
 {
     return(getFakeIntList());
 }
コード例 #16
0
 public override List <Relation> GetRelationsForPage(int pageID, Rule rule, Rule.Direction dir)
 {
     return(getFakeList(pageID, rule));
 }
コード例 #17
0
 public override List <int> GetRelationsForPageTwoHop(int pageID, Rule firstRule, Rule.Direction firstDirection, Rule secondRule, Rule.Direction secondDirection)
 {
     return(getFakeIntList());
 }
コード例 #18
0
        public override void CreateEditControls()
        {
            ddlRules = new DropDownList();
            ddlRules.Attributes["id"] = "ddlRule" + this.PropertyData.Name;

            ddlTextBox = new TextBox();

            Rule.Direction direction    = Rule.Direction.Both;
            string         SelectedRule = "";

            if (RuleSelector.Value != null && !string.IsNullOrEmpty(RuleSelector.Value.ToString()))
            {
                string[] propertyValue = RuleSelector.Value.ToString().Split(';');
                if (propertyValue != null && propertyValue.Length > 1)
                {
                    ddlTextBox.Text = RuleSelector.Value.ToString();
                    SelectedRule    = propertyValue[0];
                    direction       = (Rule.Direction)Enum.Parse(typeof(Rule.Direction), propertyValue[1]);
                }
            }
            List <Rule> allRules = RuleEngine.Instance.GetAllRulesList();

            ddlRules.Items.Clear();
            ddlRules.Items.Add(new ListItem(string.Empty, Core.LanguageHandler.Translate("selectRule", "Select rule")));
            foreach (Rule rule in allRules)
            {
                ddlRules.Items.Add(new ListItem(Core.LanguageHandler.TranslateRuleName(rule), rule.RuleName));
            }


            if (RuleSelector.Value != null)
            {
                foreach (ListItem li in ddlRules.Items)
                {
                    if (li.Value == SelectedRule)
                    {
                        li.Selected = true;
                    }
                }
            }

            string ruleName     = ddlRules.SelectedValue;
            Rule   selectedRule = RuleEngine.Instance.GetRule(ruleName);

            if (string.IsNullOrEmpty(ddlTextBox.Text))
            {
                ddlTextBox.Text = ruleName + ";Left";
            }

            StringBuilder ddlDirectionString = new StringBuilder("");

            ddlDirectionString.Append("<select class='episize240' id='" + "ddlDir" + this.PropertyData.Name + "'>");
            ddlDirectionString.Append("<option value='0' " + ((direction == Rule.Direction.Left) ? "selected" : "") + ">" + selectedRule.RuleTextLeft + "</option>");
            ddlDirectionString.Append("<option value='1' " + ((direction == Rule.Direction.Right) ? "selected" : "") + ">" + selectedRule.RuleTextRight + "</option>");
            ddlDirectionString.Append("</select>");

            LiteralControl ddlDirection = new LiteralControl(ddlDirectionString.ToString());

            StringBuilder directionValues = new StringBuilder();

            directionValues.Append("<script type='text/javascript'>");
            directionValues.Append("$(function() {");
            directionValues.Append("var rules" + this.PropertyData.Name + " = { ");
            for (int i = 0; i < allRules.Count; i++)
            {
                Rule rule = allRules[i];
                directionValues.Append(rule.RuleName + ": [");
                directionValues.Append("'" + rule.RuleTextLeft + "',");
                directionValues.Append("'" + rule.RuleTextRight + "'");
                directionValues.Append("]");
                if (i < allRules.Count - 1)
                {
                    directionValues.Append(",");
                }
            }
            directionValues.Append("};");
            directionValues.Append("$(document).ready(function() {$('select[id=\"" + "ddlRule" + this.PropertyData.Name + "\"]').change(function() {");
            //What do do when rule is changed
            directionValues.Append("var options = '';");
            directionValues.Append("$.each(rules" + this.PropertyData.Name + "[$(this).val()] || [], function(i, v) { ");
            directionValues.Append("options += '<option value=\"'+i+'\">' + v + '</option>';");
            directionValues.Append("});");
            directionValues.Append("$('select[id=\"" + "ddlDir" + this.PropertyData.Name + "\"]').html(options);");
            directionValues.Append("$('input[id=\"" + "ddlTextBox" + this.PropertyData.Name + "\"]').val($('select[id=\"" + "ddlRule" + this.PropertyData.Name + "\"]').val()+';Left');");
            directionValues.Append("});");
            directionValues.Append("});");
            //What do do when direction is changed
            directionValues.Append("$(document).ready(function() {$('select[id=\"" + "ddlDir" + this.PropertyData.Name + "\"]').change(function() {");
            directionValues.Append("$('input[id=\"" + "ddlTextBox" + this.PropertyData.Name + "\"]').val(");
            directionValues.Append("$('select[id=\"" + "ddlRule" + this.PropertyData.Name + "\"]').val()");
            directionValues.Append("+';'+");
            directionValues.Append("($('select[id=\"" + "ddlDir" + this.PropertyData.Name + "\"]').val() == '0' ? 'Left' : 'Right')");
            directionValues.Append(");");
            directionValues.Append("});");
            directionValues.Append("});");

            directionValues.Append("});");
            directionValues.Append("</script>");
            this.Controls.Add(new LiteralControl("<div style='border:1px solid #999;padding:5px;background-color:#eee;width:300px;margin-bottom:10px;'><div style='float:left;width:120px;'>Rule:</div><div float:left;>"));
            this.Controls.Add(ddlRules);
            this.Controls.Add(new LiteralControl("</div><div style='float:left;width:120px;margin-top:5px;'>Direction:</div><div float:left;margin-top:5px;>"));
            this.Controls.Add(ddlDirection);
            this.Controls.Add(new LiteralControl(directionValues.ToString()));
            this.Controls.Add(new LiteralControl("</div>"));
            if (this.PropertyData.Value != null)
            {
                ddlTextBox.Text = this.PropertyData.Value.ToString();
            }
            ddlTextBox.Attributes["id"]    = "ddlTextBox" + this.PropertyData.Name;
            ddlTextBox.Attributes["style"] = "display:none;";
            this.Controls.Add(ddlTextBox);
            this.Controls.Add(new LiteralControl("</div>"));
            SetupEditControls();
        }
コード例 #19
0
        protected void Page_Load(object sender, EventArgs e)
        {
            ErrorMessageContainer.Visible = false;
            ScriptManager.GetCurrent(this.Page).RegisterAsyncPostBackControl(Button1);
            if (CurrentRule != null)
            {
                RuleName.Text = CurrentRule.RuleName;
                IsLeftRule = (CurrentRule.RuleDirection == Rule.Direction.Left);
                RuleDirectionLiteral.Text = _ruleDirection.ToString();
            }
            else if (!string.IsNullOrEmpty(RuleName.Text))
            {
                CurrentRule = RuleEngine.Instance.GetRule(RuleName.Text);
                _ruleDirection = (Rule.Direction)Enum.Parse(typeof(Rule.Direction), RuleDirectionLiteral.Text);
            }

            if (_ruleDirection == Rule.Direction.Both)
            {
                // Rule direction not set - check page against rule
                IsLeftRule = RuleEngine.Instance.IsLeftRule(CurrentPage.PageLink.ID, CurrentRule);
            }

            if (IsLeftRule && !CurrentRule.RuleVisibleLeft || !IsLeftRule && !CurrentRule.RuleVisibleRight)
            {
                this.Visible = false;
                return;
            }

            if (!IsPostBack)
                PerformSearch_Click(null, null);

            string pageTypes = "";

            if(IsLeftRule)
                pageTypes =  HttpUtility.UrlDecode(CurrentRule.PageTypeRight);
            else
                pageTypes = HttpUtility.UrlDecode(CurrentRule.PageTypeLeft);

            if (!IsPostBack)
                if (pageTypes.Split(';').Length > 2)
                {
                    PageTypesDropDown.DataSource = pageTypes.Split(';');
                    PageTypesDropDown.DataBind();
                    PageTypesContainer.Visible = true;
                    PageTypesDropDown.SelectedIndex = PageTypesDropDown.Items.Count - 1;
                }

            RelatedRelations.DataSource = GetRelationsForPage(CurrentPage.PageLink.ID, CurrentRule);
            RelatedRelations.DataBind();
        }