Example #1
0
        /// <summary>
        /// Creates the schema type representing the trigger type
        /// </summary>
        /// <returns>Type definition for a trigger</returns>
        static XmlSchemaType CreateTriggerType()
        {
            XmlSchemaComplexContentExtension Extension = new XmlSchemaComplexContentExtension();

            Extension.BaseTypeName = GetQualifiedTypeName(ScriptSchemaStandardType.TriggerBody);
            Extension.Attributes.Add(CreateSchemaAttribute("Name", ScriptSchemaStandardType.QualifiedName, XmlSchemaUse.Required));
            Extension.Attributes.Add(CreateSchemaAttribute("If", ScriptSchemaStandardType.BalancedString, XmlSchemaUse.Optional));

            XmlSchemaComplexContent ContentModel = new XmlSchemaComplexContent();

            ContentModel.Content = Extension;

            XmlSchemaComplexType ComplexType = new XmlSchemaComplexType();

            ComplexType.Name         = GetTypeName(ScriptSchemaStandardType.Trigger);
            ComplexType.ContentModel = ContentModel;
            return(ComplexType);
        }
Example #2
0
        static void WriteComplexType(this SimpleClassFormatter formatter, XmlSchemaComplexType type, String name, CommandLineOptions options, Queue <XmlSchema> schemas, HashSet <XmlSchema> processedSchemas)
        {
            String baseType = null;
            XmlSchemaComplexContentExtension extension = type.ContentModel?.Content as XmlSchemaComplexContentExtension;

            // Check if we've a extension
            if (extension != null)
            {
                // Set base type
                baseType = extension.BaseTypeName.Name.CleanName(options.CleanNames);
                // Add schema for processing
                XmlSchema schema = LoadedSchemas.Schemas().Cast <XmlSchema>().FirstOrDefault(p => p.SchemaTypes.Contains(extension.BaseTypeName));
                if (schema != null && processedSchemas.Add(schema))
                {
                    schemas.Enqueue(schema);
                }
            }

            // Open class definition
            if (options.DataContracts)
            {
                if (name == null)
                {
                    formatter.WriteAttribute(typeof(DataContractAttribute), new KeyValuePair <String, String>("Namespace", $"\"{GetSchema(type).TargetNamespace}\""));
                }
                else
                {
                    formatter.WriteAttribute(typeof(DataContractAttribute), new KeyValuePair <String, String>("Name", $"\"{name}\""), new KeyValuePair <String, String>("Namespace", $"\"{GetSchema(type).TargetNamespace}\""));
                }
            }
            formatter.BeginClass((name ?? type.Name).CleanName(options.CleanNames), baseType, isAbstract: type.IsAbstract);

            if ((type.Particle ?? extension.Particle) is XmlSchemaGroupBase sequence)
            {
                formatter.WriteSequence(sequence, options, schemas, processedSchemas);
            }
            else if (type.Particle != null)
            {
                throw new NotImplementedException();
            }

            // Close class definition
            formatter.CloseBracket();
        }
Example #3
0
        void WriteComplexContent(XmlTextWriter xtw, string ns, XmlSchemaComplexContent content)
        {
            XmlQualifiedName qname;

            XmlSchemaComplexContentExtension ext = content.Content as XmlSchemaComplexContentExtension;

            if (ext != null)
            {
                qname = ext.BaseTypeName;
            }
            else
            {
                XmlSchemaComplexContentRestriction rest = (XmlSchemaComplexContentRestriction)content.Content;
                qname = rest.BaseTypeName;
                if (qname == arrayType)
                {
                    ParseArrayType(rest, out qname);
                    XmlSchemaElement elem = new XmlSchemaElement();
                    elem.Name           = "Item";
                    elem.SchemaTypeName = qname;

                    xtw.WriteAttributeString("arrayType", SoapEncodingNamespace, qname.Name + "[2]");
                    WriteContentItem(xtw, ns, elem, true);
                    return;
                }
            }

            // Add base map members to this map
            XmlSchemaComplexType ctype = FindComplexTyype(qname);

            WriteComplexTypeAttributes(xtw, ctype);

            if (ext != null)
            {
                // Add the members of this map
                WriteAttributes(xtw, ext.Attributes, ext.AnyAttribute);
                if (ext.Particle != null)
                {
                    WriteParticleComplexContent(xtw, ns, ext.Particle);
                }
            }

            WriteComplexTypeElements(xtw, ns, ctype);
        }
        /// <summary>
        /// Gets the extension signature.
        /// </summary>
        /// <param name="extension">The extension.</param>
        /// <param name="name">The name.</param>
        /// <returns></returns>
        private string GetExtensionSignature(XmlSchemaComplexContentExtension extension, XmlQualifiedName name)
        {
            var particle = (XmlSchemaSequence)extension.Particle;
            var fields   = particle.Items
                           .OfType <XmlSchemaElement>()
                           .Select(GetNativeElement);

            return(GetHashFor(
                       writer =>
            {
                writer.Write(GetTypeName(name));
                writer.Write(GetTypeName(extension.BaseTypeName));
                foreach (var field in fields)
                {
                    writer.Write(field.Name);
                    writer.Write(field.Type.FullName);
                }
            }));
        }
Example #5
0
        private void LoadXmlSchemaComplexType(XmlSchemaComplexType ctype)
        {
            if (ctype == null)
            {
                return;
            }
            LoadXmlSchemaObjectCollection(ctype.Attributes);
            XmlSchemaComplexContent content = ctype.ContentModel as XmlSchemaComplexContent;

            if (content != null)
            {
                XmlSchemaComplexContentExtension cext = content.Content as XmlSchemaComplexContentExtension;
                if (cext != null)
                {
                    LoadXmlSchemaObjectCollection(cext.Attributes);
                    if (cext.BaseTypeName != null)
                    {
                        string typeName = cext.BaseTypeName.Name;
                        if (xcontoler._complexTypes.ContainsKey(typeName))
                        {
                            LoadXmlSchemaComplexType(xcontoler._complexTypes[typeName]);
                        }
                    }
                    LoadXmlSchemaObject(cext.Particle);
                }
            }
            else
            {
                XmlSchemaSimpleContent scontent = ctype.ContentModel as XmlSchemaSimpleContent;
                if (scontent != null)
                {
                    XmlSchemaSimpleContentExtension sext = scontent.Content as XmlSchemaSimpleContentExtension;
                    if (sext != null)
                    {
                        LoadXmlSchemaObjectCollection(sext.Attributes);
                    }
                }
                else
                {
                    LoadXmlSchemaObject(ctype.Particle);
                }
            }
        }
