Ejemplo n.º 1
0
        /// <summary>Renders the rule.</summary>
        /// <param name="output">The output.</param>
        /// <param name="rule">The rule.</param>
        /// <param name="index">The index.</param>
        private void RenderRule([NotNull] TextBlockWriter output, [NotNull] XElement rule, int index)
        {
            Debug.ArgumentNotNull(output, "output");
            Debug.ArgumentNotNull(rule, "rule");

            Guid id;
            var  uid = rule.GetAttributeValue("uid");

            if (!Guid.TryParse(uid, out id))
            {
                id = Guid.Empty;
            }

            var isClosed = this.IsEditable && this.AllowMultiple && this.CurrentRuleId != Guid.Empty && this.CurrentRuleId != id;
            var ruleId   = "rule_" + id.ToString("B").ToUpperInvariant();
            var title    = this.GetRuleTitle(rule, index);
            var style    = isClosed ? Visibility.Collapsed : Visibility.Visible;

            this.RenderRuleTitle(output, uid, title, ruleId, isClosed);

            output.WriteStartBlock(padding: new Thickness(16, 0, 0, 0), visibility: style);

            var inner = new TextBlockWriter(new TextBlock());

            this.RenderConditions(inner, rule);
            if (!this.SkipActions)
            {
                this.RenderActions(inner, rule);
            }

            if (!inner.IsEmpty)
            {
                output.Write(inner);
            }
            else
            {
                output.WriteStartBlock(padding: new Thickness(0, 4, 0, 2));
                output.Write("This rule has no conditions.", Brushes.DarkGray);
                output.WriteEndBlock();
            }

            output.WriteEndBlock();

            if (this.AllowMultiple)
            {
                output.WriteLine("--------------------------------------------------------");
            }
        }
Ejemplo n.º 2
0
        /// <summary>Renders the no rules.</summary>
        /// <param name="output">The output.</param>
        private void RenderNoRules([NotNull] TextBlockWriter output)
        {
            Debug.ArgumentNotNull(output, "output");

            output.WriteStartBlock(padding: new Thickness(16, 0, 0, 0));
            output.Write("There are no rules defined.", Brushes.DarkGray);
            output.WriteEndBlock();
        }
Ejemplo n.º 3
0
        /// <summary>Renders the binary operator.</summary>
        /// <param name="output">The output.</param>
        /// <param name="operatorElement">The operator element.</param>
        private void RenderBinaryOperator([NotNull] TextBlockWriter output, [NotNull] XElement operatorElement)
        {
            Debug.ArgumentNotNull(output, "output");
            Debug.ArgumentNotNull(operatorElement, "operatorElement");

            var op = operatorElement.Name.LocalName;

            // var uid = operatorElement.GetAttributeValue("uid");
            // var click = StringUtil.EscapeQuote("ToggleOperator(\"" + uid + "\")");

            var right = operatorElement.Element(1);

            if (right == null)
            {
                return;
            }

            // var leftLeaf = GetLeftLeaf(right);
            // var conditionUid = leftLeaf.GetAttributeValue("uid");

            output.WriteEndBlock();
            output.WriteStartBlock();

            if (op == "and")
            {
                output.Write("    ");
            }

            if (this.IsEditable)
            {
                output.WriteHyperlink(op, this.ToggleOperator);
            }
            else
            {
                output.Write(op);
            }

            output.Write(" ");
        }
Ejemplo n.º 4
0
        /// <summary>Renders the rule title.</summary>
        /// <param name="output">The output.</param>
        /// <param name="uid">The uid.</param>
        /// <param name="title">The title.</param>
        /// <param name="ruleId">The rule id.</param>
        /// <param name="isClosed">if set to <c>true</c> [is closed].</param>
        private void RenderRuleTitle([NotNull] TextBlockWriter output, [NotNull] string uid, [NotNull] string title, [NotNull] string ruleId, bool isClosed)
        {
            Debug.ArgumentNotNull(output, "output");
            Debug.ArgumentNotNull(uid, "uid");
            Debug.ArgumentNotNull(title, "title");
            Debug.ArgumentNotNull(ruleId, "ruleId");

            if (!this.IsEditable || !this.AllowMultiple)
            {
                output.WriteStartBlock();
                output.Write(title);
                output.WriteEndBlock();

                return;
            }

            // var activeStyle = isClosed ? string.Empty : " scRuleActive";
            output.WriteStartBlock();

            output.WriteHyperlink(title, ToggleRule);

            var stackPanel = new StackPanel
            {
                Orientation = Orientation.Horizontal
            };

            stackPanel.Children.Add(new Button {
                Content = "Edit"
            });
            stackPanel.Children.Add(new Button {
                Content = "Delete"
            });

            output.Write(stackPanel);

            output.WriteEndBlock();
        }
Ejemplo n.º 5
0
        /// <summary>Renders the unary operator.</summary>
        /// <param name="output">The output.</param>
        /// <param name="operatorElement">The operator element.</param>
        private void RenderUnaryOperator([NotNull] TextBlockWriter output, [NotNull] XElement operatorElement)
        {
            Debug.ArgumentNotNull(output, "output");
            Debug.ArgumentNotNull(operatorElement, "operatorElement");

            var op = operatorElement.Name.LocalName;

            if (this.IsEditable)
            {
                output.WriteHyperlink(op, ToggleOperator);
            }
            else
            {
                output.Write(op);
            }
        }
Ejemplo n.º 6
0
        /// <summary>Renders the condition.</summary>
        /// <param name="output">The output.</param>
        /// <param name="condition">The condition.</param>
        private void RenderCondition([NotNull] TextBlockWriter output, [NotNull] XElement condition)
        {
            Assert.ArgumentNotNull(output, "output");
            Assert.ArgumentNotNull(condition, "condition");

            var id = condition.GetAttributeValue("id");

            if (string.IsNullOrEmpty(id))
            {
                return;
            }

            var uid = condition.GetAttributeValue("uid");

            if (string.IsNullOrEmpty(uid))
            {
                return;
            }

            Item item;

            using (new SecurityDisabler())
            {
                item = Client.ContentDatabase.GetItem(id);
            }

            if (item == null)
            {
                output.Write(Translate.Text(Texts.UnknownCondition0, id));
                return;
            }

            var itemText = this.GetItemText(item);

            var text = this.RenderPrefix(output, condition, itemText);

            this.RenderText(output, condition, text);
        }