Exemplo n.º 1
0
        private async Task RefreshContextAsync(TemplateViewModel selection)
        {
            if (!await EnsureCookiecutterIsInstalled())
            {
                return;
            }

            try {
                IsLoading        = true;
                IsLoadingSuccess = false;
                IsLoadingError   = false;

                var result = await _cutterClient.LoadContextAsync(selection.ClonedPath, UserConfigFilePath);

                ContextItems.Clear();
                foreach (var item in result.Item1)
                {
                    ContextItems.Add(new ContextItemViewModel(item.Name, item.DefaultValue, item.Values));
                }

                IsLoading        = false;
                IsLoadingSuccess = true;
                IsLoadingError   = false;

                _outputWindow.WriteLine(string.Empty);
                _outputWindow.WriteLine(string.Format(CultureInfo.CurrentUICulture, Strings.LoadingTemplateSuccess, selection.DisplayName));
                _outputWindow.ShowAndActivate();

                ReportTemplateEvent(CookiecutterTelemetry.TelemetryArea.Template, CookiecutterTelemetry.TemplateEvents.Load, selection);

                // Go to the context page
                ContextLoaded?.Invoke(this, EventArgs.Empty);
            } catch (InvalidOperationException ex) {
                IsLoading        = false;
                IsLoadingSuccess = false;
                IsLoadingError   = true;

                _outputWindow.WriteErrorLine(ex.Message);

                _outputWindow.WriteLine(string.Empty);
                _outputWindow.WriteLine(string.Format(CultureInfo.CurrentUICulture, Strings.LoadingTemplateFailed, selection.DisplayName));
                _outputWindow.ShowAndActivate();

                ReportTemplateEvent(CookiecutterTelemetry.TelemetryArea.Template, CookiecutterTelemetry.TemplateEvents.Load, selection, ex);
            } catch (ProcessException ex) {
                IsLoading        = false;
                IsLoadingSuccess = false;
                IsLoadingError   = true;

                _outputWindow.WriteLine(string.Format(CultureInfo.CurrentUICulture, Strings.ProcessExitCodeMessage, ex.Result.ExeFileName, ex.Result.ExitCode));
                _outputWindow.WriteLine(string.Join(Environment.NewLine, ex.Result.StandardOutputLines));
                _outputWindow.WriteErrorLine(string.Join(Environment.NewLine, ex.Result.StandardErrorLines));

                _outputWindow.WriteLine(string.Empty);
                _outputWindow.WriteLine(string.Format(CultureInfo.CurrentUICulture, Strings.LoadingTemplateFailed, selection.DisplayName));
                _outputWindow.ShowAndActivate();

                ReportTemplateEvent(CookiecutterTelemetry.TelemetryArea.Template, CookiecutterTelemetry.TemplateEvents.Load, selection, ex);
            }
        }
Exemplo n.º 2
0
        private async Task RefreshContextAsync(TemplateViewModel selection)
        {
            if (!await EnsureCookiecutterIsInstalledAsync())
            {
                return;
            }

            try {
                LoadingStatus = OperationStatus.InProgress;

                _outputWindow.ShowAndActivate();
                _outputWindow.WriteLine(Strings.LoadingTemplateStarted.FormatUI(selection.DisplayName));

                var unrenderedContext = await _cutterClient.LoadUnrenderedContextAsync(selection.ClonedPath, UserConfigFilePath);

                ContextItems.Clear();
                foreach (var item in unrenderedContext.Items.Where(it => !it.Name.StartsWith("_", StringComparison.InvariantCulture)))
                {
                    ContextItems.Add(new ContextItemViewModel(item.Name, item.Selector, item.Label, item.Description, item.Url, item.DefaultValue, item.Values));
                }

                HasPostCommands           = unrenderedContext.Commands.Count > 0;
                ShouldExecutePostCommands = HasPostCommands;

                LoadingStatus = OperationStatus.Succeeded;

                _outputWindow.WriteLine(Strings.LoadingTemplateSuccess.FormatUI(selection.DisplayName));

                ReportTemplateEvent(CookiecutterTelemetry.TelemetryArea.Template, CookiecutterTelemetry.TemplateEvents.Load, selection);

                // Go to the context page
                ContextLoaded?.Invoke(this, EventArgs.Empty);
            } catch (Exception ex) when(!ex.IsCriticalException())
            {
                LoadingStatus = OperationStatus.Failed;

                _outputWindow.WriteErrorLine(ex.Message);
                _outputWindow.WriteLine(Strings.LoadingTemplateFailed.FormatUI(selection.DisplayName));

                ReportTemplateEvent(CookiecutterTelemetry.TelemetryArea.Template, CookiecutterTelemetry.TemplateEvents.Load, selection, ex);
            }
        }
Exemplo n.º 3
0
        private async Task RefreshContextAsync(TemplateViewModel selection)
        {
            if (!await EnsureCookiecutterIsInstalled())
            {
                return;
            }

            try {
                LoadingStatus = OperationStatus.InProgress;

                _outputWindow.ShowAndActivate();
                _outputWindow.WriteLine(Strings.LoadingTemplateStarted.FormatUI(selection.DisplayName));

                var result = await _cutterClient.LoadContextAsync(selection.ClonedPath, UserConfigFilePath);

                ContextItems.Clear();
                foreach (var item in result)
                {
                    ContextItems.Add(new ContextItemViewModel(item.Name, item.DefaultValue, item.Values));
                }

                LoadingStatus = OperationStatus.Succeeded;

                _outputWindow.WriteLine(Strings.LoadingTemplateSuccess.FormatUI(selection.DisplayName));

                ReportTemplateEvent(CookiecutterTelemetry.TelemetryArea.Template, CookiecutterTelemetry.TemplateEvents.Load, selection);

                // Go to the context page
                ContextLoaded?.Invoke(this, EventArgs.Empty);
            } catch (Exception ex) when(!ex.IsCriticalException())
            {
                LoadingStatus = OperationStatus.Failed;

                _outputWindow.WriteErrorLine(ex.Message);
                _outputWindow.WriteLine(Strings.LoadingTemplateFailed.FormatUI(selection.DisplayName));

                ReportTemplateEvent(CookiecutterTelemetry.TelemetryArea.Template, CookiecutterTelemetry.TemplateEvents.Load, selection, ex);
            }
        }