public void SetFilepath(string filename) { string filepath = Path.Combine(_webRoot, filename); Filepath = filepath; TemplatePacks = TemplatePack.CreateFromFile(filepath); }
public void TestCreateFromFile() { string filepath = GetTestFilepath(@"template-report01.json"); List <TemplatePack> result = TemplatePack.CreateFromFile(filepath); Assert.NotNull(result); Assert.True(result.Count > 0); }
public override Command CreateCommand() => new Command(name: "search", description: "search for templates") { CommandHandler.Create <string>(async(searchTerm) => { var previousTemplateReportPath = _reportLocator.GetTemplateReportJsonPath(); _reporter.WriteVerboseLine($"loading previous template-report.json from '{previousTemplateReportPath}'"); var templatePacks = TemplatePack.CreateFromFile(previousTemplateReportPath); _reporter.WriteVerboseLine($"Num template packs in previous report: '{templatePacks.Count}'"); var result = _searcher.Search(searchTerm, templatePacks); List <UserOption> options = new List <UserOption>(); foreach (var template in result) { options.Add(new UserOption($"{template.Name} - ({template.TemplatePackId})", template)); } var consoleWrapper = new DirectConsoleWrapper(); PickManyPrompt pmp = new PickManyPrompt("Select templates to install (↑↓ to navigate, Space to select, and Enter to commit)", options); bool doSharprompt = true; IPromptInvoker pi; pi = doSharprompt ? (IPromptInvoker) new SharPromptInvoker() : new PromptInvoker(consoleWrapper); var promptResult = pi.GetPromptResult(pmp) as PickManyPrompt; var templatesToInstall = promptResult.UserOptions .Where(uo => uo.IsSelected) .Select(uo => uo.Value as Template); if (templatesToInstall == null) { _reporter.WriteLine("noting selected to install"); return; } var templateInstallList = templatesToInstall.ToList(); await InstallTemplatesAsync(templateInstallList); }), ArgSearchTerm() };
public override void Setup(CommandLineApplication command) { base.Setup(command); var optionTemplateReportJsonPath = command.Option <string>( "-trp|--templateReportPath", "the path to the template-report.json file", CommandOptionType.SingleValue); optionTemplateReportJsonPath.IsRequired(); //var optionAnalysisResultFilePath = command.Option<string>( // "-arp|--analysisResultPath", // "path to where the results will be written to", // CommandOptionType.SingleValue); var optionOutputDir = command.Option <string>( "-od|--output-dir", "folder path where files will be written", CommandOptionType.SingleValue); OnExecute = () => { EnableVerboseOption = OptionVerbose.HasValue(); var templateReportJsonPath = optionTemplateReportJsonPath.Value(); if (!File.Exists(templateReportJsonPath)) { throw new FileNotFoundException($"template-report.json file not found at {templateReportJsonPath}"); } var templatePacks = TemplatePack.CreateFromFile(templateReportJsonPath); List <string> createdFiles = new List <string>(); string outdir = optionOutputDir.HasValue() ? optionOutputDir.Value() : Directory.GetCurrentDirectory(); string templatePackFile = Path.Combine(outdir, "template-pack-analysis.csv"); CreateTemplatePackFile(templatePacks, templateReportJsonPath, templatePackFile); createdFiles.Add(templatePackFile); // create the json file that contains all the templates var allTemplates = new List <Template>(); var allTemplateInfos = new List <TemplateReportSummaryInfo>(); var allHostFiles = new List <TemplateHostFile>(); foreach (var tp in templatePacks) { var extractFolderPath = Path.Combine(_remoteFile.CacheFolderpath, "extracted", ($"{tp.Package}.{tp.Version}.nupkg").ToLowerInvariant()); // populate the HostFiles property of the template pack var templates = TemplatePack.GetTemplateFilesUnder(extractFolderPath); foreach (var template in templates) { var templateObj = Template.CreateFromFile(template); templateObj.TemplatePackId = tp.Package; templateObj.InitHostFilesFrom(Path.GetDirectoryName(template), templateObj.TemplatePackId, templateObj.Name); allTemplates.Add(templateObj); allTemplateInfos.Add(new TemplateReportSummaryInfo { Template = templateObj }); if (templateObj.HostFiles != null && templateObj.HostFiles.Count > 0) { allHostFiles.AddRange(templateObj.HostFiles); } } } var allTemplatesJsonPath = Path.Combine(outdir, "template-all.json"); CreateAllTemplatesJsonFile(allTemplates, allTemplatesJsonPath); createdFiles.Add(allTemplatesJsonPath); // create the template-details.csv file now var templateDetailsCsvPath = Path.Combine(outdir, "template-details.csv"); CreateTemplateDetailsCsvFile(allTemplateInfos, templateDetailsCsvPath); createdFiles.Add(templateDetailsCsvPath); var hostFileDetailsCsvPath = Path.Combine(outdir, "template-host-files.csv"); CreateHostFilesDetailsCsvFile(allHostFiles, hostFileDetailsCsvPath); createdFiles.Add(hostFileDetailsCsvPath); Console.WriteLine("Created files:"); foreach (var cf in createdFiles) { Console.WriteLine($" {cf}"); } return(1); }; }
public override void Setup(CommandLineApplication command) { base.Setup(command); var optionTemplateReportFilepath = command.Option <string>( "-trf|--template-report-file", "path to the template-report.json file", CommandOptionType.SingleValue); var optionCsvOutputPath = command.Option <string>( "-cop|--csv-output-path", "output path for the csv file, default is to create the file in the current directory", CommandOptionType.SingleValue); var optionTemplateCacheFilepath = command.Option <string>( "-tcf|--template-cache-file", "path to the templatecache.json this is ususally typically found in subfolders under %HOMEPATH%/.templateengine/dotnetcli", CommandOptionType.SingleValue); OnExecute = () => { var reportFilepath = optionTemplateReportFilepath.HasValue() ? optionTemplateReportFilepath.Value() : null; if (string.IsNullOrEmpty(reportFilepath)) { throw new ArgumentNullException("template-report-file parameter missing"); } var destPath = optionCsvOutputPath.HasValue() ? optionCsvOutputPath.Value() : Path.Combine(Directory.GetCurrentDirectory(), $"template-result.{DateTime.Now.ToString("MM.dd.yy-H.m.s.ffff")}.csv"); var destFile = destPath; if (!Path.HasExtension(destFile)) { destFile = Path.Combine(destFile, $"template-result.{DateTime.Now.ToString("MM.dd.yy-H.m.s.ffff")}.csv"); } //var destFile = Path.Combine(Directory.GetCurrentDirectory(), $"template-result.{DateTime.Now.ToString("MM.dd.yy-H.m.s.ffff")}.csv"); Console.WriteLine($"destFile: {destFile}"); var sb = new StringBuilder(); // var destFile = // load the json file var templatePack = TemplatePack.CreateFromFile(reportFilepath); sb.AppendLine("Identity,hash,hashLower,idhash,idhashLower,groupidhash,groupidHashLower,clihash,cliUpperHash,cliLowerHash"); foreach (var tp in templatePack) { foreach (var template in tp.Templates) { var hashInfo = new TemplateHashInfo { GroupIdentity = template.GroupIdentity, Identity = template.Identity, Language = template.GetLanguage() }; var hash = TemplateHashExtensions.EncodeAndGenerateHash(hashInfo); var hashLower = TemplateHashExtensions.EncodeAndGenerateHash(hashInfo, true); var idhash = TemplateHashExtensions.GenerateHash(template.Identity); var idhashLower = TemplateHashExtensions.GenerateHash(template.Identity != null? template.Identity.ToLowerInvariant():string.Empty); var groupIdHash = TemplateHashExtensions.GenerateHash(template.GroupIdentity); var groupIdHashLower = TemplateHashExtensions.GenerateHash(template.GroupIdentity != null ? template.GroupIdentity.ToLowerInvariant() : string.Empty); var cliHash = TemplateHashExtensions.GenerateHashForCli(template.Identity); var cliUpperHash = TemplateHashExtensions.GenerateHashForCliWithNormalizedCasing(template.Identity); var cliLowerHash = TemplateHashExtensions.GenerateHashForCliWithNormalizedCasing(template.Identity, false); sb.AppendLine($"{template.Identity},{hash},{hashLower},{idhash},{idhashLower},{groupIdHash},{groupIdHashLower},{cliHash},{cliUpperHash},{cliLowerHash}"); } } var templateCacheFilepath = optionTemplateCacheFilepath.HasValue() ? optionTemplateCacheFilepath.Value() : null; var idsFromTemplateCacheFile = GetIdsFromTemplateCache(templateCacheFilepath); if (idsFromTemplateCacheFile != null && idsFromTemplateCacheFile.Count > 0) { foreach (var id in idsFromTemplateCacheFile) { var hash = string.Empty; var hashLower = string.Empty; var idhash = TemplateHashExtensions.GenerateHash(id); var idhashLower = TemplateHashExtensions.GenerateHash(id.ToLowerInvariant()); var groupIdHash = string.Empty; var groupIdHashLower = string.Empty; var cliHash = TemplateHashExtensions.GenerateHashForCli(id); var cliUpperHash = TemplateHashExtensions.GenerateHashForCliWithNormalizedCasing(id); var cliLowerHash = TemplateHashExtensions.GenerateHashForCliWithNormalizedCasing(id, false); sb.AppendLine($"{id},{hash},{hashLower},{idhash},{idhashLower},{groupIdHash},{groupIdHashLower},{cliHash},{cliUpperHash},{cliLowerHash}"); } } File.WriteAllText(destFile, sb.ToString()); return(1); }; }