示例#1
0
        public static void LoadFromXml(this SpecificationsCollection collection, XElement element, string ns = null)
        {
            ns = ns ?? string.Empty;

            XmlSchemaSet schemaSet = GetShemaSet(ns);

            XmlSchema schema = ValidateXsd(element, ns, schemaSet);

            CollectionFromValidated(collection, element, schema, schemaSet, ns);
        }
示例#2
0
        public static void ToXml(this SpecificationsCollection collection, XmlWriter writer, string ns = null)
        {
            if (collection == null)
            {
                throw new ArgumentNullException(nameof(collection));
            }
            if (writer == null)
            {
                throw new ArgumentNullException(nameof(writer));
            }
            ns = ns ?? string.Empty;

            writer.WriteStartElement(Consts.CollectionRoot, ns);

            // Value references
            writer.WriteStartElement(Consts.RefValuesCollection, ns);
            foreach (var val in collection.ValuesForReference)
            {
                writer.WriteStartElement(Consts.Add, ns);
                writer.WriteAttributeString(Consts.Key, val.Key);
                XmlSerializeSpecificationVisitor.WriteValue(writer, val.Value);
                writer.WriteEndElement();
            }

            foreach (string runtimeValue in collection.AllowedRuntimeValueReferenceKeys.Except(
                         collection.ValuesForReference.Keys))
            {
                writer.WriteStartElement(Consts.Runtime, ns);
                writer.WriteAttributeString(Consts.Key, runtimeValue);
                writer.WriteEndElement();
            }

            writer.WriteEndElement();

            // Specification references
            writer.WriteStartElement(Consts.RefSpecCollection, ns);
            WriteSpecifications(collection.SpecificationsForReference, writer, ns);

            foreach (string runtimeSpec in collection.AllowedRuntimeSpecificationReferenceKeys.Except(
                         collection.SpecificationsForReference.Keys))
            {
                writer.WriteStartElement(Consts.Runtime, ns);
                writer.WriteAttributeString(Consts.Key, runtimeSpec);
                writer.WriteEndElement();
            }
            writer.WriteEndElement();

            // Main specifications
            writer.WriteStartElement(Consts.SpecCollection, ns);
            WriteSpecifications(collection.Specifications, writer, ns);
            writer.WriteEndElement();

            writer.WriteEndElement();
        }
示例#3
0
        public static string ToXml(this SpecificationsCollection collection, string ns = null)
        {
            StringBuilder stringBuilder = new StringBuilder();

            using (XmlWriter writer = XmlWriter.Create(
                       stringBuilder,
                       writerSettings))
            {
                collection.ToXml(writer, ns);
            }

            return(stringBuilder.ToString());
        }
示例#4
0
        private static void CollectionFromValidated(
            SpecificationsCollection collection,
            XElement element,
            XmlSchema schema,
            XmlSchemaSet schemaSet,
            string ns)
        {
            var values = element.Element(XName.Get(Consts.RefValuesCollection, ns));

            if (values != null)
            {
                foreach (XElement add in values.Elements(XName.Get(Consts.Add, ns)))
                {
                    string             key   = GetKey(add, ns);
                    SpecificationValue value = ParseSpecificationValue(add, schema, schemaSet, ns);
                    collection.ValuesForReference.Add(key, value);
                }

                foreach (XElement runtime in values.Elements(XName.Get(Consts.Runtime, ns)))
                {
                    string key = GetKey(runtime, ns);
                    collection.AllowedRuntimeValueReferenceKeys.Add(key);
                }
            }

            var definitions = element.Element(XName.Get(Consts.RefSpecCollection, ns));

            if (definitions != null)
            {
                foreach (XElement add in definitions.Elements(XName.Get(Consts.Add, ns)))
                {
                    string        key  = GetKey(add, ns);
                    Specification spec = FromXmlValidated(
                        add.Elements().First(e => e.Name.Namespace == ns),
                        schema,
                        schemaSet,
                        ns);
                    collection.SpecificationsForReference.Add(key, spec);
                }

                foreach (XElement runtime in definitions.Elements(XName.Get(Consts.Runtime, ns)))
                {
                    string key = GetKey(runtime, ns);
                    collection.AllowedRuntimeSpecificationReferenceKeys.Add(key);
                }
            }

            var specifications = element.Element(XName.Get(Consts.SpecCollection, ns));

            if (specifications != null)
            {
                foreach (XElement add in specifications.Elements(XName.Get(Consts.Add, ns)))
                {
                    string        key  = GetKey(add, ns);
                    Specification spec = FromXmlValidated(
                        add.Elements().First(e => e.Name.Namespace == ns),
                        schema,
                        schemaSet,
                        ns);
                    collection.Specifications.Add(key, spec);
                }
            }
        }