Esempio n. 1
0
        public void v9()
        {
            try
            {
                XmlSchemaSet sc = new XmlSchemaSet();
                sc.Add(null, Path.Combine(TestData._Root, "import_v16_b.xsd"));

                //before compile
                XmlSchema parent = sc.Add(null, Path.Combine(TestData._Root, "import_v16_a.xsd"));
                sc.Compile();
                sc.RemoveRecursive(parent);
                CError.Compare(sc.Count, 1, "Count");
                CError.Compare(sc.Contains("ns-b"), true, "Contains");

                //after compile
                parent = sc.Add(null, Path.Combine(TestData._Root, "import_v16_a.xsd"));
                sc.RemoveRecursive(parent);
                CError.Compare(sc.Count, 1, "Count");
                CError.Compare(sc.Contains("ns-b"), true, "Contains");

                return;
            }
            catch (XmlSchemaException e)
            {
                _output.WriteLine("Exception : " + e.Message);
            }
            Assert.True(false);
        }
        public void v4()
        {
            XmlSchemaSet sc         = new XmlSchemaSet();
            XmlSchema    Schema     = XmlSchema.Read(new StreamReader(new FileStream(TestData._FileXSD1, FileMode.Open, FileAccess.Read)), null);
            XmlSchema    SchemaNew1 = sc.Add(Schema);
            XmlSchema    SchemaNew2 = sc.Add("schema1.xsd", TestData._FileXSD1);

            // both schemas are added but they are dup
            Assert.Equal(sc.Count, 2);
            Assert.Equal(sc.Contains(SchemaNew1), true);
            Assert.Equal(sc.Contains(SchemaNew2), true);
            Assert.Equal(sc.IsCompiled, false);

            // check its not the same schema as first
            Assert.Equal(Schema == SchemaNew1, true);
            Assert.Equal(Schema == SchemaNew2, false);

            try
            {
                sc.Compile();
            }
            catch (XmlSchemaException)
            {
                Assert.Equal(sc.Count, 2);
                Assert.Equal(sc.Contains(SchemaNew1), true);
                Assert.Equal(sc.Contains(SchemaNew2), true);
                Assert.Equal(sc.IsCompiled, false);
                return;
            }

            Assert.True(false);
        }
