예제 #1
0
        private IViewEngine DeepEngines(ExtensionDescriptor theme)
        {
            return(_configuredEnginesCache.BindDeepEngines(theme.Id, () => {
                // The order for searching for views is:
                // 1. Current "theme"
                // 2. Base themes of the current theme (in "base" order)
                // 3. Active features from modules in dependency order

                var engines = Enumerable.Empty <IViewEngine>();
                // 1. current theme
                engines = engines.Concat(CreateThemeViewEngines(theme));

                // 2. Base themes of the current theme (in "base" order)
                engines = GetBaseThemes(theme).Aggregate(engines, (current, baseTheme) => current.Concat(CreateThemeViewEngines(baseTheme)));

                // 3. Active features from modules in dependency order
                var enabledModules = _extensionManager.EnabledFeatures(_shellDescriptor)
                                     .Reverse() // reverse from (C <= B <= A) to (A => B => C)
                                     .Where(fd => DefaultExtensionTypes.IsModule(fd.Extension.ExtensionType));

                var allLocations = enabledModules.Concat(enabledModules)
                                   .Select(fd => fd.Extension.Location + "/" + fd.Extension.Id)
                                   .Distinct(StringComparer.OrdinalIgnoreCase)
                                   .ToList();

                var moduleParams = new CreateModulesViewEngineParams {
                    VirtualPaths = allLocations
                };
                engines = engines.Concat(_viewEngineProviders.Select(vep => vep.CreateModulesViewEngine(moduleParams)));

                return new ViewEngineCollectionWrapper(engines);
            }));
        }
        public ShellBlueprint Compose(ShellSettings settings, ShellDescriptor descriptor)
        {
            Logger.Debug("Composing blueprint");

            var builtinFeatures           = BuiltinFeatures().ToList();
            var builtinFeatureDescriptors = builtinFeatures.Select(x => x.Descriptor).ToList();
            var availableFeatures         = _extensionManager.AvailableFeatures()
                                            .Concat(builtinFeatureDescriptors)
                                            .GroupBy(x => x.Id.ToLowerInvariant()) // prevent duplicates
                                            .Select(x => x.FirstOrDefault())
                                            .ToDictionary(x => x.Id, StringComparer.OrdinalIgnoreCase);
            var enabledFeatures  = _extensionManager.EnabledFeatures(descriptor).Select(x => x.Id).ToList();
            var expandedFeatures = ExpandDependencies(availableFeatures, descriptor.Features.Select(x => x.Name)).ToList();
            var autoEnabledDependencyFeatures = expandedFeatures.Except(enabledFeatures).Except(builtinFeatureDescriptors.Select(x => x.Id)).ToList();
            var featureDescriptors            = _extensionManager.EnabledFeatures(expandedFeatures.Select(x => new ShellFeature {
                Name = x
            })).ToList();
            var features = _extensionManager.LoadFeatures(featureDescriptors);

            if (descriptor.Features.Any(feature => feature.Name == "Boying.Framework"))
            {
                features = builtinFeatures.Concat(features);
            }

            var excludedTypes   = GetExcludedTypes(features);
            var modules         = BuildBlueprint(features, IsModule, BuildModule, excludedTypes);
            var dependencies    = BuildBlueprint(features, IsDependency, (t, f) => BuildDependency(t, f, descriptor), excludedTypes);
            var controllers     = BuildBlueprint(features, IsController, BuildController, excludedTypes);
            var httpControllers = BuildBlueprint(features, IsHttpController, BuildController, excludedTypes);
            var records         = BuildBlueprint(features, IsRecord, (t, f) => BuildRecord(t, f, settings), excludedTypes);

            var result = new ShellBlueprint
            {
                Settings        = settings,
                Descriptor      = descriptor,
                Dependencies    = dependencies.Concat(modules).ToArray(),
                Controllers     = controllers,
                HttpControllers = httpControllers,
                Records         = records,
            };

            Logger.Debug("Done composing blueprint.");

            if (autoEnabledDependencyFeatures.Any())
            {
                // Add any dependencies previously not enabled to the shell descriptor.
                descriptor.Features = descriptor.Features.Concat(autoEnabledDependencyFeatures.Select(x => new ShellFeature {
                    Name = x
                })).ToList();
                Logger.Information("Automatically enabled the following dependency features: {0}.", String.Join(", ", autoEnabledDependencyFeatures));
            }

            return(result);
        }
