public static DomAttribute ReadAttribute(BinaryReader reader, INameDecoder nameTable)
        {
            DomAttribute attr = new DomAttribute();

            attr.Name            = ReadString(reader, nameTable);
            attr.Region          = ReadRegion(reader, nameTable);
            attr.AttributeTarget = (AttributeTarget)reader.ReadInt32();
            attr.AttributeType   = ReadReturnType(reader, nameTable);

            // Named argument count
            uint num = ReadUInt(reader, 500);

            string[] names = new string[num];
            for (int n = 0; n < num; n++)
            {
                names [n] = ReadString(reader, nameTable);
            }

            CodeExpression[] exps = ReadExpressionArray(reader, nameTable);

            int i;

            for (i = 0; i < num; i++)
            {
                attr.AddNamedArgument(names[i], exps [i]);
            }

            for (; i < exps.Length; i++)
            {
                attr.AddPositionalArgument(exps [i]);
            }

            return(attr);
        }
Esempio n. 2
0
        private DomAttributeWithInitializers CreateServerDomAttribute(DomAttribute m, string property)
        {
            var result = new DomAttributeWithInitializers();

            try {
                result.Attribute = Document.CreateAttribute(m.Name);
            } catch (Exception ex) {
                if (Failure.IsCriticalException(ex))
                {
                    throw;
                }
                else
                {
                    throw HxlFailure.CannotCreateAttributeOnConversion(m.Name, ex);
                }
            }

            if (result.Attribute == null)
            {
                throw HxlFailure.ServerAttributeCannotBeCreated(m.Name, -1, -1);
            }

            _current.Attributes.Add(result.Attribute);
            AddImplicitType(result.Attribute.GetType());

            return(result);
        }
        private static void AttributeAppend(DomAttribute left,
                                            DomAttribute append)
        {
            var toElement       = left.OwnerElement;
            var appendThunkFrag = append as HxlAttribute.ThunkFragment;

            if (appendThunkFrag == null)
            {
                AttributeAppend(left, append.Value);
            }

            else
            {
                toElement.Attributes.Remove(append.Name);
                Func <dynamic, HxlAttribute, string> thunkLeft;

                var leftThunkFrag = left as HxlAttribute.ThunkFragment;
                if (leftThunkFrag == null)
                {
                    // No need to create a closure on the whole attribute
                    string leftValue = left.Value;
                    thunkLeft = (x, y) => leftValue;
                }
                else
                {
                    thunkLeft = leftThunkFrag._action;
                }

                var attr = HxlAttribute.Combine(left.Name, thunkLeft, appendThunkFrag._action);
                toElement.Append(attr);
            }
        }
Esempio n. 4
0
        protected void ImplSetAttribute(DomAttribute attr)
        {
            //handle some attribute
            //special for some attributes

            switch ((WellknownName)attr.LocalNameIndex)
            {
            case WellknownName.Style:
            {
                //TODO: parse and evaluate style here
                //****
                WebDom.Parser.CssParser miniCssParser = CssParserPool.GetFreeParser();
                //parse and evaluate the ruleset
                CssRuleSet parsedRuleSet = miniCssParser.ParseCssPropertyDeclarationList(attr.Value.ToCharArray());

                Css.BoxSpec spec = null;
                if (this.ParentNode != null)
                {
                    spec = ((HtmlElement)this.ParentNode).Spec;
                }
                foreach (WebDom.CssPropertyDeclaration propDecl in parsedRuleSet.GetAssignmentIter())
                {
                    SpecSetter.AssignPropertyValue(
                        _boxSpec,
                        spec,
                        propDecl);
                }
                CssParserPool.ReleaseParser(ref miniCssParser);
            }
            break;
            }
        }
        // Appends the given value to the attribute which uses a
        // merging semantic like "class"
        private static void AttributeAppend(DomAttribute left,
                                            string appendValue)
        {
            var toElement     = left.OwnerElement;
            var thunkFragment = left as HxlAttribute.ThunkFragment;

            if (thunkFragment != null)
            {
                toElement.RemoveAttribute(left.Name);

                var combo = HxlAttribute.Combine(
                    left.Name,
                    thunkFragment._action,
                    (x, y) => appendValue);
                toElement.Append(combo);
            }

            else if (!string.IsNullOrWhiteSpace(left.Value))
            {
                left.Value += " " + appendValue;
            }

            else
            {
                left.Value = appendValue;
            }
        }
Esempio n. 6
0
        public void TestDomReadWriteResourceCreateWithPersonResource()
        {
            // Arrange
            var serviceModel = ClrSampleData.ServiceModelWithBlogResourceTypes;

            var personResourceType       = serviceModel.GetResourceType <Person>();
            var personResourceIdentity   = personResourceType.ResourceIdentityInfo;
            var personFirstNameAttribute = personResourceType.GetClrAttributeInfo(StaticReflection.GetMemberName <Person>(x => x.FirstName));
            var personLastNameAttribute  = personResourceType.GetClrAttributeInfo(StaticReflection.GetMemberName <Person>(x => x.LastName));
            var personTwitterAttribute   = personResourceType.GetClrAttributeInfo(StaticReflection.GetMemberName <Person>(x => x.Twitter));

            var expected = ApiSampleData.PersonResource;

            // Act
            var actual = DomReadWriteResource.Create(
                DomType.CreateFromResourceType(personResourceType),
                DomId.CreateFromApiResourceIdentity(personResourceType, expected),
                DomAttributes.Create(
                    DomAttribute.CreateFromApiResource(personFirstNameAttribute, expected),
                    DomAttribute.CreateFromApiResource(personLastNameAttribute, expected),
                    DomAttribute.CreateFromApiResource(personTwitterAttribute, expected)),
                DomReadWriteRelationships.Create(
                    DomReadWriteRelationship.Create(ApiSampleData.PersonToCommentsRel,
                                                    DomReadWriteLinks.Create(
                                                        DomReadWriteLink.Create(Keywords.Self, DomHRef.Create(ApiSampleData.PersonToRelationshipsToCommentsHRef)),
                                                        DomReadWriteLink.Create(Keywords.Related, DomHRef.Create(ApiSampleData.PersonToCommentsHRef))))),
                DomReadWriteLinks.Create(
                    DomReadWriteLink.Create(Keywords.Self, DomHRef.Create(ApiSampleData.PersonHRef))),
                DomReadOnlyMeta.Create(ApiSampleData.ResourceMeta));

            this.OutputDomTree(actual);

            // Assert
            DomReadWriteResourceAssert.Equal(expected, actual);
        }
