private bool DescriptorHasDependency(KeyValuePair <string, FeatureShapeDescriptor> item, KeyValuePair <string, FeatureShapeDescriptor> subject) { if (item.Value.Feature.Extension.Manifest.IsTheme()) { if (subject.Value.Feature.Id == "Core") { return(true); } if (subject.Value.Feature.Extension.Manifest.IsModule()) { return(true); } if (subject.Value.Feature.Extension.Manifest.IsTheme()) { var theme = new ThemeExtensionInfo(item.Value.Feature.Extension); if (theme.HasBaseTheme()) { return(theme.BaseTheme == subject.Value.Feature.Id); } } } return(item.Value.Feature.DependencyOn(subject.Value.Feature)); }
public async Task EnableThemeFeaturesAsync(string themeName) { var themes = new Stack <string>(); while (themeName != null) { if (themes.Contains(themeName)) { throw new InvalidOperationException(H["The theme \"{0}\" is already in the stack of themes that need features enabled.", themeName].ToString()); } themes.Push(themeName); // TODO: MWP: probably follow on issue: should this be recursive? maybe with a depth limit? i.e. base3->base2->base1 ... var extensionInfo = _extensionManager.GetExtension(themeName); var theme = new ThemeExtensionInfo(extensionInfo); // Along similar lines as with ModuleAttribute, internal safety checks handled within the attribute itself themeName = theme.BaseTheme; } while (themes.Count > 0) { var themeId = themes.Pop(); await EnableFeaturesAsync(new[] { themeId }, true); } }
public async Task EnableThemeFeaturesAsync(string themeName) { var themes = new Stack <string>(); while (themeName != null) { if (themes.Contains(themeName)) { throw new InvalidOperationException(T["The theme \"{0}\" is already in the stack of themes that need features enabled.", themeName].ToString()); } themes.Push(themeName); var extensionInfo = _extensionManager.GetExtension(themeName); var theme = new ThemeExtensionInfo(extensionInfo); themeName = !string.IsNullOrWhiteSpace(theme.BaseTheme) ? theme.BaseTheme : null; } while (themes.Count > 0) { var themeId = themes.Pop(); await EnableFeaturesAsync(new[] { themeId }, true); } }
public override void Building(FeatureBuildingContext context) { if (context.ExtensionInfo.Manifest.ModuleInfo is ThemeAttribute) { var extensionInfo = new ThemeExtensionInfo(context.ExtensionInfo); if (extensionInfo.HasBaseTheme()) { context.FeatureDependencyIds = context .FeatureDependencyIds .Concat(new [] { extensionInfo.BaseTheme }) .ToArray(); } context.ExtensionInfo = extensionInfo; } }
public override void Building(FeatureBuildingContext context) { var moduleInfo = context.ExtensionInfo.Manifest.ModuleInfo; if (moduleInfo is ThemeAttribute || (moduleInfo is ModuleMarkerAttribute && moduleInfo.Type.Equals("Theme", StringComparison.OrdinalIgnoreCase))) { var extensionInfo = new ThemeExtensionInfo(context.ExtensionInfo); if (extensionInfo.HasBaseTheme()) { context.FeatureDependencyIds = context .FeatureDependencyIds .Concat(new[] { extensionInfo.BaseTheme }) .ToArray(); } context.ExtensionInfo = extensionInfo; } }
private bool IsBaseTheme(string featureId, string themeId) { // determine if the given feature is a base theme of the given theme var availableFeatures = _extensionManager.GetExtensions().Features; var themeFeature = availableFeatures.SingleOrDefault(fd => fd.Id == themeId); while (themeFeature != null && themeFeature.Extension.Manifest.IsTheme()) { var themeExtensionInfo = new ThemeExtensionInfo(themeFeature.Extension); if (!themeExtensionInfo.HasBaseTheme()) { return(false); } if (themeExtensionInfo.IsBaseThemeFeature(featureId)) { return(true); } themeFeature = availableFeatures.SingleOrDefault(fd => fd.Id == themeExtensionInfo.BaseTheme); } return(false); }
private IEnumerable <IExtensionInfo> GetBaseThemes(IExtensionInfo theme, string adminThemeId, IEnumerable <IExtensionInfo> extensions) { if (theme?.Id.Equals(adminThemeId, StringComparison.OrdinalIgnoreCase) ?? false) { return(extensions.Where(e => e.Manifest.IsTheme() && e.Id != adminThemeId)); } else { var list = new List <IExtensionInfo>(); if (theme == null) { return(list); } var themeInfo = new ThemeExtensionInfo(theme); while (true) { if (!themeInfo.HasBaseTheme()) { break; } var baseTheme = extensions.FirstOrDefault(e => themeInfo.IsBaseThemeFeature(e.Id)); if (baseTheme == null || list.Contains(baseTheme)) { break; } list.Add(baseTheme); theme = baseTheme; } return(list); } }