public void List(params string[] featureNames)
        {
            var enabled = _shellDescriptor.Features.Select(x => x.Name);
            Func <string, bool> filter = featureNames.Any() ? new Func <string, bool>(f => f.IndexOf(featureNames[0], 0, StringComparison.InvariantCultureIgnoreCase) >= 0) : new Func <string, bool>(f => true);

            if (Summary)
            {
                foreach (var feature in _featureManager.GetAvailableFeatures().Where(f => filter(f.Name)).OrderBy(f => f.Id))
                {
                    Context.Output.WriteLine(T("{0}, {1}", feature.Id, enabled.Contains(feature.Id) ? T("Enabled") : T("Disabled")));
                }
            }
            else
            {
                Context.Output.WriteLine(T("List of available features"));
                Context.Output.WriteLine(T("--------------------------"));

                var categories = _featureManager.GetAvailableFeatures().Where(f => filter(f.Name)).ToList().GroupBy(f => f.Category);
                foreach (var category in categories)
                {
                    Context.Output.WriteLine(T("Category: {0}", category.Key.OrDefault(T("General"))));
                    foreach (var feature in category.OrderBy(f => f.Id))
                    {
                        Context.Output.WriteLine(T("  Name: {0}", feature.Id));
                        Context.Output.WriteLine(T("    State:         {0}", enabled.Contains(feature.Id) ? T("Enabled") : T("Disabled")));
                        Context.Output.WriteLine(T("    Description:   {0}", feature.Description.OrDefault(T("<none>"))));
                        Context.Output.WriteLine(T("    Category:      {0}", feature.Category.OrDefault(T("<none>"))));
                        Context.Output.WriteLine(T("    Module:        {0}", feature.Extension.Id.OrDefault(T("<none>"))));
                        Context.Output.WriteLine(T("    Dependencies:  {0}", string.Join(", ", feature.Dependencies).OrDefault(T("<none>"))));
                    }
                }
            }
        }
Ejemplo n.º 2
0
        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));
                    }
                }
            }
        }
Ejemplo n.º 3
0
        public ActionResult Features()
        {
            if (!Services.Authorizer.Authorize(Permissions.ManageFeatures, T("Not allowed to manage features")))
            {
                return(new HttpUnauthorizedResult());
            }

            var featuresThatNeedUpdate = _dataMigrationManager.GetFeaturesThatNeedUpdate();

            IEnumerable <ModuleFeature> features = _featureManager.GetAvailableFeatures()
                                                   .Where(f => !DefaultExtensionTypes.IsTheme(f.Extension.ExtensionType))
                                                   .Select(f => new ModuleFeature
            {
                Descriptor          = f,                                                    //描述信息
                IsEnabled           = _shellDescriptor.Features.Any(sf => sf.Name == f.Id), //是否启用
                IsRecentlyInstalled = _moduleService.IsRecentlyInstalled(f.Extension),      //是否最近安装
                NeedsUpdate         = featuresThatNeedUpdate.Contains(f.Id),                //是否升级
                DependentFeatures   = _moduleService.GetDependentFeatures(f.Id).Where(x => x.Id != f.Id).ToList()
            })
                                                   .ToList();

            return(View(new FeaturesViewModel
            {
                Features = features,
                IsAllowed = ExtensionIsAllowed
            }));
        }
Ejemplo n.º 4
0
        public void List()
        {
            var enabled = _shellDescriptor.Features.Select(x => x.Name);

            if (Summary)
            {
                foreach (var feature in _featureManager.GetAvailableFeatures().OrderBy(f => f.Id))
                {
                    Context.Output.WriteLine(T("{0}, {1}", feature.Id, enabled.Contains(feature.Id) ? T("Enabled") : T("Disabled")));
                }
            }
            else
            {
                Context.Output.WriteLine(T("List of available features"));
                Context.Output.WriteLine(T("--------------------------"));

                var categories = _featureManager.GetAvailableFeatures().ToList().GroupBy(f => f.Category);
                foreach (var category in categories)
                {
                    Context.Output.WriteLine(T("Category: {0}", category.Key.OrDefault(T("General"))));
                    foreach (var feature in category.OrderBy(f => f.Id))
                    {
                        Context.Output.WriteLine(T("  Name: {0}", feature.Id));
                        Context.Output.WriteLine(T("    State:         {0}", enabled.Contains(feature.Id) ? T("Enabled") : T("Disabled")));
                        Context.Output.WriteLine(T("    Description:   {0}", feature.Description.OrDefault(T("<none>"))));
                        Context.Output.WriteLine(T("    Category:      {0}", feature.Category.OrDefault(T("<none>"))));
                        Context.Output.WriteLine(T("    Module:        {0}", feature.Extension.Id.OrDefault(T("<none>"))));
                        Context.Output.WriteLine(T("    Dependencies:  {0}", string.Join(", ", feature.Dependencies).OrDefault(T("<none>"))));
                    }
                }
            }
        }
Ejemplo n.º 5
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 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));
     }
 }
Ejemplo n.º 6
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 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));
     }
 }
        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);
        }
        /*
         * <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 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 bool isAdminKrakePicker(RouteData route)
        {
            var featureTheme = _featureManager
                               .GetAvailableFeatures()
                               .FirstOrDefault(f => f.Id.Equals("KrakeAdmin", StringComparison.OrdinalIgnoreCase));
            var  isKrakeTheme  = featureTheme != null;
            bool isActionIndex = route.Values.ContainsKey("action") && String.Equals(route.Values["action"].ToString(), "index", StringComparison.OrdinalIgnoreCase);

            //advanced search
            bool isPickerContent = route.Values.ContainsKey("area") && route.Values["area"].Equals("Orchard.ContentPicker");
            bool isAdmin         = route.Values.ContainsKey("controller") && route.Values["controller"].Equals("admin");

            //simple search
            bool isSearchContent = route.Values.ContainsKey("area") && route.Values["area"].Equals("Orchard.Search");
            bool isContentPicker = route.Values.ContainsKey("controller") && route.Values["controller"].Equals("ContentPicker");

            return(isActionIndex && isKrakeTheme && (isAdmin && isPickerContent || isSearchContent && isContentPicker));
        }
Ejemplo n.º 11
0
        // <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;
        }
Ejemplo n.º 12
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);
            }
        }
Ejemplo n.º 13
0
        public static Feature GetFeature(this IFeatureManager featureManager, string id)
        {
            var feature = featureManager.GetAvailableFeatures().FirstOrDefault(x => x.Id == id);

            if (feature == null)
            {
                return(null);
            }

            return(new Feature
            {
                Descriptor = feature
            });
        }