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)); }
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; }
XmlSchemaSimpleType FindDataType(XmlQualifiedName name) { TypeDesc typeDesc = scope.GetTypeDesc(name); if (typeDesc != null) { return(typeDesc.DataType); } XmlSchemaSimpleType dataType = (XmlSchemaSimpleType)schemas.Find(name, typeof(XmlSchemaSimpleType)); if (dataType != null) { return(dataType); } if (name.Namespace == XmlSchema.Namespace) { return(scope.GetTypeDesc(typeof(string)).DataType); } else { throw new InvalidOperationException(Res.GetString(Res.XmlMissingDataType, name.Name)); } }
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); }
internal void Depends(XmlSchemaObject item, ArrayList refs) { if (item == null || scope[item] != null) { return; } Type t = item.GetType(); if (typeof(XmlSchemaType).IsAssignableFrom(t)) { XmlQualifiedName baseName = XmlQualifiedName.Empty; XmlSchemaType baseType = null; XmlSchemaParticle particle = null; XmlSchemaObjectCollection attributes = null; if (item is XmlSchemaComplexType) { XmlSchemaComplexType ct = (XmlSchemaComplexType)item; if (ct.ContentModel != null) { XmlSchemaContent content = ct.ContentModel.Content; if (content is XmlSchemaComplexContentRestriction) { baseName = ((XmlSchemaComplexContentRestriction)content).BaseTypeName; attributes = ((XmlSchemaComplexContentRestriction)content).Attributes; } else if (content is XmlSchemaSimpleContentRestriction) { XmlSchemaSimpleContentRestriction restriction = (XmlSchemaSimpleContentRestriction)content; if (restriction.BaseType != null) { baseType = restriction.BaseType; } else { baseName = restriction.BaseTypeName; } attributes = restriction.Attributes; } else if (content is XmlSchemaComplexContentExtension) { XmlSchemaComplexContentExtension extension = (XmlSchemaComplexContentExtension)content; attributes = extension.Attributes; particle = extension.Particle; baseName = extension.BaseTypeName; } else if (content is XmlSchemaSimpleContentExtension) { XmlSchemaSimpleContentExtension extension = (XmlSchemaSimpleContentExtension)content; attributes = extension.Attributes; baseName = extension.BaseTypeName; } } else { attributes = ct.Attributes; particle = ct.Particle; } if (particle is XmlSchemaGroupRef) { XmlSchemaGroupRef refGroup = (XmlSchemaGroupRef)particle; particle = ((XmlSchemaGroup)schemas.Find(refGroup.RefName, typeof(XmlSchemaGroup), false)).Particle; } else if (particle is XmlSchemaGroupBase) { particle = (XmlSchemaGroupBase)particle; } } else if (item is XmlSchemaSimpleType) { XmlSchemaSimpleType simpleType = (XmlSchemaSimpleType)item; XmlSchemaSimpleTypeContent content = simpleType.Content; if (content is XmlSchemaSimpleTypeRestriction) { baseType = ((XmlSchemaSimpleTypeRestriction)content).BaseType; baseName = ((XmlSchemaSimpleTypeRestriction)content).BaseTypeName; } else if (content is XmlSchemaSimpleTypeList) { XmlSchemaSimpleTypeList list = (XmlSchemaSimpleTypeList)content; if (list.ItemTypeName != null && !list.ItemTypeName.IsEmpty) { baseName = list.ItemTypeName; } if (list.ItemType != null) { baseType = list.ItemType; } } else if (content is XmlSchemaSimpleTypeRestriction) { baseName = ((XmlSchemaSimpleTypeRestriction)content).BaseTypeName; } else if (t == typeof(XmlSchemaSimpleTypeUnion)) { XmlQualifiedName[] memberTypes = ((XmlSchemaSimpleTypeUnion)item).MemberTypes; if (memberTypes != null) { for (int i = 0; i < memberTypes.Length; i++) { XmlSchemaType type = (XmlSchemaType)schemas.Find(memberTypes[i], typeof(XmlSchemaType), false); AddRef(refs, type); } } } } if (baseType == null && !baseName.IsEmpty && baseName.Namespace != XmlSchema.Namespace) { baseType = (XmlSchemaType)schemas.Find(baseName, typeof(XmlSchemaType), false); } if (baseType != null) { AddRef(refs, baseType); } if (particle != null) { Depends(particle, refs); } if (attributes != null) { for (int i = 0; i < attributes.Count; i++) { Depends(attributes[i], refs); } } } else if (t == typeof(XmlSchemaElement)) { XmlSchemaElement el = (XmlSchemaElement)item; if (!el.SubstitutionGroup.IsEmpty) { if (el.SubstitutionGroup.Namespace != XmlSchema.Namespace) { XmlSchemaElement head = (XmlSchemaElement)schemas.Find(el.SubstitutionGroup, typeof(XmlSchemaElement), false); AddRef(refs, head); } } if (!el.RefName.IsEmpty) { el = (XmlSchemaElement)schemas.Find(el.RefName, typeof(XmlSchemaElement), false); AddRef(refs, el); } else if (!el.SchemaTypeName.IsEmpty) { XmlSchemaType type = (XmlSchemaType)schemas.Find(el.SchemaTypeName, typeof(XmlSchemaType), false); AddRef(refs, type); } else { Depends(el.SchemaType, refs); } } else if (t == typeof(XmlSchemaGroup)) { Depends(((XmlSchemaGroup)item).Particle); } else if (t == typeof(XmlSchemaGroupRef)) { XmlSchemaGroup group = (XmlSchemaGroup)schemas.Find(((XmlSchemaGroupRef)item).RefName, typeof(XmlSchemaGroup), false); AddRef(refs, group); } else if (typeof(XmlSchemaGroupBase).IsAssignableFrom(t)) { foreach (XmlSchemaObject o in ((XmlSchemaGroupBase)item).Items) { Depends(o, refs); } } else if (t == typeof(XmlSchemaAttributeGroupRef)) { XmlSchemaAttributeGroup group = (XmlSchemaAttributeGroup)schemas.Find(((XmlSchemaAttributeGroupRef)item).RefName, typeof(XmlSchemaAttributeGroup), false); AddRef(refs, group); } else if (t == typeof(XmlSchemaAttributeGroup)) { foreach (XmlSchemaObject o in ((XmlSchemaAttributeGroup)item).Attributes) { Depends(o, refs); } } else if (t == typeof(XmlSchemaAttribute)) { XmlSchemaAttribute at = (XmlSchemaAttribute)item; if (!at.RefName.IsEmpty) { at = (XmlSchemaAttribute)schemas.Find(at.RefName, typeof(XmlSchemaAttribute), false); AddRef(refs, at); } else if (!at.SchemaTypeName.IsEmpty) { XmlSchemaType type = (XmlSchemaType)schemas.Find(at.SchemaTypeName, typeof(XmlSchemaType), false); AddRef(refs, type); } else { Depends(at.SchemaType, refs); } } if (typeof(XmlSchemaAnnotated).IsAssignableFrom(t)) { XmlAttribute[] attrs = (XmlAttribute[])((XmlSchemaAnnotated)item).UnhandledAttributes; if (attrs != null) { for (int i = 0; i < attrs.Length; i++) { XmlAttribute attribute = attrs[i]; if (attribute.LocalName == Wsdl.ArrayType && attribute.NamespaceURI == Wsdl.Namespace) { string dims; XmlQualifiedName qname = TypeScope.ParseWsdlArrayType(attribute.Value, out dims, item); XmlSchemaType type = (XmlSchemaType)schemas.Find(qname, typeof(XmlSchemaType), false); AddRef(refs, type); } } } } }
private ServiceDescriptionImportWarnings Import(CodeNamespace codeNamespace, ImportContext importContext, Hashtable exportContext, StringCollection warnings) { allSchemas = new XmlSchemas(); foreach (XmlSchema schema in schemas) { allSchemas.Add(schema); } foreach (ServiceDescription description in serviceDescriptions) { foreach (XmlSchema schema in description.Types.Schemas) { allSchemas.Add(schema); } } Hashtable references = new Hashtable(); if (!allSchemas.Contains(ServiceDescription.Namespace)) { allSchemas.AddReference(ServiceDescription.Schema); references[ServiceDescription.Schema] = ServiceDescription.Schema; } if (!allSchemas.Contains(Soap.Encoding)) { allSchemas.AddReference(ServiceDescription.SoapEncodingSchema); references[ServiceDescription.SoapEncodingSchema] = ServiceDescription.SoapEncodingSchema; } allSchemas.Compile(null, false); // Segregate the schemas containing abstract types from those // containing regular XML definitions. This is important because // when you import something returning the ur-type (object), then // you need to import ALL types/elements within ALL schemas. We // don't want the RPC-based types leaking over into the XML-based // element definitions. This also occurs when you have derivation: // we need to search the schemas for derived types: but WHICH schemas // should we search. foreach (ServiceDescription description in serviceDescriptions) { foreach (Message message in description.Messages) { foreach (MessagePart part in message.Parts) { bool isEncoded; bool isLiteral; FindUse(part, out isEncoded, out isLiteral); if (part.Element != null && !part.Element.IsEmpty) { if (isEncoded) throw new InvalidOperationException(Res.GetString(Res.CanTSpecifyElementOnEncodedMessagePartsPart, part.Name, message.Name)); XmlSchemaElement element = (XmlSchemaElement)allSchemas.Find(part.Element, typeof(XmlSchemaElement)); if (element != null) { AddSchema(element.Parent as XmlSchema, isEncoded, isLiteral, abstractSchemas, concreteSchemas, references); if (element.SchemaTypeName != null && !element.SchemaTypeName.IsEmpty) { XmlSchemaType type = (XmlSchemaType)allSchemas.Find(element.SchemaTypeName, typeof(XmlSchemaType)); if (type != null) { AddSchema(type.Parent as XmlSchema, isEncoded, isLiteral, abstractSchemas, concreteSchemas, references); } } } } if (part.Type != null && !part.Type.IsEmpty) { XmlSchemaType type = (XmlSchemaType)allSchemas.Find(part.Type, typeof(XmlSchemaType)); if (type != null) { AddSchema(type.Parent as XmlSchema, isEncoded, isLiteral, abstractSchemas, concreteSchemas, references); } } } } } Hashtable imports; foreach (XmlSchemas xmlschemas in new XmlSchemas[] { abstractSchemas, concreteSchemas }) { // collect all imports imports = new Hashtable(); foreach (XmlSchema schema in xmlschemas) { AddImport(schema, imports); } // make sure we add them to the corresponding schema collections foreach (XmlSchema schema in imports.Keys) { if (references[schema] == null && !xmlschemas.Contains(schema)) { xmlschemas.Add(schema); } } } // If a schema was not referenced by either a literal or an encoded message part, // add it to both collections. There's no way to tell which it should be. imports = new Hashtable(); foreach (XmlSchema schema in allSchemas) { if (!abstractSchemas.Contains(schema) && !concreteSchemas.Contains(schema)) { AddImport(schema, imports); } } // make sure we add them to the corresponding schema collections foreach (XmlSchema schema in imports.Keys) { if (references[schema] != null) continue; if (!abstractSchemas.Contains(schema)) { abstractSchemas.Add(schema); } if (!concreteSchemas.Contains(schema)) { concreteSchemas.Add(schema); } } if (abstractSchemas.Count > 0) { foreach (XmlSchema schema in references.Values) { abstractSchemas.AddReference(schema); } StringCollection schemaWarnings = SchemaCompiler.Compile(abstractSchemas); foreach (string warning in schemaWarnings) warnings.Add(warning); } if (concreteSchemas.Count > 0) { foreach (XmlSchema schema in references.Values) { concreteSchemas.AddReference(schema); } StringCollection schemaWarnings = SchemaCompiler.Compile(concreteSchemas); foreach (string warning in schemaWarnings) warnings.Add(warning); } if (ProtocolName.Length > 0) { // If a protocol was specified, only try that one ProtocolImporter importer = FindImporterByName(ProtocolName); if (importer.GenerateCode(codeNamespace, importContext, exportContext)) return importer.Warnings; } else { // Otherwise, do "best" protocol (first one that generates something) for (int i = 0; i < importers.Length; i++) { ProtocolImporter importer = importers[i]; if (importer.GenerateCode(codeNamespace, importContext, exportContext)) { return importer.Warnings; } } } return ServiceDescriptionImportWarnings.NoCodeGenerated; }