コード例 #1
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);
        }
コード例 #2
0
        static IEnumerable <KeyValuePair <string, object> > _Parse(string text)
        {
            if (string.IsNullOrEmpty(text))
            {
                yield break;
            }
            MatchCollection matches       = KVP.Matches(text);
            int             expectedIndex = 0;

            foreach (Match match in matches)
            {
                if (match.Index > expectedIndex)
                {
                    throw HxlFailure.InvalidDirective();
                }

                Group  valueGroup = match.Groups["Value"];
                string value      = null;
                value = (valueGroup.Success ? WebUtility.HtmlDecode(valueGroup.Value.Trim('"')).Trim() : null);

                string key = (match.Groups["Key"].Value ?? string.Empty).Trim();

                yield return(new KeyValuePair <string, object>(key, value));

                expectedIndex = match.Index + match.Length;
            }
        }
コード例 #3
0
        protected override void VisitElement(HtmlElement node)
        {
            var child = Document.CreateElement(node.NodeName);

            if (child == null)
            {
                throw HxlFailure.ServerElementCannotBeCreated(node.NodeName, -1, -1);
            }

            var oldCurrent = _current;

            AppendChild(child);

            // Consolidate server attributes
            var serverAttributes
                = new Dictionary <string, DomAttributeWithInitializers>();

            AddImplicitType(child.GetType());

            foreach (var m in node.Attributes)
            {
                if (m.Name.Contains(":"))
                {
                    var    hxl = ResolveName(m.Name);
                    string id  = hxl.Name;

                    DomAttributeWithInitializers withInit;

                    // Coalesce attribute extension syntax
                    if (!serverAttributes.TryGetValue(id, out withInit))
                    {
                        withInit = CreateServerDomAttribute(m, hxl.Property);
                        serverAttributes.Add(id, withInit);
                    }

                    if (hxl.Property == null)
                    {
                        InitProperty(null, m.Value, withInit);
                    }
                    else
                    {
                        InitProperty(hxl.Property, m.Value, withInit);
                    }
                }
                else
                {
                    CreateDomAttribute(m);
                }
            }

            foreach (var m in serverAttributes.Values)
            {
                Activation.Initialize(m.Attribute, m.Initializers);
            }

            VisitRange(node.ChildNodes);

            _current = oldCurrent;
        }
コード例 #4
0
 public void OnConversionException(string property, object value, Exception exception)
 {
     // If the value looks like an expression, assume that expression parsing will handle it
     if (System.Convert.ToString(value).Contains("$"))
     {
         return;
     }
     else
     {
         throw HxlFailure.FailedToReadServerElement(exception);
     }
 }
コード例 #5
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]));
        }
コード例 #6
0
        protected override void VisitProcessingInstruction(HtmlProcessingInstruction node)
        {
            var macro = Document.CreateProcessingInstruction(node.Target, node.Data);

            // TODO Missing line numbers and positions
            // TODO Enforce directives only at document level
            int line = -1;
            int pos  = -1;

            if (macro != null &&
                (macro.Target == "xml" || (macro is HxlProcessingInstruction)))
            {
                _current.Append(macro);
                AddImplicitType(macro.GetType());
            }
            else
            {
                throw HxlFailure.DirectiveNotDefined(node.Target, line, pos);
            }
        }