Пример #1
0
 public ConsoleApplication(
     IConsoleWorkerRole worker,
     IArgsParser <TSettings> parser,
     IConsoleStatic console)
 {
     this.worker  = worker ?? throw new ArgumentNullException(nameof(worker));
     this.parser  = parser ?? throw new ArgumentNullException(nameof(parser));
     this.console = console;
 }
        public ConsoleController(IConsoleView view, IArgsParser <string> argsParser)
        {
            mView = view ?? throw new ArgumentNullException("view");

            mView.ClearOutput();

            mArgsParser = argsParser ?? throw new ArgumentNullException("argsParser");

            mView.OnNewCommandSubmited += _processNewCommand;

            mCommandsTable = new Dictionary <string, IConsoleCommand>();
        }
        /// <summary>
        /// Initializes the application and begins executing update cycles. This should be called on application startup.
        /// </summary>
        /// <typeparam name="TWorkerRole">The type of the worker that extends from <see cref="WorkerRoleBase{TSettings}"/>.</typeparam>
        /// <param name="args">Arguments passed in from the command line.</param>
        /// <param name="settings">The settings object.</param>
        /// <param name="worker">The worker object.</param>
        /// <param name="parser">The parser object.</param>
        /// <param name="log">The logging object to use for initializing logging.</param>
        /// <returns>
        /// 0 - The application ran successfully.
        /// 1 - There was an error parsing <paramref name="args"/>.
        /// </returns>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="args"/> is null.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="settings"/> is null.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="worker"/> is null.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="parser"/> is null.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="log"/> is null.
        /// </exception>
        public static int Run <TWorkerRole>(
            string[] args,
            TSettings settings,
            TWorkerRole worker,
            IArgsParser <TSettings> parser,
            ILog log)
            where TWorkerRole : WorkerRoleBase <TSettings>
        {
            Application <TSettings> app;

            if (Environment.UserInteractive)
            {
                app = new ConsoleApplication <TSettings>(worker, parser, new ConsoleStaticAdapter());
            }
            else
            {
                app = new ServiceApplication <TSettings>(worker, new ServiceBaseStaticAdapter());
            }

            var directory = new DirectoryStaticAdapter();
            var telemetryConfiguration = TelemetryConfiguration.Active;

            return(app.RunAsync(args, settings, directory, log, telemetryConfiguration).GetAwaiter().GetResult());
        }
Пример #4
0
 public void Init()
 {
     mArgsParser = new ConsoleArgsParser();
 }