Esempio n. 7
0
        public void TestDomReadWriteResourceCreateWithCommentResource()
        {
            // Arrange
            var serviceModel = ClrSampleData.ServiceModelWithBlogResourceTypes;

            var commentResourceType     = serviceModel.GetResourceType <Comment>();
            var commentResourceIdentity = commentResourceType.ResourceIdentityInfo;
            var commentBodyAttribute    = commentResourceType.GetClrAttributeInfo(StaticReflection.GetMemberName <Comment>(x => x.Body));

            var expected = ApiSampleData.CommentResource;

            // Act
            var actual = DomReadWriteResource.Create(
                DomType.CreateFromResourceType(commentResourceType),
                DomId.CreateFromApiResourceIdentity(commentResourceType, expected),
                DomAttributes.Create(
                    DomAttribute.CreateFromApiResource(commentBodyAttribute, expected)),
                DomReadWriteRelationships.Create(
                    DomReadWriteRelationship.Create(ApiSampleData.CommentToAuthorRel,
                                                    DomReadWriteLinks.Create(
                                                        DomReadWriteLink.Create(Keywords.Self, DomHRef.Create(ApiSampleData.CommentToRelationshipsToAuthorHRef)),
                                                        DomReadWriteLink.Create(Keywords.Related, DomHRef.Create(ApiSampleData.CommentToAuthorHRef))))),
                DomReadWriteLinks.Create(
                    DomReadWriteLink.Create(Keywords.Self, DomHRef.Create(ApiSampleData.CommentHRef))),
                DomReadOnlyMeta.Create(ApiSampleData.ResourceMeta));

            this.OutputDomTree(actual);

            // Assert
            DomReadWriteResourceAssert.Equal(expected, actual);
        }
Esempio n. 8
0
        public void TestDomReadWriteResourceCreateWithBlogResource()
        {
            // Arrange
            var serviceModel = ClrSampleData.ServiceModelWithBlogResourceTypes;

            var blogResourceType     = serviceModel.GetResourceType <Blog>();
            var blogResourceIdentity = blogResourceType.ResourceIdentityInfo;
            var blogNameAttribute    = blogResourceType.GetClrAttributeInfo(StaticReflection.GetMemberName <Blog>(x => x.Name));

            var expectedBlog = ApiSampleData.BlogResource;

            // Act
            var actual = DomReadWriteResource.Create(
                DomType.CreateFromResourceType(blogResourceType),
                DomId.CreateFromApiResourceIdentity(blogResourceType, expectedBlog),
                DomAttributes.Create(
                    DomAttribute.CreateFromApiResource(blogNameAttribute, expectedBlog)),
                DomReadWriteRelationships.Create(
                    DomReadWriteRelationship.Create(ApiSampleData.BlogToArticlesRel,
                                                    DomReadWriteLinks.Create(
                                                        DomReadWriteLink.Create(Keywords.Self, DomHRef.Create(ApiSampleData.BlogToRelationshipsToArticlesHRef)),
                                                        DomReadWriteLink.Create(Keywords.Related, DomHRef.Create(ApiSampleData.BlogToArticlesHRef))))),
                DomReadWriteLinks.Create(
                    DomReadWriteLink.Create(Keywords.Self, DomHRef.Create(ApiSampleData.BlogHRef))),
                DomReadOnlyMeta.Create(ApiSampleData.ResourceMeta));

            this.OutputDomTree(actual);

            // Assert
            DomReadWriteResourceAssert.Equal(expectedBlog, actual);
        }
Esempio n. 9
0
            protected override DomObject Convert(DomDocument document, DomAttribute attribute)
            {
                var buffer = new CodeBuffer();

                RewriteExpressionSyntax.MatchVariablesAndEmit(buffer, attribute.Value);
                return(new HxlExpressionAttribute(attribute.Name, buffer.ToString()));
            }
Esempio n. 10
0
 protected override void VisitAttribute(DomAttribute attribute)
 {
     _sb.Write(attribute.Name);
     _sb.Write("=");
     _sb.Write("\"");
     _sb.Write(attribute.Value);
     _sb.Write("\"");
 }
Esempio n. 11
0
        protected override void VisitAttribute(DomAttribute attribute)
        {
            string parent = stack.Peek();

            CurrentOutput.WriteLine("{0}.Attribute(\"{1}\", \"{2}\");",
                                    parent,
                                    CodeUtility.Escape(attribute.Name),
                                    CodeUtility.Escape(attribute.Value));
        }