Esempio n. 3
0
        public void LoadSchemaSetWithQueries()
        {
            XmlSchemaSet schemaSet = SchemaLoader.Queries.LoadSchemaSet();

            Assert.That(schemaSet, Is.Not.Null);
            Assert.That(schemaSet.Count, Is.EqualTo(2));
            Assert.That(schemaSet.Contains(PrefixNamespace.QueryConfigurationNamespace.Uri), Is.True);
            Assert.That(schemaSet.Contains("http://www.re-motion.org/Data/DomainObjects/Types"), Is.True);
        }
        //[Variation(Desc = "v3 - Contains with existing schema, Remove it, Contains again")]
        public void v3()
        {
            XmlSchemaSet sc     = new XmlSchemaSet();
            XmlSchema    Schema = sc.Add("xsdauthor", TestData._XsdAuthor);

            Assert.Equal(sc.Contains("xsdauthor"), true);

            sc.Remove(Schema);

            Assert.Equal(sc.Contains("xsdauthor"), false);

            return;
        }
        //[Variation(Desc = "v4 - Contains for 2 existing schemas, Remove one, Contains again", Priority = 0)]
        public void v4()
        {
            XmlSchemaSet sc      = new XmlSchemaSet();
            XmlSchema    Schema1 = sc.Add("xsdauthor", TestData._XsdAuthor);
            XmlSchema    Schema2 = sc.Add("xsdauthor", TestData._XsdNoNs);

            Assert.True(sc.Contains("xsdauthor"));

            sc.Remove(Schema1);

            Assert.True(sc.Contains("xsdauthor"));

            return;
        }
        static XmlProcessor()
        {
            SchemaSet = new XmlSchemaSet();

            var currentType   = typeof(XmlProcessor);
            var typeNamespace = currentType.Namespace;// .Substring(0,currentType.Namespace.LastIndexOf("XML.", StringComparison.Ordinal));// + "Xml";


            foreach (var pair in TypeSchemaMapping)
            {
                var xmlRoot = (XmlTypeAttribute)Attribute.GetCustomAttribute(pair.Key, typeof(XmlTypeAttribute));

                if (!SchemaSet.Contains(xmlRoot.Namespace))
                {
                    using (var stream = typeof(XmlProcessor).Assembly.GetManifestResourceStream($"{typeNamespace}." + pair.Value))
                    {
                        SchemaSet.Add(xmlRoot.Namespace, XmlReader.Create(stream));
                    }
                }
            }

            SchemaSet.Compile();

            // this prevents an exception: SignatureDescription could not be created for the signature algorithm supplied.
            // Apparently System.Security.Cryptography.Xml.SignedXml can't deal with SHA256 by default
            CryptoConfig.AddAlgorithm(typeof(RSAPKCS1SHA256SignatureDescription), "http://www.w3.org/2001/04/xmldsig-more#rsa-sha256");
        }
        public static XmlSchemaType StaticGetSchema(XmlSchemaSet schemas)
        {
            if (schemas == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("schemas");
            }

            XmlSchemaComplexType outerType = CreateOuterType();

            if (schemas.Contains(XPathMessageFilter.Namespace))
            {
                IEnumerator en = schemas.Schemas(XPathMessageFilter.Namespace).GetEnumerator();
                en.MoveNext();
                ((XmlSchema)en.Current).Items.Add(outerType);
            }
            else
            {
                XmlSchema schema = new XmlSchema();
                schema.Items.Add(outerType);
                schema.TargetNamespace = XPathMessageFilter.Namespace;

                schemas.Add(schema);
            }

            return(outerType);
        }
        static XmlSecurity()
        {
            SchemaSet = new XmlSchemaSet();

            var currentType = typeof(XmlSecurity);

            Debug.Assert(currentType.Namespace != null, "currentType.Namespace != null");
            var typeNamespace = currentType.Namespace.Substring(0, currentType.Namespace.LastIndexOf("Security", StringComparison.Ordinal)) + "Xml";

            foreach (var pair in TypeSchemaMapping)
            {
                var xmlRoot = (XmlTypeAttribute)Attribute.GetCustomAttribute(pair.Key, typeof(XmlTypeAttribute));

                if (!SchemaSet.Contains(xmlRoot.Namespace))
                {
                    using (var stream = currentType.Assembly.GetManifestResourceStream(typeNamespace + "." + pair.Value))
                    {
                        if (stream == null)
                        {
                            throw new Exception(string.Format("Error on getting resource {0}.{1}", typeNamespace, pair.Value));
                        }

                        stream.Position = 0;
                        SchemaSet.Add(xmlRoot.Namespace, XmlReader.Create(stream));
                    }
                }
            }

            SchemaSet.Compile();

            // this prevents an exception: SignatureDescription could not be created for the signature algorithm supplied.
            // Apparently System.Security.Cryptography.Xml.SignedXml can't deal with SHA256 by default
            CryptoConfig.AddAlgorithm(typeof(RSAPKCS1SHA256SignatureDescription), "http://www.w3.org/2001/04/xmldsig-more#rsa-sha256");
        }
Esempio n. 9
0
 bool LoadSchema(XmlSchemaSet set, SchemaResolver resolver, XmlNode ctx, string nsuri, string filename)
 {
     try {
         Uri baseUri = this.baseUri;
         if (!string.IsNullOrEmpty(ctx.BaseURI))
         {
             baseUri = new Uri(ctx.BaseURI);
         }
         Uri resolved;
         if (baseUri != null)
         {
             resolved = new Uri(baseUri, filename);
         }
         else
         {
             resolved = new Uri(filename, UriKind.RelativeOrAbsolute);
         }
         XmlSchema s = resolver.GetEntity(resolved, "", typeof(XmlSchema)) as XmlSchema;
         if ((s.TargetNamespace + "") != (nsuri + ""))
         {
             ReportError(Severity.Warning, SR.TNSMismatch, ctx);
         }
         else if (!set.Contains(s))
         {
             set.Add(s);
             return(true);
         }
     } catch (Exception e) {
         ReportError(Severity.Warning, string.Format(SR.SchemaLoadError, filename, e.Message), ctx);
     }
     return(false);
 }