Example #6
0
        private void GenerateComplexType(XmlSchema schema, IXmlTypeSerialiser serialiser)
        {
            XmlSchemaComplexType complexType = new XmlSchemaComplexType();

            complexType.Name = GenerateItemName(serialiser.Type);
            var particle = GenerateSchemaElementsForMembers(serialiser);

            if (serialiser.Attribute.Extends != null)
            {
                var extension = new XmlSchemaComplexContentExtension
                {
                    BaseTypeName = new XmlQualifiedName(GenerateItemName(serialiser.Attribute.Extends), NamespaceUri),
                    Particle     = particle
                };
                complexType.ContentModel = new XmlSchemaComplexContent
                {
                    Content = extension
                };
                if (!baseTypes.Contains(serialiser.Attribute.Extends))
                {
                    baseTypes.Add(serialiser.Attribute.Extends);
                }
            }
            else
            {
                complexType.Particle = particle;
            }

            schema.Items.Add(complexType);
            if (baseTypes.Contains(serialiser.Type))
            {
                baseTypes.Remove(serialiser.Type);
            }
            loadedTypes.Add(serialiser.Type, new ReferencedType
            {
                Extends      = serialiser.Attribute.Extends,
                NamespaceUri = NamespaceUri,
                TypeName     = complexType.Name,
                ElementName  = serialiser.Attribute.Name,
                Description  = serialiser.Attribute.Description
            });
        }
Example #7
0
        public Rating()
        {
            baseSchema = new XmlSchema();

            //<xs:complexType name="RatingN"> first time is empty
            XmlSchemaComplexType newType = new XmlSchemaComplexType();

            newType.Name = "";
            baseSchema.Items.Add(newType);

            //<xs:complexContent>
            XmlSchemaComplexContent complexContent = new XmlSchemaComplexContent();

            newType.ContentModel = complexContent;

            //<xs:extension base="Rating">
            XmlSchemaComplexContentExtension complexContentExtension = new XmlSchemaComplexContentExtension();

            complexContent.Content = complexContentExtension;
            complexContentExtension.BaseTypeName = new XmlQualifiedName("Rating");

            //<xs:sequence>
            XmlSchemaSequence seq = new XmlSchemaSequence();

            complexContentExtension.Particle = seq;

            //<xs:element name="Value" type="xs:integer"/>
            XmlSchemaElement elem = new XmlSchemaElement();

            seq.Items.Add(elem);
            elem.Name           = "Value";
            elem.SchemaTypeName = new XmlQualifiedName("integer", "http://www.w3.org/2001/XMLSchema");

            //to Check
            XmlSchemaMinInclusiveFacet minFacet = new XmlSchemaMinInclusiveFacet();

            minFacet.Value = "0";
            Common.addFacet(minFacet, Common.getElementFromSchema(baseSchema));

            maxRateFacet.Value = "5";
            Common.addFacet(maxRateFacet, Common.getElementFromSchema(baseSchema));
        }
Example #8
0
        XObject[] CreateProtoComplexType(XmlSchemaComplexType complexType)
        {
            if (complexType.ContentModel != null)
            {
                if ((complexType.ContentModel as XmlSchemaSimpleContent) != null)
                {
                    return(CreateProtoSimpleContent((complexType.ContentModel as XmlSchemaSimpleContent), complexType.BaseXmlSchemaType).ToArray());
                }
                else if ((complexType.ContentModel as XmlSchemaComplexContent) != null)
                {
                    return(CreateProtoComplexContent((complexType.ContentModel as XmlSchemaComplexContent), complexType.BaseXmlSchemaType).ToArray());
                }
                else
                {
                    throw new Exception("not implemented");
                }
            }
            else
            {
                var complexContentExt = new XmlSchemaComplexContentExtension();
                if (complexType.BaseXmlSchemaType != null)
                {
                    complexContentExt.BaseTypeName = complexType.BaseXmlSchemaType.QualifiedName;
                }
                else
                {
                    complexContentExt.BaseTypeName = null;
                }

                if (complexType.Attributes != null)
                {
                    foreach (var i in complexType.Attributes)
                    {
                        complexContentExt.Attributes.Add(i);
                    }
                }
                complexContentExt.Particle = complexType.Particle;
                var complexContent = new XmlSchemaComplexContent();
                complexContent.Content = complexContentExt;
                return(CreateProtoComplexContent(complexContent, complexType.BaseXmlSchemaType).ToArray());
            }
        }
Example #9
0
        internal void ExportStandardComplexType(DataContractAttribute attr, SerializationMap map, List <DataMemberInfo> members)
        {
            Type type  = map.RuntimeType;
            var  qname = map.XmlName;
            var  ct    = CreateComplexType(qname, type);

            if (type.BaseType != null && type.BaseType != typeof(object))
            {
                ExportCore(type.BaseType, false);
                var xcc = new XmlSchemaComplexContent();
                ct.ContentModel = xcc;
                var xcce = new XmlSchemaComplexContentExtension();
                xcc.Content       = xcce;
                xcce.BaseTypeName = GetSchemaTypeName(type.BaseType);
                xcce.Particle     = CreateMembersSequence(type, members, attr != null);
            }
            else
            {
                ct.Particle = CreateMembersSequence(type, members, attr != null);
            }
        }
Example #10
0
        /// <summary>
        /// Creates an element representing a conditional "Do" block, which recursively contains another type
        /// </summary>
        /// <param name="InnerType">The base type for the do block to contain</param>
        /// <returns>New schema element for the block</returns>
        static XmlSchemaElement CreateDoElement(ScriptSchemaStandardType InnerType)
        {
            XmlSchemaComplexContentExtension Extension = new XmlSchemaComplexContentExtension();

            Extension.BaseTypeName = GetQualifiedTypeName(InnerType);
            Extension.Attributes.Add(CreateSchemaAttribute("If", ScriptSchemaStandardType.BalancedString, XmlSchemaUse.Optional));

            XmlSchemaComplexContent ContentModel = new XmlSchemaComplexContent();

            ContentModel.Content = Extension;

            XmlSchemaComplexType SchemaType = new XmlSchemaComplexType();

            SchemaType.ContentModel = ContentModel;

            XmlSchemaElement Element = new XmlSchemaElement();

            Element.Name       = "Do";
            Element.SchemaType = SchemaType;
            return(Element);
        }
Example #11
0
        internal static XmlSchemaComplexType GetBaseType(this XmlSchemaComplexContentExtension extension)
        {
            var schema = extension.GetSchema();

            for (var i = 0; i < schema.Items.Count; i++)
            {
                var item = schema.Items[i];
                if (item is XmlSchemaComplexType == false)
                {
                    continue;
                }

                var complexType = item as XmlSchemaComplexType;

                if (complexType.QualifiedName == extension.BaseTypeName)
                {
                    return(complexType);
                }
            }
            return(null);
        }
