Ejemplo n.º 1
0
        public static T Read <T>(string type, string file) where T : new()
        {
            var returnValue = new T();

            if (File.Exists(file))
            {
                try
                {
                    returnValue = JsonConvert.DeserializeObject <T>(File.ReadAllText(file));
                    Logger.Info(
                        $"{type} settings read as {returnValue}");
                }
                catch (Exception ex)
                {
                    Logger.Error(ex, $"Error when parsing {file} for {type} Settings");
                    Presenter.ShowError($"Could not parse settings file {file}, so going with default {type} settings",
                                        Logger);
                }
            }
            else
            {
                Presenter.ShowMessage($"Could not find {file} so going with default {type} settings", Logger);
            }
            return(returnValue);
        }
Ejemplo n.º 2
0
        public Result Run(params Argument[] args)
        {
            Result result      = null;
            var    description = ToDescription(args);

            try
            {
                if (_showHelpContext)
                {
                    Presenter.NewLine();
                    Presenter.ShowMessage($"{description}:", Logger);
                    Presenter.NewLine();
                }
                result = RunCore(args);
            }
            catch (AggregateException ae)
            {
                var inner = ae.InnerExceptions.FirstOrDefault(e => e is HttpRequestException);
                if (inner != null)
                {
                    result = BadConnectionFailureFromException(ae);
                }
                else
                {
                    result = GenericFailureFromException(ae);
                }
            }
            catch (HttpRequestException re)
            {
                result = BadConnectionFailureFromException(re);
            }
            catch (Exception ex)
            {
                Logger.Error(ex, "An unexpected error occurred while executing this option");
                result = GenericFailureFromException(ex);
            }
            finally
            {
                if (_showHelpContext)
                {
                    Presenter.NewLine();
                    Presenter.ShowMessage($"Finished {description} with result: {result}", Logger);
                }
            }
            return(result);
        }
Ejemplo n.º 3
0
        public void ShowHelp()
        {
            if (_groupSpecification.ValueSpecifications.Length > 0 && _groupSpecification.ToString().Length > 0)
            {
                Presenter.ShowMessage($"-- {_groupSpecification} --", Logger);
            }
            if (_childGroups.Count > 0)
            {
                foreach (var childGroup in _childGroups)
                {
                    childGroup.ShowHelp();
                    Presenter.NewLine();
                }

                Presenter.NewLine();
                Presenter.ShowMessage("-- other options --", Logger);
            }

            foreach (var optionPair in _childOptions)
            {
                var help = new HelpOption(this, optionPair.Value, optionPair.Key);
                help.Run();
            }
        }
Ejemplo n.º 4
0
 public void ShowOptionHelp()
 {
     Presenter.ShowMessage($"{_specification} <- {_option}", Logger);
     _option.NotifyHelpWasShown();
 }