예제 #3
0
        public ShellBlueprint Compose(ShellSettings settings, ShellDescriptor descriptor)
        {
            Logger.Debug("Composing blueprint");

            var enabledFeatures = _extensionManager.EnabledFeatures(descriptor);
            var features        = _extensionManager.LoadFeatures(enabledFeatures);

            if (descriptor.Features.Any(feature => feature.Name == "OrchardVNext.Framework"))
            {
                features = BuiltinFeatures().Concat(features);
            }

            var excludedTypes = GetExcludedTypes(features);

            var modules      = BuildBlueprint(features, IsModule, BuildModule, excludedTypes);
            var dependencies = BuildBlueprint(features, IsDependency, (t, f) => BuildDependency(t, f, descriptor),
                                              excludedTypes);
            var controllers = BuildBlueprint(features, IsController, BuildController, excludedTypes);

            var result = new ShellBlueprint {
                Settings     = settings,
                Descriptor   = descriptor,
                Dependencies = dependencies.Concat(modules).ToArray(),
                Controllers  = controllers,
            };

            Logger.Debug("Done composing blueprint");
            return(result);
        }
예제 #4
0
        public ShellBlueprint Compose(ShellSettings settings, ShellDescriptor descriptor)
        {
            _logger.LogDebug("Composing blueprint");

            var enabledFeatures = _extensionManager.EnabledFeatures(descriptor);
            var features        = _extensionManager.LoadFeatures(enabledFeatures);

            if (descriptor.Features.Any(feature => feature.Name == "OrchardVNext.Hosting"))
            {
                features = BuiltinFeatures().Concat(features);
            }

            var excludedTypes = GetExcludedTypes(features);

            var modules      = BuildBlueprint(features, IsModule, BuildModule, excludedTypes);
            var dependencies = BuildBlueprint(features, IsDependency, (t, f) => BuildDependency(t, f, descriptor),
                                              excludedTypes);
            var hoststartup = BuildBlueprint(features, t => IsStartup(t, settings), BuildModule, excludedTypes);

            var result = new ShellBlueprint {
                Settings     = settings,
                Descriptor   = descriptor,
                Dependencies = dependencies.Concat(modules).Concat(hoststartup).ToArray()
            };

            _logger.LogDebug("Done composing blueprint");
            return(result);
        }
예제 #5
0
        private IViewEngine DeepEngines(ExtensionDescriptorEntry theme)
        {
            return(_configuredEnginesCache.BindDeepEngines(theme.Id, () =>
            {
                // 搜索视图顺序:
                // 1. 当前主图
                // 2. 基础主题
                // 3. 来自模块激活功能依赖排序

                var engines = Enumerable.Empty <IViewEngine>();
                // 1. 当前主题
                engines = engines.Concat(CreateThemeViewEngines(theme));

                // 2. 基础主题
                engines = GetBaseThemes(theme).Aggregate(engines, (current, baseTheme) => current.Concat(CreateThemeViewEngines(baseTheme)));

                // 3. 来自模块激活功能依赖排序
                var enabledModules = _extensionManager.EnabledFeatures(_shellDescriptor)
                                     .Reverse() // reverse from (C <= B <= A) to (A => B => C)
                                     .Where(fd => DefaultExtensionTypes.IsModule(fd.Extension.ExtensionType)).ToArray();

                var allLocations = enabledModules.Concat(enabledModules)
                                   .Select(fd => fd.Extension.Location + "/" + fd.Extension.Id)
                                   .Distinct(StringComparer.OrdinalIgnoreCase)
                                   .ToList();

                var moduleParams = new CreateModulesViewEngineParams {
                    VirtualPaths = allLocations
                };
                engines = engines.Concat(_viewEngineProviders.Select(vep => vep.CreateModulesViewEngine(moduleParams)));

                return new ViewEngineCollectionWrapper(engines);
            }));
        }
        public ShellBlueprint Compose(ShellSettings settings, ShellDescriptor descriptor)
        {
            Logger.Debug("Composing blueprint");

            var enabledFeatures    = extensionManager.EnabledFeatures(descriptor).ToList();
            var applicationFeature = enabledFeatures.FirstOrDefault(x => x.Id == Constants.Areas.Application);

            if (applicationFeature != null)
            {
                EnabledDependencyFeatures(enabledFeatures, descriptor, applicationFeature);
            }

            var features        = extensionManager.LoadFeatures(enabledFeatures);
            var excludedTypes   = GetExcludedTypes(features);
            var modules         = BuildBlueprint(features, IsModule, BuildModule, excludedTypes);
            var dependencies    = BuildBlueprint(features, IsDependency, BuildDependency, excludedTypes);
            var controllers     = BuildBlueprint(features, IsController, BuildController, excludedTypes);
            var httpControllers = BuildBlueprint(features, IsHttpController, BuildController, excludedTypes);

            var result = new ShellBlueprint
            {
                Settings        = settings,
                Descriptor      = descriptor,
                Dependencies    = dependencies.Concat(modules).ToArray(),
                Controllers     = controllers,
                HttpControllers = httpControllers
            };

            Logger.Debug("Done composing blueprint");
            return(result);
        }
