public ActionResult FeaturesPOST(FeaturesBulkAction bulkAction, IList <string> featureIds, bool?force)
        {
            if (!Services.Authorizer.Authorize(Permissions.ManageFeatures, T("Not allowed to manage features")))
            {
                return(new HttpUnauthorizedResult());
            }

            if (featureIds == null || !featureIds.Any())
            {
                ModelState.AddModelError("featureIds", T("Please select one or more features."));
            }

            if (ModelState.IsValid)
            {
                var availableFeatures = _moduleService.GetAvailableFeatures().Where(feature => ModuleIsAllowed(feature.Descriptor.Extension)).ToList();
                var selectedFeatures  = availableFeatures.Where(x => featureIds.Contains(x.Descriptor.Id)).ToList();
                var enabledFeatures   = availableFeatures.Where(x => x.IsEnabled && featureIds.Contains(x.Descriptor.Id)).Select(x => x.Descriptor.Id).ToList();
                var disabledFeatures  = availableFeatures.Where(x => !x.IsEnabled && featureIds.Contains(x.Descriptor.Id)).Select(x => x.Descriptor.Id).ToList();

                switch (bulkAction)
                {
                case FeaturesBulkAction.None:
                    break;

                case FeaturesBulkAction.Enable:
                    _moduleService.EnableFeatures(disabledFeatures, force == true);
                    break;

                case FeaturesBulkAction.Disable:
                    _moduleService.DisableFeatures(enabledFeatures, force == true);
                    break;

                case FeaturesBulkAction.Toggle:
                    _moduleService.EnableFeatures(disabledFeatures, force == true);
                    _moduleService.DisableFeatures(enabledFeatures, force == true);
                    break;

                case FeaturesBulkAction.Update:
                    foreach (var feature in selectedFeatures.Where(x => x.NeedsUpdate))
                    {
                        var id = feature.Descriptor.Id;
                        try {
                            _reportsCoordinator.Register("Data Migration", "Upgrade " + id, "Orchard installation");
                            _dataMigrationManager.Update(id);
                            Services.Notifier.Information(T("The feature {0} was updated successfully", id));
                        }
                        catch (Exception exception) {
                            Services.Notifier.Error(T("An error occured while updating the feature {0}: {1}", id, exception.Message));
                        }
                    }
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }

            return(RedirectToAction("Features"));
        }
示例#2
0
        public ActionResult FeaturesPOST(FeaturesBulkAction bulkAction, IList<string> featureIds, bool? force) {

            if (!Services.Authorizer.Authorize(Permissions.ManageFeatures, T("Not allowed to manage features")))
                return new HttpUnauthorizedResult();

            if (featureIds == null || !featureIds.Any()) {
                ModelState.AddModelError("featureIds", T("Please select one or more features."));
            }

            if (ModelState.IsValid) {
                var availableFeatures = _moduleService.GetAvailableFeatures().Where(feature => ModuleIsAllowed(feature.Descriptor.Extension)).ToList();
                var selectedFeatures = availableFeatures.Where(x => featureIds.Contains(x.Descriptor.Id)).ToList();
                var enabledFeatures = availableFeatures.Where(x => x.IsEnabled && featureIds.Contains(x.Descriptor.Id)).Select(x => x.Descriptor.Id).ToList();
                var disabledFeatures = availableFeatures.Where(x => !x.IsEnabled && featureIds.Contains(x.Descriptor.Id)).Select(x => x.Descriptor.Id).ToList();

                switch (bulkAction) {
                    case FeaturesBulkAction.None:
                        break;
                    case FeaturesBulkAction.Enable:
                        _moduleService.EnableFeatures(disabledFeatures, force == true);
                        break;
                    case FeaturesBulkAction.Disable:
                        _moduleService.DisableFeatures(enabledFeatures, force == true);
                        break;
                    case FeaturesBulkAction.Toggle:
                        _moduleService.EnableFeatures(disabledFeatures, force == true);
                        _moduleService.DisableFeatures(enabledFeatures, force == true);
                        break;
                    case FeaturesBulkAction.Update:
                        foreach (var feature in selectedFeatures.Where(x => x.NeedsUpdate)) {
                            var id = feature.Descriptor.Id;
                            try {
                                _reportsCoordinator.Register("Data Migration", "Upgrade " + id, "Orchard installation");
                                _dataMigrationManager.Update(id);
                                Services.Notifier.Information(T("The feature {0} was updated successfully", id));
                            }
                            catch (Exception exception) {
                                Services.Notifier.Error(T("An error occured while updating the feature {0}: {1}", id, exception.Message));
                            }
                        }
                        break;
                    default:
                        throw new ArgumentOutOfRangeException();
                }
            }

            return RedirectToAction("Features");
        }
示例#3
0
        public async Task <ActionResult> FeaturesPOST(FeaturesBulkAction bulkAction, IList <string> featureIds, bool?force)
        {
            if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageFeatures))
            {
                return(Unauthorized());
            }

            if (featureIds == null || !featureIds.Any())
            {
                ModelState.AddModelError("featureIds", T["Please select one or more features."].ToString());
            }

            if (ModelState.IsValid)
            {
                var availableFeatures  = _extensionManager.GetExtensions().Features;
                var features           = availableFeatures.Where(feature => ExtensionIsAllowed(feature.Extension)).ToList();
                var selectedFeatures   = features.Where(x => featureIds.Contains(x.Id)).ToList();
                var allEnabledFeatures = await _shellFeaturesManager.GetEnabledFeaturesAsync(); //features.Where(x => x.IsEnabled && featureIds.Contains(x.Id)).Select(x => x.Descriptor.Id).ToList();

                var idFeaturesEnabled   = allEnabledFeatures.Where(x => featureIds.Contains(x.Id)).ToList();
                var allDisabledFeatures = await _shellFeaturesManager.GetDisabledFeaturesAsync(); // DisabledFeaturesAsync //features.Where(x => !x.IsEnabled && featureIds.Contains(x.Id)).Select(x => x.Descriptor.Id).ToList();

                var idFeaturesDisabled = allDisabledFeatures.Where(x => featureIds.Contains(x.Id)).ToList();

                switch (bulkAction)
                {
                case FeaturesBulkAction.None:
                    break;

                case FeaturesBulkAction.Enable:
                    var enabledFeatures = await _shellFeaturesManager.EnableFeaturesAsync(idFeaturesDisabled, force == true);

                    foreach (var feature in enabledFeatures.ToList())
                    {
                        var featureName = availableFeatures[feature.Id].Name;
                        _notifier.Success(T["{0} was enabled", featureName]);
                    }
                    break;

                case FeaturesBulkAction.Disable:
                    var disabledFeatures = await _shellFeaturesManager.DisableFeaturesAsync(idFeaturesEnabled, force == true);

                    foreach (var feature in disabledFeatures.ToList())
                    {
                        var featureName = availableFeatures[feature.Id].Name;
                        _notifier.Success(T["{0} was disabled", featureName]);
                    }
                    break;

                case FeaturesBulkAction.Toggle:
                    var enabledFeaturesToggle = await _shellFeaturesManager.EnableFeaturesAsync(idFeaturesDisabled, force == true);

                    foreach (var feature in enabledFeaturesToggle.ToList())
                    {
                        var featureName = availableFeatures[feature.Id].Name;
                        _notifier.Success(T["{0} was enabled", featureName]);
                    }

                    var disabledFeaturesToggle = await _shellFeaturesManager.DisableFeaturesAsync(idFeaturesEnabled, force == true);

                    foreach (var feature in disabledFeaturesToggle.ToList())
                    {
                        var featureName = availableFeatures[feature.Id].Name;
                        _notifier.Success(T["{0} was disabled", featureName]);
                    }
                    break;

                case FeaturesBulkAction.Update:
                    //var featuresThatNeedUpdate = _dataMigrationManager.GetFeaturesThatNeedUpdate();
                    //var selectedFeaturesThatNeedUpdate = selectedFeatures.Where(x => featuresThatNeedUpdate.Contains(x.Id));

                    //foreach (var feature in selectedFeaturesThatNeedUpdate)
                    //{
                    //    var id = feature.Descriptor.Id;
                    //    try
                    //    {
                    //        _dataMigrationManager.Update(id);
                    //        _notifier.Success(T["The feature {0} was updated successfully", id]);
                    //    }
                    //    catch (Exception exception)
                    //    {
                    //        _notifier.Error(T["An error occurred while updating the feature {0}: {1}", id, exception.Message]);
                    //    }
                    //}
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }

            return(RedirectToAction("Features"));
        }
