internal ProjectContext GetProjectContext(ExtensionDescriptor descriptor) { var fileInfo = _hostingEnvironment .GetExtensionFileInfo(descriptor); return(GetProjectContextFromPath(fileInfo.PhysicalPath)); }
private void ProcessFeatureDescriptor(ShapeTableBuilder builder, FeatureDescriptor featureDescriptor) { var virtualFileInfo = _hostingEnviroment .GetExtensionFileInfo(featureDescriptor.Extension, "placement.json"); if (virtualFileInfo.Exists) { using (var stream = virtualFileInfo.CreateReadStream()) { using (var reader = new StreamReader(stream)) { using (var jtr = new JsonTextReader(reader)) { JsonSerializer serializer = new JsonSerializer(); var placementFile = serializer.Deserialize <PlacementFile>(jtr); ProcessPlacementFile(builder, featureDescriptor, placementFile); } } } } }
private void ProcessFeatureDescriptor(ShapeTableBuilder builder, IFeatureInfo featureDescriptor) { // TODO : (ngm) Replace with configuration Provider and read from that. // Dont use JSON Deserializer directly. var virtualFileInfo = _hostingEnviroment .GetExtensionFileInfo(featureDescriptor.Extension, "placement.json"); if (virtualFileInfo.Exists) { using (var stream = virtualFileInfo.CreateReadStream()) { using (var reader = new StreamReader(stream)) { using (var jtr = new JsonTextReader(reader)) { JsonSerializer serializer = new JsonSerializer(); var placementFile = serializer.Deserialize <PlacementFile>(jtr); ProcessPlacementFile(builder, featureDescriptor, placementFile); } } } } }
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() }) .ToList(); var enabledFeatures = _shellFeaturesManager.GetEnabledFeaturesAsync().Result .Where(Feature => !builder.ExcludedFeatureIds.Contains(Feature.Id)).ToList(); var activeExtensions = Once(enabledFeatures); var matcher = new Matcher(); foreach (var extension in _shapeTemplateViewEngines.SelectMany(x => x.TemplateFileExtensions)) { matcher.AddInclude(string.Format("*.{0}", extension)); } var hits = activeExtensions.Select(extensionDescriptor => { if (_logger.IsEnabled(LogLevel.Information)) { _logger.LogInformation("Start discovering candidate views filenames"); } var pathContexts = harvesterInfos.SelectMany(harvesterInfo => harvesterInfo.subPaths.Select(subPath => { var subPathFileInfo = _hostingEnvironment .GetExtensionFileInfo(extensionDescriptor, subPath); var directoryInfo = new DirectoryInfo(subPathFileInfo.PhysicalPath); var virtualPath = Path.Combine(extensionDescriptor.SubPath, subPath); if (!directoryInfo.Exists) { return(new { harvesterInfo.harvester, subPath, virtualPath, files = new IFileInfo[0] }); } var matches = matcher .Execute(new DirectoryInfoWrapper(directoryInfo)) .Files; var files = matches .Select(match => _hostingEnvironment .GetExtensionFileInfo(extensionDescriptor, Path.Combine(subPath, match.Path))).ToArray(); return(new { harvesterInfo.harvester, 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 = "~/" + Path.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; foreach (var feature in hit.extensionDescriptor.Features) { if (_logger.IsEnabled(LogLevel.Debug)) { _logger.LogDebug("Binding {0} as shape [{1}] for feature {2}", hit.shapeContext.harvestShapeInfo.TemplateVirtualPath, iter.shapeContext.harvestShapeHit.ShapeType, feature.Id); } builder.Describe(iter.shapeContext.harvestShapeHit.ShapeType) .From(feature) .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"); } }