public async Task <IEnumerable <IFeatureInfo> > GetAvailableFeaturesAsync()
        {
            var features = _extensionManager.GetFeatures();
            var result   = new List <IFeatureInfo>();

            foreach (var feature in features)
            {
                var isFeatureValid = true;
                foreach (var validator in _featureValidators)
                {
                    isFeatureValid = await validator.IsFeatureValidAsync(feature.Id);

                    // When a feature is marked as invalid it cannot be reintroduced.
                    if (!isFeatureValid)
                    {
                        break;
                    }
                }

                if (isFeatureValid)
                {
                    result.Add(feature);
                }
            }

            return(result);
        }
Example #2
0
        public void GetFeaturesShouldReturnBothThemesAndModules()
        {
            var features = ModuleThemeScopedExtensionManager.GetFeatures()
                           .Where(f => f.Category == "Test");

            Assert.Equal(8, features.Count());
        }
Example #3
0
        public void GetFeaturesShouldReturnAllFeaturesOrderedByDependency()
        {
            var features = ModuleScopedExtensionManager.GetFeatures();

            Assert.Equal(4, features.Count());
            Assert.Equal("Sample1", features.ElementAt(0).Id);
            Assert.Equal("Sample2", features.ElementAt(1).Id);
            Assert.Equal("Sample3", features.ElementAt(2).Id);
            Assert.Equal("Sample4", features.ElementAt(3).Id);
        }
Example #4
0
        public void GetFeaturesShouldReturnAllFeaturesOrderedByDependency()
        {
            var features = ModuleScopedExtensionManager.GetFeatures()
                           .Where(f => f.Category == "Test" && !f.Extension.IsTheme());

            Assert.Equal(4, features.Count());
            Assert.Equal("Sample1", features.ElementAt(0).Id);
            Assert.Equal("Sample2", features.ElementAt(1).Id);
            Assert.Equal("Sample3", features.ElementAt(2).Id);
            Assert.Equal("Sample4", features.ElementAt(3).Id);
        }
Example #5
0
        /// <summary>
        /// Retrieves an enumeration of the available features together with its state (enabled / disabled).
        /// </summary>
        /// <returns>An enumeration of the available features together with its state (enabled / disabled).</returns>
        public async Task <IEnumerable <ModuleFeature> > GetAvailableFeaturesAsync()
        {
            var enabledFeatures =
                await _shellFeaturesManager.GetEnabledFeaturesAsync();

            var availableFeatures = _extensionManager.GetFeatures();

            return(availableFeatures
                   .Select(f => AssembleModuleFromDescriptor(f, enabledFeatures
                                                             .Any(sf => sf.Id == f.Id))));
        }
Example #6
0
        public async Task <ActionResult> Integrations()
        {
            if (!await _authorizationService.AuthorizeAsync(User, OrchardCore.Features.Permissions.ManageFeatures)) // , T["Not allowed to manage features."]
            {
                return(Unauthorized());
            }

            var enabledFeatures = await _shellFeaturesManager.GetEnabledFeaturesAsync();

            // var alwaysEnabledFeatures = await _shellFeaturesManager.GetAlwaysEnabledFeaturesAsync();
//           var integrationFeatures = enabledFeatures.Where(extensionDescriptor =>
//           {
//               var tags = extensionDescriptor.Extension.Manifest.Tags.ToArray();
//               var isIntegrationFeature =
//                   tags.Any(x => string.Equals(x, "integration", StringComparison.OrdinalIgnoreCase));
//
//               return isIntegrationFeature;
//           });

            var moduleFeatures = new List <ModuleFeature>();

            foreach (var moduleFeatureInfo in _extensionManager
                     .GetFeatures()
                     .Where(f => !f.Extension.IsTheme() && FeatureIsAllowed(f)))
            {
                var dependentFeatures    = _extensionManager.GetDependentFeatures(moduleFeatureInfo.Id);
                var featureDependencies  = _extensionManager.GetFeatureDependencies(moduleFeatureInfo.Id);
                var isIntegrationFeature = IsIntegrationFeature(moduleFeatureInfo.Extension.Manifest);

                if (isIntegrationFeature == true)
                {
                    var moduleFeature = new ModuleFeature
                    {
                        Descriptor = moduleFeatureInfo,
                        IsEnabled  = enabledFeatures.Contains(moduleFeatureInfo),
                        // IsAlwaysEnabled = alwaysEnabledFeatures.Contains(moduleFeatureInfo),
                        //IsRecentlyInstalled = _moduleService.IsRecentlyInstalled(f.Extension),
                        //NeedsUpdate = featuresThatNeedUpdate.Contains(f.Id),
                        EnabledDependentFeatures = dependentFeatures.Where(x => x.Id != moduleFeatureInfo.Id).ToList(),
                        FeatureDependencies      = featureDependencies.Where(d => d.Id != moduleFeatureInfo.Id).ToList()
                    };

                    moduleFeatures.Add(moduleFeature);
                }
            }

            return(View(new FeaturesViewModel
            {
                Features = moduleFeatures,
                IsAllowed = FeatureIsAllowed
            }));
        }
