Beispiel #1
0
        public MainWindow()
        {
            InitializeComponent();
            DataContext = this;
            Loaded     += (sender, e) => MoveFocus(new TraversalRequest(FocusNavigationDirection.Next));
            ContCommand = new RelayCommand <object>((o) =>
            {
            });

            RightCommand = new RelayCommand <object>((o) =>
            {
                ContextItems.Clear();
                string itemClicked = (string)o;
                ContextItems.Add(new Context()
                {
                    Name = "Foo " + itemClicked, Enabled = false, guid = Guid.NewGuid()
                });
                ContextItems.Add(new Context()
                {
                    Name = "Bar " + itemClicked, Enabled = false, guid = Guid.NewGuid()
                });
                ContextItems.Add(new Context()
                {
                    Name = "Hello", Enabled = false, guid = Guid.NewGuid()
                });
            });
        }
        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);
            }
        }
        public void Reset()
        {
            ContextItems.Clear();

            ResetStatus();

            _templateLocalFolderPath = null;

            HomeClicked?.Invoke(this, EventArgs.Empty);
        }
Beispiel #4
0
        public async Task CreateFilesAsync()
        {
            var selection = SelectedTemplate;

            Debug.Assert(selection != null);
            if (selection == null)
            {
                throw new InvalidOperationException("CreateFilesAsync called with null SelectedTemplate");
            }

            ResetStatus();

            CreatingStatus           = OperationStatus.InProgress;
            OpenInExplorerFolderPath = null;

            try {
                var contextFilePath = Path.GetTempFileName();
                SaveUserInput(contextFilePath);

                _outputWindow.ShowAndActivate();
                _outputWindow.WriteLine(String.Empty);
                _outputWindow.WriteLine(Strings.RunningTemplateStarted.FormatUI(selection.DisplayName));

                await _cutterClient.GenerateProjectAsync(_templateLocalFolderPath, UserConfigFilePath, contextFilePath, OutputFolderPath);

                try {
                    File.Delete(contextFilePath);
                } catch (UnauthorizedAccessException) {
                } catch (IOException) {
                }

                _outputWindow.WriteLine(Strings.RunningTemplateSuccess.FormatUI(selection.DisplayName, OutputFolderPath));

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

                ContextItems.Clear();
                ResetStatus();
                _templateLocalFolderPath = null;
                OpenInExplorerFolderPath = OutputFolderPath;
                CreatingStatus           = OperationStatus.Succeeded;

                Home();
            } catch (Exception ex) when(!ex.IsCriticalException())
            {
                CreatingStatus = OperationStatus.Failed;

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

                ReportTemplateEvent(CookiecutterTelemetry.TelemetryArea.Template, CookiecutterTelemetry.TemplateEvents.Run, selection, ex);
            }
        }
Beispiel #5
0
        public void Should_not_output_session_id_in_details_if_no_cookie_or_id_in_request()
        {
            ContextItems.Clear();

            var request = _requestBuilder.AddSession()
                          .AddMessage(_standardTestMessage)
                          .Build();

            Target.Process(HttpContext, request);

            WaitForEvent();

            var loggedMessage = _eventArgs.Messages.FirstOrDefault();

            Assert.That(loggedMessage, Is.Not.Null);

            Assert.That(loggedMessage.Details, Does.Not.Contain("<SessionId>"));
        }
Beispiel #6
0
        public void Reset() {
            ContextItems.Clear();

            IsCloning = false;
            IsCloningSuccess = false;
            IsCloningError = false;

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

            IsCreating = false;
            IsCreatingSuccess = false;
            IsCreatingError = false;

            _templateLocalFolderPath = null;

            HomeClicked?.Invoke(this, EventArgs.Empty);
        }
Beispiel #7
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);
            }
        }
        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);
            }
        }
Beispiel #9
0
        public async Task CreateFilesAsync()
        {
            var selection = SelectedTemplate;

            Debug.Assert(selection != null);
            if (selection == null)
            {
                throw new InvalidOperationException("CreateFilesAsync called with null SelectedTemplate");
            }

            ResetStatus();

            CreatingStatus           = OperationStatus.InProgress;
            OpenInExplorerFolderPath = null;

            try {
                var contextFilePath = Path.GetTempFileName();
                SaveUserInput(contextFilePath);

                _outputWindow.ShowAndActivate();
                _outputWindow.WriteLine(String.Empty);
                _outputWindow.WriteLine(Strings.RunningTemplateStarted.FormatUI(selection.DisplayName));

                var operationResult = await _cutterClient.CreateFilesAsync(_templateLocalFolderPath, UserConfigFilePath, contextFilePath, OutputFolderPath);

                if (operationResult.FilesReplaced.Length > 0)
                {
                    _outputWindow.WriteLine(Strings.ReplacedFilesHeader);
                    foreach (var replacedfile in operationResult.FilesReplaced)
                    {
                        _outputWindow.WriteLine(Strings.ReplacedFile.FormatUI(replacedfile.OriginalFilePath, replacedfile.BackupFilePath));
                    }
                }

                var renderedContext = await _cutterClient.LoadRenderedContextAsync(_templateLocalFolderPath, UserConfigFilePath, contextFilePath, OutputFolderPath);

                _postCommands = renderedContext.Commands.ToArray();

                try {
                    File.Delete(contextFilePath);
                } catch (UnauthorizedAccessException) {
                } catch (IOException) {
                }

                if (TargetProjectLocation != null)
                {
                    try {
                        var location = new ProjectLocation()
                        {
                            FolderPath        = OutputFolderPath,
                            ProjectUniqueName = TargetProjectLocation.ProjectUniqueName,
                        };
                        _projectSystemClient.AddToProject(location, operationResult);

                        RunPostCommands();

                        ReportTemplateEvent(CookiecutterTelemetry.TelemetryArea.Template, CookiecutterTelemetry.TemplateEvents.AddToProject, selection);
                    } catch (Exception ex) when(!ex.IsCriticalException())
                    {
                        _outputWindow.WriteErrorLine(Strings.AddToProjectError.FormatUI(ex.Message));

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

                _outputWindow.WriteLine(Strings.RunningTemplateSuccess.FormatUI(selection.DisplayName, OutputFolderPath));

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

                ContextItems.Clear();
                ResetStatus();
                _templateLocalFolderPath = null;
                OpenInExplorerFolderPath = OutputFolderPath;
                CreatingStatus           = OperationStatus.Succeeded;

                if (TargetProjectLocation != null)
                {
                    // Don't show the succeeded message and open in solution explorer link when adding to project
                    CreatingStatus = OperationStatus.NotStarted;
                }

                Home();
            } catch (Exception ex) when(!ex.IsCriticalException())
            {
                CreatingStatus = OperationStatus.Failed;

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

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