コード例 #1
0
        private IEnumerable <Conditional <RenderText> > EnumerateRenderText(XElement commandElement, RenderText command, IConditionTreeItem baseConditions, IReadOnlyList <string> usedDefinitions)
        {
            // Only one text run can use a definition variable
            if (command.TextRuns.Count(r => r.Text.StartsWith("$") && availableDefinitions.Contains(r.Text.Substring(1))) > 1)
            {
                logger.LogError(commandElement, "Only one definition per text element is permitted");
                yield break;
            }

            var replaceRun      = command.TextRuns.FirstOrDefault(r => r.Text.StartsWith("$") && availableDefinitions.Contains(r.Text.Substring(1)));
            var replaceRunIndex = command.TextRuns.IndexOf(replaceRun);

            if (replaceRun == null)
            {
                // No definitions used
                yield return(new Conditional <RenderText>(command, baseConditions));

                yield break;
            }

            if (!ReportUndeclared(commandElement.GetFileRange(), new HashSet <string>(new [] { replaceRun.Text.Substring(1) }).Except(usedDefinitions).ToHashSet()))
            {
                yield break;
            }

            foreach (var definitionValue in definitionsSection.Definitions[replaceRun.Text.Substring(1)])
            {
                var conditions         = new ConditionTree(ConditionTree.ConditionOperator.AND, baseConditions, definitionValue.Conditions);
                var replacementRun     = new TextRun(definitionValue.Value, replaceRun.Formatting);
                var replacementCommand = (RenderText)command.Clone();
                replacementCommand.TextRuns.RemoveAt(replaceRunIndex);
                replacementCommand.TextRuns.Insert(replaceRunIndex, replacementRun);
                yield return(new Conditional <RenderText>(replacementCommand, conditions));
            }
        }
コード例 #2
0
        private IEnumerable <RenderDescription> ReadLineCommand(XElement element, IConditionTreeItem baseConditions, IReadOnlyList <string> usedDefinitions)
        {
            if (!element.GetAttribute("start", logger, out var start) ||
                !element.GetAttribute("end", logger, out var end))
            {
                yield break;
            }

            Console.WriteLine(start.Value);

            var startPoints = EnumerateComponentPoint(start, baseConditions, usedDefinitions).ToList();
            var endPoints   = EnumerateComponentPoint(end, baseConditions, usedDefinitions).ToList();

            foreach (var startPoint in startPoints)
            {
                foreach (var endPoint in endPoints)
                {
                    var command = new Line();

                    command.Start = startPoint.Value;
                    command.End   = endPoint.Value;

                    if (element.Attribute("thickness") != null)
                    {
                        command.Thickness = double.Parse(element.Attribute("thickness").Value);
                    }

                    var conditions = new ConditionTree(ConditionTree.ConditionOperator.AND,
                                                       baseConditions,
                                                       new ConditionTree(ConditionTree.ConditionOperator.AND, startPoint.Conditions, endPoint.Conditions));

                    yield return(new RenderDescription(conditions, new IRenderCommand[] { command }));
                }
            }
        }
コード例 #3
0
        /// <summary>
        ///     Builds the explanation of the element
        /// </summary>
        /// <param name="explanation"></param>
        /// <param name="explainSubElements">Precises if we need to explain the sub elements (if any)</param>
        public virtual void GetExplain(TextualExplanation explanation, bool explainSubElements)
        {
            explanation.Comment(this);

            if (!string.IsNullOrEmpty(getCondition()))
            {
                explanation.Write("IF ");
                if (ConditionTree != null)
                {
                    ConditionTree.GetExplain(explanation);
                }
                else
                {
                    explanation.Write(getCondition());
                }
                explanation.WriteLine(" THEN");
                explanation.Indent(2, () => explanation.Expression(this));
                explanation.WriteLine("END IF");
            }
            else
            {
                explanation.Expression(this);
                explanation.WriteLine();
            }
        }