Esempio n. 12
0
        public static HtmlDocument ParseDocument(LayoutFarm.HtmlBoxes.HtmlHost htmlHost, ExternalHtmlTreeWalker externalTreeWalker)
        {
            HtmlDocument newdoc = new HtmlDocument(htmlHost);
            //start from
            HtmlElement         domElem    = (HtmlElement)newdoc.RootNode;
            Stack <HtmlElement> elemStack  = new Stack <HtmlElement>();
            HtmlElement         newDomElem = null;

            foreach (ExternalHtmlNode node in externalTreeWalker.GetHtmlNodeIter())
            {
                switch (node.HtmlNodeKind)
                {
                case ExternalHtmlNodeKind.EnterChildContext:
                {
                    elemStack.Push(domElem);
                    if (newDomElem != null)
                    {
                        domElem = newDomElem;
                    }
                }
                break;

                case ExternalHtmlNodeKind.ExitChildContext:
                {
                    domElem = elemStack.Pop();
                }
                break;

                case ExternalHtmlNodeKind.Attribute:
                {
                    node.GetAttributeNameAndValue(out string attrName, out string attrValue);
                    DomAttribute attr = newdoc.CreateAttribute(attrName, attrValue);
                    newDomElem.SetAttribute(attr);
                }
                break;

                case ExternalHtmlNodeKind.Element:

                    newDomElem = (HtmlElement)newdoc.CreateElement(node.HtmlElementName);
                    domElem.AddChild(newDomElem);

                    //System.Diagnostics.Debug.WriteLine(new string(' ', node.Level) + node.HtmlElementName);
                    break;

                case ExternalHtmlNodeKind.TextNode:
                    DomTextNode textnode = newdoc.CreateTextNode(node.CurrentTextNodeContent.ToCharArray());
                    domElem.AddChild(textnode);
                    //System.Diagnostics.Debug.WriteLine(new string(' ', node.Level) + node.CurrentTextNodeContent);
                    break;

                case ExternalHtmlNodeKind.Document:
                    //System.Diagnostics.Debug.WriteLine("Root");
                    break;
                }
            }
            return(newdoc);
        }
Esempio n. 13
0
        protected override void VisitAttribute(DomAttribute attribute)
        {
            if (attribute == null)
                throw new ArgumentNullException("attribute");

            writer.WriteStartAttribute(attribute.Name, attribute.NamespaceUri);
            writer.WriteValue(attribute.Value);
            writer.WriteEndAttribute();
        }
Esempio n. 14
0
 public override void ResetParser()
 {
     this._resultHtmlDoc = null;
     this.openEltStack.Clear();
     this.curHtmlNode  = null;
     this.curAttr      = null;
     this.curTextNode  = null;
     this.parseState   = 0;
     this.textSnapshot = null;
 }
Esempio n. 15
0
 public override void ResetParser()
 {
     _resultHtmlDoc = null;
     _openEltStack.Clear();
     _curHtmlNode  = null;
     _curAttr      = null;
     _curTextNode  = null;
     _parseState   = 0;
     _textSnapshot = null;
 }
Esempio n. 16
0
        public void ReadWriteAttributeTest()
        {
            DomAttribute attr = new DomAttribute();

            CodePropertyReferenceExpression exp1 = new CodePropertyReferenceExpression();

            exp1.TargetObject = new CodeTypeReferenceExpression("SomeType");
            exp1.PropertyName = "SomeProperty";

            CodeTypeOfExpression exp2 = new CodeTypeOfExpression("SomeTypeOf");

            CodeBinaryOperatorExpression exp3 = new CodeBinaryOperatorExpression();

            exp3.Left     = new CodePrimitiveExpression("one");
            exp3.Right    = new CodePrimitiveExpression("two");
            exp3.Operator = CodeBinaryOperatorType.Add;

            CodePrimitiveExpression exp4 = new CodePrimitiveExpression(37);

            attr.AddPositionalArgument(exp1);
            attr.AddPositionalArgument(exp2);
            attr.AddPositionalArgument(exp3);
            attr.AddPositionalArgument(exp4);

            MemoryStream ms     = new MemoryStream();
            BinaryWriter writer = new BinaryWriter(ms);

            DomPersistence.Write(writer, DefaultNameEncoder, attr);
            byte[]       bytes  = ms.ToArray();
            DomAttribute result = DomPersistence.ReadAttribute(CreateReader(bytes), DefaultNameDecoder, null);

            Assert.AreEqual(4, result.PositionalArguments.Count);

            Assert.AreEqual(typeof(CodePropertyReferenceExpression), result.PositionalArguments [0].GetType());
            CodePropertyReferenceExpression rexp1 = (CodePropertyReferenceExpression)result.PositionalArguments [0];

            Assert.AreEqual(typeof(CodeTypeReferenceExpression), rexp1.TargetObject.GetType());
            Assert.AreEqual("SomeType", ((CodeTypeReferenceExpression)rexp1.TargetObject).Type.BaseType);
            Assert.AreEqual("SomeProperty", rexp1.PropertyName);

            Assert.AreEqual(typeof(CodeTypeOfExpression), result.PositionalArguments [1].GetType());
            Assert.AreEqual("SomeTypeOf", ((CodeTypeOfExpression)result.PositionalArguments [1]).Type.BaseType);

            Assert.AreEqual(typeof(CodeBinaryOperatorExpression), result.PositionalArguments [2].GetType());
            CodeBinaryOperatorExpression rexp3 = (CodeBinaryOperatorExpression)result.PositionalArguments [2];

            Assert.AreEqual(typeof(CodePrimitiveExpression), rexp3.Left.GetType());
            Assert.AreEqual("one", ((CodePrimitiveExpression)rexp3.Left).Value);
            Assert.AreEqual(typeof(CodePrimitiveExpression), rexp3.Right.GetType());
            Assert.AreEqual("two", ((CodePrimitiveExpression)rexp3.Right).Value);

            Assert.AreEqual(typeof(CodePrimitiveExpression), result.PositionalArguments [3].GetType());
            Assert.AreEqual(37, ((CodePrimitiveExpression)result.PositionalArguments [3]).Value);
        }
Esempio n. 17
0
        public void SetImageSource(ImageBinder imgBinder)
        {
            DomAttribute attr = this.OwnerDocument.CreateAttribute("src", imgBinder.ImageSource);

            SetDomAttribute(attr);
            //----
            if (_principalBox != null)
            {
                InternalSetImageBinder(_owner.GetImageBinder(attr.Value));
            }
        }
