private static void ExtractSoapParameters(WfServiceOperationParameterCollection rst, ServiceDescription desc, Message msg)
 {
     if (msg.Parts["parameters"] != null)
     {
         var ppsElemName = msg.Parts["parameters"].Element;
         var schema      = desc.Types.Schemas[ppsElemName.Namespace];
         System.Xml.Schema.XmlSchemaElement     innerTypes = (System.Xml.Schema.XmlSchemaElement)schema.Elements[ppsElemName];
         System.Xml.Schema.XmlSchemaComplexType xType      = innerTypes.SchemaType as System.Xml.Schema.XmlSchemaComplexType;
         if (xType != null)
         {
             System.Xml.Schema.XmlSchemaSequence xSeq = xType.Particle as System.Xml.Schema.XmlSchemaSequence;
             if (xSeq != null)
             {
                 foreach (var xItem in xSeq.Items)
                 {
                     if (xItem is System.Xml.Schema.XmlSchemaElement)
                     {
                         System.Xml.Schema.XmlSchemaElement xElem = xItem as System.Xml.Schema.XmlSchemaElement;
                         rst.Add(new WfServiceOperationParameter()
                         {
                             Name = xElem.Name, Type = SolveType(xElem.SchemaTypeName)
                         });
                     }
                 }
             }
         }
     }
 }
示例#2
0
        public static System.Xml.Schema.XmlSchemaComplexType GetTypedDataSetSchema(System.Xml.Schema.XmlSchemaSet xs)
        {
            OneTableDataSet ds = new OneTableDataSet();

            System.Xml.Schema.XmlSchemaComplexType type     = new System.Xml.Schema.XmlSchemaComplexType();
            System.Xml.Schema.XmlSchemaSequence    sequence = new System.Xml.Schema.XmlSchemaSequence();
            xs.Add(ds.GetSchemaSerializable());
            if (PublishLegacyWSDL())
            {
                System.Xml.Schema.XmlSchemaAny any = new System.Xml.Schema.XmlSchemaAny();
                any.Namespace = ds.Namespace;
                sequence.Items.Add(any);
            }
            else
            {
                System.Xml.Schema.XmlSchemaAny any1 = new System.Xml.Schema.XmlSchemaAny();
                any1.Namespace       = "http://www.w3.org/2001/XMLSchema";
                any1.MinOccurs       = new decimal(0);
                any1.ProcessContents = System.Xml.Schema.XmlSchemaContentProcessing.Lax;
                sequence.Items.Add(any1);
                System.Xml.Schema.XmlSchemaAny any2 = new System.Xml.Schema.XmlSchemaAny();
                any2.Namespace       = "urn:schemas-microsoft-com:xml-diffgram-v1";
                any2.MinOccurs       = new decimal(0);
                any2.ProcessContents = System.Xml.Schema.XmlSchemaContentProcessing.Lax;
                sequence.Items.Add(any2);
                sequence.MaxOccurs = decimal.MaxValue;
                System.Xml.Schema.XmlSchemaAttribute attribute = new System.Xml.Schema.XmlSchemaAttribute();
                attribute.Name       = "namespace";
                attribute.FixedValue = ds.Namespace;
                type.Attributes.Add(attribute);
            }
            type.Particle = sequence;
            return(type);
        }
        /// <summary>
        /// Load this schema sequence from the XmlSchemaSequence object
        /// </summary>
        /// <param name="s">The sequence object to load</param>
        public void Load(System.Xml.Schema.XmlSchemaSequence s)
        {
            if (s == null)
            {
                return;
            }

            // Iterate through all
            foreach (System.Xml.Schema.XmlSchemaObject o in s.Items)
            {
                if (o is System.Xml.Schema.XmlSchemaElement)
                {
                    RegisterElement(o as System.Xml.Schema.XmlSchemaElement);
                }
                else if (o is System.Xml.Schema.XmlSchemaChoice)
                {
                    RegisterChoice(o as System.Xml.Schema.XmlSchemaChoice);
                }
                else if (o is System.Xml.Schema.XmlSchemaSequence)
                {
                    RegisterSequence(o as System.Xml.Schema.XmlSchemaSequence);
                }
                else if (o is System.Xml.Schema.XmlSchemaGroupRef)
                {
                    Load((o as System.Xml.Schema.XmlSchemaGroupRef).Particle as System.Xml.Schema.XmlSchemaSequence);
                }
                else if (o is System.Xml.Schema.XmlSchemaAny)
                {
                    RegisterAny(o as System.Xml.Schema.XmlSchemaAny);
                }
            }
        }
