private void InitializeAvailableExpressions()
        {
            var availableElements = new Func <CompositeElement>[] {
                () => {                //Browse behavior menu items
                    var group = new CompositeElement {
                        DisplayName = "Browse behavior".Localize()
                    };
                    group.AvailableChildrenGetters.AddRange(new Func <ExpressionElement>[] {
                        () => new ConditionStoreSearchedPhrase(this.ExpressionViewModel),
                        () => new ConditionInternetSearchedPhrase(this.ExpressionViewModel),
                        () => new ConditionCurrentUrlIs(this.ExpressionViewModel),
                        () => new ConditionStoreIs(this.ExpressionViewModel),
                        () => new ConditionLanguageIs(this.ExpressionViewModel),
                        () => new ConditionCategoryIs(this.ExpressionViewModel, false),                      //without subcategories
                        () => new ConditionCategoryIs(this.ExpressionViewModel, true)                        //with subcategories
                    });
                    return(group);
                },
                () => {                //Shopper profile menu items
                    var group = new CompositeElement {
                        DisplayName = "Shopper profile".Localize()
                    };
                    group.AvailableChildrenGetters.AddRange(new Func <ExpressionElement>[] {
                        () => new ConditionShopperAge(this.ExpressionViewModel),
                        () => new ConditionGenderIs(this.ExpressionViewModel)
                    });
                    return(group);
                },
                () => {                //Shopping cart menu items
                    var group = new CompositeElement {
                        DisplayName = "Shopping cart".Localize()
                    };
                    group.AvailableChildrenGetters.AddRange(new Func <ExpressionElement>[] {
                        () => new ConditionCartTotalIs(this.ExpressionViewModel)
                    });
                    return(group);
                },
                () => {                //Shoppers geo location menu items
                    var group = new CompositeElement {
                        DisplayName = "Geo location".Localize()
                    };
                    group.AvailableChildrenGetters.AddRange(new Func <ExpressionElement>[] {
                        () => new ConditionGeoCity(this.ExpressionViewModel),
                        () => new ConditionGeoState(this.ExpressionViewModel),
                        () => new ConditionGeoCountry(this.ExpressionViewModel),
                        () => new ConditionGeoContinent(this.ExpressionViewModel),
                        () => new ConditionGeoZipCode(this.ExpressionViewModel),
                        () => new ConditionGeoTimeZone(this.ExpressionViewModel),
                        () => new ConditionGeoConnectionType(this.ExpressionViewModel),
                        () => new ConditionGeoIpRoutingType(this.ExpressionViewModel),
                        () => new ConditionGeoIspSecondLevel(this.ExpressionViewModel),
                        () => new ConditionGeoIspTopLevel(this.ExpressionViewModel),
                    });
                    return(group);
                },
            };

            ConditionBlock.WithAvailabeChildren(availableElements);
            ConditionBlock.NewChildLabel = "+ add condition".Localize(null, LocalizationScope.DefaultCategory);
        }
        public void Serialize(CompositeElement compositeElement)
        {
            var name = compositeElement.Name;

            if (aliases.ContainsKey(name))
            {
                name = aliases[name];
            }

            var childElements = childJsonElements[childJsonElements.Count - 1];
            var jsonElement   = string.Empty;

            if (compositeElement.IsCollection)
            {
                jsonElement = string.Format("{0}\"{1}\" : [\n{2}\n{0}]", Indentation(), name, string.Join(",\n", childElements));
            }
            else
            {
                jsonElement = string.Format("{0}\"{1}\" : {{\n{2}\n{0}}}", Indentation(), name, string.Join(",\n", childElements));
            }

            childJsonElements.Remove(childElements);
            childJsonElements[childJsonElements.Count - 1].Add(jsonElement);

            result = jsonElement;
        }