Example #12
0
        /// <summary>
        /// Initializes a new instance of the <see cref="VEMap"/> class.
        /// </summary>
        public VEMap()
        {
            baseSchema = new XmlSchema();

            //<xs:complexType name="VEMapN">
            XmlSchemaComplexType newType = new XmlSchemaComplexType();

            newType.Name = "";
            baseSchema.Items.Add(newType);

            //<xs:complexContent>
            XmlSchemaComplexContent complexContent = new XmlSchemaComplexContent();

            newType.ContentModel = complexContent;

            //<xs:extension base="VEMap">
            XmlSchemaComplexContentExtension complexContentExtension = new XmlSchemaComplexContentExtension();

            complexContent.Content = complexContentExtension;
            complexContentExtension.BaseTypeName = new XmlQualifiedName("VEMap");

            //<xs:sequence>
            XmlSchemaSequence seq = new XmlSchemaSequence();

            complexContentExtension.Particle = seq;

            //<xs:element name="Latitude" type="xs:string"/>
            XmlSchemaElement elem1 = new XmlSchemaElement();

            seq.Items.Add(elem1);
            elem1.Name           = "Latitude";
            elem1.SchemaTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema");

            //<xs:element name="Longitude" type="xs:string"/>
            XmlSchemaElement elem2 = new XmlSchemaElement();

            seq.Items.Add(elem2);
            elem2.Name           = "Longitude";
            elem2.SchemaTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema");
        }
Example #13
0
        /// <summary>
        /// Creates a field instance from his XML schema representation, taking the field structure from a schema and the constraints from another.
        /// </summary>
        /// <param name="schema">
        /// A <see cref="XmlSchemaSet"/> which contains the whole form to render
        /// </param>
        /// <param name="elm">
        /// A <see cref="XmlSchemaElement"/> which contains the definition of the field to instantiate
        /// </param>
        /// <returns>
        /// A <see cref="Field"/> built following the schemas above
        /// </returns>
        public static IField GetInstance(XmlSchemaSet schema, XmlSchemaObject scobj)
        {
            if (scobj is XmlSchemaElement && !((XmlSchemaElement)scobj).SchemaTypeName.IsEmpty)
            {
                XmlSchemaElement elm = (XmlSchemaElement)scobj;
                try
                {
                    foreach (XmlSchema xsd in schema.Schemas())
                    {
                        string searchname = elm.SchemaTypeName.ToString();
                        //controlla se nello schema è presente l'elemento cercato
                        if (xsd.SchemaTypes.Contains(new XmlQualifiedName(searchname)))
                        {
                            foreach (XmlSchemaObject obj in xsd.Items)
                            {
                                if (obj is XmlSchemaComplexType && ((XmlSchemaComplexType)obj).Name.ToString() == searchname)
                                {
                                    XmlSchema fieldschema = new XmlSchema();
                                    fieldschema.Items.Add(obj);
                                    XmlSchemaComplexContent          xcc  = (XmlSchemaComplexContent)((XmlSchemaComplexType)obj).ContentModel;
                                    XmlSchemaComplexContentExtension xext = (XmlSchemaComplexContentExtension)xcc.Content;

                                    Type   tipo = Type.GetType("Fields." + xext.BaseTypeName.ToString(), true);
                                    Type[] par  = { fieldschema.GetType(), typeof(string) };
                                    //elm.Name prende il nome dell'elemento contenuto in elm
                                    Object[] vals = { fieldschema, elm.Name };
                                    return((IField)tipo.GetConstructor(par).Invoke(vals));
                                }
                            }
                        }
                    }
                }
                catch (Exception)
                {
                    return(null);
                }
                return(null);
            }
            return(null);
        }
        private XmlQualifiedName ExportStructMapping(StructMapping mapping, string ns)
        {
            if (mapping.TypeDesc.IsRoot)
            {
                return(this.ExportRootMapping(mapping));
            }
            XmlSchemaComplexType type = (XmlSchemaComplexType)this.types[mapping];

            if (type == null)
            {
                if (!mapping.IncludeInSchema)
                {
                    throw new InvalidOperationException(Res.GetString("XmlSoapCannotIncludeInSchema", new object[] { mapping.TypeDesc.Name }));
                }
                this.CheckForDuplicateType(mapping.TypeName, mapping.Namespace);
                type = new XmlSchemaComplexType {
                    Name = mapping.TypeName
                };
                this.types.Add(mapping, type);
                this.AddSchemaItem(type, mapping.Namespace, ns);
                type.IsAbstract = mapping.TypeDesc.IsAbstract;
                if ((mapping.BaseMapping != null) && mapping.BaseMapping.IncludeInSchema)
                {
                    XmlSchemaComplexContentExtension extension = new XmlSchemaComplexContentExtension {
                        BaseTypeName = this.ExportStructMapping(mapping.BaseMapping, mapping.Namespace)
                    };
                    XmlSchemaComplexContent content = new XmlSchemaComplexContent {
                        Content = extension
                    };
                    type.ContentModel = content;
                }
                this.ExportTypeMembers(type, mapping.Members, mapping.Namespace);
                this.ExportDerivedMappings(mapping);
            }
            else
            {
                this.AddSchemaImport(mapping.Namespace, ns);
            }
            return(new XmlQualifiedName(type.Name, mapping.Namespace));
        }
        /// <summary>
        /// Finds the named child element contained in the extension element.
        /// </summary>
        XmlSchemaElement FindChildElement(XmlSchemaComplexContentExtension extension, QualifiedName name)
        {
            var complexType = FindNamedType(schema, extension.BaseTypeName);

            if (complexType == null)
            {
                return(null);
            }

            var matchedElement = FindChildElement(complexType, name);

            if (matchedElement != null)
            {
                return(matchedElement);
            }

            var sequence = extension.Particle as XmlSchemaSequence;

            if (sequence != null)
            {
                return(FindElement(sequence.Items, name));
            }

            var choice = extension.Particle as XmlSchemaChoice;

            if (choice != null)
            {
                return(FindElement(choice.Items, name));
            }

            var groupRef = extension.Particle as XmlSchemaGroupRef;

            if (groupRef != null)
            {
                return(FindElement(groupRef, name));
            }

            return(null);
        }