コード例 #4
0
        private IEnumerable <RenderDescription> ReadRectCommand(XElement element, IConditionTreeItem baseConditions, IReadOnlyList <string> usedDefinitions)
        {
            if (!element.GetAttribute("x", logger, out var x) ||
                !element.GetAttribute("y", logger, out var y))
            {
                yield break;
            }

            var locationPoints = EnumerateComponentPoint(x, y, baseConditions, usedDefinitions).ToList();

            foreach (var locationPoint in locationPoints)
            {
                var command = new Rectangle();

                if (element.Attribute("thickness") != null)
                {
                    command.StrokeThickness = double.Parse(element.Attribute("thickness").Value);
                }

                var fill = element.Attribute("fill");
                if (fill != null && fill.Value.ToLowerInvariant() != "false")
                {
                    command.Fill = true;
                }

                command.Width  = double.Parse(element.Attribute("width").Value);
                command.Height = double.Parse(element.Attribute("height").Value);

                command.Location = locationPoint.Value;

                var conditions = new ConditionTree(ConditionTree.ConditionOperator.AND, baseConditions, locationPoint.Conditions);
                yield return(new RenderDescription(conditions, new IRenderCommand[] { command }));
            }
        }
コード例 #5
0
        public static IConditionTreeItem And(IEnumerable <IConditionTreeItem> input)
        {
            var result = ConditionTree.Empty;

            foreach (var item in input)
            {
                result = new ConditionTree(ConditionTree.ConditionOperator.AND, result, item);
            }
            return(result);
        }
コード例 #6
0
        /// <summary>
        /// Brings up the Criteria Editor for an Award
        /// </summary>
        public void EditCriteria()
        {
            // Grab the selected treenode
            TreeNode SelectedNode = ConditionTree.SelectedNode;

            // Make sure we have a node selected
            if (SelectedNode == null)
            {
                MessageBox.Show("Please select a criteria to edit.");
                return;
            }

            // Make sure its a child node, and not the topmost
            if (SelectedNode.Parent == null) // && SelectedNode.Nodes.Count != 0)
            {
                return;
            }

            // Open correct condition editor form
            if (SelectedNode.Tag is ObjectStat)
            {
                Child = new ObjectStatForm(SelectedNode);
            }
            else if (SelectedNode.Tag is PlayerStat)
            {
                Child = new ScoreStatForm(SelectedNode);
            }
            else if (SelectedNode.Tag is MedalOrRankCondition)
            {
                Child = new MedalConditionForm(SelectedNode);
            }
            else if (SelectedNode.Tag is GlobalStatMultTimes)
            {
                Child = new GlobalStatMultTimesForm(SelectedNode);
            }
            else if (SelectedNode.Tag is ConditionList)
            {
                Child = new ConditionListForm(SelectedNode);
            }
            else
            {
                return;
            }

            if (Child.ShowDialog() == DialogResult.OK)
            {
                ConditionList NN = new ConditionList(List.Type);
                NN = (ConditionList)MedalDataParser.ParseNodeConditions(ConditionTree.Nodes[0]);

                ConditionTree.Nodes.Clear();
                ConditionTree.Nodes.Add(NN.ToTree());
                ConditionTree.Refresh();
                ConditionTree.ExpandAll();
            }
        }
