public void DisableThemeFeatures(string themeName) { var themes = new Queue <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 disabled.", themeName).Text); } var theme = _extensionManager.GetExtension(themeName); if (theme == null) { break; } themes.Enqueue(themeName); themeName = !string.IsNullOrWhiteSpace(theme.BaseTheme) ? theme.BaseTheme : null; } var currentTheme = _siteThemeService.GetCurrentThemeName(); while (themes.Count > 0) { var themeId = themes.Dequeue(); // Not disabling base theme if it's the current theme. if (themeId != currentTheme) { _featureManager.DisableFeatures(new[] { themeId }); } } }
/* * <EnabledFeatures> * <Feature Id="Orchard.ImportExport" /> */ //Enable any features that are in the list, disable features that aren't in the list public void ExecuteRecipeStep(RecipeContext recipeContext) { if (!String.Equals(recipeContext.RecipeStep.Name, "FeatureSync", StringComparison.OrdinalIgnoreCase)) { return; } var features = recipeContext.RecipeStep.Step.Descendants(); var featureIds = features.Where(f => f.Name == "Feature").Select(f => f.Attribute("Id").Value).ToList(); //we now have the list of features that are enabled on the remote site //next thing to do is add and remove features to and from this list based on our feature redactions var featureRedactions = _featureRedactionService.GetRedactions().ToList(); featureIds.AddRange(featureRedactions.Where(r => r.Enabled).Select(r => r.FeatureId)); //adding features that need to be enabled featureIds.RemoveAll(f => featureRedactions.Where(r => !r.Enabled).Select(r => r.FeatureId).Contains(f)); //removing features that need to be disabled //adding redactions may have caused duplicity featureIds = featureIds.Distinct().ToList(); var availableFeatures = _featureManager.GetAvailableFeatures(); var enabledFeatures = _featureManager.GetEnabledFeatures().ToList(); var featuresToDisable = enabledFeatures.Where(f => !featureIds.Contains(f.Id)).Select(f => f.Id).ToList(); var featuresToEnable = availableFeatures .Where(f => featureIds.Contains(f.Id)) //available features that are in the list of features that need to be enabled .Where(f => !enabledFeatures.Select(ef => ef.Id).Contains(f.Id)) //remove features that are already enabled .Select(f => f.Id) .ToList(); _featureManager.DisableFeatures(featuresToDisable, true); _featureManager.EnableFeatures(featuresToEnable, true); recipeContext.Executed = true; }
public void DisableFeaturesTest() { _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, 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 Uninstall(string packageId, string applicationPath) { var extensionToUninstall = _extensionManager.AvailableExtensions() .FirstOrDefault(extension => PackageBuilder.BuildPackageId(extension.Id, extension.ExtensionType) == packageId); if (extensionToUninstall == null) { throw new OrchardException(T("There is no extension that has the package ID \"{0}\".", packageId)); } var featureIdsToUninstall = extensionToUninstall.Features.Select(feature => feature.Id); var shellState = _shellStateManager.GetShellState(); var featureStates = shellState.Features.Where(featureState => featureIdsToUninstall.Contains(featureState.Name)); // This means that no feature from this extension wasn enabled yet, can be uninstalled directly. if (!featureStates.Any()) { _packageUninstallHandler.QueuePackageUninstall(packageId); } else { _featureManager.DisableFeatures(extensionToUninstall.Features.Select(feature => feature.Id), true); // Installed state can't be deduced from the shell state changes like for enabled state, so have to // set that explicitly. foreach (var featureState in featureStates) { _shellStateManager.UpdateInstalledState(featureState, Environment.State.Models.ShellFeatureState.State.Falling); } } }
/// <summary> /// Disables a list of features. /// </summary> /// <param name="featureIds">The IDs for the features to be disabled.</param> /// <param name="force">Boolean parameter indicating if the feature should disable the features which depend on it if required or fail otherwise.</param> public void DisableFeatures(IEnumerable <string> featureIds, bool force) { foreach (string featureId in _featureManager.DisableFeatures(featureIds, force)) { var featureName = _featureManager.GetAvailableFeatures().Where(f => f.Id == featureId).First().Name; Services.Notifier.Information(T("{0} was disabled", featureName)); } }
/// <summary> /// Disables a list of features. /// </summary> /// <param name="featureIds">The IDs for the features to be disabled.</param> /// <param name="force">Boolean parameter indicating if the feature should disable the features which depend on it if required or fail otherwise.</param> public void DisableFeatures(IEnumerable <string> featureIds, bool force) { foreach (string featureId in _featureManager.DisableFeatures(featureIds, force)) { var featureName = _featureManager.GetAvailableFeatures().Single(f => f.Id.Equals(featureId, StringComparison.OrdinalIgnoreCase)).Name; Services.Notifier.Success(T("{0} was disabled", featureName)); } }
// <Feature enable="f1,f2,f3" disable="f4" /> // Enable/Disable features. public void ExecuteRecipeStep(RecipeContext recipeContext) { if (!String.Equals(recipeContext.RecipeStep.Name, "Feature", StringComparison.OrdinalIgnoreCase)) { return; } var featuresToEnable = new List <string>(); var featuresToDisable = new List <string>(); foreach (var attribute in recipeContext.RecipeStep.Step.Attributes()) { if (String.Equals(attribute.Name.LocalName, "disable", StringComparison.OrdinalIgnoreCase)) { featuresToDisable = ParseFeatures(attribute.Value); } else if (String.Equals(attribute.Name.LocalName, "enable", StringComparison.OrdinalIgnoreCase)) { featuresToEnable = ParseFeatures(attribute.Value); } else { Logger.Error("Unrecognized attribute {0} encountered in step Feature. Skipping.", attribute.Name.LocalName); } } var availableFeatures = _featureManager.GetAvailableFeatures().Select(x => x.Id).ToArray(); foreach (var featureName in featuresToDisable) { if (!availableFeatures.Contains(featureName)) { throw new InvalidOperationException(string.Format("Could not disable feature {0} because it was not found.", featureName)); } } foreach (var featureName in featuresToEnable) { if (!availableFeatures.Contains(featureName)) { throw new InvalidOperationException(string.Format("Could not enable feature {0} because it was not found.", featureName)); } } if (featuresToDisable.Count != 0) { _featureManager.DisableFeatures(featuresToDisable, true); } if (featuresToEnable.Count != 0) { _featureManager.EnableFeatures(featuresToEnable, true); } recipeContext.Executed = true; }
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)); }
// <Feature enable="f1,f2,f3" disable="f4" /> // Enable/Disable features. public override void Execute(RecipeExecutionContext recipeContext) { var featuresToEnable = new List <string>(); var featuresToDisable = new List <string>(); foreach (var attribute in recipeContext.RecipeStep.Step.Attributes()) { if (String.Equals(attribute.Name.LocalName, "disable", StringComparison.OrdinalIgnoreCase)) { featuresToDisable = ParseFeatures(attribute.Value); } else if (String.Equals(attribute.Name.LocalName, "enable", StringComparison.OrdinalIgnoreCase)) { featuresToEnable = ParseFeatures(attribute.Value); } else { Logger.Warning("Unrecognized attribute '{0}' encountered; skipping", attribute.Name.LocalName); } } var availableFeatures = _featureManager.GetAvailableFeatures().Select(x => x.Id).ToArray(); foreach (var featureName in featuresToDisable) { if (!availableFeatures.Contains(featureName)) { throw new InvalidOperationException(string.Format("Could not disable feature {0} because it was not found.", featureName)); } } foreach (var featureName in featuresToEnable) { if (!availableFeatures.Contains(featureName)) { throw new InvalidOperationException(string.Format("Could not enable feature {0} because it was not found.", featureName)); } } if (featuresToDisable.Any()) { Logger.Information("Disabling features: {0}", String.Join(";", featuresToDisable)); _featureManager.DisableFeatures(featuresToDisable, true); } if (featuresToEnable.Any()) { Logger.Information("Enabling features: {0}", String.Join(";", featuresToEnable)); _featureManager.EnableFeatures(featuresToEnable, true); } }