Example #16
0
        public CheckBoxField(XmlSchema schema, string name)
        {
            // in this constructor it's useful to set the ID, cause GUI is calling it
            this.Name = name;

            //why don't use the former constructor? <---
            baseSchema = new XmlSchema();

            //<xs:complexType name="CheckBoxN">
            XmlSchemaComplexType newType = new XmlSchemaComplexType();

            newType.Name = ((XmlSchemaComplexType)schema.Items[0]).Name;
            baseSchema.Items.Add(newType);

            //<xs:complexContent>
            XmlSchemaComplexContent complexContent = new XmlSchemaComplexContent();

            newType.ContentModel = complexContent;

            //<xs:extension base="CheckBox">
            XmlSchemaComplexContentExtension complexContentExtension = new XmlSchemaComplexContentExtension();

            complexContent.Content = complexContentExtension;
            complexContentExtension.BaseTypeName = new XmlQualifiedName("CheckBox");

            //<xs:sequence>
            XmlSchemaSequence seq = new XmlSchemaSequence();

            complexContentExtension.Particle = seq;

            //<xs:element name="Value" type="xs:boolean" default="false"/>
            XmlSchemaElement elem = new XmlSchemaElement();

            seq.Items.Add(elem);
            elem.Name           = "Value";
            elem.SchemaTypeName = new XmlQualifiedName("boolean", "http://www.w3.org/2001/XMLSchema");
            elem.DefaultValue   = "false";
        }
        XmlQualifiedName ExportStructMapping(StructMapping mapping, string ns)
        {
            if (mapping.TypeDesc.IsRoot)
            {
                return(ExportRootMapping(mapping));
            }
            XmlSchemaComplexType type = (XmlSchemaComplexType)types[mapping];

            if (type == null)
            {
                if (!mapping.IncludeInSchema)
                {
                    throw new InvalidOperationException(Res.GetString(Res.XmlSoapCannotIncludeInSchema, mapping.TypeDesc.Name));
                }
                CheckForDuplicateType(mapping.TypeName, mapping.Namespace);
                type      = new XmlSchemaComplexType();
                type.Name = mapping.TypeName;
                types.Add(mapping, type);
                AddSchemaItem(type, mapping.Namespace, ns);
                type.IsAbstract = mapping.TypeDesc.IsAbstract;

                if (mapping.BaseMapping != null && mapping.BaseMapping.IncludeInSchema)
                {
                    XmlSchemaComplexContentExtension extension = new XmlSchemaComplexContentExtension();
                    extension.BaseTypeName = ExportStructMapping(mapping.BaseMapping, mapping.Namespace);
                    XmlSchemaComplexContent model = new XmlSchemaComplexContent();
                    model.Content     = extension;
                    type.ContentModel = model;
                }
                ExportTypeMembers(type, mapping.Members, mapping.Namespace);
                ExportDerivedMappings(mapping);
            }
            else
            {
                AddSchemaImport(mapping.Namespace, ns);
            }
            return(new XmlQualifiedName(type.Name, mapping.Namespace));
        }
Example #18
0
        /// <summary>
        /// Creates the schema type representing the node type
        /// </summary>
        /// <returns>Type definition for a node</returns>
        static XmlSchemaType CreateNodeType()
        {
            XmlSchemaComplexContentExtension Extension = new XmlSchemaComplexContentExtension();

            Extension.BaseTypeName = GetQualifiedTypeName(ScriptSchemaStandardType.NodeBody);
            Extension.Attributes.Add(CreateSchemaAttribute("Name", ScriptSchemaStandardType.Name, XmlSchemaUse.Required));
            Extension.Attributes.Add(CreateSchemaAttribute("Requires", ScriptSchemaStandardType.NameOrTagList, XmlSchemaUse.Optional));
            Extension.Attributes.Add(CreateSchemaAttribute("Produces", ScriptSchemaStandardType.TagList, XmlSchemaUse.Optional));
            Extension.Attributes.Add(CreateSchemaAttribute("After", ScriptSchemaStandardType.NameOrTagList, XmlSchemaUse.Optional));
            Extension.Attributes.Add(CreateSchemaAttribute("Token", ScriptSchemaStandardType.BalancedString, XmlSchemaUse.Optional));
            Extension.Attributes.Add(CreateSchemaAttribute("If", ScriptSchemaStandardType.BalancedString, XmlSchemaUse.Optional));
            Extension.Attributes.Add(CreateSchemaAttribute("NotifyOnWarnings", ScriptSchemaStandardType.Boolean, XmlSchemaUse.Optional));

            XmlSchemaComplexContent ContentModel = new XmlSchemaComplexContent();

            ContentModel.Content = Extension;

            XmlSchemaComplexType ComplexType = new XmlSchemaComplexType();

            ComplexType.Name         = GetTypeName(ScriptSchemaStandardType.Node);
            ComplexType.ContentModel = ContentModel;
            return(ComplexType);
        }
Example #19
0
        public static IEnumerable <XmlSchemaAttribute> XsdAttributesInScope(this XmlSchemaType ty)
        {
            if (ty != null)
            {
                XmlSchemaComplexType xmlSchemaComplexType = ty as XmlSchemaComplexType;
                if (xmlSchemaComplexType != null)
                {
                    foreach (XmlSchemaAttribute attribute in xmlSchemaComplexType.Attributes)
                    {
                        yield return(attribute);
                    }
                    if (xmlSchemaComplexType.ContentModel != null)
                    {
                        XmlSchemaComplexContent contentModel = xmlSchemaComplexType.ContentModel as XmlSchemaComplexContent;
                        if (contentModel != null)
                        {
                            XmlSchemaComplexContentExtension content = contentModel.Content as XmlSchemaComplexContentExtension;
                            if (content == null)
                            {
                                goto Label0;
                            }
                            foreach (XmlSchemaAttribute xmlSchemaAttribute in content.Attributes)
                            {
                                yield return(xmlSchemaAttribute);
                            }
                        }
                        else
                        {
                            goto Label0;
                        }
                    }
                }
            }
Label0:
            yield break;
            goto Label0;
        }
Example #20
0
        private const int MAX_ELEM_BEFORE_DROPDOWN       = 10;   //very great Name

        #region constructors

        public RadioButtonList()
        {
            baseSchema = new XmlSchema();

            XmlSchemaComplexType ctype = new XmlSchemaComplexType();

            ctype.Name = "";
            baseSchema.Items.Add(ctype);

            XmlSchemaComplexContent          complexContent          = new XmlSchemaComplexContent();
            XmlSchemaComplexContentExtension complexContentExtension = new XmlSchemaComplexContentExtension();

            complexContentExtension.BaseTypeName = new XmlQualifiedName("RadioButtonList");

            ctype.ContentModel     = complexContent;
            complexContent.Content = complexContentExtension;

            XmlSchemaSequence seq = new XmlSchemaSequence();

            complexContentExtension.Particle = seq;

            XmlSchemaElement elem = new XmlSchemaElement();

            elem.Name = "Value";
            seq.Items.Add(elem);

            XmlSchemaSimpleType            simpleType  = new XmlSchemaSimpleType();
            XmlSchemaSimpleTypeRestriction restriction = new XmlSchemaSimpleTypeRestriction();

            restriction.BaseTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema");

            elem.SchemaType    = simpleType;
            simpleType.Content = restriction;
            //for direct access
            elemPointer = elem;
        }
        void GetChildElementCompletionData(XmlCompletionDataList data, XmlSchemaComplexContentExtension extension, string prefix)
        {
            var complexType = FindNamedType(schema, extension.BaseTypeName);

            if (complexType != null)
            {
                GetChildElementCompletionData(data, complexType, prefix);
            }

            if (extension.Particle == null)
            {
                return;
            }

            var sequence = extension.Particle as XmlSchemaSequence;

            if (sequence != null)
            {
                GetChildElementCompletionData(data, sequence.Items, prefix);
                return;
            }
            var choice = extension.Particle as XmlSchemaChoice;

            if (choice != null)
            {
                GetChildElementCompletionData(data, choice.Items, prefix);
                return;
            }
            var groupRef = extension.Particle as XmlSchemaGroupRef;

            if (groupRef != null)
            {
                GetChildElementCompletionData(data, groupRef, prefix);
                return;
            }
        }