コード例 #7
0
        public ConditionsBenchmark()
        {
            pCtx = MockPromotionEvaluationContext();

            // Customer conditions
            _conditionIsRegisteredUser   = new ConditionIsRegisteredUser();
            _conditionIsEveryone         = new ConditionIsEveryone();
            _conditionIsFirstTimeBuyer   = new ConditionIsFirstTimeBuyer();
            _userGroupsContainsCondition = new UserGroupsContainsCondition()
            {
                Group = "Group7"
            };

            // Catalog conditions
            _conditionCategoryIs = new ConditionCategoryIs()
            {
                CategoryId = "8B77CD0F-5C4E-4BBA-9AEF-CD3022D0D2C1"
            };
            _conditionCodeContains = new ConditionCodeContains()
            {
                Keyword = "16-29"
            };
            _conditionCurrencyIs = new ConditionCurrencyIs()
            {
                Currency = "USD"
            };
            _conditionEntryIs = new ConditionEntryIs()
            {
                ProductIds = new string[] { "4B70F12A-25F8-4225-9A50-68C7E6DA25B3", "4B70F12A-25F8-4225-9A50-68C7E5DA25B2", "4B70F12B-25F8-4225-9A50-68C7E6DA25B2", "4B70F12A-2EF8-4225-9A50-68C7E6DA25B2", "4B70F12A-25F8-4225-9A50-68C7E6DA25B2" }
            };
            _conditionInStockQuantity = new ConditionInStockQuantity()
            {
                CompareCondition = ConditionOperation.Between, Quantity = 1, QuantitySecond = 100
            };
            _conditionHasNoSalePrice = new ConditionHasNoSalePrice();

            // Cart conditions
            _conditionAtNumItemsInCart = new ConditionAtNumItemsInCart()
            {
                CompareCondition = ConditionOperation.Between, NumItem = 1, NumItemSecond = 100
            };
            _conditionAtNumItemsInCategoryAreInCart = new ConditionAtNumItemsInCategoryAreInCart()
            {
                CompareCondition = ConditionOperation.Between, NumItem = 1, NumItemSecond = 100, CategoryId = "8B77CD0F-5C4E-4BBA-9AEF-CD3022D0D2C1"
            };
            _conditionAtNumItemsOfEntryAreInCart = new ConditionAtNumItemsOfEntryAreInCart()
            {
                CompareCondition = ConditionOperation.Between, NumItem = 1, NumItemSecond = 100, ProductId = "8B77CD0F-5C4E-4BBA-9AEF-CD3022D0D2C1"
            };
            _conditionCartSubtotalLeast = new ConditionCartSubtotalLeast()
            {
                CompareCondition = ConditionOperation.Between, SubTotal = 1, SubTotalSecond = 100
            };
        }
コード例 #8
0
        public IEnumerable <RenderDescription> Flatten(FlattenContext context)
        {
            // TODO: Group by/simplify conditions

            var flatConditions = new ConditionTree(ConditionTree.ConditionOperator.AND, context.AncestorConditions, Conditions);

            foreach (var command in Value.SelectMany(x => x.Flatten(context)))
            {
                var conditions = new ConditionTree(ConditionTree.ConditionOperator.AND, flatConditions, command.Conditions);
                yield return(new RenderDescription(conditions, new[] { command.Value }));
            }
        }
コード例 #9
0
    /// <summary>Parse the passed string into a condition and resolve against the saved GameData.</summary>
    /// <param name="script">The condition script to parse.</param>
    /// <returns>
    /// True if the script resolves to true with the current data, else false.
    /// Null or empty scripts return true as there is no condition.
    /// </returns>
    public bool Evaluate(string script)
    {
        if (string.IsNullOrWhiteSpace(script))
        {
            return(true);
        }

        var tokens = ConditionTokenizer.Tokenize(script);
        var ast    = new ConditionTree(tokens);
        var value  = Parse(ast.root);

        return(value);
    }
コード例 #10
0
 public static IConditionTreeItem AndListToTree(Stack<ConditionTreeLeaf> andList)
 {
     if (andList.Count > 1)
     {
         ConditionTree previous = new ConditionTree(ConditionTree.ConditionOperator.AND, andList.Pop(), ConditionTree.Empty);
         while (andList.Count > 0)
             previous = new ConditionTree(ConditionTree.ConditionOperator.AND, previous, andList.Pop());
         return previous;
     }
     else if (andList.Count == 1)
         return andList.Pop();
     else
         return ConditionTree.Empty;
 }