示例#4
0
        private async Task EnableOrDisableFeaturesAsync(IEnumerable <IFeatureInfo> features, FeaturesBulkAction action, bool?force)
        {
            switch (action)
            {
            case FeaturesBulkAction.None:
                break;

            case FeaturesBulkAction.Enable:
                await _shellFeaturesManager.EnableFeaturesAsync(features, force == true);
                await NotifyAsync(features);

                break;

            case FeaturesBulkAction.Disable:
                await _shellFeaturesManager.DisableFeaturesAsync(features, force == true);
                await NotifyAsync(features, enabled : false);

                break;

            case FeaturesBulkAction.Toggle:
                // The features array has already been checked for validity.
                var enabledFeatures = await _shellFeaturesManager.GetEnabledFeaturesAsync();

                var disabledFeatures = await _shellFeaturesManager.GetDisabledFeaturesAsync();

                var featuresToEnable  = disabledFeatures.Intersect(features);
                var featuresToDisable = enabledFeatures.Intersect(features);

                await _shellFeaturesManager.UpdateFeaturesAsync(featuresToDisable, featuresToEnable, force == true);
                await NotifyAsync(featuresToEnable);
                await NotifyAsync(featuresToDisable, enabled : false);

                return;

            default:
                break;
            }
        }
示例#5
0
        private async Task EnableOrDisableFeaturesAsync(IEnumerable <IFeatureInfo> features, FeaturesBulkAction action, bool?force)
        {
            switch (action)
            {
            case FeaturesBulkAction.None:
                break;

            case FeaturesBulkAction.Enable:
                await _shellFeaturesManager.EnableFeaturesAsync(features, force == true);

                Notify(features);
                break;

            case FeaturesBulkAction.Disable:

                await _shellFeaturesManager.DisableFeaturesAsync(features, force == true);

                foreach (var featureInfoToDisable in features)
                {
                    _dataMigrationManager.Uninstall(featureInfoToDisable.Id).GetAwaiter().GetResult();
                }


                Notify(features, enabled: false);
                break;

            case FeaturesBulkAction.Toggle:
                var enabledFeatures = await _shellFeaturesManager.GetEnabledFeaturesAsync();

                var disabledFeatures = await _shellFeaturesManager.GetDisabledFeaturesAsync();

                var featuresToEnable  = disabledFeatures.Intersect(features);
                var featuresToDisable = enabledFeatures.Intersect(features);

                await _shellFeaturesManager.UpdateFeaturesAsync(featuresToDisable, featuresToEnable, force == true);

                Notify(featuresToEnable);
                Notify(featuresToDisable, enabled: false);
                return;

            default:
                break;
            }
        }