static void Main(string[] args)
        {
            if (args.Length == 3)
            {
                string fileName  = args[0];
                string nameSpace = args[1];
                string setName   = args[2];

                // Check to make sure the set name is valud
                if (setName == "WITSML131" || setName == "WITSML141" || setName == "PRODML122" || setName == "RESQML201")
                {
                    // Namespace must start with a capital letter,
                    // followed by any number of word characters or dots,
                    // and ending with a word character
                    if (Regex.IsMatch(nameSpace, @"^[A-Z][\w\.]*[\w]$"))
                    {
                        // File must exist
                        if (File.Exists(fileName))
                        {
                            try
                            {
                                string             xml      = EnumValuesXMLToClass.Convert(fileName, nameSpace, new List <string>(), true, setName);
                                CodeDomProvider    provider = CodeDomProvider.CreateProvider("CSharp");
                                CompilerParameters cp       = new CompilerParameters();
                                cp.ReferencedAssemblies.Add("Energistics.DataAccess.dll");
                                cp.GenerateInMemory = false;
                                cp.OutputAssembly   = nameSpace + ".EnumValueExtensions.dll";

                                CompilerResults result = provider.CompileAssemblyFromSource(cp, xml);

                                if (result.Errors.Count > 0)
                                {
                                    foreach (string s in result.Output)
                                    {
                                        Console.Out.WriteLine(s);
                                    }
                                }
                                else
                                {
                                    Console.Out.WriteLine("Extension class created.");
                                }
                            }
                            catch (Exception e)
                            {
                                Console.Out.WriteLine("Unexpected error!");
                                Console.Out.WriteLine("Exception: {0}", e.Message);
                                if (e.InnerException != null)
                                {
                                    Console.Out.WriteLine("Inner Exception: {0}", e.InnerException.Message);
                                }
                            }
                        }
                        else
                        {
                            Console.Out.WriteLine("File '{0}' does not exist.", fileName);
                        }
                    }
                    else
                    {
                        Console.Out.WriteLine("Invalid namespace '{0}'.", nameSpace);
                    }
                }
                else
                {
                    Console.Out.WriteLine("Invalid set name '{0}'. Must be one of WITSML131, WITSML141, or PRODML122.", nameSpace);
                }
            }
            else
            {
                Console.Out.WriteLine("EnumValuesExtensionGenerator - Generates a extension class for a custom enumValues.xml file");
                Console.Out.WriteLine("");
                Console.Out.WriteLine("EnumValuesExtensionGenerator [enumValues filename] [namespace] [WITSML131 or WITSML141 or PRODML122]");
            }
        }
예제 #2
0
        private static void GenerateClasses(string setName, string currentPath)
        {
            string        mlPath         = Energistics.SchemaGatherer.SchemaGatherer.GetAppSetting(setName + "_XSD_PATH");
            string        targetFilename = String.Format(@"{0}\{1}\GeneratedEnumValues.cs", Energistics.SchemaGatherer.SchemaGatherer.GetAppSetting(setName + "_ENERGY_ML_DATA_ACCESS_PROJ_PATH"), setName);
            List <string> enumClassNames = new List <string>();

            if (!setName.Contains("ML2"))
            {
                string csCode = EnumValuesXMLToClass.Convert(Energistics.SchemaGatherer.SchemaGatherer.GetAppSetting(setName + "_ENUMVAL_PATH"), "Energistics.DataAccess." + setName, enumClassNames, false, null);
                csCode = SchemaGatherer.SchemaGatherer.CleanUpGeneratedText(csCode);

                if (targetFilename.Contains(".cs"))
                {
                    DirectorySecurity securityRules = new DirectorySecurity();
                    String            targetPath    = targetFilename.Remove(targetFilename.LastIndexOf("\\"));
                    if (!Directory.Exists(targetPath))
                    {
                        Directory.CreateDirectory(targetPath);
                    }
                }
                File.WriteAllText(targetFilename, csCode);
            }
            if (setName.Contains("PRODML"))
            {
                string prodMLPath = Energistics.SchemaGatherer.SchemaGatherer.GetAppSetting(setName + "_ENUMVALPRODML_PATH");
                if (!String.IsNullOrEmpty(prodMLPath))
                {
                    targetFilename = String.Format(@"{0}\{1}\GeneratedProdmlEnumValues.cs", Energistics.SchemaGatherer.SchemaGatherer.GetAppSetting(setName + "_ENERGY_ML_DATA_ACCESS_PROJ_PATH"), setName);
                    var text = EnumValuesXMLToClass.Convert(prodMLPath, "Energistics.DataAccess." + setName, enumClassNames, false, null);
                    text = SchemaGatherer.SchemaGatherer.CleanUpGeneratedText(text);
                    File.WriteAllText(targetFilename, text);
                }
            }

            /* HD5 previously was coded in RESQML 100, regards 200 strcuture has changed, and HD5 is not support at this moment */
            if (setName.StartsWith("RESQML100"))
            {
                ResqmlHD5Template resqmlTextTemplate = new ResqmlHD5Template();
                string            resmltext          = resqmlTextTemplate.TransformText(setName);
                resmltext = SchemaGatherer.SchemaGatherer.CleanUpGeneratedText(resmltext);
                File.WriteAllText(String.Format(@"{0}\{1}\GeneratedResqmlHDF5PartialClasses.cs", Energistics.SchemaGatherer.SchemaGatherer.GetAppSetting(setName + "_ENERGY_ML_DATA_ACCESS_PROJ_PATH"), setName), resmltext);
            }

            string versionString = Energistics.SchemaGatherer.SchemaGatherer.GetAppSetting(setName + "_VERSION_STRING");

            EnergisticsTextTemplate textTemplate = new EnergisticsTextTemplate(mlPath, setName, enumClassNames, versionString);
            String contents = textTemplate.TransformText();

            contents = SchemaGatherer.SchemaGatherer.CleanUpGeneratedText(contents);
            String prjPath = String.Format("{0}\\{1}\\", Energistics.SchemaGatherer.SchemaGatherer.GetAppSetting(setName + "_ENERGY_ML_DATA_ACCESS_PROJ_PATH"), setName);

            if (!Directory.Exists(prjPath))
            {
                Directory.CreateDirectory(prjPath);
            }
            File.WriteAllText(String.Format("{0}\\DataObjects.cs", prjPath), contents);

            string wsdlPath = Energistics.SchemaGatherer.SchemaGatherer.GetAppSetting(setName + "_WSDL");

            if (!String.IsNullOrEmpty(wsdlPath))
            {
                foreach (string wsdlFile in Directory.GetFiles(wsdlPath, "*.wsdl"))
                {
                    ProcessWSDL(String.Format("\"{0}\" /out:\"{1}\\{2}\" /namespace:Energistics.DataAccess.{2}.{3}", wsdlFile, Energistics.SchemaGatherer.SchemaGatherer.GetAppSetting(setName + "_ENERGY_ML_DATA_ACCESS_PROJ_PATH"), setName, Path.GetFileNameWithoutExtension(wsdlFile)), setName);
                }
            }
        }