Exemple #1
0
 public static void Run <TTask, TConfig>(string[] args)
     where TTask : TaskBase <TTask, TConfig>, new()
     where TConfig : TaskConfigBase <TTask, TConfig>, new()
 {
     if (args.FirstOrDefault() == "/?")
     {
         Console.WriteLine(RunParams.GetHelp());
     }
     else
     {
         Run <TTask, TConfig>(RunParams.FromConsoleArgs(args));
     }
 }
Exemple #2
0
        public static void Run <TTask, TConfig>(RunParams runParams)
            where TTask : TaskBase <TTask, TConfig>, new()
            where TConfig : TaskConfigBase <TTask, TConfig>, new()
        {
            var config = Phase.Run("Create config", () => CreateConfig <TConfig>(runParams.ConfigFullPath));

            if (runParams.ShowUi)
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new TaskToolWindow(runParams, typeof(TConfig), config, (cfg, ctrl) => RunInternal(ctrl, (TConfig)cfg)));
            }
            else
            {
                using (var logger = new Logger(new ConsoleEndpoint(), FileEndpoint.CreateForLogFile()))
                    RunInternal(new ControllerImpl(logger), config);
            }
        }
Exemple #3
0
        public static RunParams FromConsoleArgs(string[] args)
        {
            //  no parameters, launch the UI
            if (args.Length == 0)
            {
                return(new RunParams()
                {
                    ShowUi = true,
                    Wait = true,
                    ConfigFullPath = null
                });
            }
            else
            {
                //  always assume the first parameter is a config path
                var result = new RunParams {
                    ConfigFullPath = Path.GetFullPath(args[0])
                };

                //  read pairs and set values
                for (int i = 1; i < args.Length; i += 2)
                {
                    var key   = args[i];
                    var value = args[i + 1];

                    if (!properties.TryGetValue(key, out var prop))
                    {
                        throw new Exception($"Invalid RunParams property '{key}'");
                    }

                    prop.SetValue(result, Convert.ChangeType(value, prop.PropertyType));
                }

                return(result);
            }
        }