Example #3
0
        private void BuildTree(CompositeElement element)
        {
            var tokens = element.Tokens;

            if (tokens.Length == 0)
            {
                return;
            }
            if (tokens.Length == 1)
            {
                element.Child = new SimpleElement(tokens.Single());
            }
            else if (tokens.TrySeparateSimplePart(out var tuple))
            {
                element.LeftChild = new SimpleElement(tuple.SeparetedPart.First());
                CreateNextCompositeElement(tuple.OtherTokens, element);
            }
            else if (tokens.TrySeparateStylePart(out var tokenTuple))
            {
                var styleElement = CreateStyleElement(tokenTuple.SeparetedPart);
                element.LeftChild = styleElement;
                CreateNextCompositeElement(styleElement.InnerTokens, styleElement);
                CreateNextCompositeElement(tokenTuple.OtherTokens, element);
            }
            else
            {
                element.LeftChild = new SimpleElement(element.Tokens.First());
                CreateNextCompositeElement(tokens.Skip(1), element);
            }
        }
Example #4
0
        private void InitializeAvailableExpressions()
        {
            var availableElements = new Func <CompositeElement>[] {
                () => {                //Items conditions menu items
                    var group = new CompositeElement {
                        DisplayName = "Item conditions".Localize()
                    };
                    group.AvailableChildrenGetters.AddRange(new Func <ExpressionElement>[] {
                        () => new ConditionEntryIs(this.ExpressionViewModel),
                        () => new ConditionItemTypeIs(this.ExpressionViewModel),
                        () => new ConditionItemPropertyIs(this.ExpressionViewModel),
                    });
                    return(group);
                },
                () => {                //Category conditions menu items
                    var group = new CompositeElement {
                        DisplayName = "Category conditions".Localize()
                    };
                    group.AvailableChildrenGetters.AddRange(new Func <ExpressionElement>[] {
                        () => new ConditionCategoryIs(this.ExpressionViewModel),
                    });
                    return(group);
                },
            };

            ConditionBlock.WithAvailabeChildren(availableElements);
            ConditionBlock.NewChildLabel = "+ add condition".Localize(null, LocalizationScope.DefaultCategory);
        }
Example #5
0
        private void HandleIncludeDirective([NotNull] IT4Directive directive, [NotNull] CompositeElement parentElement)
        {
            var fileAttr = directive.GetAttribute(_directiveInfoManager.Include.FileAttribute.Name) as T4DirectiveAttribute;

            if (fileAttr == null)
            {
                return;
            }

            IT4Token valueToken = fileAttr.GetValueToken();

            if (valueToken == null)
            {
                return;
            }

            bool once = false;

            if (_t4Environment.VsVersion2.Major >= VsVersions.Vs2013)
            {
                string onceString = directive.GetAttributeValue(_directiveInfoManager.Include.OnceAttribute.Name);
                once = Boolean.TrueString.Equals(onceString, StringComparison.OrdinalIgnoreCase);
            }

            HandleInclude(valueToken.GetText(), fileAttr, parentElement, once);
        }
        private static void TestComposite()
        {
            Console.WriteLine("Testing composite...");
            // Create a tree structure
            var root =
                new CompositeElement("Picture");

            root.Add(new PrimitiveElement("Red Line"));
            root.Add(new PrimitiveElement("Blue Circle"));
            root.Add(new PrimitiveElement("Green Box"));

            // Create a branch
            var comp =
                new CompositeElement("Two Circles");

            comp.Add(new PrimitiveElement("Black Circle"));
            comp.Add(new PrimitiveElement("White Circle"));
            root.Add(comp);

            // Add and remove a PrimitiveElement
            var pe =
                new PrimitiveElement("Yellow Line");

            root.Add(pe);
            root.Remove(pe);

            // Recursively display nodes
            root.Display(1);
        }
Example #7
0
            public void Main()
            {
                // Create a tree structure
                CompositeElement root =
                    new CompositeElement("Picture");

                root.Add(new PrimitiveElement("Red Line"));
                root.Add(new PrimitiveElement("Blue Circle"));
                root.Add(new PrimitiveElement("Green Box"));

                // Create a branch
                CompositeElement comp =
                    new CompositeElement("Two Circles");

                comp.Add(new PrimitiveElement("Black Circle"));
                comp.Add(new PrimitiveElement("White Circle"));
                root.Add(comp);

                // Add and remove a PrimitiveElement
                PrimitiveElement pe =
                    new PrimitiveElement("Yellow Line");

                root.Add(pe);
                root.Remove(pe);

                // Recursively display nodes
                root.Display(1);
            }