Example #22
0
    public static void Main()
    {
        XmlSchema schema = new XmlSchema();

        // <xs:complexType name="address">
        XmlSchemaComplexType address = new XmlSchemaComplexType();

        schema.Items.Add(address);
        address.Name = "address";

        // <xs:sequence>
        XmlSchemaSequence sequence = new XmlSchemaSequence();

        address.Particle = sequence;

        // <xs:element name="name"   type="xs:string"/>
        XmlSchemaElement elementName = new XmlSchemaElement();

        sequence.Items.Add(elementName);
        elementName.Name           = "name";
        elementName.SchemaTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema");

        // <xs:element name="street"   type="xs:string"/>
        XmlSchemaElement elementStreet = new XmlSchemaElement();

        sequence.Items.Add(elementStreet);
        elementStreet.Name           = "street";
        elementStreet.SchemaTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema");

        // <xs:element name="city"   type="xs:string"/>
        XmlSchemaElement elementCity = new XmlSchemaElement();

        sequence.Items.Add(elementCity);
        elementCity.Name           = "city";
        elementCity.SchemaTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema");

        // <xs:complexType name="USAddress">
        XmlSchemaComplexType USAddress = new XmlSchemaComplexType();

        schema.Items.Add(USAddress);
        USAddress.Name = "USAddress";

        // <xs:complexContent>
        XmlSchemaComplexContent complexContent = new XmlSchemaComplexContent();

        USAddress.ContentModel = complexContent;

        // <xs:extension base="address">
        XmlSchemaComplexContentExtension extensionAddress = new XmlSchemaComplexContentExtension();

        complexContent.Content        = extensionAddress;
        extensionAddress.BaseTypeName = new XmlQualifiedName("address");

        // <xs:sequence>
        XmlSchemaSequence sequence2 = new XmlSchemaSequence();

        extensionAddress.Particle = sequence2;

        // <xs:element name="state" type="xs:string"/>
        XmlSchemaElement elementUSState = new XmlSchemaElement();

        sequence2.Items.Add(elementUSState);
        elementUSState.Name           = "state";
        elementUSState.SchemaTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema");


        // <xs:element name="zipcode" type="xs:positiveInteger"/>
        XmlSchemaElement elementZipcode = new XmlSchemaElement();

        sequence2.Items.Add(elementZipcode);
        elementZipcode.Name           = "zipcode";
        elementZipcode.SchemaTypeName = new XmlQualifiedName("positiveInteger", "http://www.w3.org/2001/XMLSchema");

        XmlSchemaSet schemaSet = new XmlSchemaSet();

        schemaSet.ValidationEventHandler += new ValidationEventHandler(ValidationCallbackOne);
        schemaSet.Add(schema);
        schemaSet.Compile();

        XmlSchema compiledSchema = null;

        foreach (XmlSchema schema1 in schemaSet.Schemas())
        {
            compiledSchema = schema1;
        }

        XmlNamespaceManager nsmgr = new XmlNamespaceManager(new NameTable());

        nsmgr.AddNamespace("xs", "http://www.w3.org/2001/XMLSchema");
        compiledSchema.Write(Console.Out, nsmgr);
    }
Example #23
0
        private void ExportClassDataContract(ClassDataContract classDataContract, XmlSchema schema)
        {
            XmlSchemaComplexType type = new XmlSchemaComplexType();

            type.Name = classDataContract.StableName.Name;
            schema.Items.Add(type);
            XmlElement genericInfoElement = null;

            if (classDataContract.UnderlyingType.IsGenericType)
            {
                genericInfoElement = ExportGenericInfo(classDataContract.UnderlyingType, Globals.GenericTypeLocalName, Globals.SerializationNamespace);
            }

            XmlSchemaSequence rootSequence = new XmlSchemaSequence();

            for (int i = 0; i < classDataContract.Members.Count; i++)
            {
                DataMember dataMember = classDataContract.Members[i];

                XmlSchemaElement element = new XmlSchemaElement();
                element.Name = dataMember.Name;
                XmlElement   actualTypeElement  = null;
                DataContract memberTypeContract = _dataContractSet.GetMemberTypeDataContract(dataMember);
                if (CheckIfMemberHasConflict(dataMember))
                {
                    element.SchemaTypeName = AnytypeQualifiedName;
                    actualTypeElement      = ExportActualType(memberTypeContract.StableName);
                    SchemaHelper.AddSchemaImport(memberTypeContract.StableName.Namespace, schema);
                }
                else
                {
                    SetElementType(element, memberTypeContract, schema);
                }
                SchemaHelper.AddElementForm(element, schema);
                if (dataMember.IsNullable)
                {
                    element.IsNillable = true;
                }
                if (!dataMember.IsRequired)
                {
                    element.MinOccurs = 0;
                }

                element.Annotation = GetSchemaAnnotation(actualTypeElement, ExportSurrogateData(dataMember), ExportEmitDefaultValue(dataMember));
                rootSequence.Items.Add(element);
            }

            XmlElement isValueTypeElement = null;

            if (classDataContract.BaseContract != null)
            {
                XmlSchemaComplexContentExtension extension = CreateTypeContent(type, classDataContract.BaseContract.StableName, schema);
                extension.Particle = rootSequence;
                if (classDataContract.IsReference && !classDataContract.BaseContract.IsReference)
                {
                    AddReferenceAttributes(extension.Attributes, schema);
                }
            }
            else
            {
                type.Particle = rootSequence;
                if (classDataContract.IsValueType)
                {
                    isValueTypeElement = GetAnnotationMarkup(IsValueTypeName, XmlConvert.ToString(classDataContract.IsValueType), schema);
                }
                if (classDataContract.IsReference)
                {
                    AddReferenceAttributes(type.Attributes, schema);
                }
            }
            type.Annotation = GetSchemaAnnotation(genericInfoElement, ExportSurrogateData(classDataContract), isValueTypeElement);
        }
