Exemplo n.º 1
0
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);

            var container = InitializeContainer();

            Bootstrap(container);

            MainWindow = container.Resolve <MainWindow>();
            MainWindow.Show();

            _argumentManager = container.Resolve <IArgumentManager>();

            Exit += Shutdown(container);

            try
            {
                var brush = new SolidColorBrush(WindowsColorHelper.GetSystemAccentColor());
                Resources["SystemAccentBrush"] = brush;
                Resources["SystemAccentColor"] = brush.Color;
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// .ctor
        /// </summary>
        public FileWriter(IArgumentManager argumentManager)
        {
            _ = argumentManager ?? throw new ArgumentNullException(nameof(argumentManager));
            var filePath = argumentManager.GetOutputArgument() ?? throw new ArgumentNullException("Path outputfile is null.");

            _streamWriter = new StreamWriter(filePath);
        }
        public override ICommandParserResult Parse(IArgumentManager argumentManager)
        {
            var result = new CommandParserResult(this);
            var errors = new List <Exception>();

            ParseCommands(errors, result, argumentManager);

            ParseOptions(errors, result, argumentManager);

            result.MergeResult(errors);

            return(result);
        }
Exemplo n.º 4
0
        public CommandLineCommand(CommandLineParserOptions parserOptions, IServiceProvider serviceProvider, TOption option, IValidatorsContainer validators, ILogger logger, IModelInitializer modelInitializer, IArgumentManager argumentManager)
        {
            m_parserOptions = parserOptions ?? throw new ArgumentNullException(nameof(parserOptions));
            m_commandOption = new TCommandOption();

            m_validators          = validators ?? throw new ArgumentNullException(nameof(validators));
            this.logger           = logger ?? throw new ArgumentNullException(nameof(logger));
            this.modelInitializer = modelInitializer ?? throw new ArgumentNullException(nameof(modelInitializer));
            this.argumentManager  = argumentManager ?? throw new ArgumentNullException(nameof(argumentManager));
            m_serviceProvider     = serviceProvider ?? throw new ArgumentNullException(nameof(serviceProvider));
            m_baseOption          = option ?? throw new ArgumentNullException(nameof(option));

            (m_helpOptionName, m_helpOptionNameLong) = parserOptions.GetConfiguredHelpOption();

            InitialzeModel();
        }
        private void ParseOptions(IList <Exception> errors, ParseResult <TOption> result, IArgumentManager argumentManager)
        {
            foreach (var o in m_options)
            {
                try
                {
                    var  option = o.Value;
                    bool found  = argumentManager.TryGetValue(option, out ArgumentModel model);

                    if (found && HelpRequested(result, option, model))
                    {
                        break;
                    }
                    else if (!found && option.IsRequired && !option.HasDefault)
                    {
                        throw new OptionNotFoundException(option);
                    }
                    else if ((!found && !model.HasValue && option.HasDefault) ||
                             (found && !option.CanParse(model) && option.HasDefault))
                    {
                        option.UseDefault();

                        continue;
                    }
                    else if (found && !option.CanParse(model))
                    {
                        throw new OptionParseException(option, model);
                    }

                    option.Parse(model);
                }
                catch (Exception ex)
                {
                    errors.Add(ex);
                }
            }

            result.MergeResult(m_option);
        }
        private void ParseCommands(IList <Exception> errors, ParseResult <TOption> result, IArgumentManager argumentManager)
        {
            foreach (var cmd in m_commands)
            {
                try
                {
                    if (!argumentManager.TryGetValue(cmd, out _))
                    {
                        result.MergeResult(new CommandNotFoundParserResult(cmd));

                        if (cmd.IsRequired)
                        {
                            throw new CommandNotFoundException(cmd);
                        }

                        continue;
                    }

                    var cmdParseResult = cmd.Parse(argumentManager);

                    if (result.HelpRequested)
                    {
                        break;
                    }

                    result.MergeResult(cmdParseResult);

                    if (cmdParseResult.HasErrors)
                    {
                        throw new CommandParseException(cmd, cmdParseResult.Errors);
                    }
                }
                catch (Exception ex)
                {
                    errors.Add(ex);
                }
            }
        }
 public abstract ICommandParserResult Parse(IArgumentManager argumentManager);
Exemplo n.º 8
0
 /// <summary>
 /// .ctor
 /// </summary>
 public FileInputReader(IArgumentManager argumentManager)
 {
     _filePath = argumentManager?.GetInputArgument() ?? throw new ArgumentNullException(nameof(argumentManager));
 }