Esempio n. 10
0
        public void v9(object param0)
        {
            XmlSchemaSet sc = new XmlSchemaSet();

            sc.XmlResolver = new XmlUrlResolver();

            try
            {
                XmlSchema Schema1 = sc.Add(null, Path.Combine(TestData._Root, param0.ToString()));
                sc.Compile();
                CError.Compare(sc.Count, 4, "Count");

                ICollection col = sc.Schemas("ns-d");
                foreach (XmlSchema schema in col)
                {
                    sc.Remove(schema); //should remove just one
                }

                CError.Compare(sc.Count, 3, "Count");
                CError.Compare(sc.Contains("ns-d"), false, "Contains");

                col = sc.Schemas("ns-c");
                foreach (XmlSchema schema in col)
                {
                    sc.Remove(schema); //should remove just one
                }

                CError.Compare(sc.Count, 2, "Count");
                CError.Compare(sc.Contains("ns-c"), false, "Contains");

                col = sc.Schemas("ns-b");
                foreach (XmlSchema schema in col)
                {
                    sc.Remove(schema); //should remove just one
                }

                CError.Compare(sc.Count, 1, "Count");
                CError.Compare(sc.Contains("ns-b"), false, "Contains");
                CError.Compare(sc.Contains("ns-a"), true, "Contains");
            }
            catch (Exception e)
            {
                _output.WriteLine(e.ToString());
                Assert.True(false);
            }
            return;
        }
Esempio n. 11
0
        public void LoadSchemaSet()
        {
            XmlSchemaSet schemaSet = TypesSchemaLoader.Instance.LoadSchemaSet();

            Assert.That(schemaSet, Is.Not.Null);
            Assert.That(schemaSet.Count, Is.EqualTo(1));
            Assert.That(schemaSet.Contains("http://www.re-motion.org/Data/DomainObjects/Types"), Is.True);
        }
Esempio n. 12
0
        public void GetSchemaSet()
        {
            SchemaLoaderBase schemaBaseMock = new SchemaLoaderBaseMock("http://www.re-motion.org/Core/Test/Xml/SchemaLoaderBaseMock");
            XmlSchemaSet     xmlSchemaSet   = schemaBaseMock.LoadSchemaSet();

            Assert.That(xmlSchemaSet.Count, Is.EqualTo(1));
            Assert.That(xmlSchemaSet.Contains("http://www.re-motion.org/Core/Test/Xml/SchemaLoaderBaseMock"), Is.True);
        }
        //[Variation(Desc = "v1 - Contains with null")]
        public void v1()
        {
            XmlSchemaSet sc = new XmlSchemaSet();

            Assert.False(sc.Contains((string)null));

            return;
        }
        //[Variation(Desc = "v1 - Contains with null")]
        public void v1()
        {
            XmlSchemaSet sc = new XmlSchemaSet();

            Assert.Equal(sc.Contains((string)null), false);

            return;
        }
        //[Variation(Desc = "v2 - Contains with non existing ns", Priority = 0)]
        public void v2()
        {
            XmlSchemaSet sc = new XmlSchemaSet();

            sc.Add("xsdauthor", TestData._XsdAuthor);
            Assert.Equal(sc.Contains("test"), false);
            return;
        }
        public void LoadSchemaSet()
        {
            UrlMappingSchema urlMappingSchema = new UrlMappingSchema();
            XmlSchemaSet     xmlSchemaSet     = urlMappingSchema.LoadSchemaSet();

            Assert.That(xmlSchemaSet.Count, Is.EqualTo(1));
            Assert.That(xmlSchemaSet.Contains(urlMappingSchema.SchemaUri), Is.True);
        }
Esempio n. 17
0
        //[Variation(Desc = "v4 - Contains for added with URL", Priority = 0)]
        public void v4()
        {
            XmlSchemaSet sc     = new XmlSchemaSet();
            XmlSchema    Schema = sc.Add(null, TestData._XsdAuthor);

            Assert.Equal(sc.Contains(Schema), true);

            return;
        }