Esempio n. 18
0
        protected override void VisitAttribute(DomAttribute attribute)
        {
            if (attribute == null)
                throw new ArgumentNullException("attribute");

            sb.Append(attribute.Name);
            sb.Append("=");
            sb.Append("\"");
            sb.Append(attribute.Value);
            sb.Append("\"");
        }
Esempio n. 19
0
        public bool TryGetAttribute(string attrName, out DomAttribute result)
        {
            int foundIndex = this.OwnerDocument.FindStringIndex(attrName);

            if (foundIndex < 1)
            {
                result = null;
                return(false);
            }
            return((result = FindAttribute(foundIndex)) != null);
        }
Esempio n. 20
0
 public override void SetAttribute(DomAttribute attr)
 {
     base.SetAttribute(attr);
     switch ((WellknownName)attr.LocalNameIndex)
     {
     case WellknownName.Style:
     {
         //TODO: parse and evaluate style here
         //****
     } break;
     }
 }
Esempio n. 21
0
        public void SetImageSource(string imgsrc)
        {
            //set image source
            DomAttribute attr = this.OwnerDocument.CreateAttribute("src", imgsrc);

            SetDomAttribute(attr);
            //----
            if (_principalBox != null)
            {
                InternalSetImageBinder(_owner.GetImageBinder(attr.Value));
            }
        }
Esempio n. 22
0
        public void NextAttribute_and_PreviousAttribute_adjacent_singleton()
        {
            DomDocument doc  = new DomDocument();
            var         html = doc.AppendElement("html");

            html.Attribute("lang", "en");

            DomAttribute attr = html.Attributes[0];

            Assert.Null(attr.NextAttribute);
            Assert.Null(attr.PreviousAttribute);
        }
Esempio n. 23
0
        private void InitProperty(string property, string value, DomAttributeWithInitializers withInit)
        {
            PropertyInfo prop;
            DomAttribute attr = withInit.Attribute;

            if (property == null)
            {
                var valueProp = HxlAttributeFragmentDefinition.ForComponent(attr).ValueProperty;
                if (valueProp == null)
                {
                    valueProp = Utility.ReflectGetProperty(attr.GetType(), "Value");
                }
                // TODO Might not have a value property (should implement an expression around the Value property)
                prop = valueProp;
            }
            else
            {
                // TODO Obtain line numbers
                prop = Utility.ReflectGetProperty(attr.GetType(), property);

                if (prop == null)
                {
                    throw HxlFailure.ServerAttributePropertyNotFound(attr.GetType(), property, -1, -1);
                }
            }

            if (!HxlAttributeConverter.IsExpr(value))
            {
                if (property == null)
                {
                    withInit.Attribute.Value = value;
                }

                withInit.Initializers.Add(prop.Name, value);
                return;
            }

            var buffer = new ExpressionBuffer();

            RewriteExpressionSyntax.MatchVariablesAndEmit(buffer, value);

            // TODO Could allow multiple exprs
            if (buffer.Parts.Count == 1)
            {
            }
            else
            {
                throw new NotImplementedException("ex");
            }

            attr.AddAnnotation(new ExpressionInitializers(prop, buffer.Parts[0]));
        }
Esempio n. 24
0
        CssBox CreateSelectBox(DomElement domE,
                               CssBox parentBox,
                               BoxSpec spec,
                               LayoutFarm.RootGraphic rootgfx, HtmlHost host)
        {
            //https://www.w3schools.com/html/html_form_elements.asp

            //1. as drop-down list
            //2. as list-box


            WebDom.Impl.HtmlElement htmlElem = ((WebDom.Impl.HtmlElement)domE);
            htmlElem.HasSpecialPresentation = true;
            //
            LayoutFarm.HtmlWidgets.HingeBox hingeBox = new LayoutFarm.HtmlWidgets.HingeBox(100, 30); //actual controller
            foreach (DomNode childNode in domE.GetChildNodeIterForward())
            {
                WebDom.Impl.HtmlElement childElem = childNode as WebDom.Impl.HtmlElement;
                if (childElem != null)
                {
                    //find a value
                    if (childElem.WellknownElementName == WellKnownDomNodeName.option)
                    {
                        DomAttribute domAttr = childElem.FindAttribute("value");
                        if (domAttr != null)
                        {
                            childElem.Tag = domAttr.Value;
                        }
                    }
                    hingeBox.AddItem(childElem);
                }
            }

            LayoutFarm.WebDom.Impl.HtmlElement hingeBoxDom = (LayoutFarm.WebDom.Impl.HtmlElement)hingeBox.GetPresentationDomNode((WebDom.Impl.HtmlDocument)domE.OwnerDocument);
            CssBox cssHingeBox = host.CreateBox(parentBox, hingeBoxDom, true); //create and append to the parentBox

            //
            hingeBoxDom.SetSubParentNode(domE);
            cssHingeBox.IsReplacement          = true;
            htmlElem.SpecialPresentationUpdate = (o) =>
            {
                if (hingeBox.NeedUpdateDom)
                {
                    cssHingeBox.Clear();
                    host.UpdateChildBoxes(hingeBoxDom, false);
                }
            };
#if DEBUG
            //cssHingeBox.dbugMark1 = 1;
#endif
            return(cssHingeBox);
        }
