Example #1
0
        public async Task UpdateMemoryAssetsAsync(bool cloneFirst = true)
        {
            if (cloneFirst)
            {
                await _gitClient.CloneAsync(_gitConfig);
                await UpdatePostTemplateAsync();
            }

            var tasks = new List <Task>
            {
                UpdateMemoryCategoriesAsync(),
                UpdateMemoryPostsAsync(),
                UpdateMemoryTagsAsync(),
                UpdateMemoryAboutAsync()
            };

            await Task.WhenAll(tasks);
        }
Example #2
0
        public async Task LoadTemplateAsync()
        {
            var selection = SelectedTemplate;

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

            ResetStatus();

            _checkUpdatesCancelTokenSource?.Cancel();

            if (IsCloneNeeded(selection))
            {
                CloningStatus = OperationStatus.InProgress;

                try {
                    _outputWindow.ShowAndActivate();
                    _outputWindow.WriteLine(String.Empty);
                    _outputWindow.WriteLine(Strings.CloningTemplateStarted.FormatUI(selection.DisplayName));

                    Directory.CreateDirectory(InstalledFolderPath);

                    selection.ClonedPath = await _gitClient.CloneAsync(selection.RemoteUrl, InstalledFolderPath);

                    CloningStatus = OperationStatus.Succeeded;

                    _outputWindow.WriteLine(Strings.CloningTemplateSuccess.FormatUI(selection.DisplayName, selection.ClonedPath));

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

                    await _installedSource.AddTemplateAsync(selection.ClonedPath);

                    _templateRefreshCancelTokenSource?.Cancel();
                    _templateRefreshCancelTokenSource = new CancellationTokenSource();
                    try {
                        Installed.Templates.Clear();
                        await AddFromSourceAsync(_installedSource, SearchTerm, Installed, false, CancellationToken.None);
                    } catch (OperationCanceledException) {
                    }

                    _templateLocalFolderPath = selection.ClonedPath;

                    await SetDefaultOutputFolderAsync(_templateLocalFolderPath);
                    await RefreshContextAsync(selection);
                } catch (Exception ex) when(!ex.IsCriticalException())
                {
                    CloningStatus = OperationStatus.Failed;

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

                    ReportTemplateEvent(CookiecutterTelemetry.TelemetryArea.Template, CookiecutterTelemetry.TemplateEvents.Clone, selection, ex);
                }
            }
            else
            {
                Debug.Assert(!string.IsNullOrEmpty(selection.ClonedPath));
                _templateLocalFolderPath = selection.ClonedPath;
                await SetDefaultOutputFolderAsync(_templateLocalFolderPath);
                await RefreshContextAsync(selection);
            }
        }
Example #3
0
        public async Task LoadTemplateAsync()
        {
            var selection = SelectedTemplate;

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

            if (IsCloneNeeded(selection))
            {
                IsCloning        = true;
                IsCloningSuccess = false;
                IsCloningError   = false;

                try {
                    _outputWindow.WriteLine(string.Format(CultureInfo.CurrentUICulture, Strings.CloningTemplateStarted, selection.DisplayName));

                    Directory.CreateDirectory(InstalledFolderPath);

                    var result = await _gitClient.CloneAsync(selection.RemoteUrl, InstalledFolderPath);

                    selection.ClonedPath = result.Item1;

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

                    _outputWindow.WriteLine(string.Join(Environment.NewLine, result.Item2.StandardOutputLines));
                    _outputWindow.WriteErrorLine(string.Join(Environment.NewLine, result.Item2.StandardErrorLines));

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

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

                    // We now have a new template installed, so reload that section of the results
                    _installedSource.InvalidateCache();

                    _templateRefreshCancelTokenSource?.Cancel();
                    _templateRefreshCancelTokenSource = new CancellationTokenSource();
                    try {
                        Installed.Templates.Clear();
                        await AddFromSource(_installedSource, SearchTerm, KnownMonikers.TestSuite, Installed, CancellationToken.None);
                    } catch (OperationCanceledException) {
                    }

                    _templateLocalFolderPath = selection.ClonedPath;

                    await RefreshContextAsync(selection);
                } catch (ProcessException ex) {
                    IsCloning        = false;
                    IsCloningSuccess = false;
                    IsCloningError   = 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.CloningTemplateFailed, selection.DisplayName));
                    _outputWindow.ShowAndActivate();

                    ReportTemplateEvent(CookiecutterTelemetry.TelemetryArea.Template, CookiecutterTelemetry.TemplateEvents.Clone, selection, ex);
                } catch (Exception ex) when(!ex.IsCriticalException())
                {
                    IsCloning        = false;
                    IsCloningSuccess = false;
                    IsCloningError   = true;

                    _outputWindow.WriteErrorLine(ex.Message);

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

                    ReportTemplateEvent(CookiecutterTelemetry.TelemetryArea.Template, CookiecutterTelemetry.TemplateEvents.Clone, selection, ex);
                }
            }
            else
            {
                Debug.Assert(!string.IsNullOrEmpty(selection.ClonedPath));
                _templateLocalFolderPath = selection.ClonedPath;

                await RefreshContextAsync(selection);
            }
        }