| | 1 | | using System; |
| | 2 | | using System.IO; |
| | 3 | | using System.Threading; |
| | 4 | | using System.Threading.Tasks; |
| | 5 | | using Amusoft.DotnetNew.Tests.CLI; |
| | 6 | | using Amusoft.DotnetNew.Tests.Rewriters; |
| | 7 | | using Amusoft.DotnetNew.Tests.Scopes; |
| | 8 | |
|
| | 9 | | namespace Amusoft.DotnetNew.Tests.Templating; |
| | 10 | |
|
| | 11 | | /// <summary> |
| | 12 | | /// |
| | 13 | | /// </summary> |
| | 14 | | public class TemplateInstallation : IDisposable |
| | 15 | | { |
| | 16 | | /// <summary> |
| | 17 | | /// |
| | 18 | | /// </summary> |
| | 19 | | public readonly ProjectTemplatingContext Context; |
| | 20 | |
|
| 6 | 21 | | private TemplateInstallation(ProjectTemplatingContext context) |
| | 22 | | { |
| 6 | 23 | | Context = context; |
| 6 | 24 | | } |
| | 25 | |
|
| | 26 | | internal static async Task<TemplateInstallation> CreateAsync(ProjectTemplatingContext projectTemplatingContext, Cancel |
| | 27 | | { |
| 6 | 28 | | await DotnetCli.InstallAsync(projectTemplatingContext.ProjectTemplatePath.OriginalPath, cancellationToken); |
| 6 | 29 | | var result = new TemplateInstallation(projectTemplatingContext); |
| 6 | 30 | | var dirName = Path.GetFileName(projectTemplatingContext.ProjectTemplatePath.VirtualPath); |
| 6 | 31 | | LoggingScope.TryAddRewriter(new FolderNameAliasRewriter(projectTemplatingContext.ProjectTemplatePath, $"ProjectDir:{ |
| | 32 | | // var logger = LoggingScope.Current?.Logger; |
| | 33 | | // logger?.AddRewriter(new ProjectDirectoryRewriter(projectTemplatingContext)); |
| | 34 | | // logger?.AddRewriter(new ProjectDirectoryRewriter(projectTemplatingContext)); |
| 6 | 35 | | return result; |
| 6 | 36 | | } |
| | 37 | |
|
| | 38 | | private bool _disposed; |
| | 39 | |
|
| | 40 | | /// <summary> |
| | 41 | | /// Uninstalls the template |
| | 42 | | /// </summary> |
| | 43 | | /// <param name="cancellationToken"></param> |
| | 44 | | public async Task UninstallAsync(CancellationToken cancellationToken) |
| | 45 | | { |
| 7 | 46 | | if (_disposed) |
| 1 | 47 | | return; |
| | 48 | |
|
| 6 | 49 | | await DotnetCli.UninstallAsync(Context.ProjectTemplatePath.OriginalPath, cancellationToken); |
| | 50 | |
|
| 6 | 51 | | _disposed = true; |
| 6 | 52 | | GC.SuppressFinalize(this); |
| 7 | 53 | | } |
| | 54 | |
|
| | 55 | | /// <summary> |
| | 56 | | /// Dispose |
| | 57 | | /// </summary> |
| | 58 | | public void Dispose() |
| | 59 | | { |
| 5 | 60 | | UninstallAsync(CancellationToken.None).GetAwaiter().GetResult(); |
| 5 | 61 | | } |
| | 62 | | } |