internal XmlSchemaObject AddItem(XmlSchemaObject item, XmlQualifiedName qname, XmlSchemas schemas) { if (item == null) { return null; } if ((qname == null) || qname.IsEmpty) { return null; } string str = item.GetType().Name + ":" + qname.ToString(); ArrayList list = (ArrayList) this.ObjectCache[str]; if (list == null) { list = new ArrayList(); this.ObjectCache[str] = list; } for (int i = 0; i < list.Count; i++) { XmlSchemaObject obj2 = (XmlSchemaObject) list[i]; if (obj2 == item) { return obj2; } if (this.Match(obj2, item, true)) { return obj2; } this.Warnings.Add(Res.GetString("XmlMismatchSchemaObjects", new object[] { item.GetType().Name, qname.Name, qname.Namespace })); this.Warnings.Add("DEBUG:Cached item key:\r\n" + ((string) this.looks[obj2]) + "\r\nnew item key:\r\n" + ((string) this.looks[item])); } list.Add(item); return item; }
//public override string ImportSchemaType( // string name, // string ns, // XmlSchemaObject context, // XmlSchemas schemas, // XmlSchemaImporter importer, // CodeCompileUnit compileUnit, // CodeNamespace mainNamespace, // CodeGenerationOptions options, // CodeDomProvider codeProvider) //{ // XmlSchemaSimpleType simpleType = (XmlSchemaSimpleType) schemas.Find(new XmlQualifiedName(name, ns), typeof(XmlSchemaSimpleType)); // return ImportSchemaType( // simpleType, // context, // schemas, // importer, // compileUnit, // mainNamespace, // options, // codeProvider); //} public override string ImportSchemaType( XmlSchemaType type, XmlSchemaObject context, XmlSchemas schemas, XmlSchemaImporter importer, CodeCompileUnit compileUnit, CodeNamespace mainNamespace, CodeGenerationOptions options, CodeDomProvider codeProvider) { XmlSchemaAnnotated annotatedType = type as XmlSchemaAnnotated; if (annotatedType == null) return null; if (annotatedType.Annotation == null) return null; // create the comments and add them to the hash table under the namespace of the object CreateComments(annotatedType); //mainNamespace.Types. return null; }
public override string ImportSchemaType( string name, string ns, XmlSchemaObject context, XmlSchemas schemas, XmlSchemaImporter importer, CodeCompileUnit compileUnit, CodeNamespace mainNamespace, CodeGenerationOptions options, CodeDomProvider codeProvider) { if (ns != "http://www.w3.org/2001/XMLSchema") return null; switch (name) { case "anyURI": return "System.Uri"; case "gDay": return "System.Runtime.Remoting.Metadata.W3cXsd2001.SoapDay"; case "gMonth": return "System.Runtime.Remoting.Metadata.W3cXsd2001.SoapMonth"; case "gMonthDay": return "System.Runtime.Remoting.Metadata.W3cXsd2001.SoapMonthDay"; case "gYear": return "System.Runtime.Remoting.Metadata.W3cXsd2001.SoapYear"; case "gYearMonth": return "System.Runtime.Remoting.Metadata.W3cXsd2001.SoapYearMonth"; case "duration": return "System.Runtime.Remoting.Metadata.W3cXsd2001.SoapDuration"; default: return null; } }
public override string ImportSchemaType( string name, string ns, XmlSchemaObject context, XmlSchemas schemas, XmlSchemaImporter importer, CodeCompileUnit compileUnit, CodeNamespace codeNamespace, CodeGenerationOptions options, CodeDomProvider codeGenerator) { if (IsBaseType(name, ns)) { return base.ImportSchemaType(name, ns, context, schemas, importer, compileUnit, codeNamespace, options, codeGenerator); } // Add the Namespace, except the first for (int i = 1; i < ImportNamespaces.Length; i++) { string _Import = ImportNamespaces[i]; codeNamespace.Imports.Add(new CodeNamespaceImport(_Import)); } return name; }
internal string GenerateTypedDataSet(XmlSchemaElement element, XmlSchemas schemas, CodeNamespace codeNamespace, StringCollection references, CodeDomProvider codeProvider) { if (element == null) { return null; } if (this.importedTypes[element.SchemaType] != null) { return (string) this.importedTypes[element.SchemaType]; } IList list = schemas.GetSchemas(element.QualifiedName.Namespace); if (list.Count != 1) { return null; } XmlSchema schema = list[0] as XmlSchema; if (schema == null) { return null; } DataSet dataSet = new DataSet(); using (MemoryStream stream = new MemoryStream()) { schema.Write(stream); stream.Position = 0L; dataSet.ReadXmlSchema(stream); } string name = new TypedDataSetGenerator().GenerateCode(dataSet, codeNamespace, codeProvider.CreateGenerator()).Name; this.importedTypes.Add(element.SchemaType, name); references.Add("System.Data.dll"); return name; }
public override string ImportSchemaType(XmlSchemaType type, XmlSchemaObject context, XmlSchemas schemas, XmlSchemaImporter importer, CodeCompileUnit compileUnit, CodeNamespace mainNamespace, CodeGenerationOptions options, CodeDomProvider codeProvider) { if (type == null) { return null; } if (importedTypes[type] != null) { mainNamespace.Imports.Add(new CodeNamespaceImport(typeof(DataSet).Namespace)); compileUnit.ReferencedAssemblies.Add("System.Data.dll"); return (string)importedTypes[type]; } if (!(context is XmlSchemaElement)) return null; if (type is XmlSchemaComplexType) { XmlSchemaComplexType ct = (XmlSchemaComplexType)type; if (ct.Particle is XmlSchemaSequence) { XmlSchemaObjectCollection items = ((XmlSchemaSequence)ct.Particle).Items; if (items.Count == 2 && items[0] is XmlSchemaAny && items[1] is XmlSchemaAny) { XmlSchemaAny any0 = (XmlSchemaAny)items[0]; XmlSchemaAny any1 = (XmlSchemaAny)items[1]; if (any0.Namespace == XmlSchema.Namespace && any1.Namespace == "urn:schemas-microsoft-com:xml-diffgram-v1") { string typeName = typeof(DataTable).FullName; importedTypes.Add(type, typeName); mainNamespace.Imports.Add(new CodeNamespaceImport(typeof(DataTable).Namespace)); compileUnit.ReferencedAssemblies.Add("System.Data.dll"); return typeName; } } } } return null; }
internal static StringCollection Compile(XmlSchemas schemas) { AddImports(schemas); Warnings.Clear(); schemas.Compile(new ValidationEventHandler(SchemaCompiler.ValidationCallbackWithErrorCode), true); return Warnings; }
internal string GenerateTypedDataSet(XmlSchemaElement element, XmlSchemas schemas, CodeCompileUnit compileUnit, CodeNamespace mainNamespace, CodeDomProvider codeProvider) { if (element == null) { return null; } if (this.importedTypes[element.SchemaType] != null) { return (string) this.importedTypes[element.SchemaType]; } IList list = schemas.GetSchemas(element.QualifiedName.Namespace); if (list.Count != 1) { return null; } XmlSchema schema = list[0] as XmlSchema; if (schema == null) { return null; } MemoryStream stream = new MemoryStream(); schema.Write(stream); stream.Position = 0L; DesignDataSource designDS = new DesignDataSource(); designDS.ReadXmlSchema(stream, null); stream.Close(); string str = TypedDataSetGenerator.GenerateInternal(designDS, compileUnit, mainNamespace, codeProvider, this.dataSetGenerateOptions, null); this.importedTypes.Add(element.SchemaType, str); return str; }
public static CodeNamespace Process(string xsdFile, string targetNamespace) { // Load the XmlSchema and its collection. XmlSchema xsd; using (FileStream fs = new FileStream("Untitled1.xsd", FileMode.Open)) { xsd = XmlSchema.Read(fs, null); xsd.Compile(null); } XmlSchemas schemas = new XmlSchemas(); schemas.Add(xsd); // Create the importer for these schemas. XmlSchemaImporter importer = new XmlSchemaImporter(schemas); // System.CodeDom namespace for the XmlCodeExporter to put classes in. CodeNamespace ns = new CodeNamespace(targetNamespace); XmlCodeExporter exporter = new XmlCodeExporter(ns); // Iterate schema top-level elements and export code for each. foreach (XmlSchemaElement element in xsd.Elements.Values) { // Import the mapping first. XmlTypeMapping mapping = importer.ImportTypeMapping( element.QualifiedName); // Export the code finally. exporter.ExportTypeMapping(mapping); } return ns; }
public XmlSchemaImporter (XmlSchemas schemas) { this.schemas = schemas; typeIdentifiers = new CodeIdentifiers (); InitializeExtensions (); }
private void AddSchemaImports(XmlSchemas schemas, string uri, ServiceDescriptionCollection descriptions) { int num = 0; foreach (XmlSchema schema in schemas) { if (schema != null) { if ((schema.Id == null) || (schema.Id.Length == 0)) { schema.Id = "schema" + ++num.ToString(CultureInfo.InvariantCulture); } string location = uri + "?schema=" + schema.Id; foreach (ServiceDescription description in descriptions) { if (description.Types.Schemas.Count == 0) { XmlSchema schema2 = new XmlSchema { TargetNamespace = description.TargetNamespace }; schema.ElementFormDefault = XmlSchemaForm.Qualified; this.AddExternal(schema2, schema.TargetNamespace, location); description.Types.Schemas.Add(schema2); } else { this.AddExternal(description.Types.Schemas[0], schema.TargetNamespace, location); } } this.schemaTable.Add(schema.Id, schema); } } }
public void Bug360541 () { XmlSchemaComplexType stype = GetStype (); XmlSchemaElement selem1 = new XmlSchemaElement (); selem1.Name = "schema"; selem1.SchemaType = stype; XmlSchema schema = new XmlSchema (); schema.Items.Add (selem1); XmlSchemas xs = new XmlSchemas (); xs.Add (schema); xs.Find (XmlQualifiedName.Empty, typeof (XmlSchemaElement)); selem1 = new XmlSchemaElement (); selem1.Name = "schema1"; selem1.SchemaType = stype; schema = new XmlSchema (); schema.Items.Add (selem1); xs = new XmlSchemas (); xs.Add (schema); xs.Find (XmlQualifiedName.Empty, typeof (XmlSchemaElement)); }
public static CodeNamespace GenerateCode(Stream schemaStream, string classesNamespace) { // Open schema XmlSchema schema = XmlSchema.Read(schemaStream, null); XmlSchemas schemas = new XmlSchemas(); schemas.Add(schema); schemas.Compile(null, true); // Generate code CodeNamespace code = new CodeNamespace(classesNamespace); XmlSchemaImporter importer = new XmlSchemaImporter(schemas); XmlCodeExporter exporter = new XmlCodeExporter(code); foreach (XmlSchemaElement element in schema.Elements.Values) { XmlTypeMapping mapping = importer.ImportTypeMapping(element.QualifiedName); exporter.ExportTypeMapping(mapping); } // Modify generated code using extensions schemaStream.Position = 0; // Rewind stream to the start XPathDocument xPathDoc = new XPathDocument(schemaStream); CodeGenerationContext context = new CodeGenerationContext(code, schema, xPathDoc); new ExplicitXmlNamesExtension().ApplyTo(context); new DocumentationExtension().ApplyTo(context); new FixXmlTextAttributeExtension().ApplyTo(context); new ArraysToGenericExtension().ApplyTo(context); new CamelCaseExtension().ApplyTo(context); new GetByIDExtension().ApplyTo(context); return code; }
internal SchemaImporter(XmlSchemas schemas, CodeGenerationOptions options, CodeDomProvider codeProvider, System.Xml.Serialization.ImportContext context) { if (!schemas.Contains("http://www.w3.org/2001/XMLSchema")) { schemas.AddReference(XmlSchemas.XsdSchema); schemas.SchemaSet.Add(XmlSchemas.XsdSchema); } if (!schemas.Contains("http://www.w3.org/XML/1998/namespace")) { schemas.AddReference(XmlSchemas.XmlSchema); schemas.SchemaSet.Add(XmlSchemas.XmlSchema); } this.schemas = schemas; this.options = options; this.codeProvider = codeProvider; this.context = context; this.Schemas.SetCache(this.Context.Cache, this.Context.ShareTypes); SchemaImporterExtensionsSection section = System.Configuration.PrivilegedConfigurationManager.GetSection(ConfigurationStrings.SchemaImporterExtensionsSectionPath) as SchemaImporterExtensionsSection; if (section != null) { this.extensions = section.SchemaImporterExtensionsInternal; } else { this.extensions = new SchemaImporterExtensionCollection(); } }
internal void GenerateSchemaGraph(XmlSchemas schemas) { ArrayList items = new SchemaGraph(this.Graph, schemas).GetItems(); for (int i = 0; i < items.Count; i++) { this.GetHash((XmlSchemaObject) items[i]); } }
public ServiceDescriptionImporter () { protocolName = String.Empty; schemas = new XmlSchemas (); serviceDescriptions = new ServiceDescriptionCollection (); serviceDescriptions.SetImporter (this); style = ServiceDescriptionImportStyle.Client; }
private static void AddImports(XmlSchemas schemas) { foreach (XmlSchema schema in schemas) { AddImport(schema, "http://schemas.xmlsoap.org/soap/encoding/"); AddImport(schema, "http://schemas.xmlsoap.org/wsdl/"); } }
private XmlSchemas Export (Type type, string defaultNamespace) { SoapReflectionImporter ri = new SoapReflectionImporter (defaultNamespace); XmlSchemas schemas = new XmlSchemas (); SoapSchemaExporter sx = new SoapSchemaExporter (schemas); XmlTypeMapping tm = ri.ImportTypeMapping (type); sx.ExportTypeMapping (tm); return schemas; }
private XmlSchemas Export (Type type, XmlAttributeOverrides overrides, string defaultNamespace) { XmlReflectionImporter ri = new XmlReflectionImporter (overrides, defaultNamespace); XmlSchemas schemas = new XmlSchemas (); XmlSchemaExporter sx = new XmlSchemaExporter (schemas); XmlTypeMapping tm = ri.ImportTypeMapping (type); sx.ExportTypeMapping (tm); return schemas; }
public XmlTypeExtractor(XmlSchemas schemas, Action<string> debug) { this.schemas = schemas; this.debug = debug; this.loadedSchemas = new List<string>(); this.schemaSet = new XmlSchemaSet(); ComplexTypes = new List<KeyValuePair<string, ComplexType>>(); Elements = new List<KeyValuePair<string, ComplexType>>(); }
public override string ImportSchemaType(string name, string xmlNamespace, XmlSchemaObject context, XmlSchemas schemas, XmlSchemaImporter importer, CodeCompileUnit compileUnit, CodeNamespace mainNamespace, CodeGenerationOptions options, CodeDomProvider codeProvider) { if ((this.m_direct && (context is XmlSchemaElement)) && ((string.CompareOrdinal(this.m_name, name) == 0) && (string.CompareOrdinal(this.m_targetNamespace, xmlNamespace) == 0))) { compileUnit.ReferencedAssemblies.AddRange(this.m_references); mainNamespace.Imports.AddRange(this.m_namespaceImports); return this.m_destinationType; } return null; }
public override string ImportSchemaType(string name, string schemaNamespace, XmlSchemaObject context, XmlSchemas schemas, XmlSchemaImporter importer, CodeCompileUnit compileUnit, CodeNamespace mainNamespace, CodeGenerationOptions options, CodeDomProvider codeProvider) { IList values = schemas.GetSchemas(schemaNamespace); if (values.Count != 1) { return null; } XmlSchema schema = values[0] as XmlSchema; if (schema == null) return null; XmlSchemaType type = (XmlSchemaType)schema.SchemaTypes[new XmlQualifiedName(name, schemaNamespace)]; return ImportSchemaType(type, context, schemas, importer, compileUnit, mainNamespace, options, codeProvider); }
public override string ImportSchemaType (XmlSchemaType type, XmlSchemaObject context, XmlSchemas schemas, XmlSchemaImporter importer, CodeCompileUnit compileUnit, CodeNamespace mainNamespace, CodeGenerationOptions options, CodeDomProvider codeProvider) { if (type == null) return null; var xe = context as XmlSchemaElement; if (xe == null) return null; return null; }
internal DocumentationServerType(Type type, string uri) : base(typeof(DocumentationServerProtocol)) { uri = new Uri(uri, true).GetLeftPart(UriPartial.Path); this.methodInfo = new LogicalMethodInfo(typeof(DocumentationServerProtocol).GetMethod("Documentation", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance)); ServiceDescriptionReflector reflector = new ServiceDescriptionReflector(); reflector.Reflect(type, uri); this.schemas = reflector.Schemas; this.serviceDescriptions = reflector.ServiceDescriptions; this.schemasWithPost = reflector.SchemasWithPost; this.serviceDescriptionsWithPost = reflector.ServiceDescriptionsWithPost; }
internal XmlSchemaElement FindDataSetElement(XmlSchema schema, XmlSchemas schemas) { foreach (XmlSchemaObject obj2 in schema.Items) { if ((obj2 is XmlSchemaElement) && IsDataSet((XmlSchemaElement) obj2)) { XmlSchemaElement element = (XmlSchemaElement) obj2; return (XmlSchemaElement) schemas.Find(element.QualifiedName, typeof(XmlSchemaElement)); } } return null; }
public override string ImportSchemaType (string name, string ns, XmlSchemaObject context, XmlSchemas schemas, XmlSchemaImporter importer, CodeCompileUnit compileUnit, CodeNamespace mainNamespace, CodeGenerationOptions options, CodeDomProvider codeProvider) { if (ns == "http://monkeywrench.novell.com/") { if (name != "ArrayOfString" && name != "ArrayOfInt1") { mainNamespace.Imports.Add (new CodeNamespaceImport ("MonkeyWrench.DataClasses")); mainNamespace.Imports.Add (new CodeNamespaceImport ("MonkeyWrench.DataClasses.Logic")); return name; } } return base.ImportSchemaType (name, ns, context, schemas, importer, compileUnit, mainNamespace, options, codeProvider); }
public Program() { XmlReflectionImporter _XmlReflectionImporter = new XmlReflectionImporter(); XmlSchemas _XmlSchemas = new XmlSchemas(); XmlSchemaExporter _XmlSchemaExporter = new XmlSchemaExporter(_XmlSchemas); XmlTypeMapping map = _XmlReflectionImporter.ImportTypeMapping(typeof(Database)); _XmlSchemaExporter.ExportTypeMapping(map); TextWriter _TextWriter = new StreamWriter("asd.xsd"); _XmlSchemas[0].Write(_TextWriter); _TextWriter.Close(); }
private static void Main(string[] args) { XmlSchema rootSchema = GetSchemaFromFile("fpml-main-4-2.xsd"); var schemaSet = new List<XmlSchemaExternal>(); ExtractIncludes(rootSchema, ref schemaSet); var schemas = new XmlSchemas { rootSchema }; schemaSet.ForEach(schemaExternal => schemas.Add(GetSchemaFromFile(schemaExternal.SchemaLocation))); schemas.Compile(null, true); var xmlSchemaImporter = new XmlSchemaImporter(schemas); var codeNamespace = new CodeNamespace("Hosca.FpML4_2"); var xmlCodeExporter = new XmlCodeExporter(codeNamespace); var xmlTypeMappings = new List<XmlTypeMapping>(); foreach (XmlSchemaType schemaType in rootSchema.SchemaTypes.Values) xmlTypeMappings.Add(xmlSchemaImporter.ImportSchemaType(schemaType.QualifiedName)); foreach (XmlSchemaElement schemaElement in rootSchema.Elements.Values) xmlTypeMappings.Add(xmlSchemaImporter.ImportTypeMapping(schemaElement.QualifiedName)); xmlTypeMappings.ForEach(xmlCodeExporter.ExportTypeMapping); CodeGenerator.ValidateIdentifiers(codeNamespace); foreach (CodeTypeDeclaration codeTypeDeclaration in codeNamespace.Types) { for (int i = codeTypeDeclaration.CustomAttributes.Count - 1; i >= 0; i--) { CodeAttributeDeclaration cad = codeTypeDeclaration.CustomAttributes[i]; if (cad.Name == "System.CodeDom.Compiler.GeneratedCodeAttribute") codeTypeDeclaration.CustomAttributes.RemoveAt(i); } } using (var writer = new StringWriter()) { new CSharpCodeProvider().GenerateCodeFromNamespace(codeNamespace, writer, new CodeGeneratorOptions()); //Console.WriteLine(writer.GetStringBuilder().ToString()); File.WriteAllText(Path.Combine(rootFolder, "FpML4_2.Generated.cs"), writer.GetStringBuilder().ToString()); } Console.ReadLine(); }
public override string ImportSchemaType(XmlSchemaType type, XmlSchemaObject context, XmlSchemas schemas, XmlSchemaImporter importer, CodeCompileUnit compileUnit, CodeNamespace mainNamespace, CodeGenerationOptions options, CodeDomProvider codeProvider) { if ((!this.m_direct && (type is XmlSchemaSimpleType)) && (context is XmlSchemaElement)) { XmlQualifiedName qualifiedName = ((XmlSchemaSimpleType) type).BaseXmlSchemaType.QualifiedName; if ((string.CompareOrdinal(this.m_name, qualifiedName.Name) == 0) && (string.CompareOrdinal(this.m_targetNamespace, qualifiedName.Namespace) == 0)) { compileUnit.ReferencedAssemblies.AddRange(this.m_references); mainNamespace.Imports.AddRange(this.m_namespaceImports); return this.m_destinationType; } } return null; }
internal SchemaGraph(Hashtable scope, XmlSchemas schemas) { _scope = scope; schemas.Compile(null, false); _schemas = schemas; _items = 0; foreach (XmlSchema s in schemas) { _items += s.Items.Count; foreach (XmlSchemaObject item in s.Items) { Depends(item); } } }
internal SchemaGraph(Hashtable scope, XmlSchemas schemas) { this.scope = scope; schemas.Compile(null, false); this.schemas = schemas; this.items = 0; foreach (XmlSchema schema in schemas) { this.items += schema.Items.Count; foreach (XmlSchemaObject obj2 in schema.Items) { this.Depends(obj2); } } }
private ElementAccessor ImportElement(XmlSchemaElement element, string ns) { if (!element.RefName.IsEmpty) { throw new InvalidOperationException(Res.GetString("RefSyntaxNotSupportedForElements0", new object[] { element.RefName.Name, element.RefName.Namespace })); } if (element.Name.Length == 0) { XmlQualifiedName parentName = XmlSchemas.GetParentName(element); throw new InvalidOperationException(Res.GetString("XmlElementHasNoName", new object[] { parentName.Name, parentName.Namespace })); } TypeMapping mapping = this.ImportElementType(element, ns); return(new ElementAccessor { IsSoap = true, Name = element.Name, Namespace = ns, Mapping = mapping, IsNullable = element.IsNillable, Form = XmlSchemaForm.None }); }
internal SchemaImporter(XmlSchemas schemas, CodeGenerationOptions options, ImportContext context) { if (!schemas.Contains(XmlSchema.Namespace)) { schemas.AddReference(XmlSchemas.XsdSchema); schemas.SchemaSet.Add(XmlSchemas.XsdSchema); } if (!schemas.Contains(XmlReservedNs.NsXml)) { schemas.AddReference(XmlSchemas.XmlSchema); schemas.SchemaSet.Add(XmlSchemas.XmlSchema); } _schemas = schemas; _options = options; _context = context; Schemas.SetCache(Context.Cache, Context.ShareTypes); }
internal void CheckDuplicateElement(XmlSchemaElement element, string elementNs) { if (element == null) { return; } // only check duplicate definitions for top-level element if (element.Parent == null || !(element.Parent is XmlSchema)) { return; } XmlSchemaObjectTable elements = null; if (Schema != null && Schema.TargetNamespace == elementNs) { XmlSchemas.Preprocess(Schema); elements = Schema.Elements; } else if (Schemas != null) { elements = Schemas.GlobalElements; } else { return; } foreach (XmlSchemaElement e in elements.Values) { if (e.Name == element.Name && e.QualifiedName.Namespace == elementNs) { if (Match(e, element)) { return; } // XmlSerializableRootDupName=Cannot reconcile schema for '{0}'. Please use [XmlRoot] attribute to change name or namepace of the top-level element to avoid duplicate element declarations: element name='{1} namespace='{2}'. throw new InvalidOperationException(SR.Format(SR.XmlSerializableRootDupName, _getSchemaMethod.DeclaringType.FullName, e.Name, elementNs)); } } }
void ImportDerivedTypes(XmlQualifiedName baseName) { foreach (XmlSchema schema in schemas) { if (XmlSchemas.IsDataSet(schema)) { continue; } foreach (object item in schema.Items) { if (item is XmlSchemaType) { XmlSchemaType type = (XmlSchemaType)item; if (type.DerivedFrom == baseName) { ImportType(new XmlQualifiedName(type.Name, schema.TargetNamespace), false); } } } } }
internal override void ImportDerivedTypes(XmlQualifiedName baseName) { foreach (XmlSchema schema in base.Schemas) { if (!base.Schemas.IsReference(schema) && !XmlSchemas.IsDataSet(schema)) { XmlSchemas.Preprocess(schema); foreach (object obj2 in schema.SchemaTypes.Values) { if (obj2 is XmlSchemaType) { XmlSchemaType type = (XmlSchemaType)obj2; if (type.DerivedFrom == baseName) { this.ImportType(type.QualifiedName, false); } } } } } }
private TypeMapping ImportElementType(XmlSchemaElement element, string ns) { TypeMapping mapping; if (!element.SchemaTypeName.IsEmpty) { mapping = ImportType(element.SchemaTypeName, false); } else if (element.SchemaType != null) { XmlQualifiedName parentType = XmlSchemas.GetParentName(element); if (element.SchemaType is XmlSchemaComplexType) { mapping = ImportType((XmlSchemaComplexType)element.SchemaType, ns, false); if (!(mapping is ArrayMapping)) { throw new InvalidOperationException(SR.Format(SR.XmlInvalidSchemaElementType, parentType.Name, parentType.Namespace, element.Name)); } } else { throw new InvalidOperationException(SR.Format(SR.XmlInvalidSchemaElementType, parentType.Name, parentType.Namespace, element.Name)); } } else if (!element.SubstitutionGroup.IsEmpty) { XmlQualifiedName parentType = XmlSchemas.GetParentName(element); throw new InvalidOperationException(SR.Format(SR.XmlInvalidSubstitutionGroupUse, parentType.Name, parentType.Namespace)); } else { XmlQualifiedName parentType = XmlSchemas.GetParentName(element); throw new InvalidOperationException(SR.Format(SR.XmlElementMissingType, parentType.Name, parentType.Namespace, element.Name)); } mapping.ReferencedByElement = true; return(mapping); }
private ElementAccessor ImportElement(XmlSchemaElement element, string ns) { if (!element.RefName.IsEmpty) { throw new InvalidOperationException(SR.Format(SR.RefSyntaxNotSupportedForElements0, element.RefName.Name, element.RefName.Namespace)); } if (element.Name.Length == 0) { XmlQualifiedName parentType = XmlSchemas.GetParentName(element); throw new InvalidOperationException(SR.Format(SR.XmlElementHasNoName, parentType.Name, parentType.Namespace)); } TypeMapping mapping = ImportElementType(element, ns); ElementAccessor accessor = new ElementAccessor(); accessor.IsSoap = true; accessor.Name = element.Name; accessor.Namespace = ns; accessor.Mapping = mapping; accessor.IsNullable = element.IsNillable; accessor.Form = XmlSchemaForm.None; return(accessor); }
private TypeMapping ImportElementType(XmlSchemaElement element, string ns) { TypeMapping mapping; if (!element.SchemaTypeName.IsEmpty) { mapping = this.ImportType(element.SchemaTypeName, false); } else { if (element.SchemaType != null) { XmlQualifiedName name = XmlSchemas.GetParentName(element); if (element.SchemaType is XmlSchemaComplexType) { mapping = this.ImportType((XmlSchemaComplexType)element.SchemaType, ns, false); if (!(mapping is ArrayMapping)) { throw new InvalidOperationException(Res.GetString("XmlInvalidSchemaElementType", new object[] { name.Name, name.Namespace, element.Name })); } goto Label_014F; } throw new InvalidOperationException(Res.GetString("XmlInvalidSchemaElementType", new object[] { name.Name, name.Namespace, element.Name })); } if (!element.SubstitutionGroup.IsEmpty) { XmlQualifiedName name2 = XmlSchemas.GetParentName(element); throw new InvalidOperationException(Res.GetString("XmlInvalidSubstitutionGroupUse", new object[] { name2.Name, name2.Namespace })); } XmlQualifiedName parentName = XmlSchemas.GetParentName(element); throw new InvalidOperationException(Res.GetString("XmlElementMissingType", new object[] { parentName.Name, parentName.Namespace, element.Name })); } Label_014F: mapping.ReferencedByElement = true; return(mapping); }
internal XmlSchemaExporter(XmlSchemas schemas, bool encodedFormat) { this.encodedFormat = encodedFormat; this.schemas = schemas; }
/// <include file='doc\SoapSchemaImporter.uex' path='docs/doc[@for="SoapSchemaImporter.SoapSchemaImporter4"]/*' /> /// <devdoc> /// <para>[To be supplied.]</para> /// </devdoc> internal SoapSchemaImporter(XmlSchemas schemas, CodeGenerationOptions options, CodeDomProvider codeProvider, ImportContext context) : base(schemas, options, codeProvider, context) { }
public XmlSchemaExporter(XmlSchemas schemas) { this.schemas = schemas; }
internal XmlSchemaObject AddItem(XmlSchemaObject item, XmlQualifiedName qname, XmlSchemas schemas) { if (item == null) { return(null); } if (qname == null || qname.IsEmpty) { return(null); } string key = item.GetType().Name + ":" + qname.ToString(); ArrayList list = (ArrayList)ObjectCache[key]; if (list == null) { list = new ArrayList(); ObjectCache[key] = list; } for (int i = 0; i < list.Count; i++) { XmlSchemaObject cachedItem = (XmlSchemaObject)list[i]; if (cachedItem == item) { return(cachedItem); } if (Match(cachedItem, item, true)) { return(cachedItem); } else { Warnings.Add(Res.GetString(Res.XmlMismatchSchemaObjects, item.GetType().Name, qname.Name, qname.Namespace)); Warnings.Add("DEBUG:Cached item key:\r\n" + (string)looks[cachedItem] + "\r\nnew item key:\r\n" + (string)looks[item]); } } // no match found we need to insert the new type in the cache list.Add(item); return(item); }
/// <include file='doc\SoapSchemaImporter.uex' path='docs/doc[@for="SoapSchemaImporter.SoapSchemaImporter3"]/*' /> /// <devdoc> /// <para>[To be supplied.]</para> /// </devdoc> public SoapSchemaImporter(XmlSchemas schemas, CodeGenerationOptions options, ImportContext context) : base(schemas, options, null, context) { }
/// <include file='doc\SoapSchemaImporter.uex' path='docs/doc[@for="SoapSchemaImporter.SoapSchemaImporter"]/*' /> /// <devdoc> /// <para>[To be supplied.]</para> /// </devdoc> public SoapSchemaImporter(XmlSchemas schemas) : base(schemas, CodeGenerationOptions.GenerateProperties, null, new ImportContext()) { }
internal XmlSchemaObject AddItem(XmlSchemaObject item, XmlQualifiedName qname, XmlSchemas schemas) { if (item == null) { return(null); } if ((qname == null) || qname.IsEmpty) { return(null); } string str = item.GetType().Name + ":" + qname.ToString(); ArrayList list = (ArrayList)this.ObjectCache[str]; if (list == null) { list = new ArrayList(); this.ObjectCache[str] = list; } for (int i = 0; i < list.Count; i++) { XmlSchemaObject obj2 = (XmlSchemaObject)list[i]; if (obj2 == item) { return(obj2); } if (this.Match(obj2, item, true)) { return(obj2); } this.Warnings.Add(Res.GetString("XmlMismatchSchemaObjects", new object[] { item.GetType().Name, qname.Name, qname.Namespace })); this.Warnings.Add("DEBUG:Cached item key:\r\n" + ((string)this.looks[obj2]) + "\r\nnew item key:\r\n" + ((string)this.looks[item])); } list.Add(item); return(item); }
public XmlSchemaEnumerator(XmlSchemas list) { this.list = list; this.idx = -1; this.end = list.Count - 1; }
private string GenerateSOAP(string stringNodeName, string url) { XmlTextReader xmlr = null; string returnval = null; string headerval = null; int indexOfOp = -1; int indexOfPort = -1; System.Web.Services.Description.ServiceDescription servdesc = null; System.Xml.Serialization.XmlSchemas schemas = null; XmlGenerator xmlGen = new XmlGenerator(); try { //xmlr = new XmlTextReader(urltext.Text); xmlr = new XmlTextReader(url); xmlr.WhitespaceHandling = WhitespaceHandling.None; servdesc = System.Web.Services.Description.ServiceDescription.Read(xmlr); schemas = servdesc.Types.Schemas; //Find operation matching the selected row for (int i = 0; i < servdesc.PortTypes.Count && indexOfPort == -1 && indexOfOp == -1; i++) { for (int j = 0; j < servdesc.PortTypes[i].Operations.Count && indexOfPort == -1 && indexOfOp == -1; j++) { if (servdesc.PortTypes[i].Operations[j].Name == stringNodeName) { indexOfOp = j; indexOfPort = i; } } } System.Web.Services.Description.Operation SelectedOp = null; if (indexOfPort != -1 && indexOfOp != -1) { SelectedOp = servdesc.PortTypes[indexOfPort].Operations[indexOfOp]; } else { Logger.Text += " Element not found in selected Operations \r\n"; return(""); } //Get the URL for the particular method int serviceno = -1; int portno = -1; int extno = -1; string urltosend = null; System.Web.Services.Description.Port SelectedPort = null; System.Web.Services.Description.ServiceCollection serviceColl = servdesc.Services; Logger.Text += "\r\nSelected port index: " + portlist.SelectedNode.Index + "\r\n"; bool found = false; for (int i = 0; i < serviceColl.Count && !found; i++) { for (int j = 0; j < serviceColl[i].Ports.Count && !found; j++) { if (serviceColl[i].Ports[j].Name == portlist.SelectedNode.Text) { found = true; serviceno = i; portno = j; } } } if (serviceno != -1 && portno != -1) { SelectedPort = serviceColl[serviceno].Ports[portno]; for (int k = 0; k < SelectedPort.Extensions.Count; k++) { System.Web.Services.Description.Binding basebinding = SelectedPort.Extensions[k] as System.Web.Services.Description.Binding; System.Web.Services.Description.SoapAddressBinding sab = SelectedPort.Extensions[k] as System.Web.Services.Description.SoapAddressBinding; System.Web.Services.Description.Soap12AddressBinding s12ab = SelectedPort.Extensions[k] as System.Web.Services.Description.Soap12AddressBinding; System.Web.Services.Description.HttpAddressBinding hab = SelectedPort.Extensions[k] as System.Web.Services.Description.HttpAddressBinding; if (sab != null) { urltosend = sab.Location; //Logger.Text += urltosend; } else if (s12ab != null) { urltosend = s12ab.Location; //Logger.Text += urltosend; } else { urltosend = hab.Location; //Logger.Text += urltosend; } } int bindingno = -1; int opno = -1; found = false; for (int i = 0; i < servdesc.Bindings.Count && !found; i++) { for (int j = 0; j < servdesc.Bindings[i].Operations.Count && !found; j++) { if (servdesc.Bindings[i].Operations[j].Name == stringNodeName) { bindingno = i; opno = j; found = true; } } } if (bindingno != -1 && opno != -1) { for (int k = 0; k < servdesc.Bindings[bindingno].Operations[opno].Extensions.Count; k++) { System.Web.Services.Description.Binding basebinding = servdesc.Bindings[bindingno].Operations[opno].Extensions[k] as System.Web.Services.Description.Binding; System.Web.Services.Description.SoapOperationBinding sob = servdesc.Bindings[bindingno].Operations[opno].Extensions[k] as System.Web.Services.Description.SoapOperationBinding; System.Web.Services.Description.Soap12OperationBinding s12ob = servdesc.Bindings[bindingno].Operations[opno].Extensions[k] as System.Web.Services.Description.Soap12OperationBinding; System.Web.Services.Description.HttpOperationBinding hob = servdesc.Bindings[bindingno].Operations[opno].Extensions[k] as System.Web.Services.Description.HttpOperationBinding; if (sob != null) { //urltosend += sob.SoapAction; ListViewItem item = new ListViewItem(); item.Text = "SoapAction: \"" + sob.SoapAction + "\""; httpheaderlist.Items.Add(item); for (int index = 0; index < servdesc.Bindings[bindingno].Operations[opno].Input.Extensions.Count; index++) { System.Web.Services.Description.SoapHeaderBinding shb = servdesc.Bindings[bindingno].Operations[opno].Input.Extensions[index] as System.Web.Services.Description.SoapHeaderBinding; if (shb != null) { //SoapHeader is defined //returnval += SchemaSearching(servdesc.Types.Schemas[0], shb.Message.Name); Logger.Text += "Name of header " + shb.Message.Name + "\r\n"; string headerType; //returnval += SchemaSearching(servdesc.Types.Schemas[0], servdesc.Messages[shb.Message.Name].Parts[0].Element.Name); if (servdesc.Messages[shb.Message.Name].Parts[0].Type.IsEmpty) { headerType = servdesc.Messages[shb.Message.Name].Parts[0].Element.Name; headerval += SchemaSearching(servdesc.Types.Schemas[0], headerType); } else { //Currently takes care of only one part in each message if (shb.Message.Name != null) { headerval += '<' + shb.Message.Name + '>'; for (int i = 0; i < servdesc.Messages[shb.Message.Name].Parts.Count; i++) { headerType = servdesc.Messages[shb.Message.Name].Parts[i].Type.Name; headerval += '<' + servdesc.Messages[shb.Message.Name].Parts[i].Name + '>'; headerval += SchemaSearching(servdesc.Types.Schemas[0], headerType); headerval += "</" + servdesc.Messages[shb.Message.Name].Parts[i].Name + ">"; } headerval += "</" + shb.Message.Name + '>'; } } } } break; //Logger.Text += urltosend; } else if (s12ob != null) { ListViewItem item = new ListViewItem(); item.Text = "SoapAction: \"" + sob.SoapAction + "\""; httpheaderlist.Items.Add(item); for (int index = 0; index < servdesc.Bindings[bindingno].Operations[opno].Input.Extensions.Count; index++) { System.Web.Services.Description.Soap12HeaderBinding s12hb = servdesc.Bindings[bindingno].Operations[opno].Input.Extensions[index] as System.Web.Services.Description.Soap12HeaderBinding; if (s12hb != null) { //SoapHeader is defined //returnval += SchemaSearching(servdesc.Types.Schemas[0], shb.Message.Name); Logger.Text += "Name of header " + s12hb.Message.Name + "\r\n"; string headerType; //returnval += SchemaSearching(servdesc.Types.Schemas[0], servdesc.Messages[shb.Message.Name].Parts[0].Element.Name); if (servdesc.Messages[s12hb.Message.Name].Parts[0].Type.IsEmpty) { headerType = servdesc.Messages[s12hb.Message.Name].Parts[0].Element.Name; headerval += SchemaSearching(servdesc.Types.Schemas[0], headerType); } else { //Currently takes care of only one part in each message if (s12hb.Message.Name != null) { headerval += '<' + s12hb.Message.Name + '>'; for (int i = 0; i < servdesc.Messages[s12hb.Message.Name].Parts.Count; i++) { headerType = servdesc.Messages[s12hb.Message.Name].Parts[i].Type.Name; headerval += '<' + servdesc.Messages[s12hb.Message.Name].Parts[i].Name + '>'; headerval += SchemaSearching(servdesc.Types.Schemas[0], headerType); headerval += "</" + servdesc.Messages[s12hb.Message.Name].Parts[i].Name + ">"; } headerval += "</" + s12hb.Message.Name + '>'; } } } } urltosend += s12ob.SoapAction; break; //Logger.Text += urltosend; } else if (hob != null) { urltosend += hob.Location; break; //Logger.Text += urltosend; } } } //Find the right binding Logger.Text += urltosend; Logger.Text += "\r\n"; targeturl.Text = urltosend; } //Path to XML schema definition from Operation Name //portType -> Operation:Name -> input:message // input:message == Message:Name //Message:Name -> Part:element //Types -> Schema -> Element:Name //Part:Element == Element:Name Logger.Text += " searching for " + stringNodeName + "\r\n"; //Logger.Text += " ****** " + SelectedOp.Messages.Count + " ****** "; /*for (int i = 0; i < SelectedOp.PortType.Operations.Count; i++) * { * for (int j = 0; j < SelectedOp.PortType.Operations[i].Messages.Count; j++)// +", "; * { * Logger.Text += SelectedOp.PortType.Operations[i].Messages[j].GetType() + " == "; * Logger.Text += SelectedOp.PortType.Operations[i].Messages[j].Name + "\r\n"; * } * }*/ string inputParameterType = null; string inputMessageType = SelectedOp.Messages.Input.Message.Name; // TODO: What if there are more than one service descriptions? System.Xml.Schema.XmlSchema xmlSchema = servdesc.Types.Schemas[0]; //What if there are more than one Parts if (servdesc.Messages[SelectedOp.Messages.Input.Message.Name].Parts[0].Type.IsEmpty) { inputParameterType = servdesc.Messages[SelectedOp.Messages.Input.Message.Name].Parts[0].Element.Name; returnval += SchemaSearching(xmlSchema, inputParameterType); } else { //Currently takes care of only one part in each message if (SelectedOp.Messages.Input.Message.Name != null) { returnval += '<' + SelectedOp.Messages.Input.Message.Name + '>'; for (int i = 0; i < servdesc.Messages[SelectedOp.Messages.Input.Message.Name].Parts.Count; i++) { inputParameterType = servdesc.Messages[SelectedOp.Messages.Input.Message.Name].Parts[i].Type.Name; returnval += '<' + servdesc.Messages[SelectedOp.Messages.Input.Message.Name].Parts[i].Name + '>'; returnval += SchemaSearching(xmlSchema, inputParameterType); returnval += "</" + servdesc.Messages[SelectedOp.Messages.Input.Message.Name].Parts[i].Name + ">"; } returnval += "</" + SelectedOp.Messages.Input.Message.Name + '>'; } } Logger.Text += "Selected the method : " + inputMessageType + " that needs " + inputParameterType + " as the param\r\n"; //Logger.Text += servdesc.Messages[SelectedOp.Messages.Input.Message.Name].Parts[0].Type.Name + " as the param\r\n" ; //Logger.Text += "\r\n"; /* * System.Xml.Schema.XmlSchema xmlSchema = servdesc.Types.Schemas[0]; * * foreach (object item in xmlSchema.Items) * { * * System.Xml.Schema.XmlSchemaElement schemaElement = item as System.Xml.Schema.XmlSchemaElement; * //Logger.Text += "Ref name = " + schemaElement.RefName + "\r\n"; * //Logger.Text += " -------- " + item.GetType() + "\r\n"; * if (schemaElement != null) * { * //Logger.Text += "Ref name = " + schemaElement.RefName + "\r\n"; * if (schemaElement.Name == inputParameterType) * { * Logger.Text += "\r\n1. ******************\r\n"; * returnval = xmlGen.GenerateXmlString(schemaElement, xmlSchema); * Logger.Text += returnval+"\r\n"; * Logger.Text += "\r\n******************\r\n";*/ /*Logger.Text += "Schema Element Name : " + schemaElement.Name + "\r\n" ; * System.Xml.Schema.XmlSchemaType schemaType = schemaElement.SchemaType; * Logger.Text += "Type of " + schemaElement.Name + " is " + schemaElement.SchemaTypeName + "\r\n"; * System.Xml.Schema.XmlSchemaComplexType complexType = schemaType as System.Xml.Schema.XmlSchemaComplexType; * if (complexType != null) * { * System.Xml.Schema.XmlSchemaParticle particle = complexType.Particle; * Logger.Text += "Annot : " + particle.Annotation + "\r\n" ; * if (particle != null) * { //TraverseParticle(complexType.Particle); * Logger.Text += '<' + complexType.Name + '>' + xmlGen.GenerateXmlString(complexType.Particle) + "</" + complexType.Name + '>'; * } * } * else * { * //If it's not a Complex Type element * System.Xml.Schema.XmlSchemaSimpleType simpleType = schemaType as System.Xml.Schema.XmlSchemaSimpleType; * //simpleType. * }*//* * } * } * else * { //This is a complex Type * System.Xml.Schema.XmlSchemaComplexType complexType = item as System.Xml.Schema.XmlSchemaComplexType; * if (complexType != null) * { * //Logger.Text += "Name : " + complexType.Name + "\r\n" ; * if (complexType.Name == inputParameterType) * { * Logger.Text += "Complex Type Name : " + complexType.Name + "\r\n"; * System.Xml.Schema.XmlSchemaParticle particle = complexType.Particle; * System.Xml.Schema.XmlSchemaSequence sequence = particle as System.Xml.Schema.XmlSchemaSequence; * System.Xml.Schema.XmlSchemaAll schemaall = particle as System.Xml.Schema.XmlSchemaAll; * if (sequence != null) * { * foreach (System.Xml.Schema.XmlSchemaElement childElement in sequence.Items) * { * string parameterName = childElement.Name; * string parameterType = childElement.SchemaTypeName.Name; * Logger.Text += parameterName + " is a " + parameterType; * Logger.Text += "\r\n2. ************************************\r\n"; * returnval = '<' + complexType.Name + '>' + xmlGen.GenerateXmlString(childElement, xmlSchema) + "</" + complexType.Name + '>'; * Logger.Text += returnval; * Logger.Text += "\r\n************************************\r\n"; * } * } * else * { * if (schemaall != null) * { * Logger.Text += "\r\n3. ************************************\r\n"; * returnval = '<' + complexType.Name + '>' + xmlGen.GenerateXmlString(schemaall, xmlSchema) + "</" + complexType.Name + '>'; * Logger.Text += returnval; * Logger.Text += "\r\n************************************\r\n"; * //TraverseParticle(schemaall); * } * else * { * System.Xml.Schema.XmlSchemaComplexContent cmplxContent = null; * * if (cmplxContent != null) * { * Logger.Text += cmplxContent.GetType(); * Logger.Text += "\r\n4. ************************************\r\n"; * returnval = '<' + complexType.Name + '>' + xmlGen.GenerateXmlString(cmplxContent, xmlSchema) + "</" + complexType.Name + '>'; ; * Logger.Text += returnval; * Logger.Text += "\r\n************************************\r\n"; * } * } * } * } * } * else * { * System.Xml.Schema.XmlSchemaSimpleType simpleType = item as System.Xml.Schema.XmlSchemaSimpleType; * * } * } * }*/ returnval = Encapsulate("xmlns=\"" + servdesc.TargetNamespace + "\"", headerval, returnval); return(returnval); /* * for (int k = 0; k < schemas.Count; k++) * { * XmlSchemaObjectCollection xmlelem = schemas[k].Items; * XmlSchemaObjectEnumerator enumerator = xmlelem.GetEnumerator(); * while (enumerator.MoveNext()) * { * Logger.Text += " Type of " +enumerator.Current.GetType() + "\r\n" ; * * if (enumerator.Current is XmlSchemaElement) * { * XmlSchemaElement xse = (XmlSchemaElement)enumerator.Current; * Logger.Text += xse.Name + '=' + xse.SchemaType + ", "; * //if * TraverseParticle(xse); * } * else * { * if (enumerator.Current is XmlSchemaComplexType) * { * XmlSchemaComplexType xsct = (XmlSchemaComplexType)enumerator.Current; * Logger.Text += '\'' + xsct.Name + ": "; * TraverseParticle(xsct.Particle); * if (xsct.ContentModel is XmlSchemaSimpleContent) * { * Logger.Text += "Simple; "; * } * else * { * //XmlSchemaComplexContent complexContent = (XmlSchemaComplexContent)xsct.ContentModel; * if (xsct.ContentModel is XmlSchemaComplexContent) * { * Logger.Text += "Complex; "; * } * } * Logger.Text += "\',"; * } * } * } * Logger.Text += "\r\n"; * }*/ //Path to URL from Operation Name // Operation ^ Binding:Name //Service -> Port:Binding // Binding:Name == Port:Binding // Port:Name -> (Soapaddressbinding/HttpAddressBinding/Soap12AddressBinding).Location } catch (XmlException xe) { Logger.Text += xe.ToString(); } returnval = Encapsulate("xmlns=\"" + servdesc.TargetNamespace + "\"", headerval, returnval); return(returnval); }
public SoapSchemaImporter(XmlSchemas schemas, CodeGenerationOptions options, CodeDomProvider codeProvider, ImportContext context) { _importer = new XmlSchemaImporter(schemas, options, codeProvider, context); _importer.UseEncodedFormat = true; }
public SoapSchemaImporter(XmlSchemas schemas, CodeIdentifiers typeIdentifiers, CodeGenerationOptions options) { _importer = new XmlSchemaImporter(schemas, typeIdentifiers, options); _importer.UseEncodedFormat = true; }
public SoapSchemaImporter(XmlSchemas schemas) { _importer = new XmlSchemaImporter(schemas); _importer.UseEncodedFormat = true; }
/// <include file='doc\SoapSchemaImporter.uex' path='docs/doc[@for="SoapSchemaImporter.SoapSchemaImporter"]/*' /> /// <devdoc> /// <para>[To be supplied.]</para> /// </devdoc> public SoapSchemaImporter(XmlSchemas schemas) { this.schemas = schemas; this.typeIdentifiers = new CodeIdentifiers(); }
private StructMapping ImportStructType(XmlSchemaComplexType type, string typeNs, bool excludeFromImport) { if (type.Name == null) { XmlSchemaElement element = (XmlSchemaElement)type.Parent; XmlQualifiedName parentType = XmlSchemas.GetParentName(element); throw new InvalidOperationException(SR.Format(SR.XmlInvalidSchemaElementType, parentType.Name, parentType.Namespace, element.Name)); } TypeDesc baseTypeDesc = null; Mapping baseMapping = null; if (!type.DerivedFrom.IsEmpty) { baseMapping = ImportType(type.DerivedFrom, excludeFromImport); if (baseMapping is StructMapping) { baseTypeDesc = ((StructMapping)baseMapping).TypeDesc; } else { baseMapping = null; } } if (baseMapping == null) { baseMapping = GetRootMapping(); } Mapping previousMapping = (Mapping)ImportedMappings[type]; if (previousMapping != null) { return((StructMapping)previousMapping); } string typeName = GenerateUniqueTypeName(Accessor.UnescapeName(type.Name)); StructMapping structMapping = new StructMapping(); structMapping.IsReference = Schemas.IsReference(type); TypeFlags flags = TypeFlags.Reference; if (type.IsAbstract) { flags |= TypeFlags.Abstract; } structMapping.TypeDesc = new TypeDesc(typeName, typeName, TypeKind.Struct, baseTypeDesc, flags); structMapping.Namespace = typeNs; structMapping.TypeName = type.Name; structMapping.BaseMapping = (StructMapping)baseMapping; ImportedMappings.Add(type, structMapping); if (excludeFromImport) { structMapping.IncludeInSchema = false; } CodeIdentifiers members = new CodeIdentifiers(); members.AddReserved(typeName); AddReservedIdentifiersForDataBinding(members); structMapping.Members = ImportTypeMembers(type, typeNs, members); Scope.AddTypeMapping(structMapping); ImportDerivedTypes(new XmlQualifiedName(type.Name, typeNs)); return(structMapping); }
/// <include file='doc\SoapSchemaImporter.uex' path='docs/doc[@for="SoapSchemaImporter.SoapSchemaImporter1"]/*' /> /// <devdoc> /// <para>[To be supplied.]</para> /// </devdoc> public SoapSchemaImporter(XmlSchemas schemas, CodeIdentifiers typeIdentifiers) { this.schemas = schemas; this.typeIdentifiers = typeIdentifiers; }
/// <include file='doc\SoapSchemaImporter.uex' path='docs/doc[@for="SoapSchemaImporter.SoapSchemaImporter2"]/*' /> /// <devdoc> /// <para>[To be supplied.]</para> /// </devdoc> public SoapSchemaImporter(XmlSchemas schemas, CodeIdentifiers typeIdentifiers, CodeGenerationOptions options) : base(schemas, options, null, new ImportContext(typeIdentifiers, false)) { }
private static string GetSchemaItem(XmlSchemaObject o, string ns, string details) { if (o == null) { return(null); } while (o.Parent != null && !(o.Parent is XmlSchema)) { o = o.Parent; } if (ns == null || ns.Length == 0) { XmlSchemaObject tmp = o; while (tmp.Parent != null) { tmp = tmp.Parent; } if (tmp is XmlSchema) { ns = ((XmlSchema)tmp).TargetNamespace; } } string item = null; if (o is XmlSchemaNotation) { item = SR.Format(SR.XmlSchemaNamedItem, ns, "notation", ((XmlSchemaNotation)o).Name, details); } else if (o is XmlSchemaGroup) { item = SR.Format(SR.XmlSchemaNamedItem, ns, "group", ((XmlSchemaGroup)o).Name, details); } else if (o is XmlSchemaElement) { XmlSchemaElement e = ((XmlSchemaElement)o); if (e.Name == null || e.Name.Length == 0) { XmlQualifiedName parentName = XmlSchemas.GetParentName(o); // Element reference '{0}' declared in schema type '{1}' from namespace '{2}' item = SR.Format(SR.XmlSchemaElementReference, e.RefName.ToString(), parentName.Name, parentName.Namespace); } else { item = SR.Format(SR.XmlSchemaNamedItem, ns, "element", e.Name, details); } } else if (o is XmlSchemaType) { item = SR.Format(SR.XmlSchemaNamedItem, ns, o.GetType() == typeof(XmlSchemaSimpleType) ? "simpleType" : "complexType", ((XmlSchemaType)o).Name, null); } else if (o is XmlSchemaAttributeGroup) { item = SR.Format(SR.XmlSchemaNamedItem, ns, "attributeGroup", ((XmlSchemaAttributeGroup)o).Name, details); } else if (o is XmlSchemaAttribute) { XmlSchemaAttribute a = ((XmlSchemaAttribute)o); if (a.Name == null || a.Name.Length == 0) { XmlQualifiedName parentName = XmlSchemas.GetParentName(o); // Attribure reference '{0}' declared in schema type '{1}' from namespace '{2}' return(SR.Format(SR.XmlSchemaAttributeReference, a.RefName.ToString(), parentName.Name, parentName.Namespace)); } else { item = SR.Format(SR.XmlSchemaNamedItem, ns, "attribute", a.Name, details); } } else if (o is XmlSchemaContent) { XmlQualifiedName parentName = XmlSchemas.GetParentName(o); // Check content definition of schema type '{0}' from namespace '{1}'. {2} item = SR.Format(SR.XmlSchemaContentDef, parentName.Name, parentName.Namespace, null); } else if (o is XmlSchemaExternal) { string itemType = o is XmlSchemaImport ? "import" : o is XmlSchemaInclude ? "include" : o is XmlSchemaRedefine ? "redefine" : o.GetType().Name; item = SR.Format(SR.XmlSchemaItem, ns, itemType, details); } else if (o is XmlSchema) { item = SR.Format(SR.XmlSchema, ns, details); } else { item = SR.Format(SR.XmlSchemaNamedItem, ns, o.GetType().Name, null, details); } return(item); }
internal XmlSchemaObject?AddItem(XmlSchemaObject?item, XmlQualifiedName?qname, XmlSchemas schemas) { if (item == null) { return(null); } if (qname == null || qname.IsEmpty) { return(null); } string key = $"{item.GetType().Name}:{qname}"; ArrayList?list = (ArrayList?)ObjectCache[key]; if (list == null) { list = new ArrayList(); ObjectCache[key] = list; } for (int i = 0; i < list.Count; i++) { XmlSchemaObject cachedItem = (XmlSchemaObject)list[i] !; if (cachedItem == item) { return(cachedItem); } if (Match(cachedItem, item, true)) { return(cachedItem); } else { Warnings.Add(SR.Format(SR.XmlMismatchSchemaObjects, item.GetType().Name, qname.Name, qname.Namespace)); Warnings.Add($"DEBUG:Cached item key:\r\n{(string?)looks[cachedItem]}\r\nnew item key:\r\n{(string?)looks[item]}"); } } // no match found we need to insert the new type in the cache list.Add(item); return(item); }
public XmlSchemaEnumerator(XmlSchemas list) { _list = list; _idx = -1; _end = list.Count - 1; }
public SoapSchemaExporter(XmlSchemas schemas) { _exporter = new XmlSchemaExporter(schemas, true); }