Example #7
0
        /// <summary>
        /// Enables a list of features.
        /// </summary>
        /// <param name="featureIds">The IDs for the features to be enabled.</param>
        /// <param name="force">Boolean parameter indicating if the feature should enable it's dependencies if required or fail otherwise.</param>
        public async Task EnableFeaturesAsync(IEnumerable <string> featureIds, bool force)
        {
            var featuresToEnable = _extensionManager
                                   .GetFeatures()
                                   .Where(x => featureIds.Contains(x.Id));

            var enabledFeatures = await _shellFeaturesManager.EnableFeaturesAsync(featuresToEnable, force);

            foreach (var enabledFeature in enabledFeatures)
            {
                await _notifier.SuccessAsync(H["{0} was enabled.", enabledFeature.Name]);
            }
        }
        public async Task <ActionResult> SetCurrentTheme(string id)
        {
            if (!await _authorizationService.AuthorizeAsync(User, Permissions.ApplyTheme))
            {
                return(Forbid());
            }

            if (String.IsNullOrEmpty(id))
            {
                // Don't use any theme on the front-end
            }
            else
            {
                var feature = _extensionManager.GetFeatures().FirstOrDefault(f => f.Extension.IsTheme() && f.Id == id);

                if (feature == null)
                {
                    return(NotFound());
                }
                else
                {
                    var isAdmin = IsAdminTheme(feature.Extension.Manifest);

                    if (isAdmin)
                    {
                        await _adminThemeService.SetAdminThemeAsync(id);
                    }
                    else
                    {
                        await _siteThemeService.SetSiteThemeAsync(id);
                    }

                    // Enable the feature lastly to avoid accessing a disposed IMemoryCache (due to the current shell being disposed after updating).
                    var enabledFeatures = await _shellFeaturesManager.GetEnabledFeaturesAsync();

                    var isEnabled = enabledFeatures.Any(x => x.Extension.Id == feature.Id);

                    if (!isEnabled)
                    {
                        await _shellFeaturesManager.EnableFeaturesAsync(new[] { feature }, force : true);

                        _notifier.Success(H["{0} was enabled", feature.Name ?? feature.Id]);
                    }

                    _notifier.Success(H["{0} was set as the default {1} theme", feature.Name ?? feature.Id, isAdmin ? "Admin" : "Site"]);
                }
            }

            return(RedirectToAction("Index"));
        }
        public async Task <ActionResult> Index()
        {
            if (!await _authorizationService.AuthorizeAsync(User, StandardPermissions.SiteOwner))
            {
                return(Unauthorized());
            }

            var recipeCollections = await Task.WhenAll(_recipeHarvesters.Select(x => x.HarvestRecipesAsync()));

            var recipes = recipeCollections.SelectMany(x => x);

            recipes = recipes.Where(c => !c.Tags.Contains("hidden", StringComparer.InvariantCultureIgnoreCase));

            var features = _extensionManager.GetFeatures();

            var model = recipes.Select(recipe => new RecipeViewModel
            {
                Name          = recipe.DisplayName,
                FileName      = recipe.RecipeFileInfo.Name,
                BasePath      = recipe.BasePath,
                Tags          = recipe.Tags,
                IsSetupRecipe = recipe.IsSetupRecipe,
                Feature       = features.FirstOrDefault(f => recipe.BasePath.Contains(f.Extension.SubPath))?.Name ?? "Application",
                Description   = recipe.Description
            }).ToArray();

            return(View(model));
        }
