private void Initialize() { ViewsFeature viewsFeature = new ViewsFeature(); this.ApplicationPartManager.PopulateFeature(viewsFeature); IEnumerable <CompiledViewDescriptor> compiledViewDescriptors = viewsFeature.ViewDescriptors; List <PageActionDescriptor> pageActionDescriptors = this.ActionDescriptorCollectionProvider.ActionDescriptors.Items.OfType <PageActionDescriptor>().ToList(); foreach (CompiledViewDescriptor compiledViewDescriptor in compiledViewDescriptors) { PageActionDescriptor pageActionDescriptorRazor = pageActionDescriptors.Find(pageActionDescriptor => pageActionDescriptor.RelativePath == compiledViewDescriptor.RelativePath); if (pageActionDescriptorRazor != null) { PropertyInfo piModel = compiledViewDescriptor.Type.GetProperty("Model", BindingFlags.Public | BindingFlags.Instance); if (piModel != null && piModel.PropertyType.BaseType.IsGenericType && piModel.PropertyType.BaseType.GetGenericTypeDefinition() == typeof(RazorLinkPageModel <>)) { Type linkType = piModel.PropertyType.BaseType.GenericTypeArguments[0]; PropertyInfo piName = compiledViewDescriptor.Type.GetProperty("Name", BindingFlags.Public | BindingFlags.Static); string name = (string)piName.GetValue(null, null); this.RazorPageLinkDescriptors.Add(linkType, name, pageActionDescriptorRazor.RelativePath, pageActionDescriptorRazor.ViewEnginePath); } } } }
public SharedCompilerCacheProvider( ApplicationPartManager applicationPartManager, IRazorViewEngineFileProviderAccessor fileProviderAccessor, IEnumerable <IApplicationFeatureProvider <ViewsFeature> > viewsFeatureProviders, IHostingEnvironment env) { lock (_synLock) { if (_cache == null) { var feature = new ViewsFeature(); var featureProviders = applicationPartManager.FeatureProviders .OfType <IApplicationFeatureProvider <ViewsFeature> >() .ToList(); featureProviders.AddRange(viewsFeatureProviders); var assemblyParts = new AssemblyPart[] { new AssemblyPart(Assembly.Load(new AssemblyName(env.ApplicationName))) }; foreach (var provider in featureProviders) { provider.PopulateFeature(assemblyParts, feature); } _cache = new CompilerCache(fileProviderAccessor.FileProvider, feature.Views); } } }
private IViewCompiler CreateCompiler() { var feature = new ViewsFeature(); var featureProviders = _applicationPartManager.FeatureProviders .OfType <IApplicationFeatureProvider <ViewsFeature> >() .ToList(); featureProviders.AddRange(_viewsFeatureProviders); var assemblyParts = new AssemblyPart[] { new AssemblyPart(Assembly.Load(new AssemblyName(_hostingEnvironment.ApplicationName))) }; foreach (var provider in featureProviders) { provider.PopulateFeature(assemblyParts, feature); } return(new SharedRazorViewCompiler( _fileProviderAccessor.FileProvider, _razorTemplateEngine, _csharpCompiler, _viewEngineOptions.CompilationCallback, feature.ViewDescriptors, _logger)); }
public Task StartAsync(CancellationToken cancellationToken) { // Get the names of all the application parts. This is the short assembly name for AssemblyParts var applicationParts = _partManager.ApplicationParts.Select(x => x.Name); var controllerFeature = new ControllerFeature(); _partManager.PopulateFeature(controllerFeature); var controllers = controllerFeature.Controllers.Select(x => x.Name); var tagHelperFeature = new TagHelperFeature(); _partManager.PopulateFeature(tagHelperFeature); var tagHelpers = tagHelperFeature.TagHelpers.Select(x => x.Name); var viewComponentFeature = new ViewComponentFeature(); _partManager.PopulateFeature(viewComponentFeature); var viewComponents = viewComponentFeature.ViewComponents.Select(x => x.Name); var viewsFeature = new ViewsFeature(); _partManager.PopulateFeature(viewsFeature); var views = viewsFeature.ViewDescriptors.Select(x => x.RelativePath); //Log the application parts _logger.LogInformation("Found the following Application Parts: " + Environment.NewLine + string.Join(Environment.NewLine, applicationParts)); _logger.LogInformation("Found the following Controllers: " + Environment.NewLine + string.Join(Environment.NewLine, controllers)); _logger.LogInformation("Found the following Views: " + Environment.NewLine + string.Join(Environment.NewLine, views)); _logger.LogInformation("Found the following Tag Helpers: " + Environment.NewLine + string.Join(Environment.NewLine, tagHelpers)); _logger.LogInformation("Found the following View Components: " + Environment.NewLine + string.Join(Environment.NewLine, viewComponents)); return(Task.CompletedTask); }
public IActionResult Index() { var viewModel = new FeaturesViewModel(); var controllerFeature = new ControllerFeature(); _partManager.PopulateFeature(controllerFeature); viewModel.Controllers = controllerFeature.Controllers.ToList(); var tagHelperFeature = new TagHelperFeature(); _partManager.PopulateFeature(tagHelperFeature); viewModel.TagHelpers = tagHelperFeature.TagHelpers.ToList(); var viewComponentFeature = new ViewComponentFeature(); _partManager.PopulateFeature(viewComponentFeature); viewModel.ViewComponents = viewComponentFeature.ViewComponents.ToList(); var feature = new ViewsFeature(); _partManager.PopulateFeature(feature); viewModel.Views = feature.ViewDescriptors.Select(v => v.Type.GetTypeInfo()).ToList(); return(View(viewModel)); }
// Token: 0x06000187 RID: 391 RVA: 0x000075D0 File Offset: 0x000057D0 private IViewCompiler CreateCompiler() { ViewsFeature viewsFeature = new ViewsFeature(); this._applicationPartManager.PopulateFeature <ViewsFeature>(viewsFeature); return(new HotUpdateRazorViewCompiler(this._fileProviderAccessor.FileProvider, this._razorProjectEngine, this._csharpCompiler, this._viewEngineOptions.CompilationCallback, viewsFeature.ViewDescriptors, this._logger)); }
public string GetPrecompiledResourceNames([FromServices] ApplicationPartManager applicationManager) { var feature = new ViewsFeature(); applicationManager.PopulateFeature(feature); return(string.Join(Environment.NewLine, feature.ViewDescriptors.Select(v => v.RelativePath))); }
public void PopulateFeature_PopulatesRazorCompiledItemsFromTypeAssembly() { // Arrange var item1 = Mock.Of <RazorCompiledItem>(i => i.Identifier == "Item1" && i.Type == typeof(TestView)); var item2 = Mock.Of <RazorCompiledItem>(i => i.Identifier == "Item2" && i.Type == typeof(TestPage)); var assembly = new TestAssembly(new[] { new RazorCompiledItemAttribute(typeof(TestView), "mvc.1.0.razor-page", "Item1"), new RazorCompiledItemAttribute(typeof(TestView), "mvc.1.0.razor-view", "Item1"), }); var part1 = new AssemblyPart(assembly); var part2 = new Mock <ApplicationPart>(); part2 .As <IRazorCompiledItemProvider>() .Setup(p => p.CompiledItems) .Returns(new[] { item1, item2, }); var featureProvider = new RazorCompiledItemFeatureProvider(); var feature = new ViewsFeature(); // Act featureProvider.PopulateFeature(new[] { part1, part2.Object }, feature); // Assert Assert.Equal(new[] { item1, item2 }, feature.ViewDescriptors.Select(d => d.Item)); }
protected virtual ViewsFeature GetViewFeature(ApplicationPartManager applicationManager) { var viewsFeature = new ViewsFeature(); applicationManager.PopulateFeature(viewsFeature); return(viewsFeature); }
public void OnProvidersExecuting(ActionDescriptorProviderContext context) { var newContext = new ActionDescriptorProviderContext(); _pageActionDescriptorProvider.OnProvidersExecuting(newContext); _pageActionDescriptorProvider.OnProvidersExecuted(newContext); var feature = new ViewsFeature(); _applicationPartManager.PopulateFeature(feature); var lookup = new Dictionary <string, CompiledViewDescriptor>(feature.ViewDescriptors.Count, StringComparer.Ordinal); foreach (var viewDescriptor in feature.ViewDescriptors) { // View ordering has precedence semantics, a view with a higher precedence was not // already added to the list. lookup.TryAdd(ViewPath.NormalizePath(viewDescriptor.RelativePath), viewDescriptor); } foreach (var item in newContext.Results) { var pageActionDescriptor = (PageActionDescriptor)item; if (!lookup.TryGetValue(pageActionDescriptor.RelativePath, out var compiledViewDescriptor)) { throw new InvalidOperationException($"A descriptor for '{pageActionDescriptor.RelativePath}' was not found."); } var compiledPageActionDescriptor = _compiledPageActionDescriptorFactory.CreateCompiledDescriptor( pageActionDescriptor, compiledViewDescriptor); context.Results.Add(compiledPageActionDescriptor); } }
public void ClearCache() { _precompiledViews.Clear(); var feature = new ViewsFeature(); _applicationPartManager.PopulateFeature(feature); foreach (var precompiledView in feature.ViewDescriptors) { if (!_precompiledViews.ContainsKey(precompiledView.RelativePath)) { // View ordering has precedence semantics, a view with a higher precedence was // already added to the list. _precompiledViews.Add(precompiledView.RelativePath, precompiledView); } else { var oldPreCompiledView = _precompiledViews[precompiledView.RelativePath]; if (oldPreCompiledView.Type != precompiledView.Type) { _precompiledViews[precompiledView.RelativePath] = precompiledView; } } } _cache.Clear(); }
public static IList <CompiledViewDescriptor> ViewsFeatures(this ApplicationPartManager applicationPartManager) { var feature = new ViewsFeature(); applicationPartManager.PopulateFeature(feature); return(feature.ViewDescriptors); }
public string PrintViews([FromServices] ApplicationPartManager manager) { var feature = new ViewsFeature(); manager.PopulateFeature(feature); return(string.Join("\n", feature.ViewDescriptors.Select(d => d.RelativePath))); }
public void PopulateFeature(IEnumerable <ApplicationPart> parts, ViewsFeature feature) { foreach (var item in CompiledViews) { feature.ViewDescriptors.Add(item); } }
private IViewCompiler CreateCompiler() { ViewsFeature feature = new ViewsFeature(); _applicationPartManager.PopulateFeature <ViewsFeature>(feature); return((IViewCompiler) new WyamRazorViewCompiler(_fileProviderAccessor.FileProvider, _razorProjectEngine, _csharpCompiler, _viewEngineOptions.CompilationCallback, feature.ViewDescriptors, (ILogger)_logger)); }
public void Modify() { var feature = new ViewsFeature(); _applicationPartManager.PopulateFeature(feature); _compiler = new MyViewCompiler(feature.ViewDescriptors, _loggerFactory.CreateLogger <MyViewCompiler>()); }
/// <summary> /// Initializes a new instance of <see cref="DefaultCompilerCacheProvider"/>. /// </summary> /// <param name="applicationPartManager">The <see cref="ApplicationPartManager" /></param> /// <param name="fileProviderAccessor">The <see cref="IRazorViewEngineFileProviderAccessor"/>.</param> public DefaultCompilerCacheProvider( ApplicationPartManager applicationPartManager, IRazorViewEngineFileProviderAccessor fileProviderAccessor) { var feature = new ViewsFeature(); applicationPartManager.PopulateFeature(feature); Cache = new CompilerCache(fileProviderAccessor.FileProvider, feature.Views); }
public IList <CompiledViewDescriptor> GetCompiledViewDescriptors() { var feature = new ViewsFeature(); _applicationPartManager.PopulateFeature(feature); var views = feature.ViewDescriptors; return(views); }
public void Refresh() { var feature = new ViewsFeature(); var controller = new ControllerFeature(); var contrrolerProvider = new ControllerFeatureProvider(); _applicationPartManager.PopulateFeature(feature); _applicationPartManager.PopulateFeature(controller); _compiler = new InBizViewCompiler(feature.ViewDescriptors, _loggerFactory.CreateLogger <InBizViewCompiler>()); }
protected override ViewsFeature GetViewFeature(ApplicationPartManager applicationManager) { var feature = new ViewsFeature(); foreach (var descriptor in Descriptors) { feature.ViewDescriptors.Add(descriptor); } return(feature); }
private IViewCompiler CreateCompiler() { var feature = new ViewsFeature(); _applicationPartManager.PopulateFeature(feature); return(new CustomRuntimeViewCompiler(_applicationPartManager, _fileProvider.FileProvider, _razorProjectEngine, _csharpCompiler, feature.ViewDescriptors, _logger)); }
/// <summary> /// Gets the sequence of <see cref="CompiledViewDescriptor"/> from <paramref name="applicationManager"/>. /// </summary> /// <param name="applicationManager">The <see cref="ApplicationPartManager"/>s</param> /// <returns>The sequence of <see cref="CompiledViewDescriptor"/>.</returns> protected virtual IEnumerable <CompiledViewDescriptor> GetViewDescriptors(ApplicationPartManager applicationManager) { if (applicationManager == null) { throw new ArgumentNullException(nameof(applicationManager)); } var viewsFeature = new ViewsFeature(); applicationManager.PopulateFeature(viewsFeature); return(viewsFeature.ViewDescriptors.Where(d => d.IsPrecompiled && d.ViewAttribute is RazorPageAttribute)); }
private IViewCompiler CreateCompiler() { var feature = new ViewsFeature(); _applicationPartManager.PopulateFeature(feature); return(new RazorViewCompiler( _fileProviderAccessor.FileProvider, _razorTemplateEngine, _csharpCompiler, _viewEngineOptions.CompilationCallback, feature.ViewDescriptors, _logger)); }
public void PopulateFeature(IEnumerable <ApplicationPart> parts, ViewsFeature feature) { var viewsToRemove = new List <CompiledViewDescriptor>(); foreach (var descriptor in feature.ViewDescriptors) { if (IsIdentityUIView(descriptor)) { switch (_framework) { case UIFramework.Bootstrap4: if (descriptor.Type.FullName.Contains("V5")) { // Remove V5 views viewsToRemove.Add(descriptor); } else { // Fix up paths to eliminate version subdir descriptor.RelativePath = descriptor.RelativePath.Replace("V4/", ""); } break; case UIFramework.Bootstrap5: if (descriptor.Type.FullName.Contains("V4")) { // Remove V4 views viewsToRemove.Add(descriptor); } else { // Fix up paths to eliminate version subdir descriptor.RelativePath = descriptor.RelativePath.Replace("V5/", ""); } break; default: throw new InvalidOperationException($"Unknown framework: {_framework}"); } } } foreach (var descriptorToRemove in viewsToRemove) { feature.ViewDescriptors.Remove(descriptorToRemove); } }
private IViewCompiler CreateCompiler() { var feature = new ViewsFeature(); _applicationPartManager.PopulateFeature(feature); return(new RazorViewCompiler( _fileProviderAccessor.FileProvider, _razorProjectEngine, _csharpCompiler, #pragma warning disable CS0618 // Type or member is obsolete _viewEngineOptions.CompilationCallback, #pragma warning restore CS0618 // Type or member is obsolete feature.ViewDescriptors, _compilationMemoryCacheProvider.CompilationMemoryCache, _logger)); }
public IActionResult Index() { var assembly = Assembly.LoadFile(AppDomain.CurrentDomain.BaseDirectory + "DLL\\PluginController\\PluginController.dll"); var viewAssembly = Assembly.LoadFile(AppDomain.CurrentDomain.BaseDirectory + "DLL\\PluginController\\PluginController.Views.dll"); var controllerAssemblyPart = new AssemblyPart(assembly); var viewAssemblyPart = new CompiledRazorAssemblyPart(viewAssembly); _applicationPartManager.ApplicationParts.Add(controllerAssemblyPart); _applicationPartManager.ApplicationParts.Add(viewAssemblyPart); _pluginActionDescriptorProvider.Reload(); var feature = new ViewsFeature(); _applicationPartManager.PopulateFeature <ViewsFeature>(feature); return(Content("Enabled"));; }
public Task StartAsync(CancellationToken cancellationToken) { // Get the names of all the application parts. This is the short assembly name for AssemblyParts var applicationParts = _partManager.ApplicationParts.Select(x => x.Name); // Create a controller feature, and populate it from the application parts var controllerFeature = new ViewsFeature(); _partManager.PopulateFeature(controllerFeature); // Get the names of all of the controllers var controllers = controllerFeature.ViewDescriptors.Select(x => x.Type); // Log the application parts and controllers var parts = string.Join(", ", applicationParts); var controllersTest = string.Join(", ", controllers); return(Task.CompletedTask); }
public void PopulateFeature_AddsItemsFromProviderTypes() { // Arrange var item1 = Mock.Of <RazorCompiledItem>(i => i.Identifier == "Item1" && i.Type == typeof(TestView)); var item2 = Mock.Of <RazorCompiledItem>(i => i.Identifier == "Item2" && i.Type == typeof(TestPage)); var part1 = new AssemblyPart(typeof(RazorCompiledItemFeatureProviderTest).Assembly); var part2 = new Mock <ApplicationPart>(); part2 .As <IRazorCompiledItemProvider>() .Setup(p => p.CompiledItems).Returns(new[] { item1, item2, }); var featureProvider = new RazorCompiledItemFeatureProvider(); var feature = new ViewsFeature(); // Act featureProvider.PopulateFeature(new[] { part1, part2.Object }, feature); // Assert Assert.Equal(new[] { item1, item2 }, feature.ViewDescriptors.Select(d => d.Item)); }
private void EnsureCompiledViews(ILogger logger) { if (_compiledViews is not null) { return; } var viewsFeature = new ViewsFeature(); _applicationPartManager.PopulateFeature(viewsFeature); // We need to validate that the all compiled views are unique by path (case-insensitive). // We do this because there's no good way to canonicalize paths on windows, and it will create // problems when deploying to linux. Rather than deal with these issues, we just don't support // views that differ only by case. var compiledViews = new Dictionary <string, Task <CompiledViewDescriptor> >( viewsFeature.ViewDescriptors.Count, StringComparer.OrdinalIgnoreCase); foreach (var compiledView in viewsFeature.ViewDescriptors) { Log.ViewCompilerLocatedCompiledView(logger, compiledView.RelativePath); if (!compiledViews.ContainsKey(compiledView.RelativePath)) { // View ordering has precedence semantics, a view with a higher precedence was not // already added to the list. compiledViews.TryAdd(compiledView.RelativePath, Task.FromResult(compiledView)); } } if (compiledViews.Count == 0) { Log.ViewCompilerNoCompiledViewsFound(logger); } // Safe races should be ok. We would end up logging multiple times // if this is invoked concurrently, but since this is primarily a dev-scenario, we don't think // this will happen often. We could always re-consider the logging if we get feedback. _compiledViews = compiledViews; }
public void PopulateFeature_ReplacesWithHotRelaodedItems() { // Arrange var item1 = Mock.Of <RazorCompiledItem>(i => i.Identifier == "Item1" && i.Type == typeof(TestView)); var item2 = Mock.Of <RazorCompiledItem>(i => i.Identifier == "Item2" && i.Type == typeof(TestPage) && i.Kind == "mvc.1.0.razor-page"); var applicationPart = new TestRazorCompiledItemProvider { CompiledItems = new[] { item1, item2 } }; var featureProvider = new RazorCompiledItemFeatureProvider(); // Act - 1 var feature = new ViewsFeature(); featureProvider.PopulateFeature(new[] { applicationPart }, feature); // Assert - 1 Assert.Equal(new[] { item1, item2 }, feature.ViewDescriptors.Select(d => d.Item)); // Act - 2 featureProvider.UpdateCache(new[] { typeof(object), typeof(TestReloadedPage) }); // Assert - 2 feature = new ViewsFeature(); featureProvider.PopulateFeature(new[] { applicationPart }, feature); Assert.Collection( feature.ViewDescriptors, item => { Assert.Same(item.Item, item1); }, item => { Assert.Same(typeof(TestReloadedPage), item.Item.Type); Assert.Same("Item2", item.Item.Identifier); Assert.Equal("mvc.1.0.razor-page", item.Item.Kind); Assert.Contains(typeof(RouteAttribute), item.Item.Metadata.Select(m => m.GetType())); // Verify we pick up new attributes }); }