Example #8
0
        public void VisitCompositeElement(CompositeElement compositeElement)
        {
            CompositeElement element = compositeElement as CompositeElement;

            element.line.Size      = new Size(element.SizeX, element.SizeY);
            element.line.BackColor = Color.Green;
        }
    // Entry point into console application.
    static void Main()
    {
        // Create a tree structure 
        CompositeElement root = new CompositeElement("Picture");
        root.Add(new PrimitiveElement("Red Line"));
        root.Add(new PrimitiveElement("Blue Circle"));
        root.Add(new PrimitiveElement("Green Box"));

        // Create a branch
        CompositeElement comp1 = new CompositeElement("Two Circles");
        comp1.Add(new PrimitiveElement("Black Circle"));
        comp1.Add(new PrimitiveElement("White Circle"));
        root.Add(comp1);

        // Create a branch
        CompositeElement comp2 = new CompositeElement("Two Squares");
        comp2.Add(new PrimitiveElement("Red Square"));
        comp2.Add(new PrimitiveElement("Blue Square"));
        root.Add(comp2);

        // Add and remove a PrimitiveElement
        PrimitiveElement pe1 = new PrimitiveElement("Green Line");
        root.Add(pe1);

        // Add and remove a PrimitiveElement
        PrimitiveElement pe2 = new PrimitiveElement("Yellow Line");
        root.Add(pe2);
        root.Remove(pe2);

        // Recursively display nodes
        root.Display(1);

        // Wait for user
        Console.ReadKey();
    }
Example #10
0
        public static void Main()
        {
            var root = new CompositeElement("Picture");

            root.Add(new PrimitiveElement("Red Line"));
            root.Add(new PrimitiveElement("Green Line"));
            root.Add(new PrimitiveElement("Blue Line"));


            var composition = new CompositeElement("Two Circles");

            composition.Add(new PrimitiveElement("Black Circle"));
            composition.Add(new PrimitiveElement("White Circle"));
            root.Add(composition);


            var composition1 = new CompositeElement("Two Squares");

            composition1.Add(new PrimitiveElement("Black Square"));
            composition1.Add(new PrimitiveElement("White Square"));
            root.Add(composition1);

            var primitiveElement = new PrimitiveElement("Line");

            root.Add(primitiveElement);
            root.Remove(primitiveElement);

            root.Display(5);
        }
Example #11
0
        public void VisitCompositeElement(CompositeElement compositeElement)
        {
            CompositeElement element = compositeElement as CompositeElement;

            element.line.Size      = new Size(element.SizeY, element.SizeX);
            element.line.BackColor = Color.Bisque;
        }
Example #12
0
        public IElement Parse()
        {
            var root = new CompositeElement(lexer.Tokenize());

            BuildTree(root);
            return(root);
        }
Example #13
0
        public void Main()
        {
            // Create a tree structure

            var root = new CompositeElement("Picture");

            root.Add(new PrimitiveElement("Red Line"));
            root.Add(new PrimitiveElement("Blue Circle"));
            root.Add(new PrimitiveElement("Green Box"));

            // Create a branch

            var compositeElement = new CompositeElement("Two Circles");

            compositeElement.Add(new PrimitiveElement("Black Circle"));
            compositeElement.Add(new PrimitiveElement("White Circle"));
            root.Add(compositeElement);

            // Add and remove a PrimitiveElement

            var primitive = new PrimitiveElement("Yellow Line");

            root.Add(primitive);
            root.Remove(primitive);

            // Recursively display nodes
            root.Display(1);

            //GetComposite will return null if its a primitive element
            primitive.GetComposite()?.Add(new PrimitiveElement("Black Line"));
        }
            /// <summary>
            /// Finishes building the directive by appending its name and all attributes.
            /// </summary>
            /// <param name="parent">The directive.</param>
            internal void Finish([NotNull] CompositeElement parent)
            {
                if (_firstInfo == null)
                {
                    _treeBuilder.AppendMissingToken(parent, MissingTokenType.DirectiveName);
                    return;
                }

                AttributeInfo attrInfo;

                if (_firstInfo.HasNameOnly)
                {
                    _treeBuilder.AppendNewChild(parent, _firstInfo.NameToken);
                    attrInfo = _firstInfo.Next;
                }
                else
                {
                    attrInfo = _firstInfo;
                    _treeBuilder.AppendMissingToken(parent, MissingTokenType.DirectiveName);
                }

                while (attrInfo != null)
                {
                    _treeBuilder.AppendNewChild(parent, attrInfo.ToAttribute());
                    attrInfo = attrInfo.Next;
                }
            }