示例#4
0
            public static System.Xml.Schema.XmlSchemaComplexType GetTypedTableSchema(System.Xml.Schema.XmlSchemaSet xs)
            {
                System.Xml.Schema.XmlSchemaComplexType type     = new System.Xml.Schema.XmlSchemaComplexType();
                System.Xml.Schema.XmlSchemaSequence    sequence = new System.Xml.Schema.XmlSchemaSequence();
                Dataset1 ds = new Dataset1();

                xs.Add(ds.GetSchemaSerializable());
                System.Xml.Schema.XmlSchemaAny any1 = new System.Xml.Schema.XmlSchemaAny();
                any1.Namespace       = "http://www.w3.org/2001/XMLSchema";
                any1.MinOccurs       = new decimal(0);
                any1.MaxOccurs       = decimal.MaxValue;
                any1.ProcessContents = System.Xml.Schema.XmlSchemaContentProcessing.Lax;
                sequence.Items.Add(any1);
                System.Xml.Schema.XmlSchemaAny any2 = new System.Xml.Schema.XmlSchemaAny();
                any2.Namespace       = "urn:schemas-microsoft-com:xml-diffgram-v1";
                any2.MinOccurs       = new decimal(1);
                any2.ProcessContents = System.Xml.Schema.XmlSchemaContentProcessing.Lax;
                sequence.Items.Add(any2);
                System.Xml.Schema.XmlSchemaAttribute attribute1 = new System.Xml.Schema.XmlSchemaAttribute();
                attribute1.Name       = "namespace";
                attribute1.FixedValue = ds.Namespace;
                type.Attributes.Add(attribute1);
                System.Xml.Schema.XmlSchemaAttribute attribute2 = new System.Xml.Schema.XmlSchemaAttribute();
                attribute2.Name       = "tableTypeName";
                attribute2.FixedValue = "CustomersDataTable";
                type.Attributes.Add(attribute2);
                type.Particle = sequence;
                return(type);
            }
 public static System.Xml.Schema.XmlSchemaComplexType GetTypedDataSetSchema(System.Xml.Schema.XmlSchemaSet xs) {
     DataSet1 ds = new DataSet1();
     System.Xml.Schema.XmlSchemaComplexType type = new System.Xml.Schema.XmlSchemaComplexType();
     System.Xml.Schema.XmlSchemaSequence sequence = new System.Xml.Schema.XmlSchemaSequence();
     xs.Add(ds.GetSchemaSerializable());
     System.Xml.Schema.XmlSchemaAny any = new System.Xml.Schema.XmlSchemaAny();
     any.Namespace = ds.Namespace;
     sequence.Items.Add(any);
     type.Particle = sequence;
     return type;
 }
        /// <summary>
        /// Register a sequence
        /// </summary>
        /// <param name="e">The sequence to register</param>
        protected void RegisterSequence(System.Xml.Schema.XmlSchemaSequence e)
        {
            if (content == null)
            {
                content = new List <XmlSchemaObject>();
            }

            XmlSchemaSequence seq = new XmlSchemaSequence(Schema, this);

            seq.Load(e);
            content.Add(seq);
        }
        public static System.Xml.Schema.XmlSchemaComplexType GetTypedDataSetSchema(System.Xml.Schema.XmlSchemaSet xs)
        {
            RendererProviderConfig ds = new RendererProviderConfig();

            System.Xml.Schema.XmlSchemaComplexType type     = new System.Xml.Schema.XmlSchemaComplexType();
            System.Xml.Schema.XmlSchemaSequence    sequence = new System.Xml.Schema.XmlSchemaSequence();
            xs.Add(ds.GetSchemaSerializable());
            System.Xml.Schema.XmlSchemaAny any = new System.Xml.Schema.XmlSchemaAny();
            any.Namespace = ds.Namespace;
            sequence.Items.Add(any);
            type.Particle = sequence;
            return(type);
        }
示例#8
0
        public static System.Xml.Schema.XmlSchemaComplexType GetTypedDataSetSchema(System.Xml.Schema.XmlSchemaSet xs)
        {
            View_Main_ReportsDataSet ds = new View_Main_ReportsDataSet();

            System.Xml.Schema.XmlSchemaComplexType type     = new System.Xml.Schema.XmlSchemaComplexType();
            System.Xml.Schema.XmlSchemaSequence    sequence = new System.Xml.Schema.XmlSchemaSequence();
            xs.Add(ds.GetSchemaSerializable());
            System.Xml.Schema.XmlSchemaAny any = new System.Xml.Schema.XmlSchemaAny();
            any.Namespace = ds.Namespace;
            sequence.Items.Add(any);
            type.Particle = sequence;
            return(type);
        }
        public static System.Xml.Schema.XmlSchemaComplexType GetTypedDataSetSchema(System.Xml.Schema.XmlSchemaSet xs)
        {
            ProjectFlowStatusProgressDs ds = new ProjectFlowStatusProgressDs();

            System.Xml.Schema.XmlSchemaComplexType type     = new System.Xml.Schema.XmlSchemaComplexType();
            System.Xml.Schema.XmlSchemaSequence    sequence = new System.Xml.Schema.XmlSchemaSequence();
            xs.Add(ds.GetSchemaSerializable());
            System.Xml.Schema.XmlSchemaAny any = new System.Xml.Schema.XmlSchemaAny();
            any.Namespace = ds.Namespace;
            sequence.Items.Add(any);
            type.Particle = sequence;
            return(type);
        }
