public ChildElementProcessorTest()
 {
     this.testee    = new ChildElementProcessor(this.elementProcessors, this.attributeProcessors);
     this.syntax    = new Mock <IBindingConfigurationSyntax <object> >().Object;
     this.element   = new XElement("bind");
     this.ownerMock = CreateOwnerMock("bind");
 }
 /// <summary>
 /// Handles the attribute.
 /// </summary>
 /// <param name="value">The value of the attribute.</param>
 /// <param name="owner">The owner of this instance.</param>
 /// <param name="syntax">The binding syntax.</param>
 public override void Process(
     string value,
     IOwnXmlNodeProcessor owner,
     IBindingConfigurationSyntax <object> syntax)
 {
     syntax.Named(value);
 }
 public ChildElementProcessorTest()
 {
     this.testee = new ChildElementProcessor(this.elementProcessors, this.attributeProcessors);
     this.syntax = new Mock<IBindingConfigurationSyntax<object>>().Object;
     this.element = new XElement("bind");
     this.ownerMock = CreateOwnerMock("bind");
 }
 /// <summary>
 /// Handles the attribute.
 /// </summary>
 /// <param name="value">The value of the attribute.</param>
 /// <param name="owner">The owner of this instance.</param>
 /// <param name="syntax">The binding syntax.</param>
 public override void Process(
     string value, 
     IOwnXmlNodeProcessor owner,
     IBindingConfigurationSyntax<object> syntax)
 {
     syntax.Named(value);
 }
        /// <summary>
        /// Processes the specified element.
        /// </summary>
        /// <param name="element">The element that shall be processed.</param>
        /// <param name="owner">The owner of this instance.</param>
        /// <param name="syntax">The binding syntax.</param>
        public override void Process(
            XElement element,
            IOwnXmlNodeProcessor owner,
            IBindingConfigurationSyntax <object> syntax)
        {
            XAttribute keyAttribute   = element.RequiredAttribute("key");
            XAttribute valueAttribute = element.RequiredAttribute("value");

            syntax.WithMetadata(keyAttribute.Value, valueAttribute.Value);
        }
 /// <summary>
 /// Processes the child elements.
 /// </summary>
 /// <param name="element">The element.</param>
 /// <param name="syntax">The syntax.</param>
 public void ProcessChildElements(
     XElement element,
     IBindingConfigurationSyntax <object> syntax)
 {
     foreach (var childElement in element.Elements())
     {
         var processor = this.elementProcessors.GetProcessor(childElement.Name.LocalName, this.owner.XmlNodeName);
         processor.Process(childElement, this.owner, syntax);
     }
 }
 /// <summary>
 /// Handles the attribute.
 /// </summary>
 /// <param name="value">The value of the attribute.</param>
 /// <param name="owner">The owner of this instance.</param>
 /// <param name="syntax">The binding syntax.</param>
 /// <exception cref="XmlException">An unknown scope value was found.</exception>
 public override void Process(
     string value,
     IOwnXmlNodeProcessor owner,
     IBindingConfigurationSyntax <object> syntax)
 {
     if (this.scopeHandlers.TryGetValue(value, out IScopeHandler scopeHandler))
     {
         scopeHandler.SetScope(syntax);
     }
     else
     {
         throw new XmlException(this.GetInvalidScopeErrorMessage(value, owner.XmlNodeName));
     }
 }
 /// <summary>
 /// Handles the attribute.
 /// </summary>
 /// <param name="value">The value of the attribute.</param>
 /// <param name="owner">The owner of this instance.</param>
 /// <param name="syntax">The binding syntax.</param>
 /// <exception cref="ConfigurationErrorsException">An unknown scope value was found.</exception>
 public override void Process(
     string value, 
     IOwnXmlNodeProcessor owner,
     IBindingConfigurationSyntax<object> syntax)
 {
     IScopeHandler scopeHandler;
     if (this.scopeHandlers.TryGetValue(value, out scopeHandler))
     {
         scopeHandler.SetScope(syntax);
     }
     else
     {
         throw new ConfigurationErrorsException(this.GetInvalidScopeErrorMessage(value, owner.XmlNodeName));
     }
 }
        /// <summary>
        /// Processes the attributes of the given element.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <param name="syntax">The syntax.</param>
        /// <param name="excludedAttributes">The attributes that are excluded.</param>
        public void ProcessAttributes(XElement element, IBindingConfigurationSyntax <object> syntax, IEnumerable <string> excludedAttributes)
        {
            var requiredAttributeProcessors = this.attributeProcessors.Values.Where(processor => processor.Required).ToList();

            foreach (var attribute in element.Attributes().Where(a => !excludedAttributes.Contains(a.Name.LocalName)))
            {
                var processor = this.attributeProcessors.GetProcessor(attribute.Name.LocalName, this.owner.XmlNodeName);
                processor.Process(attribute.Value, this.owner, syntax);
                requiredAttributeProcessors.Remove(processor);
            }

            if (requiredAttributeProcessors.Any())
            {
                throw new XmlException(
                          string.Format(
                              "Required attributes for element <{0}> not found: {1}",
                              element.Name,
                              string.Join(", ", requiredAttributeProcessors.Select(processor => processor.XmlNodeName).ToArray())));
            }
        }
 /// <summary>
 /// Processes the specified element.
 /// </summary>
 /// <param name="element">The element that shall be processed.</param>
 /// <param name="owner">The owner of this instance.</param>
 /// <param name="bindingSyntax">The binding syntax.</param>
 public abstract void Process(
     XElement element,
     IOwnXmlNodeProcessor owner,
     IBindingConfigurationSyntax <object> bindingSyntax);
Example #11
0
 /// <summary>
 /// Handles the attribute.
 /// </summary>
 /// <param name="value">The value of the attribute.</param>
 /// <param name="owner">The owner of this instance.</param>
 /// <param name="syntax">The binding syntax.</param>
 public abstract void Process(
     string value,
     IOwnXmlNodeProcessor owner,
     IBindingConfigurationSyntax <object> syntax);
 /// <summary>
 /// Handles the attribute.
 /// </summary>
 /// <param name="value">The value of the attribute.</param>
 /// <param name="owner">The owner of this instance.</param>
 /// <param name="syntax">The binding syntax.</param>
 public abstract void Process(
     string value, 
     IOwnXmlNodeProcessor owner, 
     IBindingConfigurationSyntax<object> syntax);
 /// <summary>
 /// Processes the attributes of the given element.
 /// </summary>
 /// <param name="element">The element.</param>
 /// <param name="syntax">The binding syntax.</param>
 public void ProcessAttributes(
     XElement element,
     IBindingConfigurationSyntax <object> syntax)
 {
     this.ProcessAttributes(element, syntax, Enumerable.Empty <string>());
 }