예제 #7
0
 public IEnumerable <Tuple <Type, Feature> > Get(Func <Type, bool> predicate)
 {
     return(_extensions
            .LoadFeatures(_extensions.EnabledFeatures(_shell.Descriptor))
            .SelectMany(feature => feature.ExportedTypes
                        .Where(predicate)
                        .Select(c => new Tuple <Type, Feature>(c, feature))));
 }
예제 #8
0
        public ShellBlueprint Compose(ShellSettings settings, ShellDescriptor descriptor)
        {
            if (_logger.IsEnabled(LogLevel.Debug))
            {
                _logger.LogDebug("Composing blueprint");
            }

            var enabledFeatures = _extensionManager.EnabledFeatures(descriptor);
            var features        = _extensionManager.LoadFeatures(enabledFeatures);

            // Requiring "Orchard.Hosting" is a shortcut for adding all referenced
            // assemblies as features.
            // TODO: Remove once all services are registered explicitly, so that the container factory
            // doesn't need to inspect ExportedTypes for the core assemblies. We can then also remove
            // some references from Orchard.Hosting.Web.

            if (descriptor.Features.Any(feature => feature.Name == "Orchard.Hosting"))
            {
                features = BuiltinFeatures().Concat(features);
            }

            var excludedTypes = GetExcludedTypes(features);

            var modules      = BuildBlueprint(features, IsModule, BuildModule, excludedTypes);
            var dependencies = BuildBlueprint(features, IsDependency, (t, f) => BuildDependency(t, f, descriptor),
                                              excludedTypes);

            var uniqueDependencies = new Dictionary <Type, DependencyBlueprint>();

            foreach (var dependency in dependencies)
            {
                if (!uniqueDependencies.ContainsKey(dependency.Type))
                {
                    uniqueDependencies.Add(dependency.Type, dependency);
                }
            }

            foreach (var dependency in modules)
            {
                if (!uniqueDependencies.ContainsKey(dependency.Type))
                {
                    uniqueDependencies.Add(dependency.Type, dependency);
                }
            }

            var result = new ShellBlueprint
            {
                Settings     = settings,
                Descriptor   = descriptor,
                Dependencies = uniqueDependencies.Values
            };

            if (_logger.IsEnabled(LogLevel.Debug))
            {
                _logger.LogDebug("Done composing blueprint");
            }
            return(result);
        }
예제 #9
0
        public ShellBlueprint Compose(ShellSettings settings, ShellDescriptor descriptor)
        {
            if (_logger.IsEnabled(LogLevel.Debug))
            {
                _logger.LogDebug("Composing blueprint");
            }

            var enabledFeatures = _extensionManager.EnabledFeatures(descriptor);
            var features        = _extensionManager.LoadFeatures(enabledFeatures);

            // Requiring "Orchard.Hosting" is a shortcut for adding all referenced
            // assemblies as features
            if (descriptor.Features.Any(feature => feature.Name == "Orchard.Hosting"))
            {
                features = BuiltinFeatures().Concat(features);
            }

            var excludedTypes = GetExcludedTypes(features);

            var modules      = BuildBlueprint(features, IsModule, BuildModule, excludedTypes);
            var dependencies = BuildBlueprint(features, IsDependency, (t, f) => BuildDependency(t, f, descriptor),
                                              excludedTypes);

            var uniqueDependencies = new Dictionary <Type, DependencyBlueprint>();

            foreach (var dependency in dependencies)
            {
                if (!uniqueDependencies.ContainsKey(dependency.Type))
                {
                    uniqueDependencies.Add(dependency.Type, dependency);
                }
            }

            foreach (var dependency in modules)
            {
                if (!uniqueDependencies.ContainsKey(dependency.Type))
                {
                    uniqueDependencies.Add(dependency.Type, dependency);
                }
            }

            var result = new ShellBlueprint
            {
                Settings     = settings,
                Descriptor   = descriptor,
                Dependencies = uniqueDependencies.Values
            };

            if (_logger.IsEnabled(LogLevel.Debug))
            {
                _logger.LogDebug("Done composing blueprint");
            }
            return(result);
        }