示例#10
0
        public static System.Xml.Schema.XmlSchemaComplexType GetTypedDataSetSchema(System.Xml.Schema.XmlSchemaSet xs)
        {
            CustomerAccountCCRMSchema ds = new CustomerAccountCCRMSchema();

            System.Xml.Schema.XmlSchemaComplexType type     = new System.Xml.Schema.XmlSchemaComplexType();
            System.Xml.Schema.XmlSchemaSequence    sequence = new System.Xml.Schema.XmlSchemaSequence();
            xs.Add(ds.GetSchemaSerializable());
            System.Xml.Schema.XmlSchemaAny any = new System.Xml.Schema.XmlSchemaAny();
            any.Namespace = ds.Namespace;
            sequence.Items.Add(any);
            type.Particle = sequence;
            return(type);
        }
        public static System.Xml.Schema.XmlSchemaComplexType GetTypedDataSetSchema(System.Xml.Schema.XmlSchemaSet xs)
        {
            F2010StateCodeSelectionData ds = new F2010StateCodeSelectionData();

            System.Xml.Schema.XmlSchemaComplexType type     = new System.Xml.Schema.XmlSchemaComplexType();
            System.Xml.Schema.XmlSchemaSequence    sequence = new System.Xml.Schema.XmlSchemaSequence();
            xs.Add(ds.GetSchemaSerializable());
            System.Xml.Schema.XmlSchemaAny any = new System.Xml.Schema.XmlSchemaAny();
            any.Namespace = ds.Namespace;
            sequence.Items.Add(any);
            type.Particle = sequence;
            return(type);
        }
        private string CreateProcessXmlFieldSchemaString(string name)
        {
            System.Xml.Schema.XmlSchema            xmlSchema   = new System.Xml.Schema.XmlSchema();
            System.Xml.Schema.XmlSchemaComplexType complexType = new System.Xml.Schema.XmlSchemaComplexType();
            System.Xml.Schema.XmlSchemaSequence    sequence    = new System.Xml.Schema.XmlSchemaSequence();
            complexType.Particle = sequence;
            System.Xml.Schema.XmlSchemaElement rootElement = new System.Xml.Schema.XmlSchemaElement();
            rootElement.SchemaType = complexType;
            rootElement.Name       = name;
            xmlSchema.Items.Add(rootElement);
            System.IO.StringWriter stream = new System.IO.StringWriter();
            xmlSchema.Write(stream);
            string outString = stream.ToString();

            stream.Close();
            stream.Dispose();
            return(outString);
        }
示例#13
0
        /// <summary>
        /// Register an XS:Sequence
        /// </summary>
        /// <param name="s">The XS:Sequence to register</param>
        protected void RegisterSequence(System.Xml.Schema.XmlSchemaSequence s)
        {
            XmlSchemaSequence seq = new XmlSchemaSequence(Schema, this);

            seq.Load(s);

            List <Object> gc = new List <object>();

            // Clean sequence
            foreach (XmlSchemaObject o in seq.Content)
            {
                XmlSchemaComplexType prnt = (XmlSchemaComplexType)this.BaseClass;
                while (prnt != null)
                {
                    prnt.Compile();

                    if (prnt.Content != null)
                    {
                        foreach (XmlSchemaObject ot in prnt.Content)
                        {
                            if (o.GetType() == ot.GetType() && o.Name == ot.Name && ot.Namespace == o.Namespace &&
                                (o as XmlSchemaComplexContent).MinOccurs == (ot as XmlSchemaComplexContent).MinOccurs &&
                                (o as XmlSchemaComplexContent).MaxOccurs == (ot as XmlSchemaComplexContent).MaxOccurs) // Found so we don't need it
                            {
                                gc.Add(o);
                            }
                            else if (o.GetType() == ot.GetType() && o.Name == ot.Name && ot.Namespace == o.Namespace && o.MifData == null) // Copy mif data as it may be useful (this is most likely a restriction)
                            {
                                o.MifData = ot.MifData;
                            }
                        }
                    }
                    prnt = (XmlSchemaComplexType)prnt.BaseClass;
                }
            }

            // Clean garbage
            foreach (Object o in gc)
            {
                seq.Content.Remove(o as XmlSchemaObject);
            }

            content = seq;
        }