Example #10
0
        public async Task Setup(IDictionary <string, object> properties, Action <string, string> reportError)
        {
            var features = _extensionManager.GetFeatures();

            var featuresToEnable = features.Where(x => x.Id == "ThisNetWorks.OrchardCore.GoogleMaps");

            await _shellFeatureManager.EnableFeaturesAsync(featuresToEnable, true);

            var ctds = _contentDefinitionManager.ListPartDefinitions();

            if (ctds.FirstOrDefault(x => x.Name == "BlogPost") != null)
            {
                _contentDefinitionManager.AlterTypeDefinition("BlogPost", builder => builder
                                                              .WithPart("GoogleMapPart"));

                var query = _session.Query <ContentItem>()
                            .With <ContentItemIndex>(x => x.ContentType == "BlogPost" && x.Published);

                var blogPosts = await query.ListAsync();

                foreach (var blogPost in blogPosts)
                {
                    blogPost.Alter <GoogleMapPart>(part =>
                    {
                        part.Marker = new LatLng {
                            Lat = GoogleMapsSettings.DefaultLatitude, Lng = GoogleMapsSettings.DefaultLongitude
                        };
                    });

                    _session.Save(blogPost);
                }
            }
        }
        public async Task <(IEnumerable <IFeatureInfo>, IEnumerable <IFeatureInfo>)> UpdateFeaturesAsync(ShellDescriptor shellDescriptor,
                                                                                                         IEnumerable <IFeatureInfo> featuresToDisable, IEnumerable <IFeatureInfo> featuresToEnable, bool force)
        {
            var alwaysEnabledIds = _alwaysEnabledFeatures.Select(sf => sf.Id).ToArray();

            var enabledFeatures = _extensionManager.GetFeatures().Where(f =>
                                                                        shellDescriptor.Features.Any(sf => sf.Id == f.Id)).ToList();

            var enabledFeatureIds = enabledFeatures.Select(f => f.Id).ToArray();

            var AllFeaturesToDisable = featuresToDisable
                                       .Where(f => !alwaysEnabledIds.Contains(f.Id))
                                       .SelectMany(feature => GetFeaturesToDisable(feature, enabledFeatureIds, force))
                                       .Distinct()
                                       .ToList();

            if (AllFeaturesToDisable.Count > 0)
            {
                foreach (var feature in AllFeaturesToDisable)
                {
                    enabledFeatures.Remove(feature);

                    if (_logger.IsEnabled(LogLevel.Information))
                    {
                        _logger.LogInformation("Feature '{FeatureName}' was disabled", feature.Id);
                    }
                }
            }

            enabledFeatureIds = enabledFeatures.Select(f => f.Id).ToArray();

            var AllFeaturesToEnable = featuresToEnable
                                      .SelectMany(feature => GetFeaturesToEnable(feature, enabledFeatureIds, force))
                                      .Distinct()
                                      .ToList();

            if (AllFeaturesToEnable.Count > 0)
            {
                if (_logger.IsEnabled(LogLevel.Information))
                {
                    foreach (var feature in AllFeaturesToEnable)
                    {
                        _logger.LogInformation("Enabling feature '{FeatureName}'", feature.Id);
                    }
                }

                enabledFeatures = enabledFeatures.Concat(AllFeaturesToEnable).Distinct().ToList();
            }

            if (AllFeaturesToDisable.Count > 0 || AllFeaturesToEnable.Count > 0)
            {
                await _shellDescriptorManager.UpdateShellDescriptorAsync(
                    shellDescriptor.SerialNumber,
                    enabledFeatures.Select(x => new ShellFeature(x.Id)).ToList(),
                    shellDescriptor.Parameters);
            }

            return(AllFeaturesToDisable, AllFeaturesToEnable);
        }