Example #24
0
        void ExportClassSchema(XmlTypeMapping map)
        {
            if (IsMapExported(map))
            {
                return;
            }
            SetMapExported(map);

            if (map.TypeData.Type == typeof(object))
            {
                foreach (XmlTypeMapping dmap in map.DerivedTypes)
                {
                    if (dmap.TypeData.SchemaType == SchemaTypes.Class)
                    {
                        ExportClassSchema(dmap);
                    }
                }
                return;
            }

            XmlSchema            schema = GetSchema(map.XmlTypeNamespace);
            XmlSchemaComplexType stype  = new XmlSchemaComplexType();

            stype.Name = map.XmlType;
            schema.Items.Add(stype);

            ClassMap cmap = (ClassMap)map.ObjectMap;

            if (cmap.HasSimpleContent)
            {
                XmlSchemaSimpleContent simple = new XmlSchemaSimpleContent();
                stype.ContentModel = simple;
                XmlSchemaSimpleContentExtension ext = new XmlSchemaSimpleContentExtension();
                simple.Content = ext;
                XmlSchemaSequence     particle;
                XmlSchemaAnyAttribute anyAttribute;
                ExportMembersMapSchema(schema, cmap, map.BaseMap, ext.Attributes, out particle, out anyAttribute);
                ext.AnyAttribute = anyAttribute;
                if (map.BaseMap == null)
                {
                    ext.BaseTypeName = cmap.SimpleContentBaseType;
                }
                else
                {
                    ext.BaseTypeName = new XmlQualifiedName(map.BaseMap.XmlType, map.BaseMap.XmlTypeNamespace);
                    ImportNamespace(schema, map.BaseMap.XmlTypeNamespace);
                    ExportClassSchema(map.BaseMap);
                }
            }
            else if (map.BaseMap != null && map.BaseMap.IncludeInSchema)
            {
                XmlSchemaComplexContent          cstype = new XmlSchemaComplexContent();
                XmlSchemaComplexContentExtension ext    = new XmlSchemaComplexContentExtension();
                ext.BaseTypeName   = new XmlQualifiedName(map.BaseMap.XmlType, map.BaseMap.XmlTypeNamespace);
                cstype.Content     = ext;
                stype.ContentModel = cstype;

                XmlSchemaSequence     particle;
                XmlSchemaAnyAttribute anyAttribute;
                ExportMembersMapSchema(schema, cmap, map.BaseMap, ext.Attributes, out particle, out anyAttribute);
                ext.Particle     = particle;
                ext.AnyAttribute = anyAttribute;
                stype.IsMixed    = HasMixedContent(map);
                cstype.IsMixed   = BaseHasMixedContent(map);

                ImportNamespace(schema, map.BaseMap.XmlTypeNamespace);
                ExportClassSchema(map.BaseMap);
            }
            else
            {
                XmlSchemaSequence     particle;
                XmlSchemaAnyAttribute anyAttribute;
                ExportMembersMapSchema(schema, cmap, map.BaseMap, stype.Attributes, out particle, out anyAttribute);
                stype.Particle     = particle;
                stype.AnyAttribute = anyAttribute;
                stype.IsMixed      = cmap.XmlTextCollector != null;
            }

            foreach (XmlTypeMapping dmap in map.DerivedTypes)
            {
                if (dmap.TypeData.SchemaType == SchemaTypes.Class)
                {
                    ExportClassSchema(dmap);
                }
            }
        }
