예제 #1
0
        public EAppExitCode run()
        {
            EAppExitCode errorCode = EAppExitCode.OK;

            if (_interactive)
            {
                log.Debug("Running in interactive CLI mode");
                errorCode = Interactive();
            }
            else
            {
                log.Debug("Running in non-interactive CLI mode");

                if (_ac.NonOptionArgs.Count > 0)                  // non-interactive cmd line; retruns error code 0 if command reply is not error
                {
                    var input = string.Join(" ", _ac.NonOptionArgs);
                    errorCode = NonInteractive(input);
                }
                else                 // non-interactive but no params
                {
                    log.Error("No commands passed on the command line!");
                    errorCode = EAppExitCode.CmdLineError;
                }
            }

            return(errorCode);
        }
예제 #2
0
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        static int Main()
        {
            #if Windows
            //Console.WriteLine("Windows!");
            #endif

            EAppExitCode exitCode = EAppExitCode.OK;

            try
            {
                log.Debug($"Started with cmdLine: {Environment.CommandLine}");
                var ac = new AppConfig();
                if (ac.HadErrors)
                {
                    log.Error("Error parsing command line arguments.\n" + ac.GetUsageHelpText());
                    exitCode = EAppExitCode.CmdLineError;
                }
                else
                {
                    IApp?app = null;

                    switch (ac.Mode.ToLower())
                    {
                    default:
                    case "cli":
                    {
                        app = new CliApp(ac, interactive: false);
                        break;
                    }

                    case "telnet":
                    {
                        app = new CliApp(ac, interactive: true);
                        break;
                    }
                    }

                    if (app != null)
                    {
                        exitCode = app.run();
                        app.Dispose();
                    }

                    log.Debug($"Exiting gracefully with exitCode {(int)exitCode} ({exitCode}).");
                }
            }
            catch (Exception ex)
            {
                log.Error("Exception", ex);
                exitCode = EAppExitCode.ExceptionError;
            }

            return(( int )exitCode);
        }
예제 #3
0
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        static int Main()
        {
            EAppExitCode exitCode = EAppExitCode.NoError;

            //try
            {
                log.Info($"Started with cmdLine: {Environment.CommandLine}");
                var ac = new AppConfig();
                if (ac.HadErrors)
                {
                    log.Error("Error parsing command line arguments.\n" + ac.GetUsageHelpText());
                    exitCode = EAppExitCode.CmdLineError;
                }
                else
                {
                    switch (ac.Mode)
                    {
                    default:
                    case "Gui":
                    {
                        var app = new GuiApp(ac);
                        exitCode = app.run();
                        app.Dispose();
                        break;
                    }

                    case "AllInOneDebug":
                    {
                        var app = new AllInOneDebugApp(ac);
                        exitCode = app.run();
                        app.Dispose();
                        break;
                    }
                    }
                    log.Debug($"Exiting gracefully with exitCode {(int)exitCode} ({exitCode}).");
                }
            }
            //catch( Exception ex )
            //{
            //	log.Error( ex );
            //	exitCode = EAppExitCode.ExceptionError;
            //}

            return(( int )exitCode);
        }
예제 #4
0
        // returns error code of the last failed command (or OK if all ok)
        EAppExitCode NonInteractive(string input)
        {
            var          split = input.Split(';');
            EAppExitCode err   = EAppExitCode.OK;

            foreach (var subcmd in split)
            {
                if (string.IsNullOrEmpty(subcmd))
                {
                    continue;
                }
                var subErr = NonInteractiveSubCmd(subcmd);
                if (subErr != EAppExitCode.OK)
                {
                    err = subErr;
                }
            }
            return(err);
        }
