Beispiel #1
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 IEnumerable <string> EnableFeatures(IEnumerable <string> featureIds, bool force)
        {
            ShellDescriptor     shellDescriptor = _shellDescriptorManager.GetShellDescriptor();
            List <ShellFeature> enabledFeatures = shellDescriptor.Features.ToList();

            IDictionary <FeatureDescriptor, bool> availableFeatures = GetAvailableFeatures()
                                                                      .ToDictionary(featureDescriptor => featureDescriptor,
                                                                                    featureDescriptor => enabledFeatures.FirstOrDefault(shellFeature => shellFeature.Name == featureDescriptor.Id) != null);

            IEnumerable <string> featuresToEnable = featureIds
                                                    .Select(featureId => EnableFeature(featureId, availableFeatures, force)).ToList()
                                                    .SelectMany(ies => ies.Select(s => s));

            if (featuresToEnable.Count() > 0)
            {
                foreach (string featureId in featuresToEnable)
                {
                    string id = featureId;

                    enabledFeatures.Add(new ShellFeature {
                        Name = id
                    });
                    if (_logger.IsEnabled(LogLevel.Information))
                    {
                        _logger.LogInformation("{0} was enabled", featureId);
                    }
                }

                _shellDescriptorManager.UpdateShellDescriptor(shellDescriptor.SerialNumber, enabledFeatures,
                                                              shellDescriptor.Parameters);
            }

            return(featuresToEnable);
        }
Beispiel #2
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 IEnumerable <string> EnableFeatures(IEnumerable <string> featureIds, bool force)
        {
            ShellDescriptor     shellDescriptor = _shellDescriptorManager.GetShellDescriptor();
            List <ShellFeature> enabledFeatures = shellDescriptor.Features.ToList();

            IDictionary <FeatureDescriptor, bool> availableFeatures = GetAvailableFeatures()
                                                                      .ToDictionary(featureDescriptor => featureDescriptor,
                                                                                    featureDescriptor => enabledFeatures.FirstOrDefault(shellFeature => shellFeature.Name == featureDescriptor.Id) != null);

            //Fix for https://orchard.codeplex.com/workitem/21176 / https://github.com/OrchardCMS/Orchard/issues/6075 - added distinct to the end to ensure each feature is only listed once
            IEnumerable <string> featuresToEnable = featureIds
                                                    .Select(featureId => EnableFeature(featureId, availableFeatures, force)).ToList()
                                                    .SelectMany(ies => ies.Select(s => s)).Distinct();

            if (featuresToEnable.Count() > 0)
            {
                foreach (string featureId in featuresToEnable)
                {
                    string id = featureId;

                    enabledFeatures.Add(new ShellFeature {
                        Name = id
                    });
                    Logger.Information("{0} was enabled", featureId);
                }

                _shellDescriptorManager.UpdateShellDescriptor(shellDescriptor.SerialNumber, enabledFeatures,
                                                              shellDescriptor.Parameters);
            }

            return(featuresToEnable);
        }
Beispiel #3
0
        public IEnumerable <string> EnableFeatures(IEnumerable <string> featureIds, bool force)
        {
            var enabledFeatures = shellDescriptor.Features.ToList();

            IDictionary <FeatureDescriptor, bool> availableFeatures = GetAvailableFeatures()
                                                                      .ToDictionary(featureDescriptor => featureDescriptor,
                                                                                    featureDescriptor => enabledFeatures.FirstOrDefault(shellFeature => shellFeature.Name == featureDescriptor.Id) != null);

            var featuresToEnable = featureIds
                                   .Select(featureId => EnableFeature(featureId, availableFeatures, force)).ToList()
                                   .SelectMany(ies => ies.Select(s => s)).ToList();

            if (featuresToEnable.Any())
            {
                foreach (var featureId in featuresToEnable)
                {
                    enabledFeatures.Add(new ShellFeature {
                        Name = featureId
                    });
                    Logger.InfoFormat("{0} was enabled", featureId);
                }

                shellDescriptorManager.UpdateShellDescriptor(shellDescriptor.SerialNumber, enabledFeatures);
            }

            return(featuresToEnable);
        }
