private async Task <IEnumerable <RecipeDescriptor> > HarvestRecipesAsync(ExtensionDescriptor extension) { var recipeLocation = _fileSystem.Combine(extension.Location, extension.Id, "Recipes"); var recipeOptions = _recipeOptions.Value; List <RecipeDescriptor> recipeDescriptors = new List <RecipeDescriptor>(); foreach (var recipeFileExtension in recipeOptions.RecipeFileExtensions) { var fileMatcher = new Matcher(System.StringComparison.OrdinalIgnoreCase); fileMatcher.AddInclude(recipeFileExtension.Key); var recipeFiles = _fileSystem.ListFiles(recipeLocation, fileMatcher); recipeDescriptors.AddRange(await recipeFiles.InvokeAsync(recipeFile => { var recipeParser = _recipeParsers.First(x => x.GetType() == recipeFileExtension.Value); using (var stream = recipeFile.CreateReadStream()) { var recipe = recipeParser.ParseRecipe(stream); recipe.Location = recipeFile.PhysicalPath.Replace(_fileSystem.RootPath, "").TrimStart(System.IO.Path.DirectorySeparatorChar); return(Task.FromResult(recipe)); } }, Logger)); } return(recipeDescriptors); }
public void Discover(ShapeTableBuilder builder) { if (_logger.IsEnabled(LogLevel.Information)) { _logger.LogInformation("Start discovering shapes"); } var harvesterInfos = _harvesters.Select(harvester => new { harvester, subPaths = harvester.SubPaths() }); var activeFeatures = _featureManager.GetEnabledFeaturesAsync().Result; var activeExtensions = Once(activeFeatures); var hits = activeExtensions.Select(extensionDescriptor => { if (_logger.IsEnabled(LogLevel.Information)) { _logger.LogInformation("Start discovering candidate views filenames"); } var matcher = new Matcher(); foreach(var extension in _shapeTemplateViewEngines.SelectMany(x => x.TemplateFileExtensions)) { matcher.AddInclude(string.Format("*.{0}", extension)); } var pathContexts = harvesterInfos.SelectMany(harvesterInfo => harvesterInfo.subPaths.Select(subPath => { var basePath = _fileSystem.Combine(extensionDescriptor.Location, extensionDescriptor.Id); var virtualPath = _fileSystem.Combine(basePath, subPath); var files = _fileSystem.ListFiles(virtualPath, matcher).ToReadOnlyCollection(); return new { harvesterInfo.harvester, basePath, subPath, virtualPath, files }; })).ToList(); if (_logger.IsEnabled(LogLevel.Information)) { _logger.LogInformation("Done discovering candidate views filenames"); } var fileContexts = pathContexts.SelectMany(pathContext => _shapeTemplateViewEngines.SelectMany(ve => { return pathContext.files.Select( file => new { fileName = Path.GetFileNameWithoutExtension(file.Name), fileVirtualPath = "~/" + _fileSystem.Combine(pathContext.virtualPath, file.Name), pathContext }); })); var shapeContexts = fileContexts.SelectMany(fileContext => { var harvestShapeInfo = new HarvestShapeInfo { SubPath = fileContext.pathContext.subPath, FileName = fileContext.fileName, TemplateVirtualPath = fileContext.fileVirtualPath }; var harvestShapeHits = fileContext.pathContext.harvester.HarvestShape(harvestShapeInfo); return harvestShapeHits.Select(harvestShapeHit => new { harvestShapeInfo, harvestShapeHit, fileContext }); }); return shapeContexts.Select(shapeContext => new { extensionDescriptor, shapeContext }).ToList(); }).SelectMany(hits2 => hits2); foreach (var iter in hits) { // templates are always associated with the namesake feature of module or theme var hit = iter; var featureDescriptors = iter.extensionDescriptor.Features.Where(fd => fd.Id == hit.extensionDescriptor.Id); foreach (var featureDescriptor in featureDescriptors) { if (_logger.IsEnabled(LogLevel.Debug)) { _logger.LogDebug("Binding {0} as shape [{1}] for feature {2}", hit.shapeContext.harvestShapeInfo.TemplateVirtualPath, iter.shapeContext.harvestShapeHit.ShapeType, featureDescriptor.Id); } builder.Describe(iter.shapeContext.harvestShapeHit.ShapeType) .From(new Feature { Descriptor = featureDescriptor }) .BoundAs( hit.shapeContext.harvestShapeInfo.TemplateVirtualPath, shapeDescriptor => displayContext => RenderAsync(shapeDescriptor, displayContext, hit.shapeContext.harvestShapeInfo, hit.shapeContext.harvestShapeHit)); } } if (_logger.IsEnabled(LogLevel.Information)) { _logger.LogInformation("Done discovering shapes"); } }
public IEnumerable <IFileInfo> ListFiles(string path) { return(_fileSystem.ListFiles(path)); }