Example #12
0
        /// <inheritdoc />
        public virtual IEnumerable <string> ExpandViewLocations(ViewLocationExpanderContext context,
                                                                IEnumerable <string> viewLocations)
        {
            if (!context.Values.ContainsKey("Theme"))
            {
                return(viewLocations);
            }

            var currentThemeId = context.Values["Theme"];

            var currentThemeAndBaseThemesOrdered = _extensionManager
                                                   .GetFeatures(new[] { currentThemeId })
                                                   .Where(x => x.Extension.Manifest.IsTheme())
                                                   .Reverse();

            if (context.ActionContext.ActionDescriptor is PageActionDescriptor page)
            {
                var pageViewLocations = PageViewLocations().ToList();
                pageViewLocations.AddRange(viewLocations);
                return(pageViewLocations);

                IEnumerable <string> PageViewLocations()
                {
                    if (page.RelativePath.Contains("/Pages/") && !page.RelativePath.StartsWith("/Pages/"))
                    {
                        var pageIndex    = page.RelativePath.LastIndexOf("/Pages/");
                        var moduleFolder = page.RelativePath.Substring(0, pageIndex);
                        var moduleId     = moduleFolder.Substring(moduleFolder.LastIndexOf("/") + 1);

                        foreach (var theme in currentThemeAndBaseThemesOrdered)
                        {
                            if (moduleId != theme.Id)
                            {
                                var themeViewsPath = "/" + theme.Extension.SubPath + "/Views/" + moduleId;
                                yield return(themeViewsPath + "/Shared/{0}" + RazorViewEngine.ViewExtension);
                            }
                        }
                    }
                }
            }

            var result = new List <string>();

            if (!String.IsNullOrEmpty(context.AreaName))
            {
                foreach (var theme in currentThemeAndBaseThemesOrdered)
                {
                    if (context.AreaName != theme.Id)
                    {
                        var themeViewsPath = '/' + theme.Extension.SubPath + "/Views/" + context.AreaName;
                        result.Add(themeViewsPath + "/{1}/{0}" + RazorViewEngine.ViewExtension);
                        result.Add(themeViewsPath + "/Shared/{0}" + RazorViewEngine.ViewExtension);
                    }
                }
            }

            result.AddRange(viewLocations);
            return(result);
        }
 public ModularPageApplicationModelProvider(
     IExtensionManager extensionManager,
     ShellDescriptor shellDescriptor)
 {
     // Pages paths of all available modules which are enabled in the current shell.
     _paths = extensionManager.GetFeatures().Where(f => shellDescriptor.Features.Any(sf =>
                                                                                     sf.Id == f.Id)).Select(f => '/' + f.Extension.SubPath + "/Pages/").Distinct();
 }
Example #14
0
        public void GetFeaturesShouldReturnCorrectThemeHeirarchy()
        {
            var features = ThemeScopedExtensionManager.GetFeatures(new[] { "DerivedThemeSample" });

            Assert.Equal(2, features.Count());
            Assert.Equal("BaseThemeSample", features.ElementAt(0).Id);
            Assert.Equal("DerivedThemeSample", features.ElementAt(1).Id);
        }
Example #15
0
 private bool IsBaseTheme(string featureId, string themeId)
 {
     // determine if the given feature is a base theme of the given theme
     return(_extensionManager
            .GetFeatures(new[] { themeId })
            .Where(x => x.Extension.Manifest.IsTheme())
            .Select(fi => new ThemeExtensionInfo(fi.Extension))
            .Any(x => x.IsBaseThemeFeature(featureId)));
 }
 public ModularPageApplicationModelProvider(
     IExtensionManager extensionManager,
     ShellDescriptor shellDescriptor)
 {
     // Available features by area in the current shell.
     _featureIdsByArea = extensionManager.GetFeatures()
                         .Where(f => shellDescriptor.Features.Any(sf => sf.Id == f.Id))
                         .ToLookup(f => f.Extension.Id, f => f.Id);
 }
Example #17
0
        /// <inheritdoc />
        public virtual IEnumerable <string> ExpandViewLocations(ViewLocationExpanderContext context,
                                                                IEnumerable <string> viewLocations)
        {
            if (!context.Values.ContainsKey("Theme"))
            {
                return(viewLocations);
            }

            var currentThemeId = context.Values["Theme"];

            var currentThemeAndBaseThemesOrdered = _extensionManager
                                                   .GetFeatures(new[] { currentThemeId })
                                                   .Where(x => x.Extension.Manifest.IsTheme())
                                                   .Reverse();

            if (context.ActionContext.ActionDescriptor is PageActionDescriptor)
            {
                if (context.PageName != null)
                {
                    var pageViewLocations = PageViewLocations().ToList();
                    pageViewLocations.AddRange(viewLocations);
                    return(pageViewLocations);
                }

                return(viewLocations);

                IEnumerable <string> PageViewLocations()
                {
                    foreach (var theme in currentThemeAndBaseThemesOrdered)
                    {
                        if (!context.PageName.StartsWith('/' + theme.Id + '/'))
                        {
                            var themeViewsPath = "/" + theme.Extension.SubPath.Replace('\\', '/').Trim('/');
                            yield return(themeViewsPath + "/Views/Shared/{0}" + RazorViewEngine.ViewExtension);
                        }
                    }
                }
            }

            var result = new List <string>();

            foreach (var theme in currentThemeAndBaseThemesOrdered)
            {
                if (context.AreaName != theme.Id)
                {
                    var themeViewsPath = '/' + theme.Extension.SubPath.Replace('\\', '/').Trim('/') +
                                         "/Views/" + context.AreaName;

                    result.Add(themeViewsPath + "/{1}/{0}" + RazorViewEngine.ViewExtension);
                    result.Add(themeViewsPath + "/Shared/{0}" + RazorViewEngine.ViewExtension);
                }
            }

            result.AddRange(viewLocations);
            return(result);
        }
