Example #1
0
        public static void Main(string[] args)
        {
            TCmdOpts cmd = new TCmdOpts();

            new TAppSettingsManager(false);

            TLogging.DebugLevel = TAppSettingsManager.GetInt32("debuglevel", 0);

            String OutputDir;

            if (!cmd.IsFlagSet("TemplateDir"))
            {
                Console.WriteLine("call: " + sampleCall);
                return;
            }

            if (cmd.IsFlagSet("plugin"))
            {
                OutputDir = cmd.GetOptValue("plugindir");

                // calculate ICTPath from outputdir
                string fullOutputPath = Path.GetFullPath(OutputDir).Replace("\\", "/");

                if (!fullOutputPath.Contains("csharp/ICT"))
                {
                    Console.WriteLine("Output path must be below the csharp/ICT directory");
                }

                CSParser.ICTPath = fullOutputPath.Substring(0, fullOutputPath.IndexOf("csharp/ICT") + "csharp/ICT".Length);
                GenerateGlueForPlugin(cmd, OutputDir);
            }
            else if (cmd.IsFlagSet("outputdir"))
            {
                OutputDir = cmd.GetOptValue("outputdir");

                // calculate ICTPath from outputdir
                string fullOutputPath = Path.GetFullPath(OutputDir).Replace("\\", "/");

                if (!fullOutputPath.Contains("csharp/ICT"))
                {
                    Console.WriteLine("Output path must be below the csharp/ICT directory");
                }

                CSParser.ICTPath = fullOutputPath.Substring(0, fullOutputPath.IndexOf("csharp/ICT") + "csharp/ICT".Length);

                GenerateGlueForOpenPetraCore(cmd, OutputDir);
            }
            else
            {
                Console.WriteLine("call: " + sampleCall);
                return;
            }
        }
Example #2
0
        /// <summary>
        /// This should be called by the constructors only;
        /// in C# one constructor cannot call another constructor, so we have moved the code to a different method
        /// </summary>
        /// <param name="CustomConfigFileName">Name of the .NET Configuration File to read from</param>
        /// <param name="AFailOnMissingConfigFile">if this is true and there is no config file, an exception is raised</param>
        private void Create(String CustomConfigFileName, bool AFailOnMissingConfigFile)
        {
            FCmdOpts = new TCmdOpts();

            if (CustomConfigFileName != "")
            {
                FConfigFileName = CustomConfigFileName;
            }
            else if (FCmdOpts.IsFlagSet("C") == true)
            {
                FConfigFileName = FCmdOpts.GetOptValue("C");
            }
            else if (FConfigFileName.Length == 0) // don't reset the name if it was set manually before
            {
                if (Environment.GetCommandLineArgs().Length == 0)
                {
                    // somehow the Environment commandlineargs are empty during debugging
                    throw new Exception("During debugging, please use the parameter -C for the config file");
                }
                else
                {
                    FConfigFileName = Environment.GetCommandLineArgs()[0] + ".config";
                }
            }

            LoadCustomAppSettingFile(AFailOnMissingConfigFile);
            FApplicationDirectory = GetValue("Server.ApplicationBinDirectory", System.IO.Path.GetDirectoryName(
                                                 System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase));
        }
Example #3
0
        /// <summary>
        /// this should be called by the constructors only;
        /// in C# one constructor cannot call another constructor, so we have moved the code to a different method
        /// </summary>
        /// <param name="CustomConfigFileName">Name of the .NET Configuration File to read from</param>
        /// <param name="AFailOnMissingConfigFile">if this is true and there is no config file, an exception is raised</param>
        /// <returns>void</returns>
        private void Create(String CustomConfigFileName, bool AFailOnMissingConfigFile)
        {
            FCmdOpts = new TCmdOpts();

            if (CustomConfigFileName != "")
            {
                FConfigFileName = CustomConfigFileName;
            }
            else if (FCmdOpts.IsFlagSet("C") == true)
            {
                FConfigFileName = FCmdOpts.GetOptValue("C");
            }
            else if (FConfigFileName.Length == 0) // don't reset the name if it was set manually before
            {
                if (Environment.GetCommandLineArgs().Length == 0)
                {
                    // somehow the Environment commandlineargs are empty during debugging
                    throw new Exception("During debugging, please use the parameter -C for the config file");
                }
                else
                {
                    FConfigFileName = Environment.GetCommandLineArgs()[0] + ".config";
                }
            }

            LoadCustomAppSettingFile(AFailOnMissingConfigFile);
        }
