Exemple #1
0
        private void localsCommandButton_OnClick(object sender, EventArgs e)
        {
            updateLocalsCommandStatusText(string.Format(Resources.ShowMessage_LocalsCommandWorking), visibility: true);
            var arguments = new List <string> {
                "all"
            };
            var settings       = ServiceLocator.GetInstance <ISettings>();
            var logError       = new LocalsArgs.Log(LogError);
            var logInformation = new LocalsArgs.Log(LogInformation);
            var localsArgs     = new LocalsArgs(arguments, settings, logInformation, logError, clear: true, list: false);

            _outputConsoleLogger.Start();
            try
            {
                _localsCommandRunner.ExecuteCommand(localsArgs);
                updateLocalsCommandStatusText(string.Format(Resources.ShowMessage_LocalsCommandSuccess, DateTime.Now.ToString(Resources.Culture)), visibility: true);
            }
            catch (Exception ex)
            {
                updateLocalsCommandStatusText(string.Format(Resources.ShowMessage_LocalsCommandFailure, DateTime.Now.ToString(Resources.Culture), ex.Message), visibility: true);
                LogError(string.Format(Resources.ShowMessage_LocalsCommandFailure, DateTime.Now.ToString(Resources.Culture), ex.Message));
                ActivityLog.LogError(NuGetUI.LogEntrySource, ex.ToString());
            }
            finally
            {
                _outputConsoleLogger.End();
            }
        }
        private void OnLocalsCommandButtonOnClick(object sender, EventArgs e)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            UpdateLocalsCommandStatusText(string.Format(CultureInfo.CurrentCulture, Resources.ShowMessage_LocalsCommandWorking), visibility: true);

            NuGetUIThreadHelper.JoinableTaskFactory.RunAsync(async() =>
            {
                try
                {
                    _outputConsoleLogger.Start();
                    await TaskScheduler.Default;
                    var arguments = new List <string> {
                        "all"
                    };
                    var settings       = await ServiceLocator.GetComponentModelServiceAsync <ISettings>();
                    var logError       = new LocalsArgs.Log(LogError);
                    var logInformation = new LocalsArgs.Log(LogInformation);
                    var localsArgs     = new LocalsArgs(arguments, settings, logInformation, logError, clear: true, list: false);
                    _localsCommandRunner.ExecuteCommand(localsArgs);
                    await UpdateLocalsCommandStatusTextAsync(string.Format(CultureInfo.CurrentCulture, Resources.ShowMessage_LocalsCommandSuccess, DateTime.Now.ToString(Resources.Culture)), visibility: true);
                }
                catch (Exception ex)
                {
                    await UpdateLocalsCommandStatusTextAsync(string.Format(CultureInfo.CurrentCulture, Resources.ShowMessage_LocalsCommandFailure, DateTime.Now.ToString(Resources.Culture), ex.Message), visibility: true);
                    LogError(string.Format(Resources.ShowMessage_LocalsCommandFailure, DateTime.Now.ToString(Resources.Culture), ex.Message));
                    ActivityLog.LogError(NuGetUI.LogEntrySource, ex.ToString());
                }
                finally
                {
                    _outputConsoleLogger.End();
                }
            }).PostOnFailure(nameof(GeneralOptionControl), nameof(OnLocalsCommandButtonOnClick));
        }
Exemple #3
0
        public static void Register(CommandLineApplication app, Func <ILogger> getLogger)
        {
            app.Command("locals", locals =>
            {
                locals.Description = Strings.LocalsCommand_Description;
                locals.HelpOption(XPlatUtility.HelpOption);

                locals.Option(
                    CommandConstants.ForceEnglishOutputOption,
                    Strings.ForceEnglishOutput_Description,
                    CommandOptionType.NoValue);

                var clear = locals.Option(
                    "-c|--clear",
                    Strings.LocalsCommand_ClearDescription,
                    CommandOptionType.NoValue);

                var list = locals.Option(
                    "-l|--list",
                    Strings.LocalsCommand_ListDescription,
                    CommandOptionType.NoValue);

                var arguments = locals.Argument(
                    "Cache Location(s)",
                    Strings.LocalsCommand_ArgumentDescription,
                    multipleValues: false);

                locals.OnExecute(() =>
                {
                    var logger  = getLogger();
                    var setting = Settings.LoadDefaultSettings(root: null, configFileName: null, machineWideSettings: null);
                    // Using both -clear and -list command options, or neither one of them, is not supported.
                    // We use MinArgs = 0 even though the first argument is required,
                    // to avoid throwing a command argument validation exception and
                    // immediately show usage help for this command instead.
                    if ((arguments.Values.Count < 1) || string.IsNullOrWhiteSpace(arguments.Values[0]))
                    {
                        throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Strings.LocalsCommand_NoArguments));
                    }
                    else if (clear.HasValue() && list.HasValue())
                    {
                        throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Strings.LocalsCommand_MultipleOperations));
                    }
                    else if (!clear.HasValue() && !list.HasValue())
                    {
                        throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Strings.LocalsCommand_NoOperation));
                    }
                    else
                    {
                        var localsArgs          = new LocalsArgs(arguments.Values, setting, logger.LogInformation, logger.LogError, clear.HasValue(), list.HasValue());
                        var localsCommandRunner = new LocalsCommandRunner();
                        localsCommandRunner.ExecuteCommand(localsArgs);
                    }

                    return(0);
                });
            });
        }