Example #18
0
        /// <inheritdoc />
        public virtual IEnumerable<string> ExpandViewLocations(ViewLocationExpanderContext context,
            IEnumerable<string> viewLocations)
        {
            if (context.AreaName == null)
            {
                return viewLocations;
            }

            HashSet<string> enabledExtensionIds = null;

            var result = new List<string>();

            if (context.PageName != null)
            {
                if (!_memoryCache.TryGetValue(PageCacheKey, out IEnumerable<string> modulePageSharedViewLocations))
                {
                    modulePageSharedViewLocations = _modulesWithPageSharedViews
                        .Where(m => GetEnabledExtensionIds().Contains(m.Id))
                        .Select(m => '/' + m.SubPath + PageSharedViewsPath);

                    _memoryCache.Set(PageCacheKey, modulePageSharedViewLocations);
                }

                result.AddRange(modulePageSharedViewLocations);
            }

            if (!_memoryCache.TryGetValue(CacheKey, out IEnumerable<string> moduleSharedViewLocations))
            {
                moduleSharedViewLocations = _modulesWithSharedViews
                    .Where(m => GetEnabledExtensionIds().Contains(m.Id))
                    .Select(m => '/' + m.SubPath + SharedViewsPath);

                _memoryCache.Set(CacheKey, moduleSharedViewLocations);
            }

            result.AddRange(moduleSharedViewLocations);
            result.AddRange(viewLocations);

            return result;

            HashSet<string> GetEnabledExtensionIds()
            {
                if (enabledExtensionIds != null)
                {
                    return enabledExtensionIds;
                }

                var enabledIds = _extensionManager.GetFeatures().Where(f => _shellDescriptor
                        .Features.Any(sf => sf.Id == f.Id)).Select(f => f.Extension.Id).ToHashSet();

                return enabledExtensionIds = _extensionManager.GetExtensions()
                    .Where(e => enabledIds.Contains(e.Id)).Select(x => x.Id).ToHashSet();
            }
        }
Example #19
0
        public ModularPageApplicationModelProvider(
            ITypeFeatureProvider typeFeatureProvider,
            IExtensionManager extensionManager,
            ShellDescriptor shellDescriptor)
        {
            // Available features in the current shell.
            _features = extensionManager.GetFeatures().Where(f => shellDescriptor.Features.Any(sf =>
                                                                                               sf.Id == f.Id)).Select(f => f);

            _typeFeatureProvider = typeFeatureProvider;
        }
        /// <inheritdoc />
        public virtual IEnumerable <string> ExpandViewLocations(ViewLocationExpanderContext context,
                                                                IEnumerable <string> viewLocations)
        {
            if (!context.Values.ContainsKey("Theme"))
            {
                return(viewLocations);
            }

            var currentThemeId = context.Values["Theme"];

            var currentThemeAndBaseThemesOrdered = _extensionManager
                                                   .GetFeatures(new[] { currentThemeId })
                                                   .Where(x => x.Extension.IsTheme())
                                                   .Reverse();

            var result = new List <string>();

            foreach (var theme in currentThemeAndBaseThemesOrdered)
            {
                if (context.AreaName != theme.Id)
                {
                    var themePagesPath = '/' + theme.Extension.SubPath + "/Pages";
                    var themeViewsPath = '/' + theme.Extension.SubPath + "/Views";

                    if (context.AreaName != null)
                    {
                        if (context.PageName != null)
                        {
                            result.Add(themePagesPath + "/{2}/{0}" + RazorViewEngine.ViewExtension);
                        }
                        else
                        {
                            result.Add(themeViewsPath + "/{2}/{1}/{0}" + RazorViewEngine.ViewExtension);
                        }
                    }

                    if (context.PageName != null)
                    {
                        result.Add(themePagesPath + "/Shared/{0}" + RazorViewEngine.ViewExtension);
                    }

                    if (context.AreaName != null)
                    {
                        result.Add(themeViewsPath + "/{2}/Shared/{0}" + RazorViewEngine.ViewExtension);
                    }

                    result.Add(themeViewsPath + "/Shared/{0}" + RazorViewEngine.ViewExtension);
                }
            }

            result.AddRange(viewLocations);
            return(result);
        }