Esempio n. 18
0
    public static XmlSchemaComplexType GetTypedDataSetSchema(XmlSchemaSet xs)
    {
        Baze baze = new Baze();
        XmlSchemaComplexType type2    = new XmlSchemaComplexType();
        XmlSchemaSequence    sequence = new XmlSchemaSequence();
        XmlSchemaAny         item     = new XmlSchemaAny {
            Namespace = baze.Namespace
        };

        sequence.Items.Add(item);
        type2.Particle = sequence;
        XmlSchema schemaSerializable = baze.GetSchemaSerializable();

        if (xs.Contains(schemaSerializable.TargetNamespace))
        {
            MemoryStream stream  = new MemoryStream();
            MemoryStream stream2 = new MemoryStream();
            try
            {
                XmlSchema current = null;
                schemaSerializable.Write(stream);
                IEnumerator enumerator = xs.Schemas(schemaSerializable.TargetNamespace).GetEnumerator();
                while (enumerator.MoveNext())
                {
                    current = (XmlSchema)enumerator.Current;
                    stream2.SetLength(0L);
                    current.Write(stream2);
                    if (stream.Length == stream2.Length)
                    {
                        stream.Position  = 0L;
                        stream2.Position = 0L;
                        while ((stream.Position != stream.Length) && (stream.ReadByte() == stream2.ReadByte()))
                        {
                        }
                        if (stream.Position == stream.Length)
                        {
                            return(type2);
                        }
                    }
                }
            }
            finally
            {
                if (stream != null)
                {
                    stream.Close();
                }
                if (stream2 != null)
                {
                    stream2.Close();
                }
            }
        }
        xs.Add(schemaSerializable);
        return(type2);
    }
