Esempio n. 1
0
        /// <summary>
        /// process comand line arguments</summary>
        public void ParseCommandLineArguments(string[] args) // [PARSE] [COMMAND LINE] UID5172911205
        {
            // options - create new file with given name if not exist
            bool CommandLineCreateIfNotExistFile = false;

            bool ShowCommandLineHelp = false;
            bool ShowDebugConsole    = false;

            // list of diagram files names for open
            List <String> CommandLineOpen = new List <String>();

            String arg;

            for (int i = 0; i < args.Length; i++)
            {
                //skip application name
                if (i == 0)
                {
                    continue;
                }

                // current processing argument
                arg = args[i];

                // [COMAND LINE] [CREATE]  oprions create new file with given name if not exist
                if (arg == "-h" || arg == "--help" || arg == "/?")
                {
                    ShowCommandLineHelp = true;
                    break;
                }
                if (arg == "-c" || arg == "--console")
                {
                    ShowDebugConsole = true;
                    break;
                }

                if (arg == "-e")
                {
                    CommandLineCreateIfNotExistFile = true;
                    break;
                }

                // [COMAND LINE] [OPEN] check if argument is diagram file
                if (Os.GetExtension(arg).ToLower() == ".diagram")
                {
                    CommandLineOpen.Add(arg);
                    break;
                }

                Program.log.Write("bed commmand line argument: " + arg);
            }

            if (ShowDebugConsole)
            {
                this.ShowConsole();
            }

            // open diagram given as arguments
            if (ShowCommandLineHelp)
            {
                String help =
                    "diagram -h --help /?  >> show this help\n" +
                    "diagram -c --console /?  >> show debug console\n" +
                    "diagram -e {filename} >> create file if not exist\n" +
                    "diagram {filepath} {filepath} >> open existing file\n";
                MessageBox.Show(help, "Command line parameters");
                return;
            }

            if (CommandLineOpen.Count == 0)
            {
                if (this.programOptions.defaultDiagram != "" && Os.FileExists(this.programOptions.defaultDiagram))
                {
                    this.OpenDiagram(this.programOptions.defaultDiagram); // open default diagram if default diagram is set
                }
                else if (this.programOptions.openLastFile && this.programOptions.recentFiles.Count > 0 && Os.FileExists(this.programOptions.recentFiles[0]))
                {
                    this.OpenDiagram(this.programOptions.recentFiles[0]); // open last file if user option is enabled UID2130542088
                }
                else
                {
                    this.OpenDiagram(); //open empty diagram UID5981683893
                }

                return;
            }

            for (int i = 0; i < CommandLineOpen.Count; i++)
            {
                string file = CommandLineOpen[i];

                // tray create diagram file if command line option is set
                if (CommandLineCreateIfNotExistFile && !Os.FileExists(file))
                {
                    try
                    {
                        Os.CreateEmptyFile(file);
                    }
                    catch (Exception ex)
                    {
                        Program.log.Write("create empty diagram file error: " + ex.Message);
                    }
                }

                if (Os.FileExists(file))
                {
                    this.OpenDiagram(file); //UID2130542088
                }
            }

            // cose application if is not diagram model opened
            this.CloseEmptyApplication();
        }