예제 #5
0
파일: Program.cs 프로젝트: pjanec/dirigent
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        static int Main()
        {
            #if Windows
            //Console.WriteLine("Windows!");
            #endif

            EAppExitCode exitCode = EAppExitCode.OK;

            try
            {
                log.Info($"Started with cmdLine: {Environment.CommandLine}");
                var ac = new AppConfig();
                if (ac.HadErrors)
                {
                    log.Error("Error parsing command line arguments.\n" + ac.GetUsageHelpText());
                    exitCode = EAppExitCode.CmdLineError;
                }
                else
                {
                    IApp?app = null;

                    switch (ac.Mode.ToLower())
                    {
                    //case "gui":  // just gui, no agent
                    //{
                    //	app = new AgentMasterApp( ac, isAgent: false, isMaster: Tools.BoolFromString( ac.IsMaster ), runGui:true );
                    //	break;
                    //}

                    //// agent + gui
                    //case "traygui":  // for compatibility with Dirigent 1.x
                    //case "trayapp":  // for compatibility with Dirigent 1.x
                    //case "trayagentgui":
                    //{
                    //	app = new AgentMasterApp( ac, isAgent: true, isMaster: Tools.BoolFromString( ac.IsMaster ), runGui:true );
                    //	break;
                    //}

                    // just agent (no gui)
                    case "":
                    case "daemon":
                    case "agent":
                    {
                        app = new AgentMasterApp(ac, isAgent: true, isMaster: Tools.BoolFromString(ac.IsMaster));
                        break;
                    }

                    // master only
                    case "master":
                    {
                        app = new AgentMasterApp(ac, isAgent: false, isMaster: true);
                        break;
                    }


                    //case "cli":
                    //{
                    //	app = new CliApp( ac, interactive: false );
                    //	break;
                    //}

                    //case "telnet":
                    //{
                    //	app = new CliApp( ac, interactive: true );
                    //	break;
                    //}

                    default:
                    {
                        log.Error($"Invalid app mode '{ac.Mode}'");
                        break;
                    }
                    }

                    if (app != null)
                    {
                        exitCode = app.run();
                        app.Dispose();
                    }

                    log.Debug($"Exiting gracefully with exitCode {(int)exitCode} ({exitCode}).");
                }
            }
            catch (Exception ex)
            {
                log.Error("Exception", ex);
                exitCode = EAppExitCode.ExceptionError;
            }

            return(( int )exitCode);
        }
예제 #6
0
        static int Main()
        {
            EAppExitCode exitCode = EAppExitCode.NoError;

            // debugging feature - shows console and waits for pressing Return before continuing with whatever else
            if (Environment.CommandLine.Contains("--attachdebugger"))
            {
                AllocConsole();
                Console.WriteLine("Attach the debugger and press Return to continue...");
                Console.ReadLine();
            }

            try
            {
                log.Info($"Started with cmdLine: {Environment.CommandLine}");
                var ac = new AppConfig();
                if (ac.HadErrors)
                {
                    log.Error("Error parsing command line arguments.\n" + ac.GetUsageHelpText());
                    exitCode = EAppExitCode.CmdLineError;
                }
                else
                {
                    bool runAgent = false;
                    bool runGui   = true;
                    bool isMaster = Tools.BoolFromString(ac.IsMaster);

                    switch (ac.Mode.ToLower())
                    {
                    // just gui, no agent
                    case "remoteControlGui":                              // for compatibility with Dirigent 1.x
                    case "gui":
                    {
                        runAgent = false;
                        runGui   = true;
                        break;
                    }

                    // agent + gui
                    default:
                    case "agent":
                    case "traygui":                              // for compatibility with Dirigent 1.x
                    case "trayapp":                              // for compatibility with Dirigent 1.x
                    {
                        runAgent = true;
                        runGui   = true;
                        break;
                    }

                    // just agent (no gui)
                    case "daemon":
                    {
                        runAgent = true;
                        runGui   = false;
                        break;
                    }

                    // master only
                    case "master":
                    {
                        runAgent = false;                                  // master is part of agent executable; if run with "--mode master", just master will run
                        runGui   = false;
                        isMaster = true;
                        break;
                    }
                    }

                    IApp app = new GuiTrayApp(ac, runAgent, runGui, isMaster);
                    exitCode = app.run();
                    app.Dispose();
                    log.Debug($"Exiting gracefully with exitCode {(int)exitCode} ({exitCode}).");
                }
            }
            catch (Exception ex)
            {
                log.Error(ex);
                exitCode = EAppExitCode.ExceptionError;
            }

            return(( int )exitCode);
        }