Example #15
0
        /// <summary>
        /// Checks if the current token represents the beginning of a code block, if yes, parse every code block after the token.
        /// </summary>
        /// <param name="tokenNodeType">The current token type.</param>
        /// <param name="parentElement">The parent element where the potential code block will be appended as a child.</param>
        /// <returns><c>true</c> is a code block has been parsed, <c>false</c> otherwise.</returns>
        private bool TryParseCodeBlock([CanBeNull] T4TokenNodeType tokenNodeType, [NotNull] CompositeElement parentElement)
        {
            if (tokenNodeType != null)
            {
                T4CodeBlock codeBlock;
                if (tokenNodeType == T4TokenNodeTypes.StatementStart)
                {
                    codeBlock = new T4StatementBlock();
                }
                else if (tokenNodeType == T4TokenNodeTypes.ExpressionStart)
                {
                    codeBlock = new T4ExpressionBlock();
                }
                else if (tokenNodeType == T4TokenNodeTypes.FeatureStart)
                {
                    codeBlock = new T4FeatureBlock();
                }
                else
                {
                    codeBlock = null;
                }

                if (codeBlock != null)
                {
                    AppendNewChild(parentElement, ParseCodeBlock(tokenNodeType, codeBlock));
                    return(true);
                }
            }
            return(false);
        }
Example #16
0
        private void Parse([NotNull] CompositeElement parentElement)
        {
            T4TokenNodeType tokenNodeType = GetNonCodeBlockTokenType(parentElement);

            while (tokenNodeType != null)
            {
                if (tokenNodeType == T4TokenNodeTypes.DirectiveStart)
                {
                    ParseDirective(parentElement);
                }
                else
                {
                    AppendNewChild(parentElement, tokenNodeType);
                    Advance();
                }
                tokenNodeType = GetNonCodeBlockTokenType(parentElement);
            }
            if (_builderLexer.HasSkippedTokens)
            {
                _builderLexer.AppendSkippedTokens(parentElement);
            }
            if (_notClosedDirectives != null)
            {
                FixTopLevelSpace(parentElement, _notClosedDirectives);
            }
        }
        public static void Execute()
        {
            // Create a tree structure
            var root = new CompositeElement("Picture");

            root.Add(new PrimitiveElement("Red Line"));
            root.Add(new PrimitiveElement("Blue Circle"));
            root.Add(new PrimitiveElement("Green Box"));

            // Create a branch
            var comp = new CompositeElement("Two Circles");

            comp.Add(new PrimitiveElement("Black Circle"));
            comp.Add(new PrimitiveElement("White Circle"));

            root.Add(comp);

            // Add and remove a PrimitiveElement
            var pe = new PrimitiveElement("Yellow Line");

            root.Add(pe);
            root.Remove(pe);

            // Recursively display nodes
            root.Exibir(1);
        }
Example #18
0
        private string CalcIndent(FormattingStageContext context)
        {
            CompositeElement parent = context.Parent;

            if (context.LeftChild != context.RightChild)
            {
                ITreeNode rChild = context.RightChild;
                if ((!context.LeftChild.HasLineFeedsTo(rChild)))
                {
                    return(null);
                }

                var psiTreeNode = context.Parent as IPsiTreeNode;

                return(psiTreeNode != null
          ? psiTreeNode.Accept(_indentVisitor, context)
          : _indentVisitor.VisitNode(parent, context));
            }
            else
            {
                var psiTreeNode = context.Parent as IPsiTreeNode;

                return(psiTreeNode != null
          ? psiTreeNode.Accept(_indentVisitor, context)
          : _indentVisitor.VisitNode(parent, context));
            }
        }
