コード例 #1
0
        public static IEnumerable <T> FlattenRoot <T>(this IRootFlattenable <T> rootFlattenable, IXmlLoadLogger logger)
        {
            if (rootFlattenable.AutoRotate == AutoRotateType.Off)
            {
                var autoRotateContext = new AutoRotateContext(false, FlipType.None, FlipState.None);
                var context           = new FlattenContext(logger, ConditionTree.Empty, autoRotateContext);
                return(rootFlattenable.Flatten(context));
            }
            else
            {
                var horizontalAutoRotateContext = new AutoRotateContext(false, FlipType.None, FlipState.None);
                var horizontalConditions        = new ConditionTreeLeaf(ConditionType.State, "horizontal", ConditionComparison.Equal, new PropertyValue(true));
                var horizontalContext           = new FlattenContext(logger, horizontalConditions, horizontalAutoRotateContext);

                var flipType = FlipType.None;
                if ((rootFlattenable.AutoRotateFlip & FlipState.Primary) == FlipState.Primary)
                {
                    flipType |= FlipType.Vertical;
                }
                if ((rootFlattenable.AutoRotateFlip & FlipState.Secondary) == FlipState.Secondary)
                {
                    flipType |= FlipType.Horizontal;
                }

                var verticalAutoRotateContext = new AutoRotateContext(true, flipType, rootFlattenable.AutoRotateFlip);
                var verticalConditions        = new ConditionTreeLeaf(ConditionType.State, "horizontal", ConditionComparison.Equal, new PropertyValue(false));
                var verticalContext           = new FlattenContext(logger, verticalConditions, verticalAutoRotateContext);

                return(rootFlattenable.Flatten(horizontalContext).Concat(rootFlattenable.Flatten(verticalContext)));
            }
        }
コード例 #2
0
        public void TestConditionParserValidConditions()
        {
            var horizontal  = new ConditionTreeLeaf(ConditionType.State, "horizontal", ConditionComparison.Equal, new PropertyUnion(true));
            var propertyEq1 = new ConditionTreeLeaf(ConditionType.Property, "Property", ConditionComparison.Equal, new PropertyUnion(1));

            var conditionTests = new Dictionary <string, IConditionTreeItem>()
            {
                { "horizontal", horizontal },
                { "$Property==1", propertyEq1 },
                { "horizontal|$Property==1", new ConditionTree(ConditionTree.ConditionOperator.OR, horizontal, propertyEq1) },
                { "horizontal,$Property==1", new ConditionTree(ConditionTree.ConditionOperator.AND, horizontal, propertyEq1) }
            };

            var parseContext = new ParseContext();

            parseContext.PropertyTypes.Add(new KeyValuePair <string, PropertyUnionType>("Property", PropertyUnionType.Double));

            ConditionParser parser = new ConditionParser(new ConditionFormat()
            {
                StatesUnderscored = false
            });

            foreach (var test in conditionTests)
            {
                var parsed = parser.Parse(test.Key, parseContext);
                Assert.AreEqual(test.Value, parsed);
            }
        }
コード例 #3
0
        private bool IsBooleanVariable(ComponentDescription description, ConditionTreeLeaf leaf)
        {
            if (leaf.Type == ConditionType.State && leaf.VariableName == "horizontal")
            {
                return(true);
            }

            return(leaf.Type == ConditionType.Property && description.Properties.FirstOrDefault(x => x.Name == leaf.VariableName).Type == PropertyType.Boolean);
        }