public static byte[] GetCodeFileBytes(string xsdFilePath, string ns, string[] includedNamespaces)
        {
            var f       = new WorkFile(xsdFilePath);
            var tmpDir  = f.CreateTempDir();
            var allCode = GenerateCode(tmpDir.FullName, ns);

            SplitByFileSource(allCode, tmpDir.FullName, includedNamespaces);
            var bytes = File.ReadAllBytes(tmpDir + f.CodeLocalName);

            Directory.Delete(tmpDir.FullName, true);
            return(bytes);
        }
Пример #2
0
        public static void Run()
        {
            // Assuming all file exists

            CodeDomProvider prov    = new CSharpCodeProvider();
            var             options = new CompilerParameters()
            {
                GenerateInMemory   = true,
                GenerateExecutable = false,
            };

            options.ReferencedAssemblies.AddRange(new string[] { "System.dll", "System.Core.dll", "System.Xml.dll", "System.Xml.Linq.dll" });
            var result = prov.CompileAssemblyFromFile(
                options,
                @"C:\Magenta Workspace\PART\Source\Core\Schemas\OIOXSD\XSD.cs"
                );

            if (!result.Errors.HasErrors)
            {
                var asm       = result.CompiledAssembly;
                var allTypes  = asm.GetTypes();
                var nameSpace = allTypes[0].Namespace;


                // Now parse the XSD files
                string dir   = @"C:\Magenta Workspace\PART\Source\Core\Schemas\OIOXSD\";
                var    files = Directory.GetFiles(dir, "*.xsd");

                foreach (var file in files)
                {
                    var fileTypes      = new WorkFile(file).DefinedTypeNames;
                    var typesToInclude = allTypes.Where(t => fileTypes.Contains(t.Name)).ToArray();

                    CodeNamespace localCodeNamespace = new CodeNamespace(nameSpace);
                    localCodeNamespace.Imports.Add(new CodeNamespaceImport("System.Xml.Serialization"));
                    localCodeNamespace.Types.AddRange(typesToInclude.Select(t => FromType(t)).ToArray());


                    string codeFileName = file.Replace(".xsd", ".designer.cs");


                    using (var w = new StreamWriter(codeFileName))
                    {
                        prov.GenerateCodeFromNamespace(localCodeNamespace, w, new CodeGeneratorOptions()
                        {
                        });
                    }
                }
            }
        }
Пример #3
0
        public void DownloadIncludes(string originalLocationDir)
        {
            var cl = new WebClient();

            foreach (var inc in IncludedUrls)
            {
                string localName       = "";
                string includeFilePath = null;

                Action copier;

                if (IsUrl(inc))
                {
                    // Web file
                    var arr = inc.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
                    localName = arr.Last();

                    copier = () =>
                    {
                        var fileBytes = cl.DownloadData(inc);
                        File.WriteAllBytes(includeFilePath, fileBytes);
                    };
                }
                else
                {
                    // local file
                    var path = inc;
                    localName = path.Split('\\').Last();

                    copier = () =>
                    {
                        File.Copy(originalLocationDir + inc, includeFilePath);
                    };
                }
                includeFilePath = new FileInfo(this.XsdFullPath).Directory + localName;
                copier();
                var incFile = new WorkFile(includeFilePath);
                //incFile.DownloadIncludes();
            }
        }