コード例 #11
0
        private IEnumerable <Conditional <ComponentPoint> > EnumerateComponentPoint(ComponentPointTemplate templatePoint, IConditionTreeItem baseConditions)
        {
            var variable = templatePoint.Variables.First();

            foreach (var condition in definitionsSection.Definitions[variable])
            {
                var cp = templatePoint.Construct(new Dictionary <string, double>
                {
                    [variable] = double.Parse(condition.Value),
                });

                var conditions = new ConditionTree(ConditionTree.ConditionOperator.AND, baseConditions, condition.Conditions);
                yield return(new Conditional <ComponentPoint>(cp, conditions));
            }
        }
コード例 #12
0
        public IEnumerable<Conditional<IRenderCommand>> Flatten(FlattenContext context)
        {
            foreach (var start in Start.Flatten(context))
            {
                foreach(var end in End.Flatten(context))
                {
                    var command = new Line(start.Value, end.Value, Thickness);
                    var conditions = new ConditionTree(
                        ConditionTree.ConditionOperator.AND,
                        start.Conditions,
                        end.Conditions);

                    yield return new Conditional<IRenderCommand>(command, conditions);
                }
            }
        }
コード例 #13
0
        /// <summary>
        /// Intializes the condition tree
        /// </summary>
        private void Initialize()
        {
            // Add Conditions to tree view
            ConditionTree.BeginUpdate();
            ConditionTree.Nodes.Clear();
            ConditionTree.Nodes.Add(List.ToTree());
            ConditionTree.EndUpdate();
            ConditionTree.ExpandAll();

            // Get the list name
            ListTypeBox.Text = ConditionList.Names[(int)List.Type];

            // Proccess list descritpion
            if (List.Type == ConditionType.And || List.Type == ConditionType.Or)
            {
                ConditionDescBox.Text = "Can contain unlimited number of sub criteria's";
            }
            else
            {
                ConditionDescBox.Text  = "Must contain ";
                ConditionDescBox.Text += (List.Type == ConditionType.Not)
                    ? "1 Sub Criteria."
                    : "2 Sub Criteria's. An optinal 3rd \"Value\" Criteria can be applied.";
            }

            // Hide value box's for unsupporting condition lists
            if (List.Type != ConditionType.Plus && List.Type != ConditionType.Div)
            {
                EnableValue.Visible = false;
                ValueBox.Visible    = false;
            }
            else
            {
                // Get our condition value, and add its value to the valuebox
                List <Condition> CL = List.GetConditions();
                if (CL.Count == 3)
                {
                    EnableValue.Checked = true;
                    ValueBox.Value      = Int32.Parse(CL[2].ToString());
                }
                else
                {
                    EnableValue.Checked = false;
                }
            }
        }
コード例 #14
0
        private IEnumerable <Conditional <ComponentPoint> > EnumerateComponentPoint(XAttribute x, XAttribute y, IConditionTreeItem baseConditions, IReadOnlyList <string> usedDefinitions)
        {
            if (!componentPointTemplateParser.TryParse(x, y, out var templatePoint))
            {
                yield break;
            }

            if (!templatePoint.Variables.Any())
            {
                if (componentPointParser.TryParse(x, y, out var componentPoint))
                {
                    yield return(new Conditional <ComponentPoint>(componentPoint, baseConditions));
                }

                yield break;
            }

            var undeclaredXUsages = templatePoint.XVariables.Except(usedDefinitions).ToHashSet();

            if (!ReportUndeclared(x.GetFileRange(), undeclaredXUsages))
            {
                yield break;
            }

            var undeclaredYUsages = templatePoint.YVariables.Except(usedDefinitions).ToHashSet();

            if (!ReportUndeclared(y.GetFileRange(), undeclaredYUsages))
            {
                yield break;
            }

            var variable = templatePoint.Variables.First();

            foreach (var condition in definitionsSection.Definitions[variable])
            {
                var cp = templatePoint.Construct(new Dictionary <string, double>
                {
                    [variable] = double.Parse(condition.Value),
                });

                var conditions = new ConditionTree(ConditionTree.ConditionOperator.AND, baseConditions, condition.Conditions);
                yield return(new Conditional <ComponentPoint>(cp, conditions));
            }
        }
