Exemple #1
0
        private void generateXmlSchemaLogic(string projectPath, string schemaPathInProject, string nameSpace, string codeFileName, bool useSvcUtil)
        {
            var projectGeneratedCodeFolderPath = StandardLibraryMethods.CombinePaths(projectPath, "Generated Code");

            if (useSvcUtil)
            {
                try {
                    StandardLibraryMethods.RunProgram(
                        StandardLibraryMethods.CombinePaths(AppStatics.DotNetToolsFolderPath, "SvcUtil"),
                        "/d:\"" + projectGeneratedCodeFolderPath + "\" /noLogo \"" + StandardLibraryMethods.CombinePaths(projectPath, schemaPathInProject) + "\" /o:\"" +
                        codeFileName + "\" /dconly /n:*," + nameSpace + " /ser:DataContractSerializer",
                        "",
                        true);
                }
                catch (Exception e) {
                    throw new UserCorrectableException("Failed to generate XML schema logic using SvcUtil.", e);
                }
            }
            else
            {
                Directory.CreateDirectory(projectGeneratedCodeFolderPath);
                try {
                    StandardLibraryMethods.RunProgram(
                        StandardLibraryMethods.CombinePaths(AppStatics.DotNetToolsFolderPath, "xsd"),
                        "/nologo \"" + StandardLibraryMethods.CombinePaths(projectPath, schemaPathInProject) + "\" /c /n:" + nameSpace + " /o:\"" +
                        projectGeneratedCodeFolderPath + "\"",
                        "",
                        true);
                }
                catch (Exception e) {
                    throw new UserCorrectableException("Failed to generate XML schema logic using xsd.", e);
                }
                var outputCodeFilePath = StandardLibraryMethods.CombinePaths(
                    projectGeneratedCodeFolderPath,
                    Path.GetFileNameWithoutExtension(schemaPathInProject) + ".cs");
                var desiredCodeFilePath = StandardLibraryMethods.CombinePaths(projectGeneratedCodeFolderPath, codeFileName);
                if (outputCodeFilePath != desiredCodeFilePath)
                {
                    try {
                        IoMethods.MoveFile(outputCodeFilePath, desiredCodeFilePath);
                    }
                    catch (IOException e) {
                        throw new UserCorrectableException("Failed to move the generated code file for an XML schema. Please try the operation again.", e);
                    }
                }
            }
        }