Example #19
0
        private void CreateNextCompositeElement(IEnumerable <Token> tokens, IElement parent)
        {
            var comp = new CompositeElement(tokens.ToArray());

            parent.Child = comp;
            BuildTree(comp);
        }
        private static void CreateTags(IDictionary <Element, Tag> tagMap, ICollection <Tag> tagList,
                                       AssemblingContext context, Element element, BeginningTag parent)
        {
            if (element is ConcreteElement)
            {
                ElementTag tag = new ElementTag(tagList.Count, context, parent, (ConcreteElement)element);
                tagMap.Add(element, tag);
                tagList.Add(tag);
            }
            else if (element is CompositeElement)
            {
                CompositeElement compositeElement = (CompositeElement)element;

                BeginningTag beginningTag = new BeginningTag(tagList.Count, context, parent, compositeElement);
                tagMap.Add(element, beginningTag);
                tagList.Add(beginningTag);

                foreach (Element e in compositeElement.GetElements())
                {
                    CreateTags(tagMap, tagList, context, e, beginningTag);
                }

                EndTag endTag = new EndTag(tagList.Count, context, parent, beginningTag);
                tagList.Add(endTag);
            }
        }
Example #21
0
        private void HandleInclude(
            [CanBeNull] string includeFileName,
            [NotNull] T4DirectiveAttribute fileAttr,
            [NotNull] CompositeElement parentElement,
            bool once
            )
        {
            FileSystemPath includePath = ResolveInclude(includeFileName);

            if (includePath.IsEmpty)
            {
                fileAttr.ValueError = String.Format(CultureInfo.InvariantCulture, "Unresolved file \"{0}\"", includePath);
                return;
            }

            if (!_existingIncludePaths.Add(includePath))
            {
                if (!once)
                {
                    fileAttr.ValueError = String.Format(CultureInfo.InvariantCulture, "Already included file \"{0}\"", includePath);
                }
                return;
            }

            FileSystemPath sourceLocation = _sourceFile.GetLocation();

            if (includePath == sourceLocation)
            {
                fileAttr.ValueError = "Recursive include";
                _existingIncludePaths.Add(includePath);
                return;
            }

            if (!includePath.ExistsFile)
            {
                fileAttr.ValueError = String.Format(CultureInfo.InvariantCulture, "File \"{0}\" not found", includePath);
                return;
            }

            // find the matching include in the existing solution source files
            // or create a new one if the include file is outside the solution
            IPsiSourceFile includeSourceFile = includePath.FindSourceFileInSolution(_solution) ?? CreateIncludeSourceFile(includePath);

            if (includeSourceFile == null)
            {
                fileAttr.ValueError = "No current solution";
                return;
            }

            ILexer    includeLexer = CreateLexer(includeSourceFile);
            var       builder      = new T4TreeBuilder(_t4Environment, _directiveInfoManager, includeLexer, includeSourceFile, _existingIncludePaths, _solution, _macroResolveModule);
            T4Include include      = builder.CreateIncludeT4Tree();

            include.Path = includePath;
            _includes.Add(include);

            // do not use AppendNewChild, we don't want the PsiBuilderLexer to move line breaks from the include into the main file.
            parentElement.AddChild(include);
        }
        public static CompositeElement Add(this CompositeElement parent, ControlElement child)
        {
            var allChildren = parent.Children.ToList();

            allChildren.Add(child);
            parent.Children = allChildren;
            return(parent);
        }
Example #23
0
 private CompositeElement handleError(CompositeElement result, SyntaxError syntaxError)
 {
     CompositeElement errorElement = TreeElementFactory.CreateErrorElement(syntaxError.Message);
     if (result == null)
         return errorElement;
     result.AppendNewChild(errorElement);
     return result;
 }