Esempio n. 19
0
        //[Variation(Desc = "v3 - Contains with existing schema, Remove it, Contains again", Priority = 0)]
        public void v3()
        {
            XmlSchemaSet sc = new XmlSchemaSet();

#pragma warning disable 0618
            XmlSchemaCollection scl = new XmlSchemaCollection();
#pragma warning restore 0618

            XmlSchema Schema = scl.Add(null, TestData._XsdAuthor);
            sc.Add(Schema);

            Assert.Equal(sc.Contains(Schema), true);

            sc.Remove(Schema);

            Assert.Equal(sc.Contains(Schema), false);

            return;
        }
        public static XmlSchema Merge(this XmlSchemaSet schemaSet, XmlSchema schema)
        {
            if (schemaSet == null)
            {
                throw new ArgumentNullException(nameof(schemaSet));
            }
            if (schema == null)
            {
                throw new ArgumentNullException(nameof(schema));
            }
            // only support XmlSchemaImport so far but Cast<XmlSchemaImport>() will throw otherwise
            var knownSchemaImports = schema.Includes.Cast <XmlSchemaImport>()
                                     .Where(xsi => schemaSet.Contains(xsi.Namespace));

            foreach (var xmlSchemaImport in knownSchemaImports)
            {
                var existingSchema = schemaSet.Schemas(xmlSchemaImport.Namespace).Cast <XmlSchema>().Single();
                existingSchema.Merge(xmlSchemaImport.Schema);
                schemaSet.Reprocess(existingSchema);
            }

            // only support XmlSchemaImport so far but Cast<XmlSchemaImport>() will throw otherwise
            var unknownSchemaImports = schema.Includes.Cast <XmlSchemaImport>()
                                       .Where(xsi => !schemaSet.Contains(xsi.Namespace));

            foreach (var xmlSchemaImport in unknownSchemaImports)
            {
                schemaSet.Add(xmlSchemaImport.Schema);
            }

            if (schemaSet.Contains(schema.TargetNamespace))
            {
                var existingSchema = schemaSet.Schemas(schema.TargetNamespace).Cast <XmlSchema>().Single();
                existingSchema.Merge(schema);
                schemaSet.Reprocess(existingSchema);
            }
            else
            {
                schemaSet.Add(schema);
            }

            return(schema);
        }
        public void v8()
        {
            bWarningCallback = false;
            bErrorCallback   = false;

            XmlSchemaSet sc = new XmlSchemaSet();

            sc.XmlResolver             = new XmlUrlResolver();
            sc.ValidationEventHandler += new ValidationEventHandler(ValidationCallback);

            XmlSchema Schema1 = sc.Add(null, Path.Combine(TestData._Root, "import_v1_a.xsd"));

            CError.Compare(sc.Count, 2, "Count after add");
            CError.Compare(sc.Contains(Schema1), true, "Contains after add");

            sc.Compile();
            CError.Compare(sc.Count, 2, "Count");
            CError.Compare(sc.Contains(Schema1), true, "Contains");

            //edit
            foreach (XmlSchemaImport imp in Schema1.Includes)
            {
                imp.SchemaLocation = "bogus";
                imp.Schema         = null;
            }

            sc.Reprocess(Schema1);

            CError.Compare(bWarningCallback, true, "Warning");
            CError.Compare(bErrorCallback, false, "Error");

            CError.Compare(sc.Count, 2, "Count");
            CError.Compare(sc.Contains(Schema1), true, "Contains");
            CError.Compare(sc.IsCompiled, false, "IsCompiled");

            sc.Compile();

            CError.Compare(sc.IsCompiled, true, "IsCompiled");
            CError.Compare(Schema1.IsCompiled, true, "IsCompiled on SOM");

            return;
        }
        public static XmlSchemaComplexType GetTypedDataSetSchema(XmlSchemaSet xs)
        {
            HaushaltsbuchDS      ds       = new HaushaltsbuchDS();
            XmlSchemaComplexType type     = new XmlSchemaComplexType();
            XmlSchemaSequence    sequence = new XmlSchemaSequence();
            XmlSchemaAny         any      = new XmlSchemaAny();

            any.Namespace = ds.Namespace;
            sequence.Items.Add(any);
            type.Particle = sequence;
            XmlSchema dsSchema = ds.GetSchemaSerializable();

            if (xs.Contains(dsSchema.TargetNamespace))
            {
                MemoryStream s1 = new MemoryStream();
                MemoryStream s2 = new MemoryStream();
                try {
                    XmlSchema schema = null;
                    dsSchema.Write(s1);
                    for (IEnumerator schemas = xs.Schemas(dsSchema.TargetNamespace).GetEnumerator(); schemas.MoveNext();)
                    {
                        schema = ((XmlSchema)(schemas.Current));
                        s2.SetLength(0);
                        schema.Write(s2);
                        if ((s1.Length == s2.Length))
                        {
                            s1.Position = 0;
                            s2.Position = 0;
                            for (; ((s1.Position != s1.Length) &&
                                    (s1.ReadByte() == s2.ReadByte()));)
                            {
                                ;
                            }
                            if ((s1.Position == s1.Length))
                            {
                                return(type);
                            }
                        }
                    }
                }
                finally {
                    if ((s1 != null))
                    {
                        s1.Close();
                    }
                    if ((s2 != null))
                    {
                        s2.Close();
                    }
                }
            }
            xs.Add(dsSchema);
            return(type);
        }
Esempio n. 23
0
        public void v2()
        {
            XmlSchemaSet sc        = new XmlSchemaSet();
            XmlSchema    Schema    = XmlSchema.Read(new StreamReader(new FileStream(TestData._FileXSD1, FileMode.Open, FileAccess.Read)), null);
            XmlSchema    SchemaNew = sc.Add(Schema);

            Assert.Equal(sc.Count, 1);
            Assert.Equal(sc.Contains(SchemaNew), true);
            Assert.Equal(sc.IsCompiled, false);
            Assert.Equal(Schema == SchemaNew, true);
        }
