Пример #1
0
        protected override Task Run(ArgAction toRun)
        {
            ConsoleOutInterceptor.Instance.Attach();
            toRun.Invoke();
            var output = ConsoleOutInterceptor.Instance.ReadAndClear();

            ConsoleOutInterceptor.Instance.Detatch();
            WriteLine(new ConsoleString(output));
            return(Task.CompletedTask);
        }
        /// <summary>
        /// Point d'entrée principal de l'application.
        /// </summary>
        static int Main(string[] args)
        {
            var exitCode = ExitCode.Error;
            var runMode  = RunMode.Canceled;
            ArgAction <App.CommandLine.Args> action = null;

            //) Parse la ligne de commande
            // Avec PowerArgs, on ne peut pas avoir une action par défaut => si args est empty, action = exe
            if (args.Length == 0)
            {
                runMode = RunMode.Exe;
            }
            else
            {
                action = PowerArgs.Args.InvokeAction <App.CommandLine.Args>(args);
                if (action.HandledException == null)
                {
                    if (action.Cancelled)
                    {
                        // cancelled est vrai quand l'aide ou la version est affichée
                        exitCode = ExitCode.Canceled;
                    }
                    else
                    {
                        // Action (Install / Uninstall)
                        runMode = action.Args.ParsedRunMode;
                    }
                }
            }

            //) Installation / Désinstallation / Demarrage normal
            switch (runMode)
            {
            case RunMode.Install:
                Installer.Install(Assembly.GetExecutingAssembly(), action.Args.ParsedInstallArgs);
                exitCode = ExitCode.Success;
                break;

            case RunMode.Uninstall:
                Installer.Uninstall(Assembly.GetExecutingAssembly());
                exitCode = ExitCode.Success;
                break;

            case RunMode.Exe:
            {
                ServiceBase[] ServicesToRun;
                ServicesToRun = new ServiceBase[] { new Service() };
                ServiceBase.Run(ServicesToRun);
            }
            break;
            }

            //) Fin
            return((int)exitCode);
        }
Пример #3
0
        public void ArgActionInvokeThrowsOnNullAction()
        {
            var args      = new string[] { };
            var argAction = new ArgAction <ActionTestArgs>();

            // Not setting .ActionArgs or .Args to leave them as null.

            try
            {
                argAction.Invoke();
                Assert.Fail("Should have thrown an exception.");
            }
            catch (Exception ex)
            {
                Assert.IsInstanceOfType(ex, typeof(MissingArgException));
                Assert.AreEqual("No action was specified", ex.Message);
            }
        }
Пример #4
0
        public void ArgActionInvokeThrowsOnNullAction()
        {
            var args = new string[] { };
            var argAction = new ArgAction<ActionTestArgs>();

            // Not setting .ActionArgs or .Args to leave them as null.

            try
            {
                argAction.Invoke();
                Assert.Fail("Should have thrown an exception.");
            }
            catch (Exception ex)
            {
                Assert.IsInstanceOfType(ex, typeof(MissingArgException));
                Assert.AreEqual("No action was specified", ex.Message);
            }
        }
Пример #5
0
 protected virtual Task <ConsoleString> Run(ArgAction toRun)
 {
     toRun.Invoke();
     return(Task.FromResult("Command finished".ToCyan()));
 }
Пример #6
0
 protected virtual Task Run(ArgAction toRun)
 {
     toRun.Invoke();
     WriteLine("Command finished".ToCyan());
     return(Task.CompletedTask);
 }
Пример #7
0
 protected virtual Task Run(ArgAction toRun)
 {
     toRun.Invoke();
     SetOutput(null);
     return(Task.CompletedTask);
 }