Пример #1
0
        private void Generation(string xsdFileName)
        {
            //try
            //{

            string subfoler       = xsdFileName.Replace(".xsd", "");
            string subBuiltInPath = System.IO.Path.Combine(rootFolder_, subfoler);

            System.IO.Directory.CreateDirectory(subBuiltInPath);

            XmlSchema rootSchema = GetSchemaFromFile(xsdFileName);

            bool noUseFile = false;

            foreach (XmlSchemaObject item in rootSchema.Items)
            {
                var csWriter = new StringWriter();

                string schemaObjectName = "";

                if (item is XmlSchemaElement)
                {
                    XmlSchemaElement xe = item as XmlSchemaElement;
                    schemaObjectName = xe.Name + "NoUseFile";
                    noUseFile        = true;
                }
                else if (item is XmlSchemaComplexType)
                {
                    XmlSchemaComplexType xsct = item as XmlSchemaComplexType;

                    //debug
                    Console.WriteLine(xsct.Name);

                    if (this.viewModelFlag_)
                    {
                        CSharpCodeGen.GeneratorViewModel gen = new GeneratorViewModel(xsct, elementRef, includePath, elementSubstitutionRef, elementGroupRef);

                        gen.makeCode();
                        csWriter.WriteLine(gen.CsCode);
                    }
                    else
                    {
                        CSharpCodeGen.Generator gen = new Generator(xsct, elementRef, includePath, elementSubstitutionRef, elementGroupRef);
                        gen.makeCode();
                        csWriter.WriteLine(gen.CsCode);
                    }

                    schemaObjectName = xsct.Name;
                }
                else if (item is XmlSchemaSimpleType)
                {
                    XmlSchemaSimpleType           xsst = item as XmlSchemaSimpleType;
                    CSharpCodeGen.GeneratorSimple gen  = new GeneratorSimple(xsst);
                    csWriter.WriteLine(gen.CsCode);
                    schemaObjectName = xsst.Name;
                }

                // gen 된 string file 저장함
                if (!noUseFile)
                {
                    if (this.viewModelFlag_)
                    {
                        File.WriteAllText(Path.Combine(subBuiltInPath, schemaObjectName + "ViewModel.cs"), csWriter.GetStringBuilder().ToString());
                    }
                    else
                    {
                        File.WriteAllText(Path.Combine(subBuiltInPath, schemaObjectName + ".cs"), csWriter.GetStringBuilder().ToString());
                    }
                }
            }
            //}
            //catch
            //{
            //    Console.WriteLine("errorOcc -----------------------------------------------------------");
            //    Console.ReadLine();
            //}
        }
        private void Generation(string xsdFileName)
        {
            //try
            //{

                string subfoler = xsdFileName.Replace(".xsd", "");
                string subBuiltInPath = System.IO.Path.Combine(rootFolder_, subfoler);
                System.IO.Directory.CreateDirectory(subBuiltInPath);

                XmlSchema rootSchema = GetSchemaFromFile(xsdFileName);

                bool noUseFile = false;

                foreach (XmlSchemaObject item in rootSchema.Items)
                {
                    var csWriter = new StringWriter();

                    string schemaObjectName = "";

                    if (item is XmlSchemaElement)
                    {

                        XmlSchemaElement xe = item as XmlSchemaElement;
                        schemaObjectName = xe.Name + "NoUseFile";
                        noUseFile = true;
                    }
                    else if (item is XmlSchemaComplexType)
                    {
                        XmlSchemaComplexType xsct = item as XmlSchemaComplexType;

                        //debug
                        Console.WriteLine(xsct.Name);

                        if (this.viewModelFlag_)
                        {
                            CSharpCodeGen.GeneratorViewModel gen = new GeneratorViewModel(xsct, elementRef, includePath, elementSubstitutionRef, elementGroupRef);

                            gen.makeCode();
                            csWriter.WriteLine(gen.CsCode);
                        }
                        else
                        {
                            CSharpCodeGen.Generator gen = new Generator(xsct, elementRef, includePath, elementSubstitutionRef, elementGroupRef);
                            gen.makeCode();
                            csWriter.WriteLine(gen.CsCode);
                        }

                        schemaObjectName = xsct.Name;
                    }
                    else if (item is XmlSchemaSimpleType)
                    {
                        XmlSchemaSimpleType xsst = item as XmlSchemaSimpleType;
                        CSharpCodeGen.GeneratorSimple gen = new GeneratorSimple(xsst);
                        csWriter.WriteLine(gen.CsCode);
                        schemaObjectName = xsst.Name;
                    }

                    // gen 된 string file 저장함
                    if (!noUseFile)
                    {
                        if (this.viewModelFlag_)
                        {
                            File.WriteAllText(Path.Combine(subBuiltInPath, schemaObjectName + "ViewModel.cs"), csWriter.GetStringBuilder().ToString());
                        }
                        else
                        {
                            File.WriteAllText(Path.Combine(subBuiltInPath, schemaObjectName + ".cs"), csWriter.GetStringBuilder().ToString());
                        }
                    }
                }
            //}
            //catch 
            //{
            //    Console.WriteLine("errorOcc -----------------------------------------------------------");
            //    Console.ReadLine();
            //}

        }