Example #25
0
        public bool ContainsColumn(XmlSchemaComplexType xmlSchemaComplexType, XmlSchemaObject columnObject)
        {
            XmlQualifiedName columnName = columnObject is XmlSchemaAttribute ?
                                          (columnObject as XmlSchemaAttribute).QualifiedName : columnObject is XmlSchemaElement ?
                                          (columnObject as XmlSchemaElement).QualifiedName : XmlQualifiedName.Empty;

            // Columns can be specified as attributes.
            foreach (XmlSchemaAttribute xmlSchemaAttribute in xmlSchemaComplexType.Attributes)
            {
                if (xmlSchemaAttribute.QualifiedName == columnName)
                {
                    return(true);
                }
            }

            // Comlex content extends a base class.  The ComplexContent is mutually exclusive of the Particle, so if the
            // particle is empty, the ComplexContent is present and should be parsed for columns.
            if (xmlSchemaComplexType.Particle == null)
            {
                // The Comlex Content describes an extension of a base class.
                if (xmlSchemaComplexType.ContentModel is XmlSchemaComplexContent)
                {
                    // Strongly type the XmlSchemaContent.
                    XmlSchemaComplexContent xmlSchemaComplexContent = xmlSchemaComplexType.ContentModel as XmlSchemaComplexContent;

                    // A complex content can be derived by extension (adding columns) or restriction (removing columns).  This
                    // section will look for the extensions to the base class.
                    if (xmlSchemaComplexContent.Content is XmlSchemaComplexContentExtension)
                    {
                        // The Complex Content Extension describes a base class and the additional columns that make up a
                        // derived class.  This section will recursively collect the columns from the base class and then parse
                        // out the extra columns in-line.
                        XmlSchemaComplexContentExtension xmlSchemaComplexContentExtension =
                            xmlSchemaComplexContent.Content as XmlSchemaComplexContentExtension;

                        // The additional columns for this inherited table are found on the <Sequence> node that follows the
                        // <Extension> node.
                        if (xmlSchemaComplexContentExtension.Particle is XmlSchemaSequence)
                        {
                            // Strongly type the XmlSchemaSequence
                            XmlSchemaSequence xmlSchemaSequence = xmlSchemaComplexContentExtension.Particle as XmlSchemaSequence;

                            // Read through the sequence and replace any column from an inherited class with the column in the
                            // derived class.  Also note that the columns are added in alphabetical order to give some amount of
                            // predictability to the way the parameter lists are constructed when there are several layers of
                            // inheritance.
                            foreach (XmlSchemaObject xmlSchemaObject in xmlSchemaSequence.Items)
                            {
                                if ((xmlSchemaObject as XmlSchemaElement).QualifiedName == columnName)
                                {
                                    return(true);
                                }
                            }
                        }

                        // The Complex Content can also contain attributes that describe columns.
                        foreach (XmlSchemaAttribute xmlSchemaAttribute in xmlSchemaComplexContentExtension.Attributes)
                        {
                            if (xmlSchemaAttribute.QualifiedName == columnName)
                            {
                                return(true);
                            }
                        }
                    }
                }
            }
            else
            {
                // This section will parse the simple particle.  The particle has no inheritiance to evaluate.
                if (xmlSchemaComplexType.Particle is XmlSchemaSequence)
                {
                    // Strongly type the XmlSchemaSequence member.
                    XmlSchemaSequence xmlSchemaSequence = xmlSchemaComplexType.Particle as XmlSchemaSequence;

                    // Each XmlSchemaElement on the Particle describes a column.
                    foreach (XmlSchemaObject xmlSchemaObject in xmlSchemaSequence.Items)
                    {
                        if ((xmlSchemaObject as XmlSchemaElement).QualifiedName == columnName)
                        {
                            return(true);
                        }
                    }
                }

                // The ComplexType can also have attributes that describe table columns.
                foreach (XmlSchemaAttribute xmlSchemaAttribute in xmlSchemaComplexType.Attributes)
                {
                    if (xmlSchemaAttribute.QualifiedName == columnName)
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Example #26
0
        static void Check(ConformanceCheckContext ctx, ConformanceChecker checker, Hashtable visitedObjects, XmlSchemaObject value)
        {
            if (value == null)
            {
                return;
            }

            if (visitedObjects.Contains(value))
            {
                return;
            }
            visitedObjects.Add(value, value);

            if (value is XmlSchemaImport)
            {
                XmlSchemaImport so = (XmlSchemaImport)value;
                checker.Check(ctx, so);
            }
            else if (value is XmlSchemaAll)
            {
                XmlSchemaAll so = (XmlSchemaAll)value;
                checker.Check(ctx, so);
                CheckObjects(ctx, checker, visitedObjects, so.Items);
            }
            else if (value is XmlSchemaAnnotation)
            {
                XmlSchemaAnnotation so = (XmlSchemaAnnotation)value;
                checker.Check(ctx, so);
                CheckObjects(ctx, checker, visitedObjects, so.Items);
            }
            else if (value is XmlSchemaAttribute)
            {
                XmlSchemaAttribute so = (XmlSchemaAttribute)value;
                checker.Check(ctx, so);
            }
            else if (value is XmlSchemaAttributeGroup)
            {
                XmlSchemaAttributeGroup so = (XmlSchemaAttributeGroup)value;
                checker.Check(ctx, so);
                CheckObjects(ctx, checker, visitedObjects, so.Attributes);
                Check(ctx, checker, visitedObjects, so.AnyAttribute);
                Check(ctx, checker, visitedObjects, so.RedefinedAttributeGroup);
            }
            else if (value is XmlSchemaAttributeGroupRef)
            {
                XmlSchemaAttributeGroupRef so = (XmlSchemaAttributeGroupRef)value;
                checker.Check(ctx, so);
            }
            else if (value is XmlSchemaChoice)
            {
                XmlSchemaChoice so = (XmlSchemaChoice)value;
                checker.Check(ctx, so);
                CheckObjects(ctx, checker, visitedObjects, so.Items);
            }
            else if (value is XmlSchemaComplexContent)
            {
                XmlSchemaComplexContent so = (XmlSchemaComplexContent)value;
                checker.Check(ctx, so);
                Check(ctx, checker, visitedObjects, so.Content);
            }
            else if (value is XmlSchemaComplexContentExtension)
            {
                XmlSchemaComplexContentExtension so = (XmlSchemaComplexContentExtension)value;
                checker.Check(ctx, so);
                Check(ctx, checker, visitedObjects, so.Particle);
                CheckObjects(ctx, checker, visitedObjects, so.Attributes);
                Check(ctx, checker, visitedObjects, so.AnyAttribute);
            }
            else if (value is XmlSchemaComplexContentRestriction)
            {
                XmlSchemaComplexContentRestriction so = (XmlSchemaComplexContentRestriction)value;
                checker.Check(ctx, so);
                Check(ctx, checker, visitedObjects, so.Particle);
                CheckObjects(ctx, checker, visitedObjects, so.Attributes);
                Check(ctx, checker, visitedObjects, so.AnyAttribute);
            }
            else if (value is XmlSchemaComplexType)
            {
                XmlSchemaComplexType so = (XmlSchemaComplexType)value;
                checker.Check(ctx, so);
                Check(ctx, checker, visitedObjects, so.ContentModel);
                Check(ctx, checker, visitedObjects, so.Particle);
                CheckObjects(ctx, checker, visitedObjects, so.Attributes);
                Check(ctx, checker, visitedObjects, so.AnyAttribute);
                Check(ctx, checker, visitedObjects, so.ContentTypeParticle);
                Check(ctx, checker, visitedObjects, so.AttributeWildcard);
            }
            else if (value is XmlSchemaElement)
            {
                XmlSchemaElement so = (XmlSchemaElement)value;
                checker.Check(ctx, so);
                Check(ctx, checker, visitedObjects, so.SchemaType);
                CheckObjects(ctx, checker, visitedObjects, so.Constraints);
            }
            else if (value is XmlSchemaGroup)
            {
                XmlSchemaGroup so = (XmlSchemaGroup)value;
                checker.Check(ctx, so);
                Check(ctx, checker, visitedObjects, so.Particle);
            }
            else if (value is XmlSchemaGroupRef)
            {
                XmlSchemaGroupRef so = (XmlSchemaGroupRef)value;
                checker.Check(ctx, so);
            }
            else if (value is XmlSchemaIdentityConstraint)
            {
                XmlSchemaIdentityConstraint so = (XmlSchemaIdentityConstraint)value;
                checker.Check(ctx, so);
                CheckObjects(ctx, checker, visitedObjects, so.Fields);
                Check(ctx, checker, visitedObjects, so.Selector);
            }
            else if (value is XmlSchemaKeyref)
            {
                XmlSchemaKeyref so = (XmlSchemaKeyref)value;
                checker.Check(ctx, so);
            }
            else if (value is XmlSchemaRedefine)
            {
                XmlSchemaRedefine so = (XmlSchemaRedefine)value;
                checker.Check(ctx, so);
                CheckObjects(ctx, checker, visitedObjects, so.Items);
            }
            else if (value is XmlSchemaSequence)
            {
                XmlSchemaSequence so = (XmlSchemaSequence)value;
                checker.Check(ctx, so);
                CheckObjects(ctx, checker, visitedObjects, so.Items);
            }
            else if (value is XmlSchemaSimpleContent)
            {
                XmlSchemaSimpleContent so = (XmlSchemaSimpleContent)value;
                checker.Check(ctx, so);
                Check(ctx, checker, visitedObjects, so.Content);
            }
            else if (value is XmlSchemaSimpleContentExtension)
            {
                XmlSchemaSimpleContentExtension so = (XmlSchemaSimpleContentExtension)value;
                checker.Check(ctx, so);
                CheckObjects(ctx, checker, visitedObjects, so.Attributes);
                Check(ctx, checker, visitedObjects, so.AnyAttribute);
            }
            else if (value is XmlSchemaSimpleContentRestriction)
            {
                XmlSchemaSimpleContentRestriction so = (XmlSchemaSimpleContentRestriction)value;
                checker.Check(ctx, so);
                CheckObjects(ctx, checker, visitedObjects, so.Attributes);
                Check(ctx, checker, visitedObjects, so.AnyAttribute);
                CheckObjects(ctx, checker, visitedObjects, so.Facets);
            }
            else if (value is XmlSchemaSimpleType)
            {
                XmlSchemaSimpleType so = (XmlSchemaSimpleType)value;
                checker.Check(ctx, so);
                Check(ctx, checker, visitedObjects, so.Content);
            }
            else if (value is XmlSchemaSimpleTypeList)
            {
                XmlSchemaSimpleTypeList so = (XmlSchemaSimpleTypeList)value;
                checker.Check(ctx, so);
            }
            else if (value is XmlSchemaSimpleTypeRestriction)
            {
                XmlSchemaSimpleTypeRestriction so = (XmlSchemaSimpleTypeRestriction)value;
                checker.Check(ctx, so);
                CheckObjects(ctx, checker, visitedObjects, so.Facets);
            }
            else if (value is XmlSchemaSimpleTypeUnion)
            {
                XmlSchemaSimpleTypeUnion so = (XmlSchemaSimpleTypeUnion)value;
                checker.Check(ctx, so);
            }
        }
Example #27
0
        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);
                        }
                    }
                }
            }
        }