Esempio n. 24
0
        public void v3()
        {
            XmlSchemaSet sc         = new XmlSchemaSet();
            XmlSchema    Schema     = XmlSchema.Read(new StreamReader(new FileStream(TestData._FileXSD1, FileMode.Open, FileAccess.Read)), null);
            XmlSchema    SchemaNew1 = sc.Add(Schema);
            XmlSchema    SchemaNew2 = sc.Add(Schema);

            Assert.Equal(1, sc.Count);
            Assert.True(sc.Contains(SchemaNew1));
            Assert.True(sc.Contains(SchemaNew2));
            Assert.False(sc.IsCompiled);
            Assert.True(Schema == SchemaNew1);
            Assert.True(Schema == SchemaNew2);

            sc.Compile();
            Assert.Equal(1, sc.Count);
            Assert.True(sc.Contains(SchemaNew1));
            Assert.True(sc.Contains(SchemaNew2));
            Assert.True(sc.IsCompiled);
        }
        public void v9()
        {
            bWarningCallback = false;
            bErrorCallback   = false;

            XmlSchemaSet sc = new XmlSchemaSet();

            sc.XmlResolver = new XmlUrlResolver();

            sc.ValidationEventHandler += new ValidationEventHandler(ValidationCallback);

            XmlSchema Schema1 = sc.Add(null, Path.Combine(TestData._Root, "reprocess_v9_a.xsd"));

            CError.Compare(sc.Count, 2, "Count after add");
            CError.Compare(sc.Contains(Schema1), true, "Contains after add");

            sc.Compile();
            CError.Compare(sc.Count, 2, "Count");
            CError.Compare(sc.Contains(Schema1), true, "Contains");

            //edit
            XmlSchemaImport imp = new XmlSchemaImport();

            imp.Namespace      = "ns-c";
            imp.SchemaLocation = "reprocess_v9_c.xsd";
            Schema1.Includes.Add(imp);

            sc.Reprocess(Schema1);

            CError.Compare(bWarningCallback, false, "Warning");
            CError.Compare(bErrorCallback, false, "Error");

            CError.Compare(sc.Count, 3, "Count");
            CError.Compare(sc.Contains(Schema1), true, "Contains");
            CError.Compare(sc.IsCompiled, false, "IsCompiled");
            sc.Compile();
            CError.Compare(sc.IsCompiled, true, "IsCompiled");
            CError.Compare(Schema1.IsCompiled, true, "IsCompiled on SOM");

            return;
        }
        public void v3()
        {
            XmlSchemaSet sc      = new XmlSchemaSet();
            XmlSchema    Schema1 = sc.Add(null, TestData._XsdAuthor);

            CError.Compare(sc.Count, 1, "AddCount");
            CError.Compare(sc.Contains(Schema1), true, "AddContains");
            CError.Compare(sc.IsCompiled, false, "AddIsCompiled");

            sc.Compile();
            CError.Compare(sc.Count, 1, "Compile");
            CError.Compare(sc.Contains(Schema1), true, "Compile Contains");

            CError.Compare(sc.IsCompiled, true, "Compile IsCompiled");
            sc.Reprocess(Schema1);
            CError.Compare(sc.Count, 1, "IsCompiled on set");
            CError.Compare(sc.IsCompiled, false, "Reprocess IsCompiled");
            CError.Compare(sc.Contains(Schema1), true, "Reprocess Contains");

            return;
        }
Esempio n. 27
0
 static void GuardSchemaInited()
 {
     if (schemas == null)
     {
         schemas = new XmlSchemaSet();
         var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("UWay.Skynet.Cloud.Data.ULinq.xsd");
         if (schemas.Contains("urn:ulinq-mapping-1.0"))
         {
             schemas.Add("urn:ulinq-mapping-1.0", XmlReader.Create(stream));
         }
     }
 }
Esempio n. 28
0
        public void v7(object param0, object param1, object param2, object param3)
        {
            XmlSchemaSet sc = new XmlSchemaSet();

            sc.XmlResolver = new XmlUrlResolver();

            try
            {
                //after compile
                XmlSchema Schema1 = sc.Add(null, Path.Combine(TestData._Root, param0.ToString()));
                sc.Compile();
                CError.Compare(sc.Count, 3, "Count");
                sc.RemoveRecursive(Schema1);
                CError.Compare(sc.Count, 0, "Count");
                CError.Compare(sc.Contains(param1.ToString()), false, "Contains");
                CError.Compare(sc.Contains(param2.ToString()), false, "Contains");
                CError.Compare(sc.Contains(param3.ToString()), false, "Contains");

                //before compile
                Schema1 = sc.Add(null, Path.Combine(TestData._Root, param0.ToString()));
                CError.Compare(sc.Count, 3, "Count");
                sc.RemoveRecursive(Schema1);
                CError.Compare(sc.Count, 0, "Count");
                CError.Compare(sc.Contains(param1.ToString()), false, "Contains");
                CError.Compare(sc.Contains(param2.ToString()), false, "Contains");
                CError.Compare(sc.Contains(param3.ToString()), false, "Contains");
            }
            catch (Exception e)
            {
                _output.WriteLine(e.ToString());
                Assert.True(false);
            }
            return;
        }