Example #21
0
        public async Task <ActionResult> Features()
        {
            if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageFeatures))
            {
                return(Forbid());
            }

            var enabledFeatures = await _shellFeaturesManager.GetEnabledFeaturesAsync();

            var alwaysEnabledFeatures = await _shellFeaturesManager.GetAlwaysEnabledFeaturesAsync();

            var moduleFeatures = new List <ModuleFeature>();

            foreach (var moduleFeatureInfo in _extensionManager
                     .GetFeatures()
                     .Where(f => !f.Extension.IsTheme() && FeatureIsAllowed(f)))
            {
                var dependentFeatures   = _extensionManager.GetDependentFeatures(moduleFeatureInfo.Id);
                var featureDependencies = _extensionManager.GetFeatureDependencies(moduleFeatureInfo.Id);

                var moduleFeature = new ModuleFeature
                {
                    Descriptor      = moduleFeatureInfo,
                    IsEnabled       = enabledFeatures.Contains(moduleFeatureInfo),
                    IsAlwaysEnabled = alwaysEnabledFeatures.Contains(moduleFeatureInfo),
                    //IsRecentlyInstalled = _moduleService.IsRecentlyInstalled(f.Extension),
                    //NeedsUpdate = featuresThatNeedUpdate.Contains(f.Id),
                    DependentFeatures   = dependentFeatures.Where(x => x.Id != moduleFeatureInfo.Id).ToList(),
                    FeatureDependencies = featureDependencies.Where(d => d.Id != moduleFeatureInfo.Id).ToList()
                };

                moduleFeatures.Add(moduleFeature);
            }

            return(View(new FeaturesViewModel
            {
                Features = moduleFeatures,
                IsAllowed = FeatureIsAllowed
            }));
        }
Example #22
0
        public Task <ShellDescriptor> GetShellDescriptorAsync()
        {
            if (_shellDescriptor == null)
            {
                _shellDescriptor = new ShellDescriptor
                {
                    Features = _extensionManager.GetFeatures().Select(x => new ShellFeature {
                        Id = x.Id
                    }).ToList()
                };
            }

            return(Task.FromResult(_shellDescriptor));
        }
 private void EnsureApplicationFeature()
 {
     if (_applicationFeature == null)
     {
         lock (this)
         {
             if (_applicationFeature == null)
             {
                 _applicationFeature = _extensionManager.GetFeatures()
                                       .FirstOrDefault(f => f.Id == _hostingEnvironment.ApplicationName);
             }
         }
     }
 }
        public ModularApplicationModelProvider(
            ITypeFeatureProvider typeFeatureProvider,
            IHostingEnvironment hostingEnvironment,
            IExtensionManager extensionManager,
            ShellDescriptor shellDescriptor,
            ShellSettings shellSettings)
        {
            _typeFeatureProvider = typeFeatureProvider;
            _hostingEnvironment  = hostingEnvironment;

            _enabledFeatureIds = extensionManager.GetFeatures().Where(f => shellDescriptor
                                                                      .Features.Any(sf => sf.Id == f.Id)).Select(f => f.Id).ToArray();

            _shellSettings = shellSettings;
        }
        public ValueTask <bool> IsFeatureValidAsync(string id)
        {
            var features = _extensionManager.GetFeatures(new[] { id });

            if (!features.Any())
            {
                return(new ValueTask <bool>(false));
            }

            if (_shellSettings.Name == ShellHelper.DefaultShellName)
            {
                return(new ValueTask <bool>(true));
            }

            return(new ValueTask <bool>(!features.Any(f => f.DefaultTenantOnly)));
        }
        public ShellContainerFactory(
            IHostingEnvironment hostingEnvironment,
            IExtensionManager extensionManager,
            IServiceProvider serviceProvider,
            ILoggerFactory loggerFactory,
            ILogger <ShellContainerFactory> logger,
            IServiceCollection applicationServices)
        {
            _applicationFeature = extensionManager.GetFeatures().FirstOrDefault(
                f => f.Id == hostingEnvironment.ApplicationName);

            _applicationServices = applicationServices;
            _serviceProvider     = serviceProvider;
            _loggerFactory       = loggerFactory;
            _logger = logger;
        }
        public DependencyVisualiserVm GetData(string filter = "")
        {
            var result = new DependencyVisualiserVm();

            var allFeatures = _extensionManager.GetFeatures().ToList();

            foreach (var featureDescriptor in allFeatures)
            {
                // Store full name including namespace as unique identifier, and user-friendly
                result.Nodes.Add(new DependencyVisualiserVm.NodesModel
                {
                    Id    = featureDescriptor.Id,  // A unique identifier
                    Label = featureDescriptor.Name // Full name including namespace
                });
            }

            foreach (var featureDescriptor in allFeatures)
            {
                foreach (var featureDescriptorDependency in featureDescriptor.Dependencies)
                {
                    var parent = result.Nodes.SingleOrDefault(n => n.Id == featureDescriptorDependency);

                    if (parent != null)
                    {
                        result.Edges.Add(new DependencyVisualiserVm.EdgesModel
                        {
                            From = featureDescriptor.Id,
                            To   = featureDescriptorDependency
                        });
                    }
                }
            }

            if (!string.IsNullOrWhiteSpace(filter))
            {
                result.Nodes = result.Nodes.Where(n => n.Id.Contains(filter)).ToList();
                result.Edges = result.Edges.Where(e => e.From.Contains(filter)).ToList();
            }

            return(result);
        }