Esempio n. 25
0
        public void TestDomReadWriteResourceCreateWithArticleResourceWithResourceLinkage()
        {
            // Arrange
            var serviceModel = ClrSampleData.ServiceModelWithBlogResourceTypes;

            var articleResourceType   = serviceModel.GetResourceType <Article>();
            var articleTitleAttribute = articleResourceType.GetClrAttributeInfo(StaticReflection.GetMemberName <Article>(x => x.Title));

            var commentResourceType = serviceModel.GetResourceType <Comment>();
            var personResourceType  = serviceModel.GetResourceType <Person>();

            var expectedArticle  = ApiSampleData.ArticleResourceWithResourceLinkage;
            var expectedAuthor   = ApiSampleData.PersonResource;
            var expectedComment1 = ApiSampleData.CommentResource1;
            var expectedComment2 = ApiSampleData.CommentResource2;

            // Act
            var actual = DomReadWriteResource.Create(
                DomType.CreateFromResourceType(articleResourceType),
                DomId.CreateFromApiResourceIdentity(articleResourceType, expectedArticle),
                DomAttributes.Create(
                    DomAttribute.CreateFromApiResource(articleTitleAttribute, expectedArticle)),
                DomReadWriteRelationships.Create(
                    DomReadWriteRelationship.Create(ApiSampleData.ArticleToAuthorRel,
                                                    DomReadWriteLinks.Create(
                                                        DomReadWriteLink.Create(Keywords.Self, DomHRef.Create(ApiSampleData.ArticleToRelationshipsToAuthorHRef)),
                                                        DomReadWriteLink.Create(Keywords.Related, DomHRef.Create(ApiSampleData.ArticleToAuthorHRef))),
                                                    DomData.CreateFromResourceIdentifier(
                                                        DomReadWriteResourceIdentifier.Create(
                                                            DomType.CreateFromResourceType(personResourceType),
                                                            DomId.CreateFromApiResourceIdentity(personResourceType, expectedAuthor)))),
                    DomReadWriteRelationship.Create(ApiSampleData.ArticleToCommentsRel,
                                                    DomReadWriteLinks.Create(
                                                        DomReadWriteLink.Create(Keywords.Self, DomHRef.Create(ApiSampleData.ArticleToRelationshipsToCommentsHRef)),
                                                        DomReadWriteLink.Create(Keywords.Related, DomHRef.Create(ApiSampleData.ArticleToCommentsHRef))),
                                                    DomDataCollection.CreateFromResourceIdentifiers(
                                                        DomReadWriteResourceIdentifier.Create(
                                                            DomType.CreateFromResourceType(commentResourceType),
                                                            DomId.CreateFromApiResourceIdentity(commentResourceType, expectedComment1)),
                                                        DomReadWriteResourceIdentifier.Create(
                                                            DomType.CreateFromResourceType(commentResourceType),
                                                            DomId.CreateFromApiResourceIdentity(commentResourceType, expectedComment2))))),
                DomReadWriteLinks.Create(
                    DomReadWriteLink.Create(Keywords.Canonical, DomHRef.Create(ApiSampleData.ArticleHRef)),
                    DomReadWriteLink.Create(Keywords.Self, DomHRef.Create(ApiSampleData.ArticleHRef))),
                DomReadOnlyMeta.Create(ApiSampleData.ResourceMeta));

            this.OutputDomTree(actual);

            // Assert
            DomReadWriteResourceAssert.Equal(expectedArticle, actual);
        }
Esempio n. 26
0
        public void Attribute_implies_parent_and_owner()
        {
            DomDocument doc  = new DomDocument();
            var         html = doc.AppendElement("html");

            html.Attribute("lang", "en");

            DomAttribute attr = html.Attributes[0];

            Assert.Same(doc, attr.OwnerDocument);
            Assert.Same(html, attr.OwnerElement);
            Assert.False(doc.UnlinkedNodes.Contains(attr));
        }
Esempio n. 27
0
        private DomAttribute CreateDomAttribute(DomAttribute m)
        {
            DomAttribute attr = Document.CreateAttribute(m.Name, m.Value);

            if (attr == null)
            {
                throw new NotImplementedException();
            }

            AddImplicitType(attr.GetType());
            _current.Attributes.Add(attr);
            return(attr);
        }
Esempio n. 28
0
        public void RemoveSelf_implies_parent_and_owner()
        {
            DomDocument doc  = new DomDocument();
            var         html = doc.AppendElement("html");

            html.Attribute("lang", "en");

            DomAttribute attr = html.Attributes[0].RemoveSelf();

            Assert.Equal(0, html.Attributes.Count);
            Assert.Same(doc, attr.OwnerDocument);
            Assert.Null(attr.ParentNode);
        }
Esempio n. 29
0
        public override void SetAttribute(DomAttribute attr)
        {
            base.SetAttribute(attr); //to base
            //----------------------

            switch ((WellknownName)attr.LocalNameIndex)
            {
            case WellknownName.Src:
            {
                switch (this.WellknownElementName)
                {
                case WellKnownDomNodeName.img:
                {
                    if (_principalBox != null)
                    {
                        CssBoxImage boxImg = (CssBoxImage)_principalBox;
                        boxImg.ImageBinder = new ImageBinder(attr.Value);
                        boxImg.InvalidateGraphics();
                    }
                }
                break;
                }
            }
            break;

            case WellknownName.Style:
            {
                //TODO: parse and evaluate style here
                //****
                WebDom.Parser.CssParser miniCssParser = CssParserPool.GetFreeParser();
                //parse and evaluate the ruleset
                CssRuleSet parsedRuleSet = miniCssParser.ParseCssPropertyDeclarationList(attr.Value.ToCharArray());

                Css.BoxSpec spec = null;
                if (this.ParentNode != null)
                {
                    spec = ((HtmlElement)this.ParentNode).Spec;
                }
                foreach (WebDom.CssPropertyDeclaration propDecl in parsedRuleSet.GetAssignmentIter())
                {
                    SpecSetter.AssignPropertyValue(
                        _boxSpec,
                        spec,
                        propDecl);
                }
                CssParserPool.ReleaseParser(ref miniCssParser);
            }
            break;
            }
        }
Esempio n. 30
0
 public bool TryGetAttribute(WellknownName wellknownHtmlName, out DomAttribute result)
 {
     var found = base.FindAttribute((int)wellknownHtmlName);
     if (found != null)
     {
         result = found;
         return true;
     }
     else
     {
         result = null;
         return false;
     }
 }
