Exemplo n.º 1
0
        public static void Main(string[] args)
        {
            System.Diagnostics.Debug.Listeners.Add(new System.Diagnostics.TextWriterTraceListener(Console.Out, "sde2spatialiteconsolewriter"));

            Arguments = new CommandLine.Utility.Arguments(args);

            // show help/usage
            if (Arguments["h"] != null || Arguments["help"] != null || args.Length.Equals(0))
            {
                Console.Write(Util.S2SHelper.HelpManual());
                return;
            }

            if (Validate())
            {
                // ESRI License Initializer generated code.
                aolicenseInitializer.InitializeApplication(
                    new esriLicenseProductCode[] { esriLicenseProductCode.esriLicenseProductCodeArcView },
                    new esriLicenseExtensionCode[] { });

                Operation.Execute();

                // ESRI License Initializer generated code.
                // Do not make any call to ArcObjects after ShutDownApplication()
                aolicenseInitializer.ShutdownApplication();
            }

            System.Diagnostics.Debug.Listeners.Remove("sde2spatialiteconsolewriter");
        }
Exemplo n.º 2
0
        private void getStatus()
        {
            string[] args = new string[] { "-n", datacard.getName() };

            CommandLineOptions commandLineOptions = new CommandLineOptions();

            CommandLine.Utility.Arguments arguments = new CommandLine.Utility.Arguments(args);

            if (string.IsNullOrEmpty(arguments["n"]))
            {
                Console.WriteLine("Some information");
            }
            bool boolVal = false;

            if (Boolean.TryParse(arguments["n"], out boolVal))
            {
                Console.WriteLine("Some information");
            }
            commandLineOptions.printerName = arguments["n"];

            if (!string.IsNullOrEmpty(arguments["j"]))
            {
                commandLineOptions.jobStatus = true;
            }

            BidiSplWrap bidiSpl = null;

            try
            {
                bidiSpl = new BidiSplWrap();
                bidiSpl.BindDevice(commandLineOptions.printerName);

                string driverVersionXml = bidiSpl.GetPrinterData(strings.SDK_VERSION);
                //Console.WriteLine(Environment.NewLine + "driver version: " + Util.ParseDriverVersionXML(driverVersionXml) + Environment.NewLine);

                string printerOptionsXML = bidiSpl.GetPrinterData(strings.PRINTER_OPTIONS2);
                PrinterOptionsValues printerOptionsValues = Util.ParsePrinterOptionsXML(printerOptionsXML);
                DisplayPrinterOptionsValues(printerOptionsValues);

                string printerCardCountXML = bidiSpl.GetPrinterData(strings.COUNTER_STATUS2);
                PrinterCounterStatus printerCounterStatusValues = Util.ParsePrinterCounterStatusXML(printerCardCountXML);
                DisplayPrinterCounterValues(printerCounterStatusValues);

                string         suppliesXML    = bidiSpl.GetPrinterData(strings.SUPPLIES_STATUS3);
                SuppliesValues suppliesValues = Util.ParseSuppliesXML(suppliesXML);
                DisplaySuppliesValues(suppliesValues);

                //string printerStatusXML = bidiSpl.GetPrinterData(strings.PRINTER_MESSAGES);
                //PrinterStatusValues printerStatusValues = Util.ParsePrinterStatusXML(printerStatusXML);
                //DisplayPrinterStatusValues(printerStatusValues);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            finally
            {
                bidiSpl.UnbindDevice();
            }
        }
        public void DoArguments(string[] args)
        {
            /*
             * List of valid arguments:
             * 
             * /sname <server name>
             * - connect to existing server by Server Name
             * 
             * /gname <group name>
             * - Connect to multiple server inside a group by providing a Group Name
            */

            string args_server_name = string.Empty;
            string args_group_name = string.Empty;
            CommandLine.Utility.Arguments a = new CommandLine.Utility.Arguments(args);
            
            if (a["sname"] != null)
            {
                this.ConnectByServerName(a["sname"]);
            }

            if (a["gname"] != null)
            {
                this.GroupConnectAll(a["gname"]);
            }
        }
        public void DoArguments(string[] args)
        {
            /*
             * List of valid arguments:
             *
             * /sname <server name>
             * - connect to existing server by Server Name
             *
             * /gname <group name>
             * - Connect to multiple server inside a group by providing a Group Name
             */

            string args_server_name = string.Empty;
            string args_group_name  = string.Empty;

            CommandLine.Utility.Arguments a = new CommandLine.Utility.Arguments(args);

            if (a["sname"] != null)
            {
                this.ConnectByServerName(a["sname"]);
            }

            if (a["gname"] != null)
            {
                this.GroupConnectAll(a["gname"]);
            }
        }
Exemplo n.º 5
0
        static void Main(string[] args)
        {
            CommandLine.Utility.Arguments arguments = new CommandLine.Utility.Arguments(args);
            Configuration.ReadConfiguration();

            #region Command Line Arguments Processing

            if (arguments["v"] != null) Illuminate.Tools.Logger.LogNameToTrace = "all";

            if (arguments["help"] != null)
            {
                Console.WriteLine("Usage: Node.exe [options]");
                Console.WriteLine("");
                Console.WriteLine("Options:");
                Console.WriteLine("-v :       Verbose mode.  This option will display all the log entries");
                Console.WriteLine("           which are being outputted for every agent.");
                Console.WriteLine("");

                return;
            }

            #endregion

            IlluminateConsole.IntroText();

            IlluminateConsole.Initialization();

            IlluminateConsole.WaitForCommand();
        }
Exemplo n.º 6
0
        static void Main(string[] args)
        {
            if (args.Length.Equals(0))
            {
                Usage();
                return;
            }

            //ESRI License Initializer generated code.
            m_AOLicenseInitializer.InitializeApplication(new esriLicenseProductCode[] { esriLicenseProductCode.esriLicenseProductCodeArcView },
                                                         new esriLicenseExtensionCode[] { });

            Arguments = new CommandLine.Utility.Arguments(args);


            string mxdfilepath   = string.Empty;
            string directorypath = string.Empty;
            string excludedbpath = string.Empty;

            if (Arguments["mxd"] != null)
            {
                mxdfilepath = Arguments["mxd"];
            }
            else if (Arguments["d"] != null)
            {
                directorypath = Arguments["d"];
            }

            if (Arguments["x"] != null)
            {
                ExcludeDBPath = Arguments["x"];
            }

            if (!string.IsNullOrEmpty(mxdfilepath))
            {
                AnalyzeMXD(mxdfilepath);
            }
            else if (!string.IsNullOrEmpty(directorypath))
            {
                if (Arguments["o"] != null)
                {
                    ReportFilePath = Arguments["o"];
                }

                AnalyzeMXDDirectory(directorypath);
            }

            //ESRI License Initializer generated code.
            //Do not make any call to ArcObjects after ShutDownApplication()
            m_AOLicenseInitializer.ShutdownApplication();
        }
Exemplo n.º 7
0
        /// <summary>
        /// Process the arguments passed to the console program
        /// </summary>
        /// <param name="args"></param>
        private static int ParseArguments(string[] args)
        {
            try
            {
                //Parse the Command Line
                CommandLine.Utility.Arguments CommandLine = new CommandLine.Utility.Arguments(args);

                // Verify parameters passed are legal then stuff into variables
                CheckAndSetParameters(ref _GRNodeName, "GRNodeName", CommandLine, true, System.Net.Dns.GetHostName());
                CheckAndSetParameters(ref _GalaxyName, "GalaxyName", CommandLine, true);
                CheckAndSetParameters(ref _Username, "Username", CommandLine, true, "");
                CheckAndSetParameters(ref _Password, "Password", CommandLine, true);
                CheckAndSetParameters(ref _BackupFileName, "BackupFileName", CommandLine, true);
                CheckAndSetParameters(ref _BackupType, "BackupType", CommandLine, true, "CompleteCAB");
                CheckAndSetParameters(ref _BackupFolderName, "BackupFolder", CommandLine, true);
                CheckAndSetParameters(ref _ObjectList, "ObjectList", CommandLine, true);

                /*
                 * NOT USED - TODO: Need to figure out what the intended purpose of this ws!
                 * CheckAndSetParameters(ref _FileDetail, "FileDetail", CommandLine, true);
                 */

                CheckAndSetParameters(ref _IncludeConfigVersion, "IncludeConfigVersion", CommandLine, true, "false");
                CheckAndSetParameters(ref _FilterType, "FilterType", CommandLine, true);
                CheckAndSetParameters(ref _Filter, "Filter", CommandLine, true);
                CheckAndSetParameters(ref _PasswordToEncrypt, "PasswordToEncrypt", CommandLine, true);
                CheckAndSetParameters(ref _EncryptedPassword, "EncryptedPassword", CommandLine, true);
                CheckAndSetParameters(ref _ChangeLogTimestampStartFilter, "ChangeLogTimestampStartFilter", CommandLine, true, "1/1/1970");
                CheckAndSetParameters(ref _CustomSQLSelection, "CustomSQLSelection", CommandLine, true, "");
                CheckAndSetParameters(ref _OverwriteFiles, "OverwriteFiles", CommandLine, true, "true");
                CheckAndSetParameters(ref _ObjectListFile, "ObjectListFile", CommandLine, true, "");

                CheckAndSetParameters(ref _ObjectSelection, "ObjectSelection", CommandLine, true, "");
                CheckAndSetParameters(ref _BackupResult, "BackupResult", CommandLine, true, "");


                // Success
                return(0);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Creates a workspace to the SDE database from the command line args
        /// </summary>
        /// <param name="args">The command line args.</param>
        /// <returns>IWorkspace interface to the SDEWorkspace</returns>
        internal static IWorkspace Workspace(ref CommandLine.Utility.Arguments args)
        {
            // TODO: Maybe extend this to work with personal/file geodb in the future. Shouldn't be too difficult.
            IWorkspace workspace = null;

            string server   = args["s"] ?? string.Empty;
            string instance = args["i"] ?? string.Empty;
            string user     = args["u"] ?? string.Empty;
            string password = args["p"] ?? string.Empty;
            string database = args["D"] ?? string.Empty;
            string authmode = args["m"] ?? string.Empty;
            string version  = args["V"] ?? string.Empty;

            IPropertySet propertyset = Utility.ArcSDEConnPropSet(server, instance, user, password, database, version, authmode);

            IWorkspaceFactory factory = new SdeWorkspaceFactoryClass();

            workspace = factory.Open(propertyset, 0);

            return(workspace);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Gets the SDE table parameter from the command line args
        /// </summary>
        /// <param name="args">The  command line args.</param>
        /// <returns>sde table name</returns>
        internal static string GetSDETable(ref CommandLine.Utility.Arguments args)
        {
            try
            {
                if (args != null)
                {
                    string tabcol = args["l"] ?? string.Empty;

                    if (!string.IsNullOrEmpty(tabcol))
                    {
                        return(tabcol.Split(',')[0]);
                    }
                }

                return(null);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.StackTrace);
                return(null);
            }
        }
Exemplo n.º 10
0
        static void Main(string[] args)
        {
            try
            {
                // Start with the logging
                log4net.Config.BasicConfigurator.Configure();

                log.Info("Starting aaBackup");

                // First store off the arguments
                _args = new CommandLine.Utility.Arguments(args);

                // Parse the input parameters
                ParseArguments(args);

                // First call the setup routine
                Setup();

                //If the user has passed us a password to encrypt then do that and  bail out.
                if (_PasswordToEncrypt.Length > 0)
                {
                    log.Info("Encrypting password");
                    WriteEncryptedPassword(_PasswordToEncrypt);
                    log.Info("Password encryption complete");
                    return;
                }

                // If the user has passed an encrypted password then decrypt it
                // and set it to the current working password
                if (_EncryptedPassword.Length > 0)
                {
                    log.Info("Decrypting password");

                    // Set the password to the the decrypted password
                    _Password = DecryptPassword(_EncryptedPassword);
                }

                // Instantiate the Object
                caaExport BackupObj = new caaExport();

                // Set the parms

                BackupObj.GRNodeName = _GRNodeName;
                BackupObj.GalaxyName = _GalaxyName;
                BackupObj.Username   = _Username;
                BackupObj.Password   = _Password;
                //BackupObj.BackupFolderName = _BackupFolderName;
                //BackupObj.BackupType = _BackupType;
                //BackupObj.ChangeLogTimestampStartFilter = DateTime.Parse(_ChangeLogTimestampStartFilter);

                BackupObj.Connect();

                BackupObj.BackupCompleteCAB(_BackupFileName);
            }
            catch (Exception ex)
            {
                log.Error(ex);
            }
            finally
            {
                log.Info("Backup complete");
                //Console.WriteLine("Enter to Continue to Finish");
                //Console.ReadLine();
            }
        }
Exemplo n.º 11
0
        static void Main(string[] args)
        {
            Console.WriteLine("OrmObjects CodeGen utility.");
            Console.WriteLine();

            CommandLine.Utility.Arguments cmdLine = new CommandLine.Utility.Arguments(args);

            string          outputLanguage;
            string          outputFolder;
            OrmObjectsDef   ormObjectsDef;
            string          inputFilename;
            CodeDomProvider codeDomProvider;
            bool            split, separateFolder;

            string[] skipEntities;
            string[] processEntities;
            OrmCodeDomGeneratorSettings settings = new OrmCodeDomGeneratorSettings();
            bool validateOnly, testRun;

            if (cmdLine["?"] != null || cmdLine["h"] != null || cmdLine["help"] != null || args == null || args.Length == 0)
            {
                Console.WriteLine("Command line parameters:");
                Console.WriteLine("  -f\t- source xml file");
                Console.WriteLine("  -v\t- validate input file against schema only");
                Console.WriteLine("  -t\t- test run (generate files in memory)");
                Console.WriteLine("  -l\t- code language [cs, vb] (\"cs\" by default)");
                //Console.WriteLine("  -p\t- generate partial classes (\"false\" by default)");
                Console.WriteLine("  -sp\t- split entity class and entity's schema definition\n\t\t  class code by diffrent files (\"false\" by default)");
                Console.WriteLine("  -sk\t- skip entities");
                Console.WriteLine("  -e\t- entities to process");
                //Console.WriteLine("  -cB\t- behaviour of class codegenerator\n\t\t  [Objects, PartialObjects] (\"Objects\" by default)");
                Console.WriteLine("  -sF\t- create folder for each entity.");
                Console.WriteLine("  -o\t- output files folder.");
                Console.WriteLine("  -pmp\t- private members prefix (\"_\" by default)");
                Console.WriteLine("  -cnP\t- class name prefix (null by default)");
                Console.WriteLine("  -cnS\t- class name suffix (null by default)");
                Console.WriteLine("  -fnP\t- file name prefix (null by default)");
                Console.WriteLine("  -fnS\t- file name suffix (null by default)");
                return;
            }

            if (cmdLine["f"] != null)
            {
                inputFilename = cmdLine["f"];
            }
            else
            {
                Console.WriteLine("Please give 'f' parameter");
                return;
            }

            validateOnly = (cmdLine["v"] != null);
            testRun      = (cmdLine["t"] != null);

            if (cmdLine["l"] != null)
            {
                outputLanguage = cmdLine["l"];
            }
            else
            {
                outputLanguage = "CS";
            }

            if (cmdLine["sF"] != null)
            {
                separateFolder = true;
            }
            else
            {
                separateFolder = false;
            }
            LanguageSpecificHacks languageHacks = LanguageSpecificHacks.None;

            if (outputLanguage.ToUpper() == "VB")
            {
                codeDomProvider = new VBCodeProvider();
                languageHacks   = LanguageSpecificHacks.VisualBasic;
            }
            else if (outputLanguage.ToUpper() == "CS")
            {
                codeDomProvider = new CSharpCodeProvider();
                languageHacks   = LanguageSpecificHacks.CSharp;
            }
            else
            {
                Console.WriteLine("Error: incorrect value in \"l\" parameter.");
                return;
            }

            if (cmdLine["sp"] != null)
            {
                split = true;
            }
            else
            {
                split = false;
            }


            if (cmdLine["o"] != null)
            {
                outputFolder = cmdLine["o"];
            }
            else
            {
                outputFolder = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
                if (string.IsNullOrEmpty(outputFolder))
                {
                    outputFolder = System.IO.Path.GetPathRoot(System.Reflection.Assembly.GetExecutingAssembly().Location);
                }
            }

            if (cmdLine["sk"] != null)
            {
                skipEntities = cmdLine["sk"].Split(',');
            }
            else
            {
                skipEntities = new string[] { }
            };

            if (cmdLine["e"] != null)
            {
                processEntities = cmdLine["e"].Split(',');
            }
            else
            {
                processEntities = new string[] { }
            };

            if (cmdLine["pmp"] != null)
            {
                settings.PrivateMembersPrefix = cmdLine["pmp"];
            }

            if (cmdLine["fnP"] != null)
            {
                settings.FileNamePrefix = cmdLine["fnP"];
            }
            if (cmdLine["fnS"] != null)
            {
                settings.FileNameSuffix = cmdLine["fnS"];
            }

            if (cmdLine["cnP"] != null)
            {
                settings.ClassNamePrefix = cmdLine["cnP"];
            }
            if (cmdLine["cnS"] != null)
            {
                settings.ClassNameSuffix = cmdLine["cnS"];
            }

            if (!System.IO.File.Exists(inputFilename))
            {
                Console.WriteLine("Error: source file not found.");
                return;
            }

            if (!System.IO.Directory.Exists(outputFolder))
            {
                Console.WriteLine("Error: output folder not found.");
                return;
            }
            if (string.IsNullOrEmpty(System.IO.Path.GetDirectoryName(outputFolder)))
            {
                outputFolder = System.IO.Path.GetPathRoot(outputFolder + System.IO.Path.DirectorySeparatorChar.ToString());
            }
            else
            {
                outputFolder = System.IO.Path.GetDirectoryName(outputFolder + System.IO.Path.DirectorySeparatorChar.ToString());
            }

            try
            {
                Console.Write("Parsing file '{0}'...   ", inputFilename);
                using (XmlReader rdr = XmlReader.Create(inputFilename))
                {
                    ormObjectsDef = OrmObjectsDef.LoadFromXml(rdr, new XmlUrlResolver());
                }
                Console.WriteLine("done!");
                if (validateOnly)
                {
                    Console.WriteLine("Input file validation success.");
                    return;
                }
            }
            catch (Exception exc)
            {
                Console.WriteLine("error: {0}", exc.Message);
                if (exc.InnerException != null)
                {
                    Console.WriteLine("error: {0}", exc.InnerException.Message);
                }
                return;
            }

            if (!Directory.Exists(outputFolder))
            {
                try
                {
                    Directory.CreateDirectory(outputFolder);
                }
                catch (Exception)
                {
                }
            }

            OrmCodeDomGenerator gen = new OrmCodeDomGenerator(ormObjectsDef);


            settings.Split = split;
            settings.LanguageSpecificHacks = languageHacks;

            Console.WriteLine("Generation entities from file '{0}' using these settings:", inputFilename);
            Console.WriteLine("  Output folder: {0}", outputFolder);
            Console.WriteLine("  Language: {0}", outputLanguage.ToLower());
            Console.WriteLine("  Split files: {0}", split);
            Console.WriteLine("  Skip entities: {0}", string.Join(" ", skipEntities));
            Console.WriteLine("  Process entities: {0}", string.Join(" ", processEntities));


            List <string> errorList     = new List <string>();
            int           totalEntities = 0;
            int           totalFiles    = 0;

            foreach (EntityDescription entity in ormObjectsDef.Entities)
            {
                bool skip = false;
                if (processEntities.Length != 0)
                {
                    skip = true;
                    foreach (string processEntityId in processEntities)
                    {
                        if (processEntityId == entity.Identifier)
                        {
                            skip = false;
                            break;
                        }
                    }
                }
                foreach (string skipEntityId in skipEntities)
                {
                    if (skipEntityId == entity.Identifier)
                    {
                        skip = true;
                        break;
                    }
                }

                if (skip)
                {
                    continue;
                }

                string privateFolder;
                if (separateFolder)
                {
                    privateFolder = outputFolder + System.IO.Path.DirectorySeparatorChar.ToString() + entity.Name + System.IO.Path.DirectorySeparatorChar;
                }
                else
                {
                    privateFolder = outputFolder + System.IO.Path.DirectorySeparatorChar.ToString();
                }

                Dictionary <string, CodeCompileUnit> unitsDic;

                unitsDic = gen.GetEntityDom(entity.Identifier, settings);

                Console.Write(".");

                if (!System.IO.Directory.Exists(privateFolder))
                {
                    System.IO.Directory.CreateDirectory(privateFolder);
                }
                foreach (string name in unitsDic.Keys)
                {
                    Console.Write(".");
                    try
                    {
                        GenerateCode(codeDomProvider, unitsDic[name], System.IO.Path.GetFullPath(privateFolder + System.IO.Path.DirectorySeparatorChar.ToString() + name), testRun);
                        Console.Write(".");
                        totalFiles++;
                    }
                    catch (Exception exc)
                    {
                        Console.Write(".");
                        errorList.Add(
                            string.Format("Entity: {0}; file: {1}; message: {2}", entity.Identifier, name, exc.Message));
                    }
                }
                totalEntities++;
            }

            Console.WriteLine();

            Console.WriteLine("Result:");
            Console.WriteLine("\t {0} entities processed", totalEntities);
            Console.WriteLine("\t {0} files generated", totalFiles);
            Console.WriteLine("\t {0} errors encountered", errorList.Count);
            if (errorList.Count != 0)
            {
                Console.WriteLine("Errors:");
                foreach (string s in errorList)
                {
                    Console.WriteLine("\t" + s);
                    for (int i = 0; i < Console.WindowWidth; i++)
                    {
                        Console.Write("-");
                    }
                    Console.WriteLine();
                }
            }
        }
Exemplo n.º 12
0
        static void Main(string[] args)
        {
            Console.WriteLine("Orm xml schema generator. v0.1 2007");
            if (args.Length == 0)
            {
                ShowUsage();
                return;
            }

            CommandLine.Utility.Arguments param = new CommandLine.Utility.Arguments(args);

            string server = null;

            if (!param.TryGetParam("S", out server))
            {
                server = "(local)";
            }

            string m = null;

            if (!param.TryGetParam("M", out m))
            {
                m = "msft";
            }

            switch (m)
            {
            case "msft":
                //do nothing
                break;

            default:
                Console.WriteLine("Invalid manufacturer parameter.");
                ShowUsage();
                return;
            }

            string db = null;

            if (!param.TryGetParam("D", out db))
            {
                Console.WriteLine("Database is not specified");
                ShowUsage();
                return;
            }

            string e;
            string user = null;
            string psw  = null;

            if (!param.TryGetParam("E", out e))
            {
                e = "false";
                if (!param.TryGetParam("U", out user))
                {
                    Console.WriteLine("User is not specified");
                    ShowUsage();
                    return;
                }
                if (!param.TryGetParam("P", out psw))
                {
                    Console.Write("Password: "******"schemas", out schemas);

            string namelike = null;

            param.TryGetParam("name", out namelike);

            string file = null;

            if (!param.TryGetParam("O", out file))
            {
                file = server + ".xml";
            }

            string merge = null;

            if (!param.TryGetParam("F", out merge))
            {
                merge = "merge";
            }
            switch (merge)
            {
            case "merge":
            case "error":
                //do nothing
                break;

            default:
                Console.WriteLine("Invalid \"Existing file behavior\" parameter.");
                ShowUsage();
                return;
            }

            string drop = null;

            if (!param.TryGetParam("R", out drop))
            {
                drop = "false";
            }
            bool dr = bool.Parse(drop);

            string namesp = string.Empty;

            param.TryGetParam("N", out namesp);

            string u = null;

            if (!param.TryGetParam("Y", out u))
            {
                u = "false";
            }
            bool unify = bool.Parse(u);

            string tr = null;

            if (!param.TryGetParam("T", out tr))
            {
                tr = "false";
            }
            bool transform = bool.Parse(tr);

            Generator g = new Generator(server, m, db, i, user, psw, transform);

            g.MakeWork(schemas, namelike, file, merge, dr, namesp, unify);

            Console.WriteLine("Done!");
            //Console.ReadKey();
        }
Exemplo n.º 13
0
        static void Main(string[] args)
        {
            Console.WriteLine("Worm code generator utility.");
            Console.WriteLine();

            CommandLine.Utility.Arguments cmdLine = new CommandLine.Utility.Arguments(args);

            string          outputLanguage;
            string          outputFolder;
            WXMLModel       model;
            string          inputFilename;
            CodeDomProvider codeDomProvider;
            bool            split, separateFolder;

            string[] skipEntities;
            string[] processEntities;
            WXMLCodeDomGeneratorSettings settings = new WXMLCodeDomGeneratorSettings();

            if (cmdLine["?"] != null || cmdLine["h"] != null || cmdLine["help"] != null || args == null || args.Length == 0)
            {
                Console.WriteLine("Command line parameters:");
                Console.WriteLine("  -f\t- source xml file");
                Console.WriteLine("  -v\t- validate input file against schema only");
                Console.WriteLine("  -t\t- test run (generate files in memory)");
                Console.WriteLine("  -l\t- code language [cs, vb] (\"cs\" by default)");
                //Console.WriteLine("  -p\t- generate partial classes (\"false\" by default)");
                Console.WriteLine("  -sp\t- split entity class and entity's schema definition\n\t\t  class code by diffrent files (\"false\" by default)");
                Console.WriteLine("  -sk\t- skip entities");
                Console.WriteLine("  -e\t- entities to process");
                //Console.WriteLine("  -cB\t- behaviour of class codegenerator\n\t\t  [Objects, PartialObjects] (\"Objects\" by default)");
                Console.WriteLine("  -sF\t- create folder for each entity.");
                Console.WriteLine("  -o\t- output files folder.");
                Console.WriteLine("  -pmp\t- private members prefix (\"_\" by default)");
                Console.WriteLine("  -cnP\t- class name prefix (null by default)");
                Console.WriteLine("  -cnS\t- class name suffix (null by default)");
                Console.WriteLine("  -fnP\t- file name prefix (null by default)");
                Console.WriteLine("  -fnS\t- file name suffix (null by default)");
                Console.WriteLine("  -propsT\t- use type instead of entity name in props (false by default)");
                //Console.WriteLine("  -rm\t- remove old m2m methods (false by default)");
                Console.WriteLine("  -of\t- generate one file (false by default)");
                //Console.WriteLine("  -so\t- generate entity schema only (false by default)");
                return;
            }

            if (cmdLine["f"] != null)
            {
                inputFilename = cmdLine["f"];
            }
            else
            {
                Console.WriteLine("Please give 'f' parameter");
                return;
            }

            bool validateOnly = (cmdLine["v"] != null);
            bool testRun      = (cmdLine["t"] != null);

            if (cmdLine["l"] != null)
            {
                outputLanguage = cmdLine["l"];
            }
            else
            {
                outputLanguage = "CS";
            }

            if (cmdLine["sF"] != null)
            {
                separateFolder = true;
            }
            else
            {
                separateFolder = false;
            }
            LanguageSpecificHacks languageHacks = LanguageSpecificHacks.None;

            if (outputLanguage.ToUpper() == "VB")
            {
                codeDomProvider = new VBCodeProvider();
                languageHacks   = LanguageSpecificHacks.VisualBasic;
            }
            else if (outputLanguage.ToUpper() == "CS")
            {
                codeDomProvider = new CSharpCodeProvider();
                languageHacks   = LanguageSpecificHacks.CSharp;
            }
            else
            {
                Console.WriteLine("Error: incorrect value in \"l\" parameter.");
                return;
            }

            if (cmdLine["sp"] != null)
            {
                split = true;
            }
            else
            {
                split = false;
            }


            if (cmdLine["o"] != null)
            {
                outputFolder = cmdLine["o"];
            }
            else
            {
                outputFolder = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
                if (string.IsNullOrEmpty(outputFolder))
                {
                    outputFolder = Path.GetPathRoot(System.Reflection.Assembly.GetExecutingAssembly().Location);
                }
            }

            if (cmdLine["sk"] != null)
            {
                skipEntities = cmdLine["sk"].Split(',');
            }
            else
            {
                skipEntities = new string[] { }
            };

            if (cmdLine["e"] != null)
            {
                processEntities = cmdLine["e"].Split(',');
            }
            else
            {
                processEntities = new string[] { }
            };

            if (cmdLine["pmp"] != null)
            {
                settings.PrivateMembersPrefix = cmdLine["pmp"];
            }

            if (cmdLine["fnP"] != null)
            {
                settings.FileNamePrefix = cmdLine["fnP"];
            }
            if (cmdLine["fnS"] != null)
            {
                settings.FileNameSuffix = cmdLine["fnS"];
            }

            if (cmdLine["cnP"] != null)
            {
                settings.ClassNamePrefix = cmdLine["cnP"];
            }
            if (cmdLine["cnS"] != null)
            {
                settings.ClassNameSuffix = cmdLine["cnS"];
            }

            if (cmdLine["propsT"] != null)
            {
                settings.UseTypeInProps = true;
            }

            //if (cmdLine["rm"] != null)
            //{
            //    settings.RemoveOldM2M = true;
            //}

            //if (cmdLine["os"] != null)
            //{
            //    settings.OnlySchema = true;
            //}

            bool oneFile = false;

            if (cmdLine["of"] != null)
            {
                oneFile = true;
            }

            if (!File.Exists(inputFilename))
            {
                Console.WriteLine("Error: source file {0} not found.", inputFilename);
                return;
            }

            //if (!System.IO.Directory.Exists(outputFolder))
            //{
            //    Console.WriteLine("Error: output folder not found.");
            //    return;
            //}
            if (string.IsNullOrEmpty(Path.GetDirectoryName(outputFolder)))
            {
                outputFolder = Path.GetPathRoot(outputFolder + Path.DirectorySeparatorChar.ToString());
            }
            else
            {
                outputFolder = Path.GetDirectoryName(outputFolder + Path.DirectorySeparatorChar.ToString());
            }

            try
            {
                Console.Write("Parsing file '{0}'...   ", inputFilename);
                using (XmlReader rdr = XmlReader.Create(inputFilename))
                {
                    model = WXMLModel.LoadFromXml(rdr, new XmlUrlResolver());
                }
                Console.WriteLine("done!");
                if (validateOnly)
                {
                    Console.WriteLine("Input file validation success.");
                    return;
                }
            }
            catch (Exception exc)
            {
                Console.WriteLine("error: {0}", exc.Message);
                Console.WriteLine("callstack: {0}", exc.StackTrace);
                if (exc.InnerException != null)
                {
                    Console.WriteLine("error: {0}", exc.InnerException.Message);
                }
                return;
            }

            if (!Directory.Exists(outputFolder))
            {
                try
                {
                    Directory.CreateDirectory(outputFolder);
                }
                catch (Exception)
                {
                }
            }

            var gen = new WXMLToWorm.WormCodeDomGenerator(model, settings);


            //settings.Split = split;
            settings.LanguageSpecificHacks = languageHacks;

            Console.WriteLine("Generation entities from file '{0}' using these settings:", inputFilename);
            Console.WriteLine("  Output folder: {0}", System.IO.Path.GetFullPath(outputFolder));
            Console.WriteLine("  Language: {0}", outputLanguage.ToLower());
            Console.WriteLine("  Split files: {0}", split);
            Console.WriteLine("  Skip entities: {0}", string.Join(" ", skipEntities));
            Console.WriteLine("  Process entities: {0}", string.Join(" ", processEntities));


            if (oneFile)
            {
                string privateFolder = outputFolder + Path.DirectorySeparatorChar.ToString();

                CodeCompileUnit unit = gen.GetFullSingleUnit(typeof(VBCodeProvider).IsAssignableFrom(codeDomProvider.GetType()) ? LinqToCodedom.CodeDomGenerator.Language.VB : LinqToCodedom.CodeDomGenerator.Language.CSharp);

                if (!Directory.Exists(privateFolder))
                {
                    Directory.CreateDirectory(privateFolder);
                }

                string outputFileName = Path.GetFullPath(privateFolder + Path.DirectorySeparatorChar.ToString() +
                                                         Path.GetFileNameWithoutExtension(inputFilename));

                GenerateCode(codeDomProvider, unit, outputFileName, testRun);

                Console.WriteLine();

                Console.WriteLine("Result:");

                Console.WriteLine("\t{0} single generated.");
            }
            else
            {
                GenerateMultipleFilesOutput(outputFolder, model, codeDomProvider, separateFolder,
                                            skipEntities, processEntities, testRun, gen);
            }
        }
Exemplo n.º 14
0
        public static void Main(string[] args)
        {
            try
            {
                var arguments = new CommandLine.Utility.Arguments(args, true);

                string cometUrl = arguments.GetValueOrDefault("cometurl", "http://comet.apphb.com/comet.axd");

                string channel = arguments.GetValueOrDefault("channel");
                if (!channel.StartsWith("/"))
                    channel = "/" + channel;

                if (string.IsNullOrEmpty(channel))
                    throw new ArgumentException("Missing channel");

                var transports = new List<ClientTransport>();
                transports.Add(new LongPollingTransport(null));

                var client = new BayeuxClient(cometUrl, transports);

                client.getChannel(Channel_Fields.META + "/**")
                    .addListener(new MetaListener());

                client.handshake();
                client.waitFor(10000, new List<BayeuxClient.State>() { BayeuxClient.State.CONNECTED });
                if (!client.Connected)
                {
                    throw new InvalidOperationException("Failed to connect to comet server");
                }

                computerStatus = new Dictionary<string, bool?>(StringComparer.OrdinalIgnoreCase);

                bool listen = false;
                HashSet<string> waitForCompletion = null;
                int waitTimeoutSeconds = 30;

                StringBuilder jsonData = new StringBuilder();
                foreach (var kvp in arguments)
                {
                    switch (kvp.Key)
                    {
                        case "channel":
                        case "cometurl":
                            // Ignore
                            break;

                        case "listen":
                            listen = true;
                            break;
                        case "wait":
                            waitForCompletion = new HashSet<string>();
                            foreach (var server in kvp.Value.Split(','))
                                waitForCompletion.Add(server.Trim());
                            break;
                        case "waitsec":
                            waitTimeoutSeconds = int.Parse(kvp.Value);
                            break;
                        default:
                            Console.WriteLine(string.Format("Sending notify for data: {0}={1}", kvp.Key, kvp.Value));
                            if (jsonData.Length > 0)
                                jsonData.Append(',');
                            jsonData.AppendFormat("\"{0}\":\"{1}\"", kvp.Key, kvp.Value);
                            break;
                    }
                }

                var chn = client.getChannel(channel);

                var msgListener = new MsgListener();
                msgListener.StatusReceived += new EventHandler<StatusEventArgs>(MsgListener_StatusReceived);
                if (listen || waitForCompletion != null)
                {
                    chn.subscribe(msgListener);
                }

                client.waitForEmptySendQueue(1000);

                if (jsonData.Length > 0)
                {
                    chn.publish('{' + jsonData.ToString() + '}');
                    Console.WriteLine("Sending data: " + jsonData.ToString());
                }

                bool? overallResult = null;
                if (waitForCompletion != null)
                {
                    lastStatus = DateTime.Now;

                    while ((DateTime.Now - lastStatus).TotalSeconds <= waitTimeoutSeconds)
                    {
                        // Check if all servers have reported in
                        int failed = 0;
                        int succeeded = 0;
                        foreach (var server in waitForCompletion)
                        {
                            bool? status;
                            if (computerStatus.TryGetValue(server, out status))
                            {
                                if (status.HasValue)
                                {
                                    if (status.Value)
                                        succeeded++;
                                    else
                                        failed++;
                                }
                            }
                        }

                        if (failed + succeeded == waitForCompletion.Count)
                        {
                            // Done
                            overallResult = failed == 0;
                            break;
                        }

                        System.Threading.Thread.Sleep(100);
                    }

                    chn.unsubscribe(msgListener);
                }

                if (listen)
                {
                    Console.WriteLine("Hit <enter> to exit");
                    Console.ReadLine();

                    chn.unsubscribe(msgListener);
                }

                Console.WriteLine("Waiting for queue to be sent");
                client.waitForEmptySendQueue(1000);

                Console.WriteLine("Disconnecting");
                client.disconnect();
                client.waitFor(2000, new List<BayeuxClient.State>() { BayeuxClient.State.DISCONNECTED });

                if (waitForCompletion != null)
                {
                    foreach (var server in waitForCompletion)
                    {
                        bool? status;
                        computerStatus.TryGetValue(server, out status);

                        if (!status.HasValue)
                            Console.WriteLine(string.Format("{0} - no response", server));
                        else if(status.Value)
                            Console.WriteLine(string.Format("{0} - successful", server));
                        else
                            Console.WriteLine(string.Format("{0} - failure", server));
                    }

                    if (!overallResult.HasValue)
                    {
                        Console.WriteLine("Time out");
                        Environment.Exit(1);
                    }
                    else
                    {
                        if (overallResult.Value)
                        {
                            Console.WriteLine("Successful!");
                            Environment.Exit(0);
                        }
                        else
                        {
                            Console.WriteLine("Failure");
                            Environment.Exit(200);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error: " + ex.ToString());
                Environment.Exit(255);
            }
        }
Exemplo n.º 15
0
        static void Main(string[] args)
        {
            /*
             * WantedEncoding (mandatory)
             * Extensions CSV array of complete file paths
             * BasePath
             * SingleFile
             * Help
             */
            if (args == null || args.Length == 0)
            {
                PrintHelpMessage();
                return;
            }
            var compiledArgs = new CommandLine.Utility.Arguments(args);
            if (!string.IsNullOrEmpty(compiledArgs["Help"]))
            {
                PrintHelpMessage();
                return;
            }
            string wantedEncodingString = compiledArgs["WantedEncoding"];
            if (string.IsNullOrEmpty(wantedEncodingString))
            {
                PrintWantedEncodingNeeded();
                return;
            }

            Encoding wantedEncoding = Encoding.GetEncoding(wantedEncodingString);

            string singleFile = compiledArgs["SingleFile"];
            string basePath = compiledArgs["BasePath"];

            if (string.IsNullOrEmpty(singleFile) && string.IsNullOrEmpty(basePath))
            {
                PrintSingleOrBasePathNeeded();
                return;
            }

            if (!string.IsNullOrEmpty(singleFile))
            {
                if (!File.Exists(singleFile))
                {
                    PrintFileMissing(singleFile);
                    return;
                }
                if (ConvertToEncoding.EncodingConverter.Converter.ConvertSingleFile(singleFile, wantedEncoding))
                {
                    PrintFileModified(singleFile, wantedEncodingString);
                    return;
                }
                else
                {
                    PrintFileNotModified(singleFile, wantedEncodingString);
                    return;
                }
            }
            //If we got here, base path is not null
            string[] Extensions = null;
            string extensionParam = compiledArgs["Extensions"];
            if (!string.IsNullOrEmpty(extensionParam))
            {
                Extensions = extensionParam.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
            }

            string[] modified = ConvertToEncoding.EncodingConverter.Converter.Convert(new
                ConvertToEncoding.EncodingConverter.ConverterParams
                {
                    BasePath = basePath,
                    WantedEncoding = wantedEncoding,
                    Extensions = Extensions
                });

            PrintModifiedN(basePath, modified, wantedEncodingString);
        }
Exemplo n.º 16
0
        /// <summary>
        /// Review the command line parameters for a specific parameter
        /// If it is present then push the parameter into the provided variable
        /// </summary>
        /// <param name="ParameterVariable"></param>
        /// <param name="ParameterName"></param>
        /// <param name="CommandLine"></param>
        /// <returns></returns>
        private static int CheckAndSetParameters(ref string ParameterVariable, string ParameterName, CommandLine.Utility.Arguments CommandLine, Boolean AllowEmpty, string DefaultValue = "")
        {
            try
            {
                log.Debug("Verifying parameter " + ParameterName + " is not null");
                // Verify the parameter is present
                if (CommandLine[ParameterName] != null)
                {
                    // Set the variable if present
                    ParameterVariable = CommandLine[ParameterName].ToString();
                    log.Debug("Set " + ParameterName + " to " + ParameterVariable);
                }
                else
                {
                    log.Debug("Considering allowempty");
                    // If we are not allowing empties, then error.
                    if (!AllowEmpty)
                    {
                        // Warn the user the parameter is missing
                        throw new Exception("Missing parameter value for " + ParameterName);
                    }
                    else
                    {
                        // Set the return to an empty string
                        ParameterVariable = DefaultValue;
                        log.Debug("Set " + ParameterName + " to default value of " + ParameterVariable);
                    }
                }

                log.Debug("Returning Success");
                // Success
                return(0);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 17
0
        static void Main(string[] args)
        {
            Console.WriteLine("Worm xml schema generator. v0.3 2007");
            if (args.Length == 0)
            {
                ShowUsage();
                return;
            }

            CommandLine.Utility.Arguments param = new CommandLine.Utility.Arguments(args);

            string server = null;

            if (!param.TryGetParam("S", out server))
            {
                server = "(local)";
            }

            string dbName = null;

            if (!param.TryGetParam("D", out dbName))
            {
                if (!File.Exists(server))
                {
                    Console.WriteLine("Database is not specified or file {0} not found", server);
                    ShowUsage();
                    return;
                }
            }

            string e;
            string user = null;
            string psw  = null;

            if (!param.TryGetParam("E", out e))
            {
                e = "false";
                bool showUser = true;
                if (!param.TryGetParam("U", out user))
                {
                    Console.Write("User: "******"P", out psw))
                {
                    if (showUser)
                    {
                        Console.WriteLine("User: "******"Password: "******"schemas", out schemas);

            string namelike = null;

            param.TryGetParam("name", out namelike);

            string file = null;

            if (!param.TryGetParam("O", out file))
            {
                file = dbName + ".xml";
            }

            string merge = null;

            if (!param.TryGetParam("F", out merge))
            {
                merge = "merge";
            }
            switch (merge)
            {
            case "merge":
            case "error":
                //do nothing
                break;

            default:
                Console.WriteLine("Invalid \"Existing file behavior\" parameter.");
                ShowUsage();
                return;
            }

            string drop = null;

            if (!param.TryGetParam("R", out drop))
            {
                drop = "false";
            }
            bool dr = bool.Parse(drop);

            string namesp = dbName;

            param.TryGetParam("N", out namesp);

            string u = "true";

            if (!param.TryGetParam("Y", out u))
            {
                u = "false";
            }
            bool unify = bool.Parse(u);

            string hi = "true";

            if (!param.TryGetParam("H", out hi))
            {
                hi = "false";
            }
            bool hie = bool.Parse(hi);

            string tr = "true";

            if (!param.TryGetParam("T", out tr))
            {
                tr = "false";
            }
            bool transform = bool.Parse(tr);

            string es = "true";

            if (!param.TryGetParam("ES", out es))
            {
                es = "false";
            }
            bool escapeTables = bool.Parse(es);

            string ec = "true";

            if (!param.TryGetParam("EC", out ec))
            {
                ec = "false";
            }
            bool escapeColumns = bool.Parse(ec);

            string cn = "true";

            if (!param.TryGetParam("CN", out cn))
            {
                cn = "false";
            }
            bool capitalize = bool.Parse(cn);

            string ss = "false";

            if (!param.TryGetParam("SS", out ss))
            {
                ss = "false";
            }
            bool showStatement = bool.Parse(ss);

            string v = "1";

            if (!param.TryGetParam("V", out v))
            {
                v = "1";
            }

            DatabaseProvider dp = null;
            string           m  = null;

            if (!param.TryGetParam("M", out m))
            {
                m = "msft";
            }

            switch (m)
            {
            case "msft":
            case "mssql":
                if (i)
                {
                    dp = new MSSQLProvider(server, dbName);
                }
                else
                {
                    dp = new MSSQLProvider(server, dbName, user, psw);
                }

                break;

            case "sqlce":
                dp = new SQLCEProvider(server, psw);

                break;

            case "mysql":
                if (i)
                {
                    dp = new MySQLProvider(server, dbName);
                }
                else
                {
                    dp = new MySQLProvider(server, dbName, user, psw);
                }

                break;

            default:
                Console.WriteLine("Invalid manufacturer parameter.");
                ShowUsage();
                return;
            }

            dp.OnDatabaseConnecting += (sender, conn) => Console.WriteLine("Connecting to \"{0}\"...", FilterPsw(conn));
            dp.OnStartLoadDatabase  += (sender, cmd) => Console.WriteLine("Retriving tables via {0}...", showStatement ? cmd : string.Empty);

            SourceView db = dp.GetSourceView(schemas, namelike, escapeTables, escapeColumns);

            WXMLModel model = null;

            if (File.Exists(file))
            {
                if (merge == "error")
                {
                    Console.WriteLine("The file " + file + " is already exists.");
                    ShowUsage();
                    return;
                }
                Console.WriteLine("Loading file " + file);
                model = WXMLModel.LoadFromXml(new System.Xml.XmlTextReader(file));
            }
            else
            {
                model               = new WXMLModel();
                model.Namespace     = namesp;
                model.SchemaVersion = v;
                if (!Path.IsPathRooted(file))
                {
                    file = Path.Combine(Directory.GetCurrentDirectory(), file);
                }
                //File.Create(file);
            }

            SourceToModelConnector g = new SourceToModelConnector(db, model);

            Console.WriteLine("Generating xml...");
            HashSet <EntityDefinition> ents = new HashSet <EntityDefinition>();

            g.OnEntityCreated += (sender, entity) =>
            {
                Console.WriteLine("Create class {0} ({1})", entity.Name, entity.Identifier);
                ents.Add(entity);
            };

            g.OnPropertyCreated += (sender, prop, created) =>
            {
                EntityDefinition entity = prop.Entity;
                if (!ents.Contains(entity))
                {
                    ents.Add(entity);
                    Console.WriteLine("Alter class {0} ({1})", entity.Name, entity.Identifier);
                }
                Console.WriteLine("\t{1} property {2}.{0}", prop.Name, created ? "Add" : "Alter", entity.Name);
            };

            g.OnPropertyRemoved += (sender, prop) => Console.WriteLine("Remove: {0}.{1}", prop.Entity.Name, prop.Name);

            g.ApplySourceViewToModel(dr,
                                     hie ? relation1to1.Hierarchy : unify ? relation1to1.Unify : relation1to1.Default,
                                     transform,
                                     capitalize,
                                     dp.CaseSensitive);

            using (System.Xml.XmlTextWriter writer = new System.Xml.XmlTextWriter(file, Encoding.UTF8))
            {
                writer.Formatting = System.Xml.Formatting.Indented;
                model.GetXmlDocument().Save(writer);
            }

            Console.WriteLine("Done!");
            //Console.ReadKey();
        }