public void EnablingADependencyByItselfDoesNothing() { // sanity check Assert.That(EnabledFeatures, Is.Empty); // enable "Laser.Orchard.GDPR" _featureManager.EnableFeatures(new string[] { "Laser.Orchard.GDPR" }); // Only "Laser.Orchard.GDPR" is enabled Assert.That(EnabledFeatures.Count(), Is.EqualTo(1)); Assert.That(EnabledFeatures.First(), Is.EqualTo("Laser.Orchard.GDPR")); }
public void EnableThemeFeatures(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).Text); } themes.Push(themeName); var theme = _extensionManager.GetExtension(themeName); themeName = !string.IsNullOrWhiteSpace(theme.BaseTheme) ? theme.BaseTheme : null; } while (themes.Count > 0) { var themeId = themes.Pop(); foreach (var featureId in _featureManager.EnableFeatures(new[] { themeId }, true)) { if (themeId != featureId) { var featureName = _featureManager.GetAvailableFeatures().First(f => f.Id.Equals(featureId, StringComparison.OrdinalIgnoreCase)).Name; Services.Notifier.Success(T("{0} was enabled", featureName)); } } } }
/* * <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 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)); }
public void Activated() { // Let's make sure that the basic set of features is enabled. If there are any that are not enabled, then let's enable them first. var theseFeaturesShouldAlwaysBeActive = new[] { "Common", "Containers", "Contents", "Dashboard", "Feeds", "Navigation", "Reports", "Scheduling", "Settings", "Shapes", "Title" }; var enabledFeatures = _featureManager.GetEnabledFeatures().Select(f => f.Id).ToList(); var featuresToEnable = theseFeaturesShouldAlwaysBeActive.Where(shouldBeActive => !enabledFeatures.Contains(shouldBeActive)).ToList(); if (featuresToEnable.Any()) { _featureManager.EnableFeatures(featuresToEnable, true); } foreach (var feature in _dataMigrationManager.GetFeaturesThatNeedUpdate()) { try { _dataMigrationManager.Update(feature); } catch (Exception ex) { if (ex.IsFatal()) { throw; } Logger.Error("Could not run migrations automatically on " + feature, ex); } } }
public void Activated() { // Let's make sure that the basic set of features is enabled. If there are any that are not enabled, then let's enable them first. var theseFeaturesShouldAlwaysBeActive = new[] { "Settings" }; theseFeaturesShouldAlwaysBeActive = theseFeaturesShouldAlwaysBeActive.Concat( _featureManager.GetAvailableFeatures().Where(f => f.Id != "Coevery.Setup").Select(f => f.Id)).ToArray(); var enabledFeatures = _featureManager.GetEnabledFeatures().Select(f => f.Id).ToList(); var featuresToEnable = theseFeaturesShouldAlwaysBeActive.Where(shouldBeActive => !enabledFeatures.Contains(shouldBeActive)).ToList(); if (featuresToEnable.Any()) { _featureManager.EnableFeatures(featuresToEnable, true); } foreach (var feature in _dataMigrationManager.GetFeaturesThatNeedUpdate()) { try { _dataMigrationManager.Update(feature); } catch (Exception e) { Logger.Error("Could not run migrations automatically on " + feature, e); } } }
public void Enabled(Feature feature) { var keyFeaturesToEnable = new List <string>(); // we check in the lists of dependencies for those KeyFeatures that are not currently enabled foreach (var keyFeatureDescriptor in _keyFeaturesProviders.SelectMany(kfp => kfp .DisabledKeyFeatures(feature))) { // the feature we just enabled is a dependency of the keyFeature represented by the // keyFeatureDescriptor. If all other dependencies are enabled already, we enable the // keyFeature too. In other words, if any of the dependencies is disabled we should do // nothing. if (_featureManager .GetDisabledFeatures() // this is an IEnumerable<FeatureDescriptor> .Any(dfd => keyFeatureDescriptor .Dependencies // this is an IEnumerable<string> of the dependecies' names .Contains(dfd.Id))) { continue; // go to the next keyFeatureDescriptor } // All dependencies are now enabled, so we enable the KeyFeature too keyFeaturesToEnable.Add(keyFeatureDescriptor.Id); } // Actually enable the KeyFeatures _featureManager.EnableFeatures(keyFeaturesToEnable); }
/// <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 void EnableFeatures(IEnumerable <string> featureIds, bool force) { foreach (string featureId in _featureManager.EnableFeatures(featureIds, force)) { var featureName = _featureManager.GetAvailableFeatures().First(f => f.Id.Equals(featureId, StringComparison.OrdinalIgnoreCase)).Name; Services.Notifier.Information(T("{0} was enabled", featureName)); } }
/// <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 void EnableFeatures(IEnumerable <string> featureIds, bool force) { foreach (string featureId in _featureManager.EnableFeatures(featureIds, force)) { var featureName = _featureManager.GetAvailableFeatures().Where(f => f.Id == featureId).First().Name; Services.Notifier.Information(T("{0} was enabled", 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; }
// <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); } }
public void EnableFeaturesWithDependenciesTest() { _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>()); IEnumerable <string> featuresToEnable = new[] { "SuperWiki" }; // Try to enable without forcing dependencies should fail IEnumerable <string> enabledFeatures = featureManager.EnableFeatures(featuresToEnable, false); Assert.That(enabledFeatures.Count(), Is.EqualTo(0)); Assert.That(featureManager.GetEnabledFeatures().Count(), Is.EqualTo(0)); // Enabling while forcing dependencies should succeed. enabledFeatures = featureManager.EnableFeatures(featuresToEnable, true); Assert.That(enabledFeatures.Contains("SuperWiki"), Is.True); Assert.That(enabledFeatures.Contains("SuperWikiDep"), Is.True); Assert.That(featureManager.GetEnabledFeatures().Count(), Is.EqualTo(2)); }
public int UpdateFrom1() { _featureManager.EnableFeatures(new string[] { "Laser.Orchard.Queries" }, true); SchemaBuilder.AlterTable("DynamicProjectionPartRecord", table => table .AddColumn <bool>("ReturnsHqlResults") ); SchemaBuilder.AlterTable("DynamicProjectionPartRecord", table => table .AddColumn <string>("TypeForFilterForm") ); SchemaBuilder.AlterTable("DynamicProjectionPartRecord", table => table .AddColumn <string>("ShapeForResults") ); ContentDefinitionManager.AlterTypeDefinition( "DynamicProjection", type => type .WithPart("QueryPickerPart", p => p .WithSetting("QueryPickerPartSettings.IsForHqlQueries", bool.TrueString)) .WithIdentity() ); return(2); }
public void Activated() { EnsureDistributedLockSchemaExists(); IDistributedLock @lock; if (_distributedLockService.TryAcquireLock(GetType().FullName, TimeSpan.FromMinutes(30), TimeSpan.FromMilliseconds(250), out @lock)) { using (@lock) { // Let's make sure that the basic set of features is enabled. If there are any that are not enabled, then let's enable them first. var theseFeaturesShouldAlwaysBeActive = new[] { "Settings", "Shapes", }; var enabledFeatures = _featureManager.GetEnabledFeatures().Select(f => f.Id).ToList(); var featuresToEnable = theseFeaturesShouldAlwaysBeActive.Where(shouldBeActive => !enabledFeatures.Contains(shouldBeActive)).ToList(); if (featuresToEnable.Any()) { _featureManager.EnableFeatures(featuresToEnable, true); } foreach (var feature in _dataMigrationManager.GetFeaturesThatNeedUpdate()) { try { _dataMigrationManager.Update(feature); } catch (Exception ex) { if (ex.IsFatal()) { throw; } Logger.Error("Could not run migrations automatically on " + feature, ex); } } } } }
public void EnableThemeFeatures(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).Text); } themes.Push(themeName); var theme = _extensionManager.GetExtension(themeName); themeName = !string.IsNullOrWhiteSpace(theme.BaseTheme) ? theme.BaseTheme : null; } while (themes.Count > 0) { _featureManager.EnableFeatures(new[] { themes.Pop() }); } }