Example #28
0
        /// <summary>
        /// Creates the an xml schema for a complex type. This method automatically takes care of
        /// any base classes that must be added.
        /// <para />
        /// This method already adds the <see cref="XmlSchemaComplexType" /> to the <see cref="XmlSchemaSet" />.
        /// </summary>
        /// <param name="type">The type to create the complex schema for.</param>
        /// <param name="schema">The schema.</param>
        /// <param name="schemaSet">The schema set.</param>
        /// <param name="serializationManager">The serialization manager.</param>
        /// <param name="generateFlatSchema">A value indicating whether the schema should be generated as flat schema.</param>
        /// <param name="exportedTypes">The exported types.</param>
        /// <returns>The complex schema for the specified type.</returns>
        private static XmlSchemaComplexType CreateSchemaComplexType(Type type, XmlSchema schema, XmlSchemaSet schemaSet, ISerializationManager serializationManager, bool generateFlatSchema, HashSet <string> exportedTypes)
        {
            // Determine name, which is complex in generic types
            string typeName = GetTypeNameForSchema(type);

            // First, add the type, otherwise we might get into a stackoverflow when using generic base types
            // <xs:complexType>
            var modelBaseType = new XmlSchemaComplexType();

            modelBaseType.Name    = typeName;
            modelBaseType.IsMixed = false;

            schema.Items.Add(modelBaseType);

            var propertiesSequence = GetPropertiesSequence(type, schema, schemaSet, serializationManager, exportedTypes);

            // If flat, don't generate base classes, just the type itself
            if (generateFlatSchema)
            {
                modelBaseType.Particle = propertiesSequence;
                return(modelBaseType);
            }

            if (type.IsGenericType)
            {
                var genericComplexType = new XmlSchemaComplexType();
                genericComplexType.Name = typeName;

                // <xs:annotation>
                var annotation = new XmlSchemaAnnotation();

                // <xs:appinfo>
                var appInfo = new XmlSchemaAppInfo();

                //<GenericType xmlns="http://schemas.microsoft.com/2003/10/Serialization/" Name="DataContractBaseOf{0}{#}" Namespace="http://schemas.datacontract.org/2004/07/STC">
                //  <GenericParameter Name="ProfileDateRange2" Namespace="http://schemas.datacontract.org/2004/07/STC.Meter.ProfileData"/>
                //</GenericType>
                var genericTypeElement = new XElement("GenericType");
                genericTypeElement.Add(new XAttribute("Name", string.Format("{0}Of{{0}}{{#}}", typeName)));
                genericTypeElement.Add(new XAttribute("Namespace", GetTypeNamespaceForSchema(type)));

                foreach (var genericArgument in type.GetGenericArgumentsEx())
                {
                    var genericArgumentQualifiedName = AddTypeToSchemaSet(genericArgument, schemaSet, serializationManager, exportedTypes);
                    var genericArgumentElement       = new XElement("GenericParameter");
                    genericArgumentElement.Add(new XAttribute("Name", genericArgumentQualifiedName.Name));
                    genericArgumentElement.Add(new XAttribute("Namespace", genericArgumentQualifiedName.Namespace));
                    genericTypeElement.Add(genericArgumentElement);
                }

                var conversionDoc = new XmlDocument();
                appInfo.Markup = new XmlNode[] { conversionDoc.CreateTextNode(genericTypeElement.ToString()) };

                annotation.Items.Add(appInfo);
            }

            var baseTypeQualifiedName = AddTypeToSchemaSet(type.BaseType, schemaSet, serializationManager, exportedTypes);

            if (baseTypeQualifiedName != null)
            {
                // <xs:extensions base="address">
                var complexContentExtension = new XmlSchemaComplexContentExtension();
                complexContentExtension.BaseTypeName = baseTypeQualifiedName;
                complexContentExtension.Particle     = propertiesSequence;

                // <xs:complexContent>
                var complexContent = new XmlSchemaComplexContent();
                complexContent.Content = complexContentExtension;

                modelBaseType.ContentModel = complexContent;
            }
            else
            {
                modelBaseType.Particle = propertiesSequence;
            }

            return(modelBaseType);
        }
 XmlSchemaAttribute FindAttribute(XmlSchemaComplexContentExtension extension, string name)
 {
     return(FindAttribute(extension.Attributes, name));
 }
Example #30
0
        public XmlSchemaComplexType FindBaseType(XmlSchemaObject baseObject)
        {
            if (baseObject is XmlSchemaComplexContentExtension)
            {
                XmlSchemaComplexContentExtension baseComplexContentExtension = baseObject as XmlSchemaComplexContentExtension;
                return(FindComplexType(baseComplexContentExtension));
            }

            if (baseObject is XmlSchemaComplexType)
            {
                XmlSchemaComplexType baseComplexType = baseObject as XmlSchemaComplexType;
                if (baseComplexType.Parent is XmlSchemaElement)
                {
                    XmlSchemaElement baseElement = baseComplexType.Parent as XmlSchemaElement;

                    XmlSchemaIdentityConstraint primaryKey = FindPrimaryKey(baseElement);
                    if (primaryKey == null)
                    {
                        return(null);
                    }

                    foreach (XmlSchemaObject xmlSchemaObject in RootSchema.Items)
                    {
                        if (xmlSchemaObject is XmlSchemaElement)
                        {
                            if (IsDataSetElement(xmlSchemaObject))
                            {
                                XmlSchemaElement dataSetElement = xmlSchemaObject as XmlSchemaElement;

                                foreach (XmlSchemaIdentityConstraint xmlSchemaIdentityConstraint in dataSetElement.Constraints)
                                {
                                    if (xmlSchemaIdentityConstraint is XmlSchemaKeyref)
                                    {
                                        XmlSchemaKeyref xmlSchemaKeyref = xmlSchemaIdentityConstraint as XmlSchemaKeyref;
                                        if (this.FindSelector(xmlSchemaKeyref) == baseElement)
                                        {
                                            bool isMatch = xmlSchemaKeyref.Fields.Count == primaryKey.Fields.Count;
                                            for (int index = 0; index < xmlSchemaKeyref.Fields.Count; index++)
                                            {
                                                XmlSchemaXPath xPath1 = (XmlSchemaXPath)xmlSchemaKeyref.Fields[index];
                                                XmlSchemaXPath xPath2 = (XmlSchemaXPath)primaryKey.Fields[index];
                                                if (xPath1.XPath != xPath2.XPath)
                                                {
                                                    isMatch = false;
                                                    break;
                                                }
                                            }

                                            if (isMatch)
                                            {
                                                XmlSchemaIdentityConstraint xmlSchemaKey     = FindKey(xmlSchemaKeyref);
                                                XmlSchemaElement            xmlSchemaElement = FindSelector(xmlSchemaKey);
                                                return(xmlSchemaElement.SchemaType as XmlSchemaComplexType);
                                            }
                                        }
                                    }
                                }
                            }
                            else
                            {
                                XmlSchemaElement tableElement = xmlSchemaObject as XmlSchemaElement;

                                foreach (XmlSchemaIdentityConstraint xmlSchemaIdentityConstraint in tableElement.Constraints)
                                {
                                }
                            }
                        }
                    }

                    return(null);
                }
            }

            return(null);
        }