Example #24
0
        private void ParseDirective([NotNull] CompositeElement parentElement)
        {
            var directive = new T4Directive();

            // appends the directive start token (<#@)
            AppendNewChild(directive, T4TokenNodeTypes.DirectiveStart);
            Advance();

            // builds the directive (name and attributes)
            var             directiveBuilder = new DirectiveBuilder(this);
            T4TokenNodeType tokenType        = GetTokenType();

            while (tokenType != null && !tokenType.IsTag)
            {
                if (tokenType == T4TokenNodeTypes.Name)
                {
                    directiveBuilder.AddName();
                }
                else if (tokenType == T4TokenNodeTypes.Equal)
                {
                    directiveBuilder.AddEqual();
                }
                else if (tokenType == T4TokenNodeTypes.Quote)
                {
                    directiveBuilder.AddQuote();
                }
                else if (tokenType == T4TokenNodeTypes.Value)
                {
                    directiveBuilder.AddValue();
                }
                tokenType = Advance();
            }
            directiveBuilder.Finish(directive);

            // appends the block end token if available
            if (tokenType == T4TokenNodeTypes.BlockEnd)
            {
                AppendNewChild(directive, T4TokenNodeTypes.BlockEnd);
                Advance();
            }
            else
            {
                AppendMissingToken(directive, MissingTokenType.BlockEnd);
                if (_notClosedDirectives == null)
                {
                    _notClosedDirectives = new List <T4Directive>();
                }
                _notClosedDirectives.Add(directive);
            }

            AppendNewChild(parentElement, directive);

            // checks if we're including a file
            if (directive.IsSpecificDirective(_directiveInfoManager.Include))
            {
                HandleIncludeDirective(directive, parentElement);
            }
        }
        public static CompositeElement AddChildren(this CompositeElement parent, params FormElement[] children)
        {
            var allChildren = parent.Children.ToList();

            allChildren.AddRange(children.ToList());
            parent.Children = allChildren;

            return(parent);
        }
Example #26
0
        private T4TokenNodeType GetNonCodeBlockTokenType(CompositeElement parentElement)
        {
            var tokenNodeType = GetTokenType();

            while (TryParseCodeBlock(tokenNodeType, parentElement))
            {
                tokenNodeType = Advance();
            }
            return(tokenNodeType);
        }
Example #27
0
        public bool PreSerializeElement(CompositeElement element)
        {
            if (ignoreList.Contains(element.Name))
            {
                return(false);
            }

            childXmlElements.Add(new List <string>());
            return(true);
        }
Example #28
0
        protected TypedExpressionElementBase(string displayName, IExpressionViewModel expressionViewModel)
        {
            DisplayName = displayName;

            _exludingEl = new CompositeElement();
            _exludingEl.HeaderElements.Add(new LabelElement {
                Label = "excluding".Localize()
            });
            _exludingEl.NewChildLabel = "+ excluding".Localize();
            ExpressionViewModel       = expressionViewModel;
        }
        public static IEnumerable <T> FindChildren <T>(this CompositeElement element, Predicate <T> predicate)
            where T : TreeElement
        {
            var firstChild = (TreeElement)element.FirstChild;

            for (var treeElement1 = firstChild; treeElement1 != null; treeElement1 = treeElement1.nextSibling)
            {
                if (treeElement1 is T treeElement2 && predicate(treeElement2))
                {
                    yield return(treeElement2);
                }
            }
        }
Example #30
0
        private void SkipNestedBraces(CompositeElement result)
        {
            while (myOriginalLexer.TokenType != ShaderLabTokenType.RBRACE)
            {
                Skip(result);
                if (myOriginalLexer.TokenType == ShaderLabTokenType.LBRACE)
                {
                    SkipNestedBraces(result);
                }
            }

            // Skip the final RBRACE
            Skip(result);
        }
Example #31
0
        public static ICompositeElementViewModel CreateComposite(CompositeElement model)
        {
            switch (model)
            {
            case GroupElement elementGroup:
                return(new GroupElementViewModel(elementGroup));

            case LinearLayoutElement linearLayout:
                return(new LinearLayoutElementViewModel(linearLayout));

            default:
                return(new NullCompositeViewModel());
            }
        }
Example #32
0
 /// <summary>
 /// Unclosed directives may have trailing spaces that are skipped then added at file level by the <see cref="PsiBuilderLexer"/>.
 /// In this T4 parser, space tokens can only appear inside directives so we're putting them back in.
 /// </summary>
 /// <param name="file">The file containing non closed directives.</param>
 /// <param name="notClosedDirectives">The list of directives that aren't closed.</param>
 private static void FixTopLevelSpace([NotNull] CompositeElement file, [NotNull] IEnumerable <T4Directive> notClosedDirectives)
 {
     foreach (T4Directive directive in notClosedDirectives)
     {
         ITreeNode potentialSpace = directive.NextSibling;
         if (potentialSpace == null || potentialSpace.GetTokenType() != T4TokenNodeTypes.Space)
         {
             continue;
         }
         file.DeleteChildRange(potentialSpace, potentialSpace);
         Assertion.Assert(directive.LastChild is IErrorElement, "directive.LastChild is IErrorElement");
         directive.AddChildBefore(potentialSpace, directive.LastChild);
     }
 }