コード例 #15
0
 public static IConditionTreeItem AndListToTree(Stack <ConditionTreeLeaf> andList)
 {
     if (andList.Count > 1)
     {
         ConditionTree previous = new ConditionTree(ConditionTree.ConditionOperator.AND, andList.Pop(), ConditionTree.Empty);
         while (andList.Count > 0)
         {
             previous = new ConditionTree(ConditionTree.ConditionOperator.AND, previous, andList.Pop());
         }
         return(previous);
     }
     else if (andList.Count == 1)
     {
         return(andList.Pop());
     }
     else
     {
         return(ConditionTree.Empty);
     }
 }
コード例 #16
0
        private void UpdateDependencies()
        {
            foreach (SmartPlaylistSource s in dependencies)
            {
                s.Updated -= OnDependencyUpdated;
            }

            dependencies.Clear();

            if (ConditionTree != null)
            {
                foreach (SmartPlaylistQueryValue value in ConditionTree.SearchForValues <SmartPlaylistQueryValue> ())
                {
                    SmartPlaylistSource playlist = value.ObjectValue;
                    if (playlist != null)
                    {
                        playlist.Updated += OnDependencyUpdated;
                        dependencies.Add(playlist);
                    }
                }
            }
        }
コード例 #17
0
        private void UpdateRoot()
        {
            ConditionList NList = new ConditionList(List.Type);

            // Add existing nodes to the new list
            foreach (TreeNode E in ConditionTree.Nodes[0].Nodes)
            {
                NList.Add((Condition)E.Tag);
            }

            // Add condition value if enabled
            if (ValueBox.Enabled)
            {
                NList.Add(new ConditionValue(ValueBox.Value.ToString()));
            }

            // update tree
            ConditionTree.BeginUpdate();
            ConditionTree.Nodes.Clear();
            ConditionTree.Nodes.Add(NList.ToTree());
            ConditionTree.ExpandAll();
            ConditionTree.EndUpdate();
        }
コード例 #18
0
        /// <summary>
        /// Deletes the selected criteria node
        /// </summary>
        public void DeleteCriteria()
        {
            TreeNode SelectedNode = ConditionTree.SelectedNode;

            // Make sure we have a node selected
            if (SelectedNode == null)
            {
                MessageBox.Show("Please select a criteria to edit.");
                return;
            }

            // Make sure we can't delete the parent node
            // Mostly because we need to keep references intact
            if (SelectedNode.Parent == null)
            {
                return;
            }

            // Dont delete on Plus / Div Trees
            if (!(SelectedNode.Tag is ConditionList))
            {
                TreeNode Parent = SelectedNode.Parent;
                if (Parent == null)
                {
                    return;
                }

                // If we are in the root condition list
                if (Parent.Parent == null || Parent.Parent.Tag == null)
                {
                    ConditionTree.Nodes.Remove(SelectedNode);
                    return;
                }

                // Get the parents condition list
                ConditionList C = (ConditionList)Parent.Tag;

                // Remove the whole tree if its a not statement
                if (C.Type == ConditionType.Not)
                {
                    ConditionTree.Nodes.Remove(Parent);
                }

                // We donot handle nested condition lists in this form
                else if (C.Type == ConditionType.Plus || C.Type == ConditionType.Div)
                {
                    ConditionTree.SelectedNode = Parent;
                    EditCriteria();
                }
                else
                {
                    ConditionTree.Nodes.Remove(SelectedNode);
                }
            }
            else
            {
                ConditionTree.Nodes.Remove(SelectedNode);
            }

            ConditionTree.Refresh();
        }