internal static async Task CreateAsync(string inputPath, string outfile, string certThumbprint, TextWriter output, TextWriter error) { try { if (Directory.Exists(inputPath)) { output.WriteCommandHeader($"Creating template package from folder {inputPath}."); if (!string.IsNullOrWhiteSpace(certThumbprint)) { output.WriteCommandText($"The template package will be signed using the cert matching {certThumbprint} as thumbprint."); await TemplatePackage.PackAndSignAsync(inputPath, outfile, certThumbprint, "text/plain").ConfigureAwait(false); output.WriteCommandText($"Templates package file '{outfile}' successfully created."); } else { output.WriteCommandText($"No cert thumbprint provided, the template package will not be signed."); await TemplatePackage.PackAsync(inputPath, outfile, "text/plain").ConfigureAwait(false); } output.WriteCommandText($"Templates package file '{outfile}' successfully created."); } else { error.WriteCommandText($"{inputPath} is not a valid folder to create a Templates Package."); } } catch (Exception ex) { error.WriteException(ex, "Unexpected exception creating templates package."); } }
public async Task Pack_FolderAsync() { int filesInCurrentFolder = new DirectoryInfo(Environment.CurrentDirectory).GetFiles("*", SearchOption.AllDirectories).Count(); var inFolder = Environment.CurrentDirectory; var outDir = @"C:\Temp\PackTests"; var outFile = Path.Combine(outDir, "JustPacked.mstx"); var extractDir = Path.Combine(outDir, "Extraction"); await _templatePackage.PackAsync(inFolder, outFile, MediaTypeNames.Text.Plain); await _templatePackage.ExtractAsync(outFile, extractDir, null, CancellationToken.None); int filesInExtractionFolder = new DirectoryInfo(extractDir).GetFiles("*", SearchOption.AllDirectories).Count(); Assert.Equal(filesInCurrentFolder, filesInExtractionFolder); Directory.Delete(outDir, true); }
public async Task Pack_FolderWithDefaultNamingAsync() { int filesInCurrentFolder = new DirectoryInfo(Environment.CurrentDirectory).GetFiles("*", SearchOption.AllDirectories).Count(); var inFolder = Environment.CurrentDirectory; var outDir = @"C:\Temp\PackTests"; var extractDir = Path.Combine(outDir, "Extraction"); var outFile = await TemplatePackage.PackAsync(inFolder); await TemplatePackage.ExtractAsync(outFile, extractDir, false); int filesInExtractionFolder = new DirectoryInfo(extractDir).GetFiles("*", SearchOption.AllDirectories).Count(); Assert.Equal(filesInCurrentFolder, filesInExtractionFolder); File.Delete(outFile); Directory.Delete(outDir, true); }