Example #33
0
        protected void AssertChildsList(CompositeElement compositeElement, params Action<IElement> [] actions)
        {
            int index = 0;
            for (TreeElement child = compositeElement.firstChild;
                 child != compositeElement.lastChild; child = child.nextSibling, index++)
            {
                if(index >= actions.Length)
                {
                    Assert.Fail("There is child unnecessary with index " + index + " " + child);
                }

                actions[index](child);
            }

            if(index < actions.Length - 1)
                Assert.Fail("There is no element with index  " + index);
        }
Example #34
0
        private IXmlAttributeValue ParseAttributeValueAspect(IXmlAttributeValue xmlAttributeValue, CompositeElement newAttributeValue, StringParse stringParse)
        {
            if (xmlAttributeValue == null) throw new ArgumentNullException("xmlAttributeValue");
            if (newAttributeValue == null) throw new ArgumentNullException("newAttributeValue");
            if (stringParse == null) throw new ArgumentNullException("stringParse");
            CompositeElement result = null;

            string rawValue = xmlAttributeValue.UnquotedValue;

            try
            {
                result = stringParse(rawValue);
            }
            catch (SyntaxError syntaxError)
            {
                result = (CompositeElement)syntaxError.ParsingResult;
                result = handleError(result, syntaxError);
            }

            newAttributeValue.AddChild(new XmlToken(L4NTokenNodeType.QUOTE, new StringBuffer(new string('\"', 1)), 0, 1));
            newAttributeValue.AddChild(result);
            int resultLegth = result.GetText().Length;
            if(resultLegth < rawValue.Length)
            {
                string suffix = rawValue.Substring(resultLegth);
                StringBuffer sb = new StringBuffer(suffix);
                XmlToken suffixToken = new XmlToken(L4NTokenNodeType.TEXT , sb, 0, suffix.Length);
                newAttributeValue.AddChild(suffixToken);
            }
            newAttributeValue.AddChild(new XmlToken(L4NTokenNodeType.QUOTE, new StringBuffer(new string('\"', 1)), 0, 1));

            return (IXmlAttributeValue)newAttributeValue;
        }
  public static void Main( string[] args )
  {   
    // Create a tree structure 
    CompositeElement root = new CompositeElement( "Picture" );
    root.Add( new PrimitiveElement( "Red Line" ));
    root.Add( new PrimitiveElement( "Blue Circle" ));
    root.Add( new PrimitiveElement( "Green Box" ));

    CompositeElement comp = new CompositeElement( "Two Circles" );
    comp.Add( new PrimitiveElement( "Black Circle" ) );
    comp.Add( new PrimitiveElement( "White Circle" ) );
    root.Add( comp );

    // Add and remove a PrimitiveElement
    PrimitiveElement l = new PrimitiveElement( "Yellow Line" );
    root.Add( l );
    root.Remove( l );

    // Recursively display nodes
    root.Display( 1 );
  }
Example #36
0
        private Visual3D CreateMarkerTree(CompositeElement joint)
        {
            ContainerUIElement3D marker = CreateMarker(1, 0.05);
            joint.Visual = marker;

            Transform3DGroup transforms = new Transform3DGroup();
            marker.Transform = transforms;

            transforms.Children.Add(new MatrixTransform3D());

            Vector3D offset = joint.Offset.Value;
            transforms.Children.Add(new TranslateTransform3D(offset));

            foreach (CompositeElement child in joint.JointList)
            {
                marker.Children.Add(CreateMarkerTree(child));
            }

            return marker;
        }
Example #37
0
 /// <summary>
 /// Appends a new composite element to the tree.
 /// </summary>
 /// <param name="parentElement">The parent element.</param>
 /// <param name="childElement">The child element.</param>
 private void AppendNewChild(CompositeElement parentElement, TreeElement childElement)
 {
     _builderLexer.AppendNewChild(parentElement, childElement);
 }
Example #38
0
 private T4TokenNodeType GetNonCodeBlockTokenType(CompositeElement parentElement)
 {
     var tokenNodeType = GetTokenType();
     while (TryParseCodeBlock(tokenNodeType, parentElement))
         tokenNodeType = Advance();
     return tokenNodeType;
 }