Esempio n. 29
0
        /// <summary>
        /// Returns the WaterML XmlSchema, v1
        /// <para>This is an embdeded resource, "cuahsiTimeSeries_v1"</para>
        /// </summary>
        /// <param name="xs"></param>
        /// <returns></returns>
        public static XmlQualifiedName WaterMLSchema(XmlSchemaSet xs)
        {
            //// This method is called by the framework to get the schema for this type.
            //// We return an existing schema from disk.

            xs.XmlResolver = new XmlUrlResolver();

            // if you do not include this line, then it does not work
            // xs.Add("http://www.opengis.net/ows/1.1", "http://schemas.opengis.net/ows/1.1.0/owsGetCapabilities.xsd");
            StringCollection schemaListing = (StringCollection)Properties.Settings.Default.schemasReferenced;

            foreach (string s in schemaListing)
            {
                string[] nameSchema = s.Split(new string[] { " " }, StringSplitOptions.None);
                if (nameSchema.Length == 2)
                {
                    if (nameSchema[0].Equals("http://www.w3.org/XML/1998/namespace"))
                    {
                        break;
                    }
                    xs.Add(nameSchema[0], nameSchema[1]);
                }
                else
                {
                    // throw a warnign to a log file
                }
            }
            {
            }

            /* this is trying to remove the xml namespace that
             * is improperly added.
             * It needs to be added with an XML namespace
             *
             * But if you just remove it.
             * xs.Remove()
             * things break badly
             */
            if (xs.Contains("http://www.w3.org/XML/1998/namespace"))
            {
                ICollection xmlnamespace = xs.Schemas("http://www.w3.org/XML/1998/namespace");
                foreach (XmlSchema x in xmlnamespace)
                {
                    //xs.Remove(x)
                }
            }
            xs.Add(GetSchemaResource.Schema());

            return(new XmlQualifiedName(TypeName
                                        , "http://www.cuahsi.org/his/wof"
                                        ));
        }
Esempio n. 30
0
        private dynamic GetParameters(string nameSpace, string name, XmlSchemaSet xmlSchemaSet)
        {
            List <Parameter> parameters = new List <Parameter>();

            if (xmlSchemaSet.Contains(nameSpace))
            {
                foreach (XmlSchema xmlSchema in xmlSchemaSet.Schemas(nameSpace))
                {
                    foreach (dynamic xmlElement in xmlSchema.Items)
                    {
                        if (xmlElement.Name == name)
                        {
                            XmlSchemaComplexType xmlSchemaComplexType = new XmlSchemaComplexType();
                            if (IsPropertyExist(xmlElement, "ElementSchemaType"))
                            {
                                xmlSchemaComplexType = xmlElement.ElementSchemaType;
                            }
                            else
                            {
                                xmlSchemaComplexType = xmlElement as XmlSchemaComplexType;
                            }

                            XmlSchemaParticle particle = xmlSchemaComplexType.Particle;
                            XmlSchemaSequence sequence = particle as System.Xml.Schema.XmlSchemaSequence;

                            if (sequence != null)
                            {
                                foreach (XmlSchemaElement element in sequence.Items)
                                {
                                    if (!this.ExistParameterName(element.Name, parameters))
                                    {
                                        if (element.ElementSchemaType is XmlSchemaComplexType)
                                        {
                                            parameters.Add(new Parameter(element.Name, element.ElementSchemaType.Name,
                                                                         this.GetParameters(element.ElementSchemaType.QualifiedName.Namespace,
                                                                                            element.ElementSchemaType.Name,
                                                                                            xmlSchemaSet), element.QualifiedName.Namespace));
                                        }
                                        else
                                        {
                                            parameters.Add(new Parameter(element.Name, element.SchemaTypeName.Name, null, xmlSchema.TargetNamespace));
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return(parameters);
        }