Beispiel #4
0
        public IEnumerable <Feature> GetEnabledFeatures()
        {
            var currentShellDescriptor = _shellDescriptorManager.GetShellDescriptor();

            if (currentShellDescriptor == null) // 当存储中找不到 Shell 信息时(可能初始化系统)我们应该启用所有模块。
            {
                var allFeatures = this.GetAvailableFeatures();
                _shellDescriptorManager.UpdateShellDescriptor(Enumerable.Empty <String>(), Enumerable.Empty <ShellParameter>());
                return(allFeatures);
            }
            return(_moduleManager.GetEnabledFeatures(currentShellDescriptor).Select(this.LoadFeature));
        }
        public void ExecuteRecipeStepTest() {
            _folders.Manifests.Add("SuperWiki", @"
Name: SuperWiki
Version: 1.0.3
OrchardVersion: 1
Features:
    SuperWiki: 
        Description: My super wiki module for Orchard.
");

            IShellDescriptorManager shellDescriptorManager = _container.Resolve<IShellDescriptorManager>();
            // No features enabled
            shellDescriptorManager.UpdateShellDescriptor(0,
                Enumerable.Empty<ShellFeature>(),
                Enumerable.Empty<ShellParameter>());

            ModuleRecipeHandler moduleRecipeHandler = _container.Resolve<ModuleRecipeHandler>();

            RecipeContext recipeContext = new RecipeContext { RecipeStep = new RecipeStep { Name = "Module", Step = new XElement("SuperWiki") } };
            recipeContext.RecipeStep.Step.Add(new XAttribute("packageId", "Orchard.Module.SuperWiki"));
            recipeContext.RecipeStep.Step.Add(new XAttribute("repository", "test"));

            IFeatureManager featureManager = _container.Resolve<IFeatureManager>();
            IEnumerable<FeatureDescriptor> enabledFeatures = featureManager.GetEnabledFeatures();
            Assert.That(enabledFeatures.Count(), Is.EqualTo(0));
            moduleRecipeHandler.ExecuteRecipeStep(recipeContext);


            var availableFeatures = featureManager.GetAvailableFeatures().Where(x => x.Id == "SuperWiki").FirstOrDefault();
            Assert.That(availableFeatures.Id, Is.EqualTo("SuperWiki"));
            Assert.That(recipeContext.Executed, Is.True);
        }
        public void EnableFeaturesTest()
        {
            _folders.Manifests.Add("SuperWiki", @"
Name: SuperWiki
Version: 1.0.3
OrchardVersion: 1
Features:
    SuperWiki: 
        Description: My super wiki module for Orchard.
");

            // Initialize the shell descriptor with 0 features
            IShellDescriptorManager shellDescriptorManager = _container.Resolve <IShellDescriptorManager>();
            IFeatureManager         featureManager         = _container.Resolve <IFeatureManager>();

            shellDescriptorManager.UpdateShellDescriptor(0,
                                                         Enumerable.Empty <ShellFeature>(),
                                                         Enumerable.Empty <ShellParameter>());

            IEnumerable <string> featuresToEnable = new [] { "SuperWiki" };

            // Enable all features
            IEnumerable <string> enabledFeatures = featureManager.EnableFeatures(featuresToEnable);

            Assert.That(enabledFeatures, Is.EqualTo(featuresToEnable));
            Assert.That(featureManager.GetEnabledFeatures().Count(), Is.EqualTo(1));
        }
Beispiel #7
0
        public void DisableFeaturesTest()
        {
            _folders.Manifests.Add("SuperWiki", @"
Name: SuperWiki
Version: 1.0.3
CoeveryVersion: 1
Features:
    SuperWiki: 
        Description: My super wiki module for Coevery.
");

            // Initialize the shell descriptor with 0 features
            IShellDescriptorManager shellDescriptorManager = _container.Resolve <IShellDescriptorManager>();
            IFeatureManager         featureManager         = _container.Resolve <IFeatureManager>();

            shellDescriptorManager.UpdateShellDescriptor(0,
                                                         new [] { new ShellFeature {
                                                                      Name = "SuperWiki"
                                                                  } },
                                                         Enumerable.Empty <ShellParameter>());

            IEnumerable <string> featuresToDisable = new [] { "SuperWiki" };

            // Disable the feature
            featureManager.DisableFeatures(featuresToDisable);
            Assert.That(featureManager.GetEnabledFeatures().Count(), Is.EqualTo(0));
        }
        public void ExecuteRecipeStepTest()
        {
            _folders.Manifests.Add("SuperWiki", @"
Name: SuperWiki
Version: 1.0.3
OrchardVersion: 1
Features:
    SuperWiki: 
        Description: My super wiki theme for Orchard.
");
            _packagesInRepository.AddPublishedPackage(new PublishedPackage {
                Id              = "Orchard.Theme.SuperWiki",
                PackageType     = DefaultExtensionTypes.Theme,
                Title           = "SuperWiki",
                Version         = "1.0.3",
                IsLatestVersion = true,
            });

            IShellDescriptorManager shellDescriptorManager = _container.Resolve <IShellDescriptorManager>();

            // No features enabled
            shellDescriptorManager.UpdateShellDescriptor(0,
                                                         Enumerable.Empty <ShellFeature>(),
                                                         Enumerable.Empty <ShellParameter>());

            ThemeRecipeHandler themeRecipeHandler = _container.Resolve <ThemeRecipeHandler>();

            RecipeContext recipeContext = new RecipeContext {
                RecipeStep = new RecipeStep {
                    Name = "Theme", Step = new XElement("SuperWiki")
                }
            };

            recipeContext.RecipeStep.Step.Add(new XAttribute("packageId", "Orchard.Theme.SuperWiki"));
            recipeContext.RecipeStep.Step.Add(new XAttribute("repository", "test"));

            IFeatureManager featureManager = _container.Resolve <IFeatureManager>();
            IEnumerable <FeatureDescriptor> enabledFeatures = featureManager.GetEnabledFeatures();

            Assert.That(enabledFeatures.Count(), Is.EqualTo(0));
            themeRecipeHandler.ExecuteRecipeStep(recipeContext);

            // without setting enable no feature should be activated...
            featureManager.GetEnabledFeatures();
            Assert.That(enabledFeatures.Count(), Is.EqualTo(0));

            // Adding enable the feature should get active
            recipeContext.RecipeStep.Step.Add(new XAttribute("enable", true));
            themeRecipeHandler.ExecuteRecipeStep(recipeContext);

            enabledFeatures = featureManager.GetEnabledFeatures();
            Assert.That(enabledFeatures.FirstOrDefault(feature => feature.Id.Equals("SuperWiki")), Is.Not.Null);
            Assert.That(enabledFeatures.Count(), Is.EqualTo(1));
            Assert.That(recipeContext.Executed, Is.True);
        }
Beispiel #9
0
        public ActionResult IndexPost()
        {
            var cbk = Request["cbk"] ?? string.Empty;

            var newFeatures = _featureManager.GetRequiredFeatures().Concat(cbk.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries));

            _shellDescriptorManager.UpdateShellDescriptor(_shellDescriptor.SerialNumber + 1, newFeatures.Select(i => new ShellFeature {
                Name = i
            }));

            return(RedirectToAction("Index"));
        }
        public void DisableFeaturesWithDependenciesTest()
        {
            _folders.Manifests.Add("SuperWiki", @"
Name: SuperWiki
Version: 1.0.3
OrchardVersion: 1
Features:
    SuperWiki: 
        Description: My super wiki module for Orchard.
        Dependencies: SuperWikiDep
    SuperWikiDep:
        Description: My super wiki module for Orchard dependency.
");

            // Initialize the shell descriptor with 0 features
            IShellDescriptorManager shellDescriptorManager = _container.Resolve <IShellDescriptorManager>();
            IFeatureManager         featureManager         = _container.Resolve <IFeatureManager>();

            shellDescriptorManager.UpdateShellDescriptor(0,
                                                         Enumerable.Empty <ShellFeature>(),
                                                         Enumerable.Empty <ShellParameter>());

            // Enable both features by relying on the dependency
            Assert.That(featureManager.EnableFeatures(new [] { "SuperWiki" }, true).Count(), Is.EqualTo(2));

            IEnumerable <string> featuresToDisable = new[] { "SuperWikiDep" };

            // Try to enable without forcing dependencies should fail
            IEnumerable <string> disabledFeatures = featureManager.DisableFeatures(featuresToDisable, false);

            Assert.That(disabledFeatures.Count(), Is.EqualTo(0));
            Assert.That(featureManager.GetEnabledFeatures().Count(), Is.EqualTo(2));

            // Enabling while forcing dependencies should succeed.
            disabledFeatures = featureManager.DisableFeatures(featuresToDisable, true);
            Assert.That(disabledFeatures.Contains("SuperWiki"), Is.True);
            Assert.That(disabledFeatures.Contains("SuperWikiDep"), Is.True);
            Assert.That(featureManager.GetEnabledFeatures().Count(), Is.EqualTo(0));
        }
Beispiel #11
0
        private void UpdateShell()
        {
            var descriptor = _shellDescriptorManager.GetShellDescriptor();

            _shellDescriptorManager.UpdateShellDescriptor(descriptor.SerialNumber, descriptor.Features, descriptor.Parameters);
        }