Esempio n. 31
0
        static bool ProcessAttribute(DomAttribute item)
        {
            // TODO Could be escaped expression (performance)

            if (item is HxlAttribute ||
                (item.Value ?? string.Empty).Contains("$"))
            {
                item.Retain();
                return(true);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 32
0
        public bool TryGetAttribute(WellknownName wellknownHtmlName, out DomAttribute result)
        {
            var found = base.FindAttribute((int)wellknownHtmlName);

            if (found != null)
            {
                result = found;
                return(true);
            }
            else
            {
                result = null;
                return(false);
            }
        }
Esempio n. 33
0
 private void btnOK_Click(object sender, EventArgs e)
 {
     _InputAttributes.Clear();
     foreach (DataGridViewRow row in dgvAttributes.Rows)
     {
         if (row.Index != dgvAttributes.NewRowIndex)
         {
             DomAttribute item = new DomAttribute();
             item.Name  = Convert.ToString(row.Cells[0].Value);
             item.Value = Convert.ToString(row.Cells[1].Value);
             _InputAttributes.Add(item);
         }
     }//foreach
     this.DialogResult = System.Windows.Forms.DialogResult.OK;
     this.Close();
 }
Esempio n. 34
0
        protected virtual void VisitAttribute(DomAttribute attribute)
        {
            if (attribute == null)
                throw new ArgumentNullException("attribute");

            DefaultVisit(attribute);
        }
Esempio n. 35
0
 void IDomNodeVisitor.Visit(DomAttribute attribute)
 {
     VisitAttribute(attribute);
 }
Esempio n. 36
0
			public void AddAttributes (MonoDevelop.Projects.Dom.AbstractMember member, Attributes optAttributes)
			{
				if (optAttributes == null || optAttributes.Attrs == null)
					return;
				foreach (var attr in optAttributes.Attrs) {
					DomAttribute domAttribute = new DomAttribute ();
					domAttribute.Name = attr.Name;
					domAttribute.Region = ConvertRegion (attr.Location, attr.Location);
					domAttribute.AttributeType = new DomReturnType (attr.Name);
					if (attr.PosArguments != null) {
						for (int i = 0; i < attr.PosArguments.Count; i++) {
							var val = attr.PosArguments[i].Expr as Constant;
							if (val == null) {
								continue;
							}
							domAttribute.AddPositionalArgument (new CodePrimitiveExpression (val.GetValue ()));
						}
					}
					if (attr.NamedArguments != null) {
						for (int i = 0; i < attr.NamedArguments.Count; i++) {
							var val = attr.NamedArguments[i].Expr as Constant;
							if (val == null)
								continue;
							domAttribute.AddNamedArgument (((NamedArgument)attr.NamedArguments[i]).Name, new CodePrimitiveExpression (val.GetValue ()));
						}
					}
					
					member.Add (domAttribute);
				}
			}
Esempio n. 37
0
			public void AddAttributes (MonoDevelop.Projects.Dom.AbstractMember member, Attributes optAttributes)
			{
				if (optAttributes == null || optAttributes.Attrs == null)
					return;
				foreach (var attr in optAttributes.Attrs) {
					DomAttribute domAttribute = new DomAttribute ();
					domAttribute.Name = attr.Name;
					domAttribute.Region = ConvertRegion (attr.Location, attr.Location);
					domAttribute.AttributeType = new DomReturnType (attr.Name);
					member.Add (domAttribute);
				}
			}
Esempio n. 38
0
			static void AddAttributes (AbstractMember member, IEnumerable<ICSharpCode.NRefactory.Ast.AttributeSection> attributes)
			{
				CodeDomVisitor domVisitor = new CodeDomVisitor ();
				foreach (ICSharpCode.NRefactory.Ast.AttributeSection attributeSection in attributes) {
					foreach (ICSharpCode.NRefactory.Ast.Attribute attribute in attributeSection.Attributes) {
						DomAttribute domAttribute = new DomAttribute ();
						domAttribute.Name = attribute.Name;
						domAttribute.Region = ConvertRegion (attribute.StartLocation, attribute.EndLocation);
						domAttribute.AttributeType = new DomReturnType (attribute.Name);
						member.Add (domAttribute);
						foreach (ICSharpCode.NRefactory.Ast.Expression exp in attribute.PositionalArguments)
							domAttribute.AddPositionalArgument ((CodeExpression)exp.AcceptVisitor (domVisitor, null));
						foreach (ICSharpCode.NRefactory.Ast.NamedArgumentExpression nexp in attribute.NamedArguments)
							domAttribute.AddNamedArgument (nexp.Name, (CodeExpression)nexp.Expression.AcceptVisitor (domVisitor, null));
					}
				}
			}
Esempio n. 39
0
        void LexStateChanged(HtmlLexerEvent lexEvent, int startIndex, int len)
        {
            switch (lexEvent)
            {
                case HtmlLexerEvent.CommentContent:
                    {
                        //var commentContent = this.textSnapshot.Copy(startIndex, len); 

                    } break;
                case HtmlLexerEvent.FromContentPart:
                    {

                        if (curTextNode == null)
                        {
                            curTextNode = _resultHtmlDoc.CreateTextNode(
                                HtmlDecodeHelper.DecodeHtml(this.textSnapshot, startIndex, len));

                            if (curHtmlNode != null)
                            {
                                curHtmlNode.AddChild(curTextNode);
                            }
                        }
                        else
                        {
                            curTextNode.AppendTextContent(HtmlDecodeHelper.DecodeHtml(this.textSnapshot, startIndex, len));

                        }
                    } break;
                case HtmlLexerEvent.AttributeValueAsLiteralString:
                    {
                        //assign value and add to parent
                        curAttr.Value = textSnapshot.Substring(startIndex, len);
                        curHtmlNode.AddAttribute(curAttr);

                    } break;

                case HtmlLexerEvent.Attribute:
                    {
                        string nodename = textSnapshot.Substring(startIndex, len);
                        curAttr = this._resultHtmlDoc.CreateAttribute(null, nodename);

                    } break;
                case HtmlLexerEvent.NodeNameOrAttribute:
                    {
                        string name = textSnapshot.Substring(startIndex, len);
                        switch (parseState)
                        {
                            case 0:
                                {
                                    //create element 
                                    DomElement elem = this._resultHtmlDoc.CreateElement(null, name);
                                    if (curHtmlNode != null)
                                    {
                                        curHtmlNode.AddChild(elem);
                                        openEltStack.Push(curHtmlNode);
                                    }
                                    curHtmlNode = elem;
                                    parseState = 1;//attribute
                                    curTextNode = null;
                                    curAttr = null;
                                    waitingAttrName = null;
                                } break;
                            case 1:
                                {
                                    //wait for attr value 
                                    if (waitingAttrName != null)
                                    {
                                        //push waiting attr
                                        curAttr = this._resultHtmlDoc.CreateAttribute(null, waitingAttrName);
                                        curAttr.Value = "";
                                        curHtmlNode.AddAttribute(curAttr);
                                        curAttr = null;
                                    }
                                    waitingAttrName = name;
                                } break;
                            case 2:
                                {
                                    //****
                                    //node name after open slash
                                    //TODO: review here,avoid direct string comparison
                                    if (curHtmlNode.LocalName == name)
                                    {
                                        if (openEltStack.Count > 0)
                                        {
                                            waitingAttrName = null;
                                            curTextNode = null;
                                            curAttr = null;
                                            curHtmlNode = openEltStack.Pop();
                                        }
                                        parseState = 3;
                                    }
                                    else
                                    {
                                        //if not equal then check if current node need close tag or not
                                        if (HtmlDecodeHelper.IsSingleTag(curHtmlNode.LocalNameIndex))
                                        {
                                            if (openEltStack.Count > 0)
                                            {
                                                waitingAttrName = null;
                                                curHtmlNode = openEltStack.Pop();
                                                curAttr = null;
                                                curTextNode = null;
                                            }
                                            if (curHtmlNode.LocalName == name)
                                            {
                                                if (openEltStack.Count > 0)
                                                {
                                                    curTextNode = null;
                                                    curAttr = null;
                                                    curHtmlNode = openEltStack.Pop();
                                                    waitingAttrName = null;
                                                }
                                                parseState = 3;
                                            }
                                            else
                                            {
                                                //implement err handling here!
                                                throw new NotSupportedException();
                                            }
                                        }
                                        else
                                        {
                                            //implement err handling here!
                                            throw new NotSupportedException();
                                        }
                                    }
                                } break;
                            case 4:
                                {
                                    //attribute value as id
                                    if (curAttr != null)
                                    {
                                        curAttr.Value = name;
                                        curAttr = null;
                                        parseState = 0;
                                        waitingAttrName = null;
                                    }
                                    else
                                    {

                                    }
                                } break;
                            case 10:
                                {
                                    //document node 

                                    parseState = 11;
                                    //after docnodename , this may be attr of the document node
                                    this.domDocNode = (DomDocumentNode)this._resultHtmlDoc.CreateDocumentNodeElement();
                                    domDocNode.DocNodeName = name;
                                } break;
                            case 11:
                                {
                                    //doc 
                                    domDocNode.AddParameter(name);

                                } break;
                            default:
                                {
                                } break;
                        }

                    } break;
                case HtmlLexerEvent.VisitCloseAngle:
                    {
                        //close angle of current new node
                        //enter into its content

                        if (parseState == 11)
                        {
                            //add doctype to html
                            this._resultHtmlDoc.RootNode.AddChild(this.domDocNode);
                            domDocNode = null;
                        } 

                        if (waitingAttrName != null)
                        {
                            curAttr = this._resultHtmlDoc.CreateAttribute(null, waitingAttrName);
                            curAttr.Value = "";
                            curHtmlNode.AddAttribute(curAttr);
                            curAttr = null;
                        }


                        waitingAttrName = null;
                        parseState = 0;
                        curTextNode = null;
                        curAttr = null;
                    } break;
                case HtmlLexerEvent.VisitAttrAssign:
                    {
                        parseState = 4;
                    } break;
                case HtmlLexerEvent.VisitOpenSlashAngle:
                    {
                        parseState = 2;
                    } break;
                case HtmlLexerEvent.VisitCloseSlashAngle:
                    {

                        if (openEltStack.Count > 0)
                        {
                            curTextNode = null;
                            curAttr = null;
                            waitingAttrName = null;
                            curHtmlNode = openEltStack.Pop();
                        }
                        parseState = 0;

                    } break;
                case HtmlLexerEvent.VisitOpenAngleExclimation:
                    {
                        parseState = 10;
                    } break;
                default:
                    {
                        //1. visit open angle
                    } break;

            }
        }
Esempio n. 40
0
 public void ResetParser()
 {
     this._resultHtmlDoc = null;
     this.openEltStack.Clear();
     this.curHtmlNode = null;
     this.curAttr = null;
     this.curTextNode = null;
     this.parseState = 0;
     this.textSnapshot = null;
 }
Esempio n. 41
0
 void IDomValue.Initialize(DomAttribute attribute)
 {
     this.attribute = attribute;
 }
			IEnumerable<IAttribute> ConvertAttributes (Attributes optAttributes, IMemberContext mc)
			{
				List<IAttribute> atts = new List<IAttribute> ();
				
				if (optAttributes == null || optAttributes.Attrs == null)
					return atts;
				ResolveContext ctx = new ResolveContext (mc);
				foreach (var section in optAttributes.Sections) {
				
					foreach (var attr in section) {
						DomAttribute domAttribute = new DomAttribute ();
						domAttribute.Name = ConvertQuoted (attr.Name);
						domAttribute.Region = ConvertRegion (attr.Location, attr.Location);
						domAttribute.AttributeType = ConvertReturnType (attr.TypeNameExpression);
						if (attr.PosArguments != null) {
							for (int i = 0; i < attr.PosArguments.Count; i++) {
								CodeExpression domExp;
								var exp = attr.PosArguments [i].Expr;
								
								if (exp is TypeOf) {
									TypeOf tof = (TypeOf)exp;
									IReturnType rt = ConvertReturnType (tof.TypeExpression);
									domExp = new CodeTypeOfExpression (rt.FullName);
								} else if (exp is Binary) {
									// Currently unsupported in the old dom (will be in the new dom)
									continue;
								} else if (exp is Constant) {
									try {
										var res = exp.Resolve (ctx);
										var val = res as Constant;
										if (val == null)
											continue;
										domExp = new CodePrimitiveExpression (val.GetValue ());
									} catch {
										continue;
									}
								} else {
									try {
										domExp = ResolveMemberAccessExpression (exp);
									} catch {
										continue;
									}
								}
								if (domExp != null)
									domAttribute.AddPositionalArgument (domExp);
							}
						}
						if (attr.NamedArguments != null) {
							for (int i = 0; i < attr.NamedArguments.Count; i++) {
								var val = attr.NamedArguments [i].Expr as Constant;
								if (val == null)
									continue;
								domAttribute.AddNamedArgument (((NamedArgument)attr.NamedArguments [i]).Name, new CodePrimitiveExpression (val.GetValue ()));
							}
						}
						
						atts.Add (domAttribute);
					}
				}
				return atts;
			}
Esempio n. 43
0
		public static DomAttribute ReadAttribute (BinaryReader reader, INameDecoder nameTable, IDomObjectTable objectTable)
		{
			DomAttribute attr = new DomAttribute ();
			attr.Name = ReadString (reader, nameTable);
			attr.Region = ReadRegion (reader, nameTable);
			attr.AttributeTarget = (AttributeTarget)reader.ReadInt32 ();
			attr.AttributeType = ReadReturnType (reader, nameTable, objectTable);
			
			// Named argument count
			uint num = ReadUInt (reader, 500);
			string[] names = new string[num];
			for (int n=0; n<num; n++)
				names [n] = ReadString (reader, nameTable);
			
			CodeExpression[] exps = ReadExpressionArray (reader, nameTable);
			
			int i;
			for (i=0; i<num; i++)
				attr.AddNamedArgument (names [i], exps [i]);
			
			for (; i<exps.Length; i++)
				attr.AddPositionalArgument (exps [i]);

			return attr;
		}
		public void ReadWriteAttributeTest ()
		{
			DomAttribute attr = new DomAttribute ();
			
			CodePropertyReferenceExpression exp1 = new CodePropertyReferenceExpression ();
			exp1.TargetObject = new CodeTypeReferenceExpression ("SomeType");
			exp1.PropertyName = "SomeProperty";
			
			CodeTypeOfExpression exp2 = new CodeTypeOfExpression ("SomeTypeOf");
			
			CodeBinaryOperatorExpression exp3 = new CodeBinaryOperatorExpression ();
			exp3.Left = new CodePrimitiveExpression ("one");
			exp3.Right = new CodePrimitiveExpression ("two");
			exp3.Operator = CodeBinaryOperatorType.Add;
			
			CodePrimitiveExpression exp4 = new CodePrimitiveExpression (37);
			
			attr.AddPositionalArgument (exp1);
			attr.AddPositionalArgument (exp2);
			attr.AddPositionalArgument (exp3);
			attr.AddPositionalArgument (exp4);
			
			MemoryStream ms = new MemoryStream ();
			BinaryWriter writer = new BinaryWriter (ms);
			DomPersistence.Write (writer, DefaultNameEncoder, attr);
			byte[] bytes = ms.ToArray ();
			DomAttribute result = DomPersistence.ReadAttribute (CreateReader (bytes), DefaultNameDecoder);
			
			Assert.AreEqual (4, result.PositionalArguments.Count);
			
			Assert.AreEqual (typeof(CodePropertyReferenceExpression), result.PositionalArguments [0].GetType ());
			CodePropertyReferenceExpression rexp1 = (CodePropertyReferenceExpression) result.PositionalArguments [0];
			Assert.AreEqual (typeof(CodeTypeReferenceExpression), rexp1.TargetObject.GetType ());
			Assert.AreEqual ("SomeType", ((CodeTypeReferenceExpression)rexp1.TargetObject).Type.BaseType);
			Assert.AreEqual ("SomeProperty", rexp1.PropertyName);
			
			Assert.AreEqual (typeof(CodeTypeOfExpression), result.PositionalArguments [1].GetType ());
			Assert.AreEqual ("SomeTypeOf", ((CodeTypeOfExpression)result.PositionalArguments [1]).Type.BaseType);
			
			Assert.AreEqual (typeof(CodeBinaryOperatorExpression), result.PositionalArguments [2].GetType ());
			CodeBinaryOperatorExpression rexp3 = (CodeBinaryOperatorExpression) result.PositionalArguments [2];
			Assert.AreEqual (typeof(CodePrimitiveExpression), rexp3.Left.GetType ());
			Assert.AreEqual ("one", ((CodePrimitiveExpression)rexp3.Left).Value);
			Assert.AreEqual (typeof(CodePrimitiveExpression), rexp3.Right.GetType ());
			Assert.AreEqual ("two", ((CodePrimitiveExpression)rexp3.Right).Value);
			
			Assert.AreEqual (typeof(CodePrimitiveExpression), result.PositionalArguments [3].GetType ());
			Assert.AreEqual (37, ((CodePrimitiveExpression)result.PositionalArguments [3]).Value);
		}