예제 #10
0
        /// <summary>
        /// 组合外壳蓝图。
        /// </summary>
        /// <param name="settings">外壳设置。</param>
        /// <param name="descriptor">外壳描述符。</param>
        /// <returns>外壳蓝图。</returns>
        public ShellBlueprint Compose(ShellSettings settings, ShellDescriptor descriptor)
        {
            Logger.Debug("组合外壳蓝图");

            var enabledFeatures = _extensionManager.EnabledFeatures(descriptor);
            var features        = _extensionManager.LoadFeatures(enabledFeatures).ToArray();

            if (descriptor.Features.Any(feature => feature.Name == "SuperRocket.Framework"))
            {
                features = features.Concat(BuiltinFeatures()).ToArray();
            }

            var excludedTypes = GetExcludedTypes(features).ToArray();

            var modules      = BuildBlueprint(features, IsModule, BuildModule, excludedTypes);
            var dependencies = BuildBlueprint(features, IsDependency, BuildDependency, excludedTypes);

            var result = new ShellBlueprint
            {
                Settings     = settings,
                Descriptor   = descriptor,
                Dependencies = dependencies.Concat(modules).ToArray()
            };

            Logger.Debug("准备应用外部组合策略。");
            var context = new CompositionStrategyApplyContext
            {
                Features       = features,
                ExcludedTypes  = excludedTypes,
                ShellBlueprint = result
            };

            _compositionStrategyProviders.Invoke(i => i.Apply(context), Logger);
            Logger.Debug("应用外部组合策略成功。");

            Logger.Debug("组合外壳蓝图完成。");
            return(result);
        }
예제 #11
0
        public ShellBlueprint Compose(ShellSettings settings, ShellDescriptor descriptor)
        {
            if (_logger.IsEnabled(LogLevel.Debug))
            {
                _logger.LogDebug("Composing blueprint");
            }

            var enabledFeatures = _extensionManager.EnabledFeatures(descriptor);
            var features        = _extensionManager.LoadFeatures(enabledFeatures);

            // Statup classes are the only types that are automatically added to the blueprint
            var dependencies = BuildBlueprint(features, IsStartup, BuildModule, Enumerable.Empty <string>());

            var uniqueDependencies = new Dictionary <Type, DependencyBlueprint>();

            foreach (var dependency in dependencies)
            {
                if (!uniqueDependencies.ContainsKey(dependency.Type))
                {
                    uniqueDependencies.Add(dependency.Type, dependency);
                }
            }

            var result = new ShellBlueprint
            {
                Settings     = settings,
                Descriptor   = descriptor,
                Dependencies = uniqueDependencies.Values
            };

            if (_logger.IsEnabled(LogLevel.Debug))
            {
                _logger.LogDebug("Done composing blueprint");
            }
            return(result);
        }
예제 #12
0
        /// <summary>
        /// Retrieves the enabled features.
        /// </summary>
        /// <returns>An enumeration of feature descriptors for the enabled features.</returns>
        public IEnumerable <FeatureDescriptor> GetEnabledFeatures()
        {
            var currentShellDescriptor = _shellDescriptorManager.GetShellDescriptor();

            return(_extensionManager.EnabledFeatures(currentShellDescriptor));
        }
예제 #13
0
        /// <summary>
        /// Retrieves the enabled features.
        /// </summary>
        /// <returns>An enumeration of feature descriptors for the enabled features.</returns>
        public async Task <IEnumerable <FeatureDescriptor> > GetEnabledFeaturesAsync()
        {
            var currentShellDescriptor = await _shellDescriptorManager.GetShellDescriptorAsync();

            return(_extensionManager.EnabledFeatures(currentShellDescriptor));
        }