private void ReadXmlProperties(XmlReader reader)
        {
            var list = new List <PropertyExtractor>();

            reader.MoveToContent();
            reader.AssertStartElement("Properties", SchemaAnnotations.NAMESPACE);
            Precedence = reader.HasAttribute("precedence")
                                ? reader.GetAttribute("precedence").IfNotNull(v => v.Parse <ExtractorPrecedence>())
                                : default(ExtractorPrecedence);
            reader.ReadStartElement("Properties", SchemaAnnotations.NAMESPACE);
            while (reader.NodeType == XmlNodeType.Element)
            {
                var name = new XmlQualifiedName(reader.LocalName, reader.NamespaceURI);
                var mode = reader.HasAttribute("mode")
                                        ? reader.GetAttribute("mode").IfNotNull(v => v.Parse <ExtractionMode>())
                                        : reader.HasAttribute("promoted")
                                                ? Convert.ToBoolean(reader.GetAttribute("promoted"))
                                                        ? ExtractionMode.Promote
                                                        : default(ExtractionMode)
                                                : default(ExtractionMode);
                var qnameValueMode = reader.HasAttribute("qnameValue")
                                        ? reader.GetAttribute("qnameValue").IfNotNull(v => v.Parse <QNameValueExtractionMode>())
                                        : QNameValueExtractionMode.Default;
                if (reader.HasAttribute("xpath"))
                {
                    var xpathExpression = reader.GetAttribute("xpath");
                    var extractor       = qnameValueMode == QNameValueExtractionMode.Default
                                                ? new XPathExtractor(name, xpathExpression, mode)
                                                : new QNameValueExtractor(name, xpathExpression, mode, qnameValueMode);
                    list.Add(extractor);
                }
                else if (reader.HasAttribute("value"))
                {
                    var extractor = new ConstantExtractor(name, reader.GetAttribute("value"), mode);
                    list.Add(extractor);
                }
                else if (!reader.HasAttribute("mode"))
                {
                    throw new ConfigurationErrorsException("ExtractionMode is missing for PropertyExtractor without a Value or an XPath.");
                }
                else
                {
                    var extractor = new PropertyExtractor(name, mode);
                    list.Add(extractor);
                }
                reader.Read();
            }
            if (!reader.EOF)
            {
                reader.AssertEndElement("Properties", SchemaAnnotations.NAMESPACE);
                reader.ReadEndElement();
            }
            Extractors = list.ToArray();
        }
示例#2
0
        public override void ReadXml(XmlReader reader)
        {
            reader.AssertStartElement("Extractors");
            var isEmpty = reader.IsEmptyElement;

            reader.ReadStartElement("Extractors");
            if (isEmpty)
            {
                return;
            }
            base.ReadXml(reader);
            reader.ReadEndElement("Extractors");
        }
        public override void ReadXml(XmlReader reader)
        {
            if (reader == null)
            {
                throw new ArgumentNullException(nameof(reader));
            }
            reader.AssertStartElement("Extractors");
            var isEmpty = reader.IsEmptyElement;

            reader.ReadStartElement("Extractors");
            if (isEmpty)
            {
                return;
            }
            base.ReadXml(reader);
            reader.ReadEndElement("Extractors");
        }
示例#4
0
        public static IMicroComponent DeserializeMicroPipelineComponent(this XmlReader reader)
        {
            if (reader == null)
            {
                throw new ArgumentNullException(nameof(reader));
            }
            reader.AssertStartElement(Constants.MICRO_COMPONENT_ELEMENT_NAME);
            var microPipelineComponentType = Type.GetType(reader.GetMandatoryAttribute(Constants.MICRO_COMPONENT_TYPE_ATTRIBUTE_NAME), true);

            if (!typeof(IMicroComponent).IsAssignableFrom(microPipelineComponentType))
            {
                throw new ConfigurationErrorsException($"{microPipelineComponentType.AssemblyQualifiedName} does not implement {nameof(IMicroComponent)}.");
            }

            // reset position to an element as required to call ReadSubtree()
            reader.MoveToElement();
            var microPipelineComponentXmlSubtree = reader.ReadSubtree();

            IMicroComponent component;

            if (typeof(IXmlSerializable).IsAssignableFrom(microPipelineComponentType))
            {
                component = (IMicroComponent)Activator.CreateInstance(microPipelineComponentType);
                // relieve micro pipeline components from having to deal with surrounding mComponent XML element
                microPipelineComponentXmlSubtree.MoveToContent();
                reader.ReadStartElement(Constants.MICRO_COMPONENT_ELEMENT_NAME);
                ((IXmlSerializable)component).ReadXml(microPipelineComponentXmlSubtree);
            }
            else
            {
                var overrides = new XmlAttributeOverrides();
                overrides.Add(microPipelineComponentType, new XmlAttributes {
                    XmlRoot = new XmlRootAttribute(Constants.MICRO_COMPONENT_ELEMENT_NAME)
                });
                var serializer = CachingXmlSerializerFactory.Create(microPipelineComponentType, overrides);
                component = (IMicroComponent)serializer.Deserialize(microPipelineComponentXmlSubtree);
            }

            reader.Skip();
            return(component);
        }
        internal static IMicroPipelineComponent DeserializeMicroPipelineComponent(this XmlReader reader)
        {
            reader.AssertStartElement("mComponent");
            var microPipelineComponentType = Type.GetType(reader.GetMandatoryAttribute("name"), true);

            if (!typeof(IMicroPipelineComponent).IsAssignableFrom(microPipelineComponentType))
            {
                throw new ConfigurationErrorsException(
                          string.Format(
                              "{0} does not implement {1}.",
                              microPipelineComponentType.AssemblyQualifiedName,
                              typeof(IMicroPipelineComponent).Name));
            }

            // reset position to an element as required to call ReadSubtree()
            reader.MoveToElement();
            var microPipelineComponentXmlSubtree = reader.ReadSubtree();

            IMicroPipelineComponent component;

            if (typeof(IXmlSerializable).IsAssignableFrom(microPipelineComponentType))
            {
                component = (IMicroPipelineComponent)Activator.CreateInstance(microPipelineComponentType);
                // relieve micro pipeline components from having to deal with surrounding mComponent XML element
                microPipelineComponentXmlSubtree.MoveToContent();
                reader.ReadStartElement("mComponent");
                ((IXmlSerializable)component).ReadXml(microPipelineComponentXmlSubtree);
            }
            else
            {
                var overrides = new XmlAttributeOverrides();
                overrides.Add(microPipelineComponentType, new XmlAttributes {
                    XmlRoot = new XmlRootAttribute("mComponent")
                });
                var serializer = Stateless.Xml.Serialization.XmlSerializerFactory.Create(microPipelineComponentType, overrides);
                component = (IMicroPipelineComponent)serializer.Deserialize(microPipelineComponentXmlSubtree);
            }

            reader.Skip();
            return(component);
        }