Example #28
0
        /// <inheritdoc />
        public virtual IEnumerable <string> ExpandViewLocations(ViewLocationExpanderContext context,
                                                                IEnumerable <string> viewLocations)
        {
            var themeManager = context
                               .ActionContext
                               .HttpContext
                               .RequestServices
                               .GetService <IThemeManager>();

            if (themeManager != null)
            {
                var currentTheme = themeManager.GetThemeAsync().GetAwaiter().GetResult();

                if (currentTheme == null)
                {
                    return(Enumerable.Empty <string>());
                }

                var currentThemeAndBaseThemesOrdered = _extensionManager
                                                       .GetFeatures(new[] { currentTheme.Id })
                                                       .Where(x => x.Extension.Manifest.IsTheme())
                                                       .Reverse();

                var result = new List <string>();

                foreach (var theme in currentThemeAndBaseThemesOrdered)
                {
                    var themeViewsPath = Path.Combine(
                        Path.DirectorySeparatorChar + theme.Extension.SubPath,
                        "Views",
                        context.AreaName != theme.Id ? context.AreaName : string.Empty);

                    result.Add(Path.Combine(themeViewsPath, "{1}", "{0}.cshtml"));
                    result.Add(Path.Combine(themeViewsPath, "Shared", "{0}.cshtml"));
                }

                return(result);
            }

            return(Enumerable.Empty <string>());
        }
Example #29
0
        private bool IsBaseTheme(string featureId, string themeId)
        {
            // determine if the given feature is a base theme of the given theme
            var availableFeatures = _extensionManager.GetFeatures();

            var themeFeature = availableFeatures.SingleOrDefault(f => f.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(f => f.Id == themeExtensionInfo.BaseTheme);
            }
            return(false);
        }
Example #30
0
        private async Task MigrateToVuetifyTheme()
        {
            var vuetifyModule = _extensionManager.GetFeatures(new [] {
                "VuetifyTheme",
                "OrchardCore.ContentTypes",
                "StatCan.OrchardCore.DisplayHelpers",
                "StatCan.OrchardCore.Menu",
                Constants.Features.Vuetify,
                Constants.Features.Alert,
                Constants.Features.Card,
                Constants.Features.ExpansionPanel,
                Constants.Features.Grid,
                Constants.Features.Image,
                Constants.Features.List,
                Constants.Features.Schedule,
                Constants.Features.Tabs,
                Constants.Features.Timeline,
            });
            await _shellFeaturesManager.EnableFeaturesAsync(vuetifyModule, true);

            await _siteThemeService.SetSiteThemeAsync("VuetifyTheme");
        }