Example #4
0
        /// <summary>
        /// returns true if the value is on the command line or in the config file
        /// </summary>
        /// <returns>void</returns>
        public static Boolean HasValue(String Key)
        {
            Boolean    ReturnValue;
            XmlElement appsetting;

            ReturnValue = false;

            if ((FCmdOpts != null) && FCmdOpts.IsFlagSet(Key))
            {
                ReturnValue = true;
            }
            else if (FAppSettingsElement != null)
            {
                appsetting = (XmlElement)FAppSettingsElement.SelectSingleNode("add[@key='" + Key + "']");

                if (appsetting != null)
                {
                    ReturnValue = true;
                }
            }

            return(ReturnValue);
        }
Example #5
0
        public static void Main(string[] args)
        {
            TCmdOpts cmdLine = new TCmdOpts();
            string operation, xmlfile, outputfile;

            try
            {
                operation = cmdLine.GetOptValue("do");
                xmlfile = cmdLine.GetOptValue("petraxml");
                outputfile = cmdLine.GetOptValue("outputFile");
                TWriteSQL.eDatabaseType dbms = TWriteSQL.StringToDBMS(cmdLine.GetOptValue("dbms"));

                if (operation == "sql")
                {
                    System.Console.WriteLine("Reading xml file {0}...", xmlfile);
                    TDataDefinitionParser parser = new TDataDefinitionParser(xmlfile);
                    TDataDefinitionStore store = new TDataDefinitionStore();

                    if (parser.ParseDocument(ref store))
                    {
                        if (dbms == TWriteSQL.eDatabaseType.Sqlite)
                        {
                            // we want to write directly to the database
                            string password = "";

                            if (cmdLine.IsFlagSet("password"))
                            {
                                password = cmdLine.GetOptValue("password");
                            }

                            if (!TSQLiteWriter.CreateDatabase(store, outputfile, password))
                            {
                                Environment.Exit(-1);
                            }
                        }
                        else
                        {
                            // create an sql script that will be loaded into the database later
                            TWriteSQL.WriteSQL(store, dbms, outputfile);
                        }
                    }
                }

                if (operation == "load")
                {
                    if (dbms == TWriteSQL.eDatabaseType.MySQL)
                    {
                        TLoadMysql.LoadData(cmdLine.GetOptValue("database"), cmdLine.GetOptValue("username"),
                            cmdLine.GetOptValue("password"), cmdLine.GetOptValue("sqlfile"));
                    }
                    else if (dbms == TWriteSQL.eDatabaseType.Sqlite)
                    {
                        System.Console.WriteLine("Reading xml file {0}...", xmlfile);
                        TDataDefinitionParser parser = new TDataDefinitionParser(xmlfile);
                        TDataDefinitionStore store = new TDataDefinitionStore();

                        if (parser.ParseDocument(ref store))
                        {
                            if (dbms == TWriteSQL.eDatabaseType.Sqlite)
                            {
                                // we want to write directly to the database
                                string password = "";

                                if (cmdLine.IsFlagSet("password"))
                                {
                                    password = cmdLine.GetOptValue("password");
                                }

                                TSQLiteWriter.ExecuteLoadScript(store, outputfile,
                                    cmdLine.GetOptValue("datapath"),
                                    cmdLine.GetOptValue("sqlfile"),
                                    password);
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                System.Console.WriteLine("Error " + e.GetType().ToString() + ": " + e.Message);
                System.Console.WriteLine(e.StackTrace);
                System.Console.WriteLine();
                System.Console.WriteLine("generate the SQL files to create the database in SQL");
                System.Console.WriteLine(
                    "usage: GenerateSQL -do:<operation> -dbms:<type of database system> -petraxml:<path and filename of petra.xml> -outputFile:<path and filename of the output file>");
                System.Console.WriteLine("operations available:");
                System.Console.WriteLine("  sql ");
                System.Console.WriteLine("    sample call: ");
                System.Console.WriteLine(
                    "        GenerateSQL -do:sql -dbms:postgresql -petraxml:u:/sql/datadefinition/petra.xml -outputFile:U:/setup/petra0300/petra.sql");
                System.Console.WriteLine("Available database managment systems and their code:");
                System.Console.WriteLine("  postgresql (Recommended)");
                System.Console.WriteLine("  mysql (experimental)");
                System.Console.WriteLine("  sqlite (for the light version)");
                System.Environment.Exit(-1);
            }
        }
Example #6
0
        /// <summary>
        /// this should be called by the constructors only;
        /// in C# one constructor cannot call another constructor, so we have moved the code to a different method
        /// </summary>
        /// <param name="CustomConfigFileName">Name of the .NET Configuration File to read from</param>
        /// <param name="AFailOnMissingConfigFile">if this is true and there is no config file, an exception is raised</param>
        /// <returns>void</returns>
        private void Create(String CustomConfigFileName, bool AFailOnMissingConfigFile)
        {
            FCmdOpts = new TCmdOpts();

            if (CustomConfigFileName != "")
            {
                FConfigFileName = CustomConfigFileName;
            }
            else if (FCmdOpts.IsFlagSet("C") == true)
            {
                FConfigFileName = FCmdOpts.GetOptValue("C");
            }
            else if (FConfigFileName.Length == 0) // don't reset the name if it was set manually before
            {
                if (Environment.GetCommandLineArgs().Length == 0)
                {
                    // somehow the Environment commandlineargs are empty during debugging
                    throw new Exception("During debugging, please use the parameter -C for the config file");
                }
                else
                {
                    FConfigFileName = Environment.GetCommandLineArgs()[0] + ".config";
                }
            }

            LoadCustomAppSettingFile(AFailOnMissingConfigFile);
        }
Example #7
0
        int run()
        {
            new TAppSettingsManager(false);

            cmdLine = new TCmdOpts();

            if (!cmdLine.IsFlagSet("do")
                || ((cmdLine.GetOptValue("do") == "dataset") && (!cmdLine.IsFlagSet("input") || !cmdLine.IsFlagSet("outputNamespace")))
                || ((cmdLine.GetOptValue("do") == "referencecount")
                    && (!cmdLine.IsFlagSet("inputclient") || !cmdLine.IsFlagSet("outputserver") || !cmdLine.IsFlagSet("templatedir"))))
            {
                System.Console.WriteLine("GenerateORM: generate Typed Tables and Datasets");
                System.Console.WriteLine("usage: GenerateORM -do:<operation> -petraxml:<xyz/petra.xml>");
                System.Console.WriteLine("operations available:");
                System.Console.WriteLine("  defaulttables ");
                System.Console.WriteLine("           with parameters: ");
                System.Console.WriteLine("                 -outputshared:<path to ICT/Petra/Shared>");
                System.Console.WriteLine("  dataaccess ");
                System.Console.WriteLine("           with parameters: ");
                System.Console.WriteLine("                 -outputshared:<path to ICT/Petra/Shared>");
                System.Console.WriteLine("  dataset ");
                System.Console.WriteLine("           with parameters: ");
                System.Console.WriteLine("                 -input:<dataset XML file>");
                System.Console.WriteLine("                 -outputNamespace:<Namespace of the file>");
                System.Console.WriteLine("  cachedtables ");
                System.Console.WriteLine("           with parameters: ");
                System.Console.WriteLine("                 -cachedef:<dataset XML file>");
                System.Console.WriteLine("                 -outputshared:<path to ICT/Petra/Shared>");
                System.Console.WriteLine("  referencecount ");
                System.Console.WriteLine("           with parameters: ");
                System.Console.WriteLine("                 -inputclient:<path to ICT/Petra/Client>");
                System.Console.WriteLine("                 -outputserver:<path to ICT/Petra/Server>");
                System.Console.WriteLine("                 -templatedir:<path to inc/template/src>");
                System.Console.WriteLine(
                    "       e.g. GenerateORM -do:dataset -petraxml:U:/sql/datadefinition/petra.xml -input:U:/sql/datadefinition/dataset.xml -outputNamespace:Ict.Petra.Shared.MCommon.Data.Dataset");
                return 100;
            }

            try
            {
                if (cmdLine.GetOptValue("do") == "referencecount")
                {
                    // No need to parse the petra.xml document for this task - so we just run and exit
                    new TLogging();
                    TCreateReferenceCountConnectors createConnectors = new TCreateReferenceCountConnectors();

                    if (!createConnectors.CreateFiles(cmdLine.GetOptValue("outputserver"), cmdLine.GetOptValue("inputclient"),
                            cmdLine.GetOptValue("templatedir")))
                    {
                        return -1;
                    }

                    return 0;
                }

                parser = new TDataDefinitionParser(cmdLine.GetOptValue("petraxml"));
                store = new TDataDefinitionStore();

                if (parser.ParseDocument(ref store))
                {
                    if ((cmdLine.GetOptValue("do") == "defaulttables") || (cmdLine.GetOptValue("do") == "datatables"))
                    {
                        CodeGenerationTable.WriteTypedTable(store, "partner", cmdLine.GetOptValue(
                                "outputshared") + "/lib/data/",
                            "Ict.Petra.Shared.MPartner.Partner.Data",
                            "Partner.Tables");
                        CodeGenerationTable.WriteTypedTable(store, "mailroom", cmdLine.GetOptValue(
                                "outputshared") + "/lib/data/",
                            "Ict.Petra.Shared.MPartner.Mailroom.Data",
                            "Mailroom.Tables");
                        CodeGenerationTable.WriteTypedTable(store, "personnel", cmdLine.GetOptValue(
                                "outputshared") + "/lib/data/",
                            "Ict.Petra.Shared.MPersonnel.Personnel.Data",
                            "Personnel.Tables");
                        CodeGenerationTable.WriteTypedTable(store, "units", cmdLine.GetOptValue(
                                "outputshared") + "/lib/data/",
                            "Ict.Petra.Shared.MPersonnel.Units.Data",
                            "Units.Tables");
                        CodeGenerationTable.WriteTypedTable(store, "conference", cmdLine.GetOptValue(
                                "outputshared") + "/lib/data/",
                            "Ict.Petra.Shared.MConference.Data",
                            "Conference.Tables");
                        CodeGenerationTable.WriteTypedTable(store, "hospitality", cmdLine.GetOptValue(
                                "outputshared") + "/lib/data/",
                            "Ict.Petra.Shared.MHospitality.Data",
                            "Hospitality.Tables");
                        CodeGenerationTable.WriteTypedTable(store, "account", cmdLine.GetOptValue(
                                "outputshared") + "/lib/data/",
                            "Ict.Petra.Shared.MFinance.Account.Data",
                            "Account.Tables");
                        CodeGenerationTable.WriteTypedTable(store, "ap", cmdLine.GetOptValue(
                                "outputshared") + "/lib/data/",
                            "Ict.Petra.Shared.MFinance.AP.Data",
                            "AP.Tables");
                        CodeGenerationTable.WriteTypedTable(store, "ar", cmdLine.GetOptValue(
                                "outputshared") + "/lib/data/",
                            "Ict.Petra.Shared.MFinance.AR.Data",
                            "AR.Tables");
                        CodeGenerationTable.WriteTypedTable(store, "gift", cmdLine.GetOptValue(
                                "outputshared") + "/lib/data/",
                            "Ict.Petra.Shared.MFinance.Gift.Data",
                            "Gift.Tables");
                        CodeGenerationTable.WriteTypedTable(store, "sysman", cmdLine.GetOptValue(
                                "outputshared") + "/lib/data/",
                            "Ict.Petra.Shared.MSysMan.Data",
                            "SysMan.Tables");
                        CodeGenerationTable.WriteTypedTable(store, "common", cmdLine.GetOptValue(
                                "outputshared") + "/lib/data/",
                            "Ict.Petra.Shared.MCommon.Data",
                            "Common.Tables");

                        CodeGenerationTableValidation.WriteValidation(store, "partner", cmdLine.GetOptValue(
                                "outputshared") + "/lib/MPartner/validation/",
                            "Ict.Petra.Shared.MPartner.Partner.Validation",
                            "Partner.Validation");
                        CodeGenerationTableValidation.WriteValidation(store, "mailroom", cmdLine.GetOptValue(
                                "outputshared") + "/lib/MPartner/validation/",
                            "Ict.Petra.Shared.MPartner.Mailroom.Validation",
                            "Mailroom.Validation");
                        CodeGenerationTableValidation.WriteValidation(store, "personnel", cmdLine.GetOptValue(
                                "outputshared") + "/lib/MPersonnel/validation/",
                            "Ict.Petra.Shared.MPersonnel.Personnel.Validation",
                            "Personnel.Validation");
                        CodeGenerationTableValidation.WriteValidation(store, "units", cmdLine.GetOptValue(
                                "outputshared") + "/lib/MPersonnel/validation/",
                            "Ict.Petra.Shared.MPersonnel.Units.Validation",
                            "Units.Validation");
                        CodeGenerationTableValidation.WriteValidation(store, "conference", cmdLine.GetOptValue(
                                "outputshared") + "/lib/MConference/validation/",
                            "Ict.Petra.Shared.MConference.Validation",
                            "Conference.Validation");
                        CodeGenerationTableValidation.WriteValidation(store, "hospitality", cmdLine.GetOptValue(
                                "outputshared") + "/lib/MHospitality/validation/",
                            "Ict.Petra.Shared.MHospitality.Validation",
                            "Hospitality.Validation");
                        CodeGenerationTableValidation.WriteValidation(store, "account", cmdLine.GetOptValue(
                                "outputshared") + "/lib/MFinance/validation/",
                            "Ict.Petra.Shared.MFinance.Account.Validation",
                            "Account.Validation");
                        CodeGenerationTableValidation.WriteValidation(store, "ap", cmdLine.GetOptValue(
                                "outputshared") + "/lib/MFinance/validation/",
                            "Ict.Petra.Shared.MFinance.AP.Validation",
                            "AP.Validation");
                        CodeGenerationTableValidation.WriteValidation(store, "ar", cmdLine.GetOptValue(
                                "outputshared") + "/lib/MFinance/validation/",
                            "Ict.Petra.Shared.MFinance.AR.Validation",
                            "AR.Validation");
                        CodeGenerationTableValidation.WriteValidation(store, "gift", cmdLine.GetOptValue(
                                "outputshared") + "/lib/MFinance/validation/",
                            "Ict.Petra.Shared.MFinance.Gift.Validation",
                            "Gift.Validation");
                        CodeGenerationTableValidation.WriteValidation(store, "sysman", cmdLine.GetOptValue(
                                "outputshared") + "/lib/MSysMan/validation/",
                            "Ict.Petra.Shared.MSysMan.Validation",
                            "SysMan.Validation");
                        CodeGenerationTableValidation.WriteValidation(store, "common", cmdLine.GetOptValue(
                                "outputshared") + "/lib/MCommon/validation/",
                            "Ict.Petra.Shared.MCommon.Validation",
                            "Common.Validation");

                        TGenerateTableList.WriteTableList(store, cmdLine.GetOptValue(
                                "outputshared") + Path.DirectorySeparatorChar + "TableList-generated.cs");
                        TGenerateTableList.WriteDBClean(store, Path.GetDirectoryName(cmdLine.GetOptValue(
                                    "petraxml")) + Path.DirectorySeparatorChar + "basedata" + Path.DirectorySeparatorChar + "clean.sql");
                    }
                    else if (cmdLine.GetOptValue("do") == "dataaccess")
                    {
                        CodeGenerationAccess.WriteTypedDataAccess(store, "partner", cmdLine.GetOptValue(
                                "outputshared") + "/lib/data/",
                            "Ict.Petra.Server.MPartner.Partner.Data.Access",
                            "Partner.Access");
                        CodeGenerationAccess.WriteTypedDataAccess(store, "mailroom", cmdLine.GetOptValue(
                                "outputshared") + "/lib/data/",
                            "Ict.Petra.Server.MPartner.Mailroom.Data.Access",
                            "Mailroom.Access");
                        CodeGenerationAccess.WriteTypedDataAccess(store, "personnel", cmdLine.GetOptValue(
                                "outputshared") + "/lib/data/",
                            "Ict.Petra.Server.MPersonnel.Personnel.Data.Access",
                            "Personnel.Access");
                        CodeGenerationAccess.WriteTypedDataAccess(store, "units", cmdLine.GetOptValue(
                                "outputshared") + "/lib/data/",
                            "Ict.Petra.Server.MPersonnel.Units.Data.Access",
                            "Units.Access");
                        CodeGenerationAccess.WriteTypedDataAccess(store, "conference", cmdLine.GetOptValue(
                                "outputshared") + "/lib/data/",
                            "Ict.Petra.Server.MConference.Data.Access",
                            "Conference.Access");
                        CodeGenerationAccess.WriteTypedDataAccess(store, "hospitality", cmdLine.GetOptValue(
                                "outputshared") + "/lib/data/",
                            "Ict.Petra.Server.MHospitality.Data.Access",
                            "Hospitality.Access");
                        CodeGenerationAccess.WriteTypedDataAccess(store, "account", cmdLine.GetOptValue(
                                "outputshared") + "/lib/data/",
                            "Ict.Petra.Server.MFinance.Account.Data.Access",
                            "Account.Access");
                        CodeGenerationAccess.WriteTypedDataAccess(store, "ap", cmdLine.GetOptValue(
                                "outputshared") + "/lib/data/",
                            "Ict.Petra.Server.MFinance.AP.Data.Access",
                            "AP.Access");
                        CodeGenerationAccess.WriteTypedDataAccess(store, "ar", cmdLine.GetOptValue(
                                "outputshared") + "/lib/data/",
                            "Ict.Petra.Server.MFinance.AR.Data.Access",
                            "AR.Access");
                        CodeGenerationAccess.WriteTypedDataAccess(store, "gift", cmdLine.GetOptValue(
                                "outputshared") + "/lib/data/",
                            "Ict.Petra.Server.MFinance.Gift.Data.Access",
                            "Gift.Access");
                        CodeGenerationAccess.WriteTypedDataAccess(store, "sysman", cmdLine.GetOptValue(
                                "outputshared") + "/lib/data/",
                            "Ict.Petra.Server.MSysMan.Data.Access",
                            "SysMan.Access");
                        CodeGenerationAccess.WriteTypedDataAccess(store, "common", cmdLine.GetOptValue(
                                "outputshared") + "/lib/data/",
                            "Ict.Petra.Server.MCommon.Data.Access",
                            "Common.Access");
                        CodeGenerationCascading.WriteTypedDataCascading(store, cmdLine.GetOptValue(
                                "outputshared") + "/lib/data/",
                            "Ict.Petra.Server.MCommon.Data.Cascading",
                            "Cascading");
                    }
                    else if (cmdLine.GetOptValue("do") == "dataset")
                    {
                        string[] groups = new string[] {
                            "common", "mailroom", "sysman", "partner",
                            "account", "gift", "ap", "ar", "personnel", "units", "conference", "hospitality"
                        };

                        CodeGenerationDataset.CreateTypedDataSets(cmdLine.GetOptValue("input"),
                            cmdLine.GetOptValue("outputdir"),
                            cmdLine.GetOptValue("outputNamespace"),
                            store, groups,
                            cmdLine.GetOptValue("outputFilename"));
                    }
                    else if (cmdLine.GetOptValue("do") == "datasetaccess")
                    {
                        string[] groups = new string[] {
                            "common", "mailroom", "sysman", "partner",
                            "account", "gift", "ap", "ar", "personnel", "units", "conference", "hospitality"
                        };

                        CodeGenerationDatasetAccess.CreateTypedDataSets(cmdLine.GetOptValue("input"),
                            cmdLine.GetOptValue("outputdir"),
                            cmdLine.GetOptValue("outputNamespace"),
                            store, groups,
                            cmdLine.GetOptValue("outputFilename"));
                    }
                    else if (cmdLine.GetOptValue("do") == "cachedtables")
                    {
                        Ict.Tools.CodeGeneration.CachedTables.TGenerateCachedTables.WriteCachedTables(
                            store,
                            cmdLine.GetOptValue("cachedef"),
                            cmdLine.GetOptValue("outputshared"),
                            cmdLine.GetOptValue("TemplateDir"));
                    }
                    else
                    {
                        Console.WriteLine("could not recognise: " + cmdLine.GetOptValue("do"));
                    }
                }
            }
            catch (Exception E)
            {
                System.Console.WriteLine(E.Message);
                System.Console.WriteLine(E.StackTrace);
                return 100;
                // System.Console.ReadLine();
            }
            return 0;
        }
Example #8
0
        public static void Main(string[] args)
        {
            TCmdOpts cmd = new TCmdOpts();

            new TAppSettingsManager(false);

            TLogging.DebugLevel = TAppSettingsManager.GetInt32("debuglevel", 0);

            String OutputDir;

            if (!cmd.IsFlagSet("TemplateDir"))
            {
                Console.WriteLine("call: " + sampleCall);
                return;
            }

            if (cmd.IsFlagSet("outputdir"))
            {
                OutputDir = cmd.GetOptValue("outputdir");

                // calculate ICTPath from outputdir
                string fullOutputPath = Path.GetFullPath(OutputDir).Replace("\\", "/");

                if (!fullOutputPath.Contains("csharp/ICT"))
                {
                    Console.WriteLine("Output path must be below the csharp/ICT directory");
                }

                CSParser.ICTPath = fullOutputPath.Substring(0, fullOutputPath.IndexOf("csharp/ICT") + "csharp/ICT".Length);
            }
            else
            {
                Console.WriteLine("call: " + sampleCall);
                return;
            }

            TNamespace namespaceRoot;

            try
            {
                Console.WriteLine("parsing all cs files for namespaces...");
                namespaceRoot = TNamespace.ParseFromDirectory(OutputDir + "/Server/lib/");

                if (namespaceRoot.Children.Count < 1)
                {
                    Console.WriteLine("problems with parsing namespaces from " + OutputDir + "/Server/lib/");
                    Environment.Exit(-1);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Console.WriteLine(e.StackTrace);
                Environment.Exit(-1);
                return;
            }

            try
            {
                CreateInterfaces interfaces = new CreateInterfaces();
                interfaces.CreateFiles(namespaceRoot, OutputDir + "/Shared/lib/Interfaces", cmd.GetOptValue("TemplateDir"));
                CreateInstantiators instantiators = new CreateInstantiators();
                instantiators.CreateFiles(namespaceRoot, OutputDir + "/Server/lib", cmd.GetOptValue("TemplateDir"));
                TCreateConnectors connectors = new TCreateConnectors();
                connectors.CreateFiles(namespaceRoot, OutputDir + "/Server/lib", cmd.GetOptValue("TemplateDir"));
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Console.WriteLine(e.StackTrace);
                Environment.Exit(-1);
            }
        }
Example #9
0
        public static void Main(string[] args)
        {
            try
            {
                // establish connection to database
                TCmdOpts settings = new TCmdOpts();

                if (!settings.IsFlagSet("Server.ODBC_DSN"))
                {
                    Console.WriteLine(
                        "sample call: " +
                        "ExportDataProgress.exe -Server.ODBC_DSN:Petra2_2sa -username:demo_sql -password:demo -sql:\"SELECT * from pub.a_account\" -output:test.xml");
                    Environment.Exit(-1);
                }

                new TLogging("debug.log");

                TDataBase db = new TDataBase();

                TDBType dbtype = TDBType.ProgressODBC;

                if (settings.IsFlagSet("Server.RDBMSType"))
                {
                    dbtype = CommonTypes.ParseDBType(settings.GetOptValue("Server.RDBMSType"));
                }

                if (dbtype != TDBType.ProgressODBC)
                {
                    throw new Exception("at the moment only Progress ODBC db is supported");
                }

                db.EstablishDBConnection(dbtype,
                    settings.GetOptValue("Server.ODBC_DSN"),
                    "",
                    "",
                    settings.GetOptValue("username"),
                    settings.GetOptValue("password"),
                    "");
                DBAccess.GDBAccessObj = db;

                TLogging.DebugLevel = 10;

                string sqlText = "";

                if (!settings.IsFlagSet("sql"))
                {
                    Console.WriteLine("Please enter sql and finish with semicolon: ");

                    while (!sqlText.Trim().EndsWith(";"))
                    {
                        sqlText += " " + Console.ReadLine();
                    }

                    sqlText = sqlText.Substring(0, sqlText.Length - 1);
                }
                else
                {
                    sqlText = settings.GetOptValue("sql");
                    Console.WriteLine(sqlText);
                }

                TDBTransaction transaction = DBAccess.GDBAccessObj.BeginTransaction(IsolationLevel.ReadUncommitted);

                DataTable table = db.SelectDT(sqlText, "temp", transaction);

                XmlDocument doc = TDataBase.DataTableToXml(table);

                if (settings.IsFlagSet("output"))
                {
                    if (settings.GetOptValue("output").EndsWith("yml"))
                    {
                        TYml2Xml.Xml2Yml(doc, settings.GetOptValue("output"));
                    }
                    else if (settings.GetOptValue("output").EndsWith("csv"))
                    {
                        TCsv2Xml.Xml2Csv(doc, settings.GetOptValue("output"));
                    }
                    else if (settings.GetOptValue("output").EndsWith("xml"))
                    {
                        StreamWriter sw = new StreamWriter(settings.GetOptValue("output"));
                        sw.Write(TXMLParser.XmlToString2(doc));
                        sw.Close();
                    }
                }
                else
                {
                    TYml2Xml.Xml2Yml(doc, "temp.yml");
                    StreamReader sr = new StreamReader("temp.yml");
                    Console.WriteLine(sr.ReadToEnd());
                    sr.Close();
                }

                db.RollbackTransaction();
                db.CloseDBConnection();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Console.WriteLine(e.StackTrace);
            }
        }