示例#14
0
 public static System.Xml.Schema.XmlSchemaComplexType GetTypedTableSchema(System.Xml.Schema.XmlSchemaSet xs) {
     System.Xml.Schema.XmlSchemaComplexType type = new System.Xml.Schema.XmlSchemaComplexType();
     System.Xml.Schema.XmlSchemaSequence sequence = new System.Xml.Schema.XmlSchemaSequence();
     IBDataset ds = new IBDataset();
     xs.Add(ds.GetSchemaSerializable());
     System.Xml.Schema.XmlSchemaAny any1 = new System.Xml.Schema.XmlSchemaAny();
     any1.Namespace = "http://www.w3.org/2001/XMLSchema";
     any1.MinOccurs = new decimal(0);
     any1.MaxOccurs = decimal.MaxValue;
     any1.ProcessContents = System.Xml.Schema.XmlSchemaContentProcessing.Lax;
     sequence.Items.Add(any1);
     System.Xml.Schema.XmlSchemaAny any2 = new System.Xml.Schema.XmlSchemaAny();
     any2.Namespace = "urn:schemas-microsoft-com:xml-diffgram-v1";
     any2.MinOccurs = new decimal(1);
     any2.ProcessContents = System.Xml.Schema.XmlSchemaContentProcessing.Lax;
     sequence.Items.Add(any2);
     System.Xml.Schema.XmlSchemaAttribute attribute1 = new System.Xml.Schema.XmlSchemaAttribute();
     attribute1.Name = "namespace";
     attribute1.FixedValue = ds.Namespace;
     type.Attributes.Add(attribute1);
     System.Xml.Schema.XmlSchemaAttribute attribute2 = new System.Xml.Schema.XmlSchemaAttribute();
     attribute2.Name = "tableTypeName";
     attribute2.FixedValue = "SPR_TOVDataTable";
     type.Attributes.Add(attribute2);
     type.Particle = sequence;
     return type;
 }
示例#15
0
 public static System.Xml.Schema.XmlSchemaComplexType GetTypedDataSetSchema(System.Xml.Schema.XmlSchemaSet xs) {
     IBDataset ds = new IBDataset();
     System.Xml.Schema.XmlSchemaComplexType type = new System.Xml.Schema.XmlSchemaComplexType();
     System.Xml.Schema.XmlSchemaSequence sequence = new System.Xml.Schema.XmlSchemaSequence();
     xs.Add(ds.GetSchemaSerializable());
     System.Xml.Schema.XmlSchemaAny any = new System.Xml.Schema.XmlSchemaAny();
     any.Namespace = ds.Namespace;
     sequence.Items.Add(any);
     type.Particle = sequence;
     return type;
 }
示例#16
0
        /// <summary> Generate a Writer method for a XmlSchemaElement. </summary>
        public static void GenerateElementWriter(System.Xml.Schema.XmlSchemaElement schemaElt, string schemaEltName, Refly.CodeDom.MethodDeclaration method, System.Xml.Schema.XmlSchemaComplexType refSchemaType, System.Xml.Schema.XmlSchemaObjectCollection schemaItems)
        {
            bool schemaEltIsRoot = Utils.IsRoot(schemaEltName);

            method.Attributes = System.CodeDom.MemberAttributes.Public | System.CodeDom.MemberAttributes.Overloaded;
            method.Doc.Summary.AddText(" Write a " + schemaEltName + " XML Element from attributes in a " + (schemaEltIsRoot?"type":"member") + ". ");             // Create the <summary />
            method.Signature.Parameters.Add(typeof(System.Xml.XmlWriter), "writer");
            if (schemaEltIsRoot)
            {
                method.Signature.Parameters.Add(typeof(System.Type), "type");
            }
            else
            {
                method.Signature.Parameters.Add(typeof(System.Reflection.MemberInfo), "member");
                method.Signature.Parameters.Add(schemaEltName + "Attribute", "attribute");
                method.Signature.Parameters.Add("BaseAttribute", "parentAttribute");
                method.Signature.Parameters.Add(typeof(System.Type), "mappedClass");
            }

            // Beginning of the method's body
            if (schemaEltIsRoot)
            {
                method.Body.Add(Refly.CodeDom.Stm.Snippet(string.Format(
                                                              @"object[] attributes = {1}.GetCustomAttributes(typeof({0}Attribute), false);
			if(attributes.Length == 0)
				return;
			{0}Attribute attribute = attributes[0] as {0}Attribute;
", schemaEltName, schemaEltIsRoot ? "type" : "member"))); // Note : Root should never allow multiple !
            }
            method.Body.Add(Refly.CodeDom.Stm.Snippet(string.Format(
                                                          "writer.WriteStartElement( \"{0}\" );", schemaElt.Name)));


            System.Xml.Schema.XmlSchemaComplexType type = schemaElt.SchemaType as System.Xml.Schema.XmlSchemaComplexType;
            if (type == null && !schemaElt.SchemaTypeName.IsEmpty)            // eg:  <xs:element name="cache" type="cacheType" />
            {
                type = refSchemaType;
            }

            if (type != null)
            {
                // Add the attributes
                System.Collections.ArrayList attributes = Utils.GetAttributes(type.Attributes);
                log.Debug("Add Attributes: Count=" + attributes.Count);
                foreach (System.Xml.Schema.XmlSchemaAttribute attrib in attributes)
                {
                    string attribName       = attrib.Name + attrib.RefName.Name;               // One is empty
                    string methodAttribName = "attribute." + Utils.Capitalize(attribName);
                    method.Body.Add(Refly.CodeDom.Stm.Comment("Attribute: <" + attribName + ">"));

                    // If the attribute is not explicitly marked required, then we consider it optionnal
                    if (attrib.Use != System.Xml.Schema.XmlSchemaUse.Required)
                    {
                        if ("System.Boolean" == Utils.GetAttributeTypeName(schemaElt, attrib))
                        {
                            method.Body.Add(Refly.CodeDom.Stm.Snippet(
                                                string.Format(@"if( {0} )", methodAttribName + "Specified")));
                        }
                        else
                        {
                            method.Body.Add(Refly.CodeDom.Stm.Snippet(
                                                string.Format(@"if({0} != {1})", methodAttribName,
                                                              Utils.GetUnspecifiedValue(schemaElt, attrib))));
                        }
                    }
                    // Write the value
                    if (attrib.Use == System.Xml.Schema.XmlSchemaUse.Required)
                    {
                        // Here, we use a helper if the field is not specified (mainly used for "name" which is the name of the member)
                        log.Debug("  Create Helper for " + (schemaEltIsRoot ? "ClassType" : "MemberInfo") + " <" + schemaElt.Name + "> <" + attribName + ">");
                        string helper = string.Format(@"{0}=={1} ? DefaultHelper.Get_{2}_{3}_DefaultValue({4}) : ",                          // "typed" method name :)
                                                      methodAttribName, Utils.GetUnspecifiedValue(schemaElt, attrib), schemaEltName,
                                                      Utils.Capitalize(attribName),
                                                      schemaEltIsRoot ? "type" : "member");
                        method.Body.Add(Refly.CodeDom.Stm.Snippet(
                                            string.Format(@"writer.WriteAttributeString(""{0}"", {2}{1});",
                                                          attribName, AttributeToXmlValue(schemaElt, attrib, attribName, schemaEltIsRoot), helper)));
                    }
                    else
                    {
                        method.Body.Add(Refly.CodeDom.Stm.Snippet(
                                            string.Format(@"writer.WriteAttributeString(""{0}"", {1});",
                                                          attribName, AttributeToXmlValue(schemaElt, attrib, attribName, schemaEltIsRoot))));
                        if (schemaEltName == "Property" && attribName == "type")
                        {
                            // Special case to handle Patterns for <property ... type="..." />
                            // Eg: set Nullables.NHibernate.NullableXXXType for Nullables.NullableXXX
                            method.Body.Add(Refly.CodeDom.Stm.Snippet(@"else
			{
				System.Type type = null;
				if(member is System.Reflection.PropertyInfo)
					type = (member as System.Reflection.PropertyInfo).PropertyType;
				else if(member is System.Reflection.FieldInfo)
					type = (member as System.Reflection.FieldInfo).FieldType;
				if(type != null) // Transform using RegularExpressions
				{
					string typeName = HbmWriterHelper.GetNameWithAssembly(type);
					foreach(System.Collections.DictionaryEntry pattern in Patterns)
					{
						if(System.Text.RegularExpressions.Regex.IsMatch(typeName, pattern.Key as string))
						{
							writer.WriteAttributeString( ""type"",
								System.Text.RegularExpressions.Regex.Replace(typeName,
									pattern.Key as string,
									pattern.Value as string) );
							break;
						}
					}
				}
			}"            ));
                        }
                    }
                }

                // Add the elements
                method.Body.Add(Refly.CodeDom.Stm.Snippet(
                                    schemaEltIsRoot ? @"
			WriteUserDefinedContent(writer, type, null, attribute);"             : @"
			WriteUserDefinedContent(writer, member, null, attribute);"
                                    ));

                if (type.Particle is System.Xml.Schema.XmlSchemaSequence)
                {
                    System.Xml.Schema.XmlSchemaSequence seq     = (schemaElt.SchemaType as System.Xml.Schema.XmlSchemaComplexType).Particle as System.Xml.Schema.XmlSchemaSequence;
                    System.Collections.ArrayList        members = Utils.GetElements(seq.Items, schemaItems);
                    if (!schemaEltIsRoot)
                    {
                        method.Body.Add(Refly.CodeDom.Stm.Snippet(string.Format(@"
			System.Collections.ArrayList memberAttribs = GetSortedAttributes(member);
			int attribPos; // Find the position of the {0}Attribute (its <sub-element>s must be after it)
			for(attribPos=0; attribPos<memberAttribs.Count; attribPos++)
				if( memberAttribs[attribPos] is {0}Attribute
					&& ((BaseAttribute)memberAttribs[attribPos]).Position == attribute.Position )
					break; // found
			int i = attribPos + 1;
", schemaEltName)));
                    }

                    foreach (System.Xml.Schema.XmlSchemaElement member in members)
                    {
                        if (member.RefName.Name != null && member.RefName.Name != string.Empty &&
                            member.Name != null && member.Name != string.Empty)
                        {
                            log.Error(string.Format("Both member.RefName.Name({0}) & member.Name({1}) are not empty", member.RefName.Name, member.Name));
                        }
                        string realMemberName = member.Name + member.RefName.Name;                         // One of them should be empty
                        string memberName     = Utils.Capitalize(realMemberName);
                        string listName       = memberName + "List";
                        string attributeName  = memberName + "Attribute";
                        log.Debug(schemaEltName + " Element: <" + realMemberName + ">");
                        method.Body.Add(Refly.CodeDom.Stm.Comment("Element: <" + realMemberName + ">"));
                        // There are three way to treat elements:
                        // if(eltName is root)
                        //     if(memberName is root)
                        //         => They are both root, so we process the nestedTypes (eg. <class> to <sub-class>)
                        //     else
                        //         => It is an element of a root => we add them as element
                        // else
                        //     => They are both members, so we use the member again (eg. <list> to <one-to-many>)
                        if (schemaEltIsRoot)
                        {
                            if (Utils.IsRoot(memberName))
                            {
                                method.Body.Add(Refly.CodeDom.Stm.Snippet(string.Format(
                                                                              @"WriteNested{0}Types(writer, type);", memberName)));
                            }
                            else
                            {
                                method.Body.Add(Refly.CodeDom.Stm.Snippet(string.Format(
                                                                              @"System.Collections.ArrayList {1} = FindAttributedMembers( attribute, typeof({2}), type );
			foreach( System.Reflection.MemberInfo member in {1} )
			"            , memberName, listName, attributeName) + "{"
                                                                          + string.Format(
                                                                              @"
				object[] objects = member.GetCustomAttributes(typeof({2}), false);
				System.Collections.ArrayList memberAttribs = new System.Collections.ArrayList();
				memberAttribs.AddRange(objects);
				memberAttribs.Sort();
" + (Utils.CanContainItself(memberName) ?
     // => Just take the first (others will be inside it)
     @"				Write{0}(writer, member, memberAttribs[0] as {2}, attribute, type);"
                                                                        :
     @"				foreach(object memberAttrib in memberAttribs)
					Write{0}(writer, member, memberAttrib as {2}, attribute, type);"                    ),
                                                                              memberName, listName, attributeName) + @"
			}"            ));
                            }
                            method.Body.Add(Refly.CodeDom.Stm.Snippet(
                                                "WriteUserDefinedContent(writer, type, typeof(" + attributeName + "), attribute);"));
                        }
                        else
                        {
                            method.Body.Add(Refly.CodeDom.Stm.Snippet(
                                                @"for(; i<memberAttribs.Count; i++)
			{
				BaseAttribute memberAttrib = memberAttribs[i] as BaseAttribute;
				if( IsNextElement(memberAttrib, parentAttribute, attribute.GetType())
					|| IsNextElement(memberAttrib, attribute, typeof("                     + attributeName + @")) )
					break; // next attributes are 'elements' of the same level OR for 'sub-elements'"
                                                + (Utils.IsRoot(memberName) ? ""                  // A NotRoot can not contain a Root! eg. [DynComp] can't contain a [Comp] (instead, use [CompProp])
                                                                : @"
				else
				{"
                                                   + (Utils.CanContainItself(memberName) ? "" : @"
					if( memberAttrib is "                     + schemaEltName + @"Attribute )
						break; // Following attributes are for this "                         + schemaEltName) + @"
					if( memberAttrib is "                     + attributeName + @" )
						Write"                         + memberName + @"(writer, member, memberAttrib as " + attributeName + @", attribute, mappedClass);
				}"                ) + @"
			}"            ));
                            method.Body.Add(Refly.CodeDom.Stm.Snippet(
                                                "WriteUserDefinedContent(writer, member, typeof(" + attributeName + "), attribute);"));
                        }
                    }
                }

                if (type.IsMixed)                // used by elements like <param>
                {
                    method.Body.Add(Refly.CodeDom.Stm.Snippet(@"
			// Write the content of this element (mixed=""true"")
			writer.WriteString(attribute.Content);"            ));
                }
            }
            else
            {
                System.Text.StringBuilder sb = new System.Text.StringBuilder();
                sb.Append("Unknow Element: ").Append(schemaElt.Name);
                if (schemaElt.SchemaType != null)
                {
                    sb.Append(", SchemaType = ").Append(schemaElt.SchemaType).Append(" - ").Append(schemaElt.SchemaType.Name);
                }
                if (!schemaElt.SchemaTypeName.IsEmpty)
                {
                    sb.Append(", SchemaTypeName = ").Append(schemaElt.SchemaTypeName.Name);
                }
                if (schemaElt.ElementSchemaType != null)
                {
                    sb.Append(", ElementType = ").Append(schemaElt.ElementSchemaType.Name);
                }
                log.Warn(sb.ToString());
            }

            method.Body.Add(Refly.CodeDom.Stm.Snippet(@"
			writer.WriteEndElement();"            ));
        }
示例#17
0
        /// <summary> Add the content of the method IsNextElement(). </summary>
        public static void FillIsNextElement(Refly.CodeDom.MethodDeclaration method, System.Xml.Schema.XmlSchemaObjectCollection schemaItems)
        {
            method.Attributes = System.CodeDom.MemberAttributes.Public | System.CodeDom.MemberAttributes.Overloaded;
            method.Doc.Summary.AddText(" Tells if 'element1' come after 'element2' in rootType's 'sub-elements' order. ");             // Create the <summary />
            method.Signature.Parameters.Add("BaseAttribute", "element1");
            method.Signature.Parameters.Add("BaseAttribute", "baseAttrib");
            method.Signature.Parameters.Add(typeof(System.Type), "typeOfElement2");
            method.Signature.ReturnType = new Refly.CodeDom.TypeTypeDeclaration(typeof(bool));

            method.Body.Add(Refly.CodeDom.Stm.Snippet(
                                @"if( element1 == null )
				return false;"                ));

            foreach (System.Xml.Schema.XmlSchemaObject obj in schemaItems)
            {
                if (obj is System.Xml.Schema.XmlSchemaElement)
                {
                    System.Xml.Schema.XmlSchemaElement elt = obj as System.Xml.Schema.XmlSchemaElement;
                    method.Body.Add(Refly.CodeDom.Stm.Snippet(@"
			if( baseAttrib is "             + Utils.Capitalize(elt.Name) + @"Attribute )
			{"            ));

                    if (elt.SchemaType is System.Xml.Schema.XmlSchemaComplexType)
                    {
                        System.Xml.Schema.XmlSchemaComplexType type = elt.SchemaType as System.Xml.Schema.XmlSchemaComplexType;

                        // Add the elements
                        if (type.Particle is System.Xml.Schema.XmlSchemaSequence)
                        {
                            System.Xml.Schema.XmlSchemaSequence seq     = (elt.SchemaType as System.Xml.Schema.XmlSchemaComplexType).Particle as System.Xml.Schema.XmlSchemaSequence;
                            System.Collections.ArrayList        members = Utils.GetElements(seq.Items, schemaItems);
                            for (int i = 0; i < members.Count; i++)
                            {
                                System.Xml.Schema.XmlSchemaElement member = members[i] as System.Xml.Schema.XmlSchemaElement;
                                if (member.RefName.Name == string.Empty)
                                {
                                    continue;                                                            // Ignore elements like <query> and <sql-query>
                                }
                                string memberName = Utils.Capitalize(member.Name + member.RefName.Name); // One of them is empty

                                System.Text.StringBuilder sb = new System.Text.StringBuilder();
                                sb.Append(
                                    @"	if( typeOfElement2 == typeof("+ memberName + @"Attribute) )
				{
					if( "                    );
                                for (int j = i + 1; j < members.Count; j++)
                                {
                                    System.Xml.Schema.XmlSchemaElement nextMember = members[j] as System.Xml.Schema.XmlSchemaElement;
                                    if (nextMember.RefName.Name == string.Empty)
                                    {
                                        continue;                                                                        // Ignore elements like <query> and <sql-query>
                                    }
                                    string nextMemberName = Utils.Capitalize(nextMember.Name + nextMember.RefName.Name); // One of them is empty
                                    sb.Append("element1 is " + nextMemberName + "Attribute || ");
                                }
                                // Add "typeOfElement2 == null" at the end to handle "||" and empty "if()" without compilation warning
                                sb.Append(@"typeOfElement2 == null )
						return true;
				}"                );
                                method.Body.Add(Refly.CodeDom.Stm.Snippet(sb.ToString()));
                            }
                        }
                    }
                    method.Body.Add(Refly.CodeDom.Stm.Snippet("}"));
                }
            }

            method.Body.Add(Refly.CodeDom.Stm.Snippet("return false;"));
            // -----------------------------------------------------------------
        }
 /// <summary> Convert the elements in the Collection to an ArrayList </summary>
 public static System.Collections.ArrayList GetElements(System.Xml.Schema.XmlSchemaObjectCollection seqItems, System.Xml.Schema.XmlSchemaObjectCollection schemaItems)
 {
     System.Collections.ArrayList elements = new System.Collections.ArrayList();
     foreach (System.Xml.Schema.XmlSchemaObject obj in seqItems)
     {
         if (obj is System.Xml.Schema.XmlSchemaElement)
         {
             elements.Add(obj);
         }
         else if (obj is System.Xml.Schema.XmlSchemaChoice)
         {
             System.Xml.Schema.XmlSchemaChoice choice = obj as System.Xml.Schema.XmlSchemaChoice;
             // Add each element of the choice
             foreach (System.Xml.Schema.XmlSchemaObject item in choice.Items)
             {
                 if (item is System.Xml.Schema.XmlSchemaElement)
                 {
                     elements.Add(item);
                 }
                 else if (item is System.Xml.Schema.XmlSchemaGroupRef)
                 {
                     // Find the Group
                     string groupName = (obj as System.Xml.Schema.XmlSchemaGroupRef).RefName.Name;
                     System.Xml.Schema.XmlSchemaGroup group = null;
                     foreach (System.Xml.Schema.XmlSchemaObject schemaItem in schemaItems)
                     {
                         if (schemaItem is System.Xml.Schema.XmlSchemaGroup && groupName == (schemaItem as System.Xml.Schema.XmlSchemaGroup).Name)
                         {
                             group = schemaItem as System.Xml.Schema.XmlSchemaGroup;                                     // Found
                             break;
                         }
                     }
                     if (group == null)                          // Not found
                     {
                         throw new System.Exception("Unknown xs:group " + groupName + string.Format(", nh-mapping.xsd({0})", obj.LineNumber));
                     }
                     elements.AddRange(GetElements(group.Particle.Items, schemaItems));
                 }
                 else if (item is System.Xml.Schema.XmlSchemaSequence)
                 {
                     System.Xml.Schema.XmlSchemaSequence subSeq = item as System.Xml.Schema.XmlSchemaSequence;
                     elements.AddRange(GetElements(subSeq.Items, schemaItems));
                 }
                 else
                 {
                     log.Warn("Unknown Object: " + item.ToString() + string.Format(", nh-mapping.xsd({0})", item.LineNumber));
                 }
             }
         }
         else if (obj is System.Xml.Schema.XmlSchemaGroupRef)
         {
             // Find the Group
             string groupName = (obj as System.Xml.Schema.XmlSchemaGroupRef).RefName.Name;
             System.Xml.Schema.XmlSchemaGroup group = null;
             foreach (System.Xml.Schema.XmlSchemaObject schemaItem in schemaItems)
             {
                 if (schemaItem is System.Xml.Schema.XmlSchemaGroup && groupName == (schemaItem as System.Xml.Schema.XmlSchemaGroup).Name)
                 {
                     group = schemaItem as System.Xml.Schema.XmlSchemaGroup;                             // Found
                     break;
                 }
             }
             if (group == null)                  // Not found
             {
                 throw new System.Exception("Unknown xs:group " + groupName + string.Format(", nh-mapping.xsd({0})", obj.LineNumber));
             }
             elements.AddRange(GetElements(group.Particle.Items, schemaItems));
         }
         else if (obj is System.Xml.Schema.XmlSchemaSequence)
         {
             System.Xml.Schema.XmlSchemaSequence subSeq = obj as System.Xml.Schema.XmlSchemaSequence;
             elements.AddRange(GetElements(subSeq.Items, schemaItems));
         }
         else
         {
             log.Warn("Unknown Object: " + obj.ToString() + string.Format(", nh-mapping.xsd({0})", obj.LineNumber));
         }
     }
     return(elements);
 }
 public static System.Xml.Schema.XmlSchemaComplexType GetTypedDataSetSchema(System.Xml.Schema.XmlSchemaSet xs) {
     NorthwindDataSet ds = new NorthwindDataSet();
     System.Xml.Schema.XmlSchemaComplexType type = new System.Xml.Schema.XmlSchemaComplexType();
     System.Xml.Schema.XmlSchemaSequence sequence = new System.Xml.Schema.XmlSchemaSequence();
     xs.Add(ds.GetSchemaSerializable());
     if (PublishLegacyWSDL()) {
         System.Xml.Schema.XmlSchemaAny any = new System.Xml.Schema.XmlSchemaAny();
         any.Namespace = ds.Namespace;
         sequence.Items.Add(any);
     }
     else {
         System.Xml.Schema.XmlSchemaAny any1 = new System.Xml.Schema.XmlSchemaAny();
         any1.Namespace = "http://www.w3.org/2001/XMLSchema";
         any1.MinOccurs = new decimal(0);
         any1.ProcessContents = System.Xml.Schema.XmlSchemaContentProcessing.Lax;
         sequence.Items.Add(any1);
         System.Xml.Schema.XmlSchemaAny any2 = new System.Xml.Schema.XmlSchemaAny();
         any2.Namespace = "urn:schemas-microsoft-com:xml-diffgram-v1";
         any2.MinOccurs = new decimal(0);
         any2.ProcessContents = System.Xml.Schema.XmlSchemaContentProcessing.Lax;
         sequence.Items.Add(any2);
         sequence.MaxOccurs = decimal.MaxValue;
         System.Xml.Schema.XmlSchemaAttribute attribute = new System.Xml.Schema.XmlSchemaAttribute();
         attribute.Name = "namespace";
         attribute.FixedValue = ds.Namespace;
         type.Attributes.Add(attribute);
     }
     type.Particle = sequence;
     return type;
 }