public void Discover(ShapeTableBuilder builder) { builder.Describe("Price") .OnDisplaying(displaying => { displaying.ShapeMetadata.Alternates.Add("Parts_" + displaying.ShapeMetadata.DisplayType); }); }
public void Discover(ShapeTableBuilder builder) { builder.Describe("Widget") .Configure(descriptor => { // todo: have "alternates" for chrome descriptor.Wrappers.Add("Widget_Wrapper"); descriptor.Wrappers.Add("Widget_ControlWrapper"); }) .OnCreated(created => { var widget = created.Shape; widget.Child.Add(created.New.PlaceChildContent(Source: widget)); }) .OnDisplaying(displaying => { var widget = displaying.Shape; widget.Classes.Add("widget"); ContentItem contentItem = displaying.Shape.ContentItem; if (contentItem != null) { widget.Classes.Add("widget-" + contentItem.ContentType.HtmlClassify()); var zoneName = contentItem.As<WidgetPart>().Zone; // Widget__[ZoneName] e.g. Widget-SideBar displaying.ShapeMetadata.Alternates.Add("Widget__" + zoneName); // Widget__[ContentType] e.g. Widget-BlogArchive displaying.ShapeMetadata.Alternates.Add("Widget__" + contentItem.ContentType); } }); }
public void Discover(ShapeTableBuilder builder) { builder.Describe("Content") .OnCreated(created => { var content = created.Shape; content.Child.Add(created.New.PlaceChildContent(Source: content)); }) .OnDisplaying(displaying => { ContentItem contentItem = displaying.Shape.ContentItem; if (contentItem != null) { // Alternates in order of specificity. // Display type > content type > specific content > display type for a content type > display type for specific content // BasicShapeTemplateHarvester.Adjust will then adjust the template name // Content__[DisplayType] e.g. Content-Summary displaying.ShapeMetadata.Alternates.Add("Content_" + EncodeAlternateElement(displaying.ShapeMetadata.DisplayType)); // Content__[ContentType] e.g. Content-BlogPost, displaying.ShapeMetadata.Alternates.Add("Content__" + EncodeAlternateElement(contentItem.ContentType)); // Content__[Id] e.g. Content-42, displaying.ShapeMetadata.Alternates.Add("Content__" + contentItem.Id); // Content_[DisplayType]__[ContentType] e.g. Content-BlogPost.Summary displaying.ShapeMetadata.Alternates.Add("Content_" + displaying.ShapeMetadata.DisplayType + "__" + EncodeAlternateElement(contentItem.ContentType)); // Content_[DisplayType]__[Id] e.g. Content-42.Summary displaying.ShapeMetadata.Alternates.Add("Content_" + displaying.ShapeMetadata.DisplayType + "__" + contentItem.Id); } }); }
private void ProcessFeatureDescriptor(ShapeTableBuilder builder, FeatureDescriptor featureDescriptor) { var virtualPath = featureDescriptor.Extension.Location + "/" + featureDescriptor.Extension.Id + "/Placement.info"; var placementFile = _placementFileParser.Parse(virtualPath); if (placementFile != null) { ProcessPlacementFile(builder, featureDescriptor, placementFile); } }
public void Discover(ShapeTableBuilder builder) { builder.Describe("LogOn") .OnDisplaying(displaying => { var clientsData = _openAuthAuthenticationClients .Select(client => _orchardOpenAuthClientProvider.GetClientData(client.ProviderName)) .Where(x => x != null) .ToList(); var shape = displaying.Shape; var metadata = displaying.ShapeMetadata; shape.ClientsData = clientsData; metadata.Type = "OpenAuthLogOn"; }); builder.Describe("Register") .OnDisplaying(displaying => { var clientsData = _openAuthAuthenticationClients .Select(client => _orchardOpenAuthClientProvider.GetClientData(client.ProviderName)) .Where(x => x != null) .ToList(); var shape = displaying.Shape; var metadata = displaying.ShapeMetadata; shape.ClientsData = clientsData; metadata.Type = "OpenAuthRegister"; }); }
public void Discover(ShapeTableBuilder builder) { builder.Describe("Media") .OnDisplaying(displaying => { ContentItem contentItem = displaying.Shape.ContentItem; if (contentItem != null) { // Alternates in order of specificity. // Display type > content type > specific content > display type for a content type > display type for specific content // BasicShapeTemplateHarvester.Adjust will then adjust the template name // Media__[DisplayType] e.g. Media-Summary displaying.ShapeMetadata.Alternates.Add("Media_" + EncodeAlternateElement(displaying.ShapeMetadata.DisplayType)); // Media__[ContentType] e.g. Media-BlogPost, displaying.ShapeMetadata.Alternates.Add("Media__" + EncodeAlternateElement(contentItem.ContentType)); // Media__[Id] e.g. Media-42, displaying.ShapeMetadata.Alternates.Add("Media__" + contentItem.Id); // Media_[DisplayType]__[ContentType] e.g. Media-Image.Summary displaying.ShapeMetadata.Alternates.Add("Media_" + displaying.ShapeMetadata.DisplayType + "__" + EncodeAlternateElement(contentItem.ContentType)); // Media_[DisplayType]__[Id] e.g. Media-42.Summary displaying.ShapeMetadata.Alternates.Add("Media_" + displaying.ShapeMetadata.DisplayType + "__" + contentItem.Id); } }); }
public void Discover(ShapeTableBuilder builder) { builder.Describe("Foo") .OnDisplaying(displaying => displaying.ChildContent = new HtmlString("<h1>Hi</h1>") ); }
public void Discover(ShapeTableBuilder builder) { builder.Describe("Parts_Comments") .OnDisplaying(shapeDisplayingContext => { var settings = this.orchardServices.WorkContext.CurrentSite.As<DisqusSettingsPart>(); shapeDisplayingContext.Shape.DisqusSettings = settings; shapeDisplayingContext.Shape.DisqusUniqueId = GetUniqueIdentifier(shapeDisplayingContext.Shape.ContentPart.ContentItem); shapeDisplayingContext.ShapeMetadata.Wrappers.Add("CommentsWrapper"); }); builder.Describe("Parts_Comments_Count") .OnDisplaying(shapeDisplayingContext => { var settings = this.orchardServices.WorkContext.CurrentSite.As<DisqusSettingsPart>(); shapeDisplayingContext.Shape.DisqusSettings = settings; shapeDisplayingContext.Shape.DisqusUniqueId = GetUniqueIdentifier(shapeDisplayingContext.Shape.ContentPart.ContentItem); shapeDisplayingContext.ShapeMetadata.Wrappers.Add("CountWrapper"); }); builder.Describe("Parts_Blogs_BlogPost_List") .OnDisplaying(shapeDisplayingContext => { var settings = this.orchardServices.WorkContext.CurrentSite.As<DisqusSettingsPart>(); shapeDisplayingContext.Shape.DisqusSettings = settings; shapeDisplayingContext.ShapeMetadata.Wrappers.Add("ListWrapper"); }); }
public void Discover(ShapeTableBuilder builder) { builder.Describe("Content_Edit") .OnDisplaying(displaying => { var shape = displaying.Shape; shape.Metadata.Alternates.Add("Content_Edit__Default"); }); }
public ShapeTable GetShapeTable(string themeName) { // Use a lazy initialized factory to prevent multiple threads from building // the same table in parallel as it is costly return _shapeTables.GetOrAdd(themeName ?? "", new Lazy<ShapeTable>(() => { _logger.LogInformation("Start building shape table"); IList<IReadOnlyList<ShapeAlteration>> alterationSets = new List<IReadOnlyList<ShapeAlteration>>(); foreach (var bindingStrategy in _bindingStrategies) { Feature strategyDefaultFeature = _typeFeatureProvider.GetFeatureForDependency(bindingStrategy.GetType()); var builder = new ShapeTableBuilder(strategyDefaultFeature); bindingStrategy.Discover(builder); var builtAlterations = builder.BuildAlterations().ToReadOnlyCollection(); if (builtAlterations.Any()) { alterationSets.Add(builtAlterations); } } var alterations = alterationSets .SelectMany(shapeAlterations => shapeAlterations) .Where(alteration => IsModuleOrRequestedTheme(alteration, themeName)) .OrderByDependenciesAndPriorities(AlterationHasDependency, GetPriority) .ToList(); var descriptors = alterations.GroupBy(alteration => alteration.ShapeType, StringComparer.OrdinalIgnoreCase) .Select(group => group.Aggregate( new ShapeDescriptor { ShapeType = group.Key }, (descriptor, alteration) => { alteration.Alter(descriptor); return descriptor; })).ToList(); foreach (var descriptor in descriptors) { foreach (var alteration in alterations.Where(a => a.ShapeType == descriptor.ShapeType).ToList()) { var local = new ShapeDescriptor { ShapeType = descriptor.ShapeType }; alteration.Alter(local); descriptor.BindingSources.Add(local.BindingSource); } } var result = new ShapeTable { Descriptors = descriptors.ToDictionary(sd => sd.ShapeType, StringComparer.OrdinalIgnoreCase), Bindings = descriptors.SelectMany(sd => sd.Bindings).ToDictionary(kv => kv.Key, kv => kv.Value, StringComparer.OrdinalIgnoreCase), }; //await _eventBus.NotifyAsync<IShapeTableEventHandler>(x => x.ShapeTableCreated(result)); _logger.LogInformation("Done building shape table"); return result; })).Value; }
public void Discover(ShapeTableBuilder builder) { builder.Describe("Parts_MenuWidget").OnDisplaying(context => { var contentItem = (ContentItem)context.Shape.ContentItem; var widgetPart = contentItem.As<WidgetPart>(); var menuWidgetPart = contentItem.As<MenuWidgetPart>(); var menuShape = context.Shape.Menu; var widgetName = widgetPart.Name.ToSafeName(); var menu = mMenuService.Value.GetMenu(menuWidgetPart.MenuContentItemId); var menuName = menu.As<TitlePart>().Title.ToSafeName(); var zoneName = widgetPart.Zone; if (!String.IsNullOrWhiteSpace(widgetName)) context.ShapeMetadata.Alternates.Add($"Parts_MenuWidget__WidgetName__{widgetName}"); context.ShapeMetadata.Alternates.Add($"Parts_MenuWidget__MenuName__{menuName}"); context.ShapeMetadata.Alternates.Add($"Parts_MenuWidget__MenuLevel__{menuWidgetPart.StartLevel}"); context.ShapeMetadata.Alternates.Add($"Parts_MenuWidget__MenuName__{menuName}__MenuLevel{menuWidgetPart.StartLevel}"); context.ShapeMetadata.Alternates.Add($"Parts_MenuWidget__Zone__{zoneName}"); context.ShapeMetadata.Alternates.Add($"Parts_MenuWidget__Zone__{zoneName}__MenuName__{menuName}"); menuShape.MenuWidget = contentItem; menuShape.SafeMenuName = menuName; }); builder.Describe("Menu").OnDisplaying(ConfigureMenuShape); builder.Describe("Breadcrumb").OnDisplaying(ConfigureMenuShape); }
public void Discover(ShapeTableBuilder builder) { builder.Describe("Post_Body_Editor") .OnDisplaying(displaying => { string flavor = displaying.Shape.EditorFlavor; displaying.ShapeMetadata.Alternates.Add("Post_Body_Editor__" + flavor); }); // We support multiple forum types, but need to be able to skin forum admin shapes, so add alternates for any content type that has a ForumPart. builder.Describe("Content").OnDisplaying(displaying => { var content = (ContentItem) displaying.Shape.ContentItem; if (content.Parts.All(x => x.PartDefinition.Name != typeof (ForumPart).Name)) return; var displayType = !String.IsNullOrWhiteSpace(displaying.ShapeMetadata.DisplayType) ? displaying.ShapeMetadata.DisplayType : "Detail"; var alternates = new[] { string.Format("Content__{0}", content.ContentType), string.Format("Content__{0}_{1}", content.ContentType, displayType), }; foreach (var alternate in alternates.Where(alternate => !displaying.ShapeMetadata.Alternates.Contains(alternate))) { displaying.ShapeMetadata.Alternates.Add(alternate); } }); }
public void Discover(ShapeTableBuilder builder) { builder.Describe("HeadScripts") .OnDisplaying(shapeDisplayingContext => { if (!_imagesLoadedService.GetAutoEnable()) return; if (!_imagesLoadedService.GetAutoEnableAdmin()) { var request = _workContext.Value.HttpContext.Request; if (AdminFilter.IsApplied(request.RequestContext)) { return; } } var resourceManager = _workContext.Value.Resolve<IResourceManager>(); var scripts = resourceManager.GetRequiredResources("script"); string includejs = "imagesLoaded"; var currentHighlight = scripts .Where(l => l.Name == includejs) .FirstOrDefault(); if (currentHighlight == null) { resourceManager.Require("script", includejs).AtFoot(); } }); }
public void Discover(ShapeTableBuilder builder) { builder.Describe("Body_Editor") .OnDisplaying(displaying => { string flavor = displaying.Shape.EditorFlavor; displaying.ShapeMetadata.Alternates.Add("Body_Editor__" + flavor); }); }
public void Discover(ShapeTableBuilder builder) { builder.Describe("HeadLinks") .OnDisplaying(shapeDisplayingContext => { string faviconUrl = _faviconService.GetFaviconUrl(); if (!string.IsNullOrWhiteSpace(faviconUrl)) { // Get the current favicon from head var resourceManager = _wca.GetContext().Resolve<IResourceManager>(); var links = resourceManager.GetRegisteredLinks(); var currentFavicon = links .Where(l => l.Rel == "shortcut icon" && l.Type == "image/x-icon") .FirstOrDefault(); // Modify if found if (currentFavicon != default(LinkEntry)) { currentFavicon.Href = faviconUrl; } else { // Add the new one resourceManager.RegisterLink(new LinkEntry { Type = "image/x-icon", Rel = "shortcut icon", Href = faviconUrl }); } } }); }
public void Discover(ShapeTableBuilder builder) { builder.Describe("Menu") .OnDisplaying(displaying => { string displayType = displaying.Shape.DisplayType; if (!string.IsNullOrWhiteSpace(displayType)) { displaying.Shape.Metadata.Alternates.Add("Menu_" + EncodeAlternateElement(displayType)); } }); builder.Describe("MenuItem") .OnDisplaying(displaying => { string displayType = displaying.Shape.Menu.DisplayType; if (!string.IsNullOrWhiteSpace(displayType)) { displaying.Shape.Metadata.Alternates.Add("MenuItem_" + EncodeAlternateElement(displayType)); } }); builder.Describe("MenuItemLink") .OnDisplaying(displaying => { string displayType = displaying.Shape.Menu.DisplayType; if (!string.IsNullOrWhiteSpace(displayType)) { displaying.Shape.Metadata.Alternates.Add("MenuItemLink_" + EncodeAlternateElement(displayType)); } }); }
public void Discover(ShapeTableBuilder builder) { builder.Describe("Content") .OnCreated(created => { var content = created.Shape; content.Child.Add(created.New.PlaceChildContent(Source: content)); }) .OnDisplaying(displaying => { ContentItem contentItem = displaying.Shape.ContentItem; if (contentItem != null) { // Alternates in order of specificity. // Display type > content type > specific content > display type for a content type > display type for specific content // Content__[DisplayType] e.g. Content.Summary displaying.ShapeMetadata.Alternates.Add("Content_" + displaying.ShapeMetadata.DisplayType); // Content__[ContentType] e.g. Content-BlogPost displaying.ShapeMetadata.Alternates.Add("Content__" + contentItem.ContentType); // Content__[Id] e.g. Content-42 displaying.ShapeMetadata.Alternates.Add("Content__" + contentItem.Id); // Content_[DisplayType]__[ContentType] e.g. Content-BlogPost.Summary displaying.ShapeMetadata.Alternates.Add("Content_" + displaying.ShapeMetadata.DisplayType + "__" + contentItem.ContentType); // Content_[DisplayType]__[Id] e.g. Content-42.Summary displaying.ShapeMetadata.Alternates.Add("Content_" + displaying.ShapeMetadata.DisplayType + "__" + contentItem.Id); if ( !displaying.ShapeMetadata.DisplayType.Contains("Admin") ) displaying.ShapeMetadata.Wrappers.Add("Content_ControlWrapper"); } }); }
public void Discover(ShapeTableBuilder builder) { builder.Describe("Content").OnDisplaying(displaying => { if (!displaying.ShapeMetadata.DisplayType.Contains("Admin")) { displaying.ShapeMetadata.Wrappers.Add("Content_ControlWrapper"); } }); }
public void Discover(ShapeTableBuilder builder) { builder.Describe("EditorTemplate").OnDisplaying(context => { if (context.Shape.TemplateName != "Parts.Layout") return; _resourceManager.Value.Require("script", "MainBit.Layouts.LayoutEditors"); }); }
public void Discover(ShapeTableBuilder builder) { builder.Describe("OptionSet") .OnDisplaying(displaying => { var shape = displaying.Shape; shape.Classes.Add("option-set"); }); }
public void Discover(ShapeTableBuilder builder) { builder.Describe("Parts_Layout").OnDisplaying(context => { if (context.ShapeMetadata.DisplayType != "Dashboard") return; context.ShapeMetadata.Alternates.Add("Parts_Layout_Dashboard"); }); }
public void Discover(ShapeTableBuilder builder) { builder.Describe("Content") .OnDisplaying(displaying => { if (displaying.ShapeMetadata.DisplayType == "Navigation") { displaying.ShapeMetadata.Alternates.Add("Content_Navigation"); } }); }
public void Discover(ShapeTableBuilder builder) { builder.Describe("Parts_ProjectionPart") .OnDisplaying(displaying => { var shape = displaying.Shape; if (!string.IsNullOrWhiteSpace(shape.ContentPart.Record.PagerSuffix)) { shape.Metadata.Alternates.Add("Parts_ProjectionPart__" + shape.ContentPart.Record.PagerSuffix); } }); }
public void Discover(ShapeTableBuilder builder) { // hack: This is important when using the Input shape directly, but it doesn't come into play // when using a 'master' shape yet. builder.Describe("Input").Configure(descriptor => descriptor.Wrappers.Add("InputWrapper")); builder.Describe("SelectList").Configure(descriptor => descriptor.Wrappers.Add("InputWrapper")); builder.Describe("Textarea").Configure(descriptor => descriptor.Wrappers.Add("InputWrapper")); builder.Describe("Form").OnCreating(ctx => ctx.Behaviors.Add(new PropertiesAreItems())); builder.Describe("Fieldset").OnCreating(ctx => ctx.Behaviors.Add(new PropertiesAreItems())); }
public void Discover(ShapeTableBuilder builder) { builder.Describe("Parts_Containable_Edit").OnDisplaying(displaying=> { ContentItem item = displaying.Shape.ContentItem; if (item.ContentType == "StaffGroup") displaying.ShapeMetadata.Alternates.Add("Containable_StaffGroup"); }); }
public void Discover(ShapeTableBuilder builder) { builder.Describe("Layout").OnDisplaying(displaying => { // Remove default layout wrapper displaying.ShapeMetadata.Wrappers.Clear(); // Add SEOKit layout wrapper with custom title handling displaying.ShapeMetadata.Wrappers.Add("SEODocument"); }); }
public void Discover(ShapeTableBuilder builder) { builder.Describe("ContentPicker") .OnDisplaying(displaying => { ContentItem contentItem = displaying.Shape.ContentItem; if (contentItem != null) { displaying.ShapeMetadata.Alternates.Add("ContentPicker_" + displaying.ShapeMetadata.DisplayType); } }); }
public void Discover(ShapeTableBuilder builder) { builder.Describe("EditorTemplate").OnDisplaying(context => { if (context.Shape.TemplateName != "Parts.Layout") return; _resourceManager.Value.Require("stylesheet", "DynamicForms.FormElements"); _resourceManager.Value.Require("script", "DynamicForms.FormElements"); }); }
public void Discover(ShapeTableBuilder builder) { builder.Describe("Content") .OnCreating(creating => { creating.Behaviors.Add( new ZoneProxyBehavior(new Dictionary<string, Func<dynamic>> { { "Layout", () => _workContextAccessor.GetContext().Layout } }) ); }); }
public void Discover(ShapeTableBuilder builder) { builder.Describe("Table") .OnCreating(creating => { creating.Behaviors.Add(new RowHoldingBehavior(()=>creating.New.Row())); }); builder.Describe("Row") .OnCreating(creating => { creating.Behaviors.Add(new CellHoldingBehavior(() => creating.New.Cell())); }); }
public ShapeTable GetShapeTable(string themeName) { return(_cacheManager.Get(themeName ?? "", x => { Logger.Information("Start building shape table"); var alterationSets = _parallelCacheContext.RunInParallel(_bindingStrategies, bindingStrategy => { Feature strategyDefaultFeature = bindingStrategy.Metadata.ContainsKey("Feature") ? (Feature)bindingStrategy.Metadata["Feature"] : null; var builder = new ShapeTableBuilder(strategyDefaultFeature); bindingStrategy.Value.Discover(builder); return builder.BuildAlterations().ToReadOnlyCollection(); }); var alterations = alterationSets .SelectMany(shapeAlterations => shapeAlterations) .Where(alteration => IsModuleOrRequestedTheme(alteration, themeName)) .OrderByDependenciesAndPriorities(AlterationHasDependency, GetPriority) .ToList(); var descriptors = alterations.GroupBy(alteration => alteration.ShapeType, StringComparer.OrdinalIgnoreCase) .Select(group => group.Aggregate( new ShapeDescriptor { ShapeType = group.Key }, (descriptor, alteration) => { alteration.Alter(descriptor); return descriptor; })).ToList(); foreach (var descriptor in descriptors) { foreach (var alteration in alterations.Where(a => a.ShapeType == descriptor.ShapeType).ToList()) { var local = new ShapeDescriptor { ShapeType = descriptor.ShapeType }; alteration.Alter(local); descriptor.BindingSources.Add(local.BindingSource); } } var result = new ShapeTable { Descriptors = descriptors.ToDictionary(sd => sd.ShapeType, StringComparer.OrdinalIgnoreCase), Bindings = descriptors.SelectMany(sd => sd.Bindings).ToDictionary(kv => kv.Key, kv => kv.Value, StringComparer.OrdinalIgnoreCase), }; _shapeTableEventHandlers.Invoke(ctx => ctx.ShapeTableCreated(result), Logger); Logger.Information("Done building shape table"); return result; })); }
public ShapeTable GetShapeTable(string themeName) { var cacheKey = $"ShapeTable:{themeName}"; ShapeTable shapeTable; if (!_memoryCache.TryGetValue(cacheKey, out shapeTable)) { if (_logger.IsEnabled(LogLevel.Information)) { _logger.LogInformation("Start building shape table"); } IList <IReadOnlyList <ShapeAlteration> > alterationSets = new List <IReadOnlyList <ShapeAlteration> >(); foreach (var bindingStrategy in _bindingStrategies) { Feature strategyDefaultFeature = _typeFeatureProvider.GetFeatureForDependency(bindingStrategy.GetType()); var builder = new ShapeTableBuilder(strategyDefaultFeature); bindingStrategy.Discover(builder); var builtAlterations = builder.BuildAlterations().ToReadOnlyCollection(); if (builtAlterations.Any()) { alterationSets.Add(builtAlterations); } } var alterations = alterationSets .SelectMany(shapeAlterations => shapeAlterations) .Where(alteration => IsModuleOrRequestedTheme(alteration, themeName)) .OrderByDependenciesAndPriorities(AlterationHasDependency, GetPriority) .ToList(); var descriptors = alterations.GroupBy(alteration => alteration.ShapeType, StringComparer.OrdinalIgnoreCase) .Select(group => group.Aggregate( new ShapeDescriptor { ShapeType = group.Key }, (descriptor, alteration) => { alteration.Alter(descriptor); return(descriptor); })).ToList(); foreach (var descriptor in descriptors) { foreach (var alteration in alterations.Where(a => a.ShapeType == descriptor.ShapeType).ToList()) { var local = new ShapeDescriptor { ShapeType = descriptor.ShapeType }; alteration.Alter(local); descriptor.BindingSources.Add(local.BindingSource); } } shapeTable = new ShapeTable { Descriptors = descriptors.ToDictionary(sd => sd.ShapeType, StringComparer.OrdinalIgnoreCase), Bindings = descriptors.SelectMany(sd => sd.Bindings).ToDictionary(kv => kv.Key, kv => kv.Value, StringComparer.OrdinalIgnoreCase), }; //await _eventBus.NotifyAsync<IShapeTableEventHandler>(x => x.ShapeTableCreated(result)); if (_logger.IsEnabled(LogLevel.Information)) { _logger.LogInformation("Done building shape table"); } _memoryCache.Set(cacheKey, shapeTable, new MemoryCacheEntryOptions { Priority = CacheItemPriority.NeverRemove }); } return(shapeTable); }
public ShapeTable GetShapeTable(string themeName) { // Use a lazy initialized factory to prevent multiple threads from building // the same table in parallel as it is costly return(_shapeTables.GetOrAdd(themeName ?? "", new Lazy <ShapeTable>(() => { if (_logger.IsEnabled(LogLevel.Information)) { _logger.LogInformation("Start building shape table"); } IList <IReadOnlyList <ShapeAlteration> > alterationSets = new List <IReadOnlyList <ShapeAlteration> >(); foreach (var bindingStrategy in _bindingStrategies) { Feature strategyDefaultFeature = _typeFeatureProvider.GetFeatureForDependency(bindingStrategy.GetType()); var builder = new ShapeTableBuilder(strategyDefaultFeature); bindingStrategy.Discover(builder); var builtAlterations = builder.BuildAlterations().ToReadOnlyCollection(); if (builtAlterations.Any()) { alterationSets.Add(builtAlterations); } } var alterations = alterationSets .SelectMany(shapeAlterations => shapeAlterations) .Where(alteration => IsModuleOrRequestedTheme(alteration, themeName)) .OrderByDependenciesAndPriorities(AlterationHasDependency, GetPriority) .ToList(); var descriptors = alterations.GroupBy(alteration => alteration.ShapeType, StringComparer.OrdinalIgnoreCase) .Select(group => group.Aggregate( new ShapeDescriptor { ShapeType = group.Key }, (descriptor, alteration) => { alteration.Alter(descriptor); return descriptor; })).ToList(); foreach (var descriptor in descriptors) { foreach (var alteration in alterations.Where(a => a.ShapeType == descriptor.ShapeType).ToList()) { var local = new ShapeDescriptor { ShapeType = descriptor.ShapeType }; alteration.Alter(local); descriptor.BindingSources.Add(local.BindingSource); } } var result = new ShapeTable { Descriptors = descriptors.ToDictionary(sd => sd.ShapeType, StringComparer.OrdinalIgnoreCase), Bindings = descriptors.SelectMany(sd => sd.Bindings).ToDictionary(kv => kv.Key, kv => kv.Value, StringComparer.OrdinalIgnoreCase), }; //await _eventBus.NotifyAsync<IShapeTableEventHandler>(x => x.ShapeTableCreated(result)); if (_logger.IsEnabled(LogLevel.Information)) { _logger.LogInformation("Done building shape table"); } return result; })).Value); }
public ShapeTable GetShapeTable(string themeId) { var cacheKey = $"ShapeTable:{themeId}"; ShapeTable shapeTable; if (!_memoryCache.TryGetValue(cacheKey, out shapeTable)) { if (_logger.IsEnabled(LogLevel.Information)) { _logger.LogInformation("Start building shape table"); } var excludedFeatures = _shapeDescriptors.Count == 0 ? new List <string>() : _shapeDescriptors.Select(kv => kv.Value.Feature.Id).Distinct().ToList(); foreach (var bindingStrategy in _bindingStrategies) { IFeatureInfo strategyFeature = _typeFeatureProvider.GetFeatureForDependency(bindingStrategy.GetType()); if (!(bindingStrategy is IShapeTableHarvester) && excludedFeatures.Contains(strategyFeature.Id)) { continue; } var builder = new ShapeTableBuilder(strategyFeature, excludedFeatures); bindingStrategy.Discover(builder); var builtAlterations = builder.BuildAlterations(); BuildDescriptors(bindingStrategy, builtAlterations); } var enabledFeatureIds = _shellFeaturesManager.GetEnabledFeaturesAsync().Result.Select(fd => fd.Id).ToList(); var descriptors = _shapeDescriptors .Where(sd => IsEnabledModuleOrRequestedTheme(sd.Value, themeId, enabledFeatureIds)) .OrderByDependenciesAndPriorities(DescriptorHasDependency, GetPriority) .GroupBy(sd => sd.Value.ShapeType, StringComparer.OrdinalIgnoreCase) .Select(group => new ShapeDescriptorIndex ( shapeType: group.Key, alterationKeys: group.Select(kv => kv.Key), descriptors: _shapeDescriptors )); shapeTable = new ShapeTable { Descriptors = descriptors.Cast <ShapeDescriptor>().ToDictionary(sd => sd.ShapeType, StringComparer.OrdinalIgnoreCase), Bindings = descriptors.SelectMany(sd => sd.Bindings).ToDictionary(kv => kv.Key, kv => kv.Value, StringComparer.OrdinalIgnoreCase) }; if (_logger.IsEnabled(LogLevel.Information)) { _logger.LogInformation("Done building shape table"); } _memoryCache.Set(cacheKey, shapeTable, new MemoryCacheEntryOptions { Priority = CacheItemPriority.NeverRemove }); } return(shapeTable); }