public void ExecuteInvokesHandlersWithSteps()
        {
            var recipes = (List <Recipe>)_recipeHarvester.HarvestRecipes("Sample1");

            Assert.That(recipes.Count, Is.EqualTo(1));

            var sampleRecipe = recipes[0];

            _recipeManager.Execute(sampleRecipe);

            Assert.That(CustomRecipeHandler.AttributeValue == "value1");
        }
        public ActionResult InstallPackageDetailsPOST(PackagingInstallViewModel packagingInstallViewModel, string redirectUrl)
        {
            if (_shellSettings.Name != ShellSettings.DefaultName || !Services.Authorizer.Authorize(StandardPermissions.SiteOwner, T("Not authorized to add sources")))
            {
                return(new HttpUnauthorizedResult());
            }

            try {
                if (_recipeHarvester != null && _recipeManager != null)
                {
                    IEnumerable <Recipe> recipes = _recipeHarvester.HarvestRecipes(packagingInstallViewModel.ExtensionDescriptor.Id)
                                                   .Where(loadedRecipe => packagingInstallViewModel.Recipes.FirstOrDefault(recipeViewModel => recipeViewModel.Execute && recipeViewModel.Recipe.Name.Equals(loadedRecipe.Name)) != null);

                    foreach (Recipe recipe in recipes)
                    {
                        try {
                            _recipeManager.Execute(recipe);
                        }
                        catch {
                            Services.Notifier.Error(T("Recipes contains {0} unsupported module installation steps.", recipe.Name));
                        }
                    }
                }

                // Enable selected features
                if (packagingInstallViewModel.Features.Count > 0)
                {
                    IEnumerable <string> featureIds = packagingInstallViewModel.Features
                                                      .Where(feature => feature.Enable)
                                                      .Select(feature => feature.FeatureDescriptor.Id);

                    // Enable the features and its dependencies using recipes, so that they are run after the module's recipes

                    var recipe = new Recipe {
                        Name        = "Test",
                        RecipeSteps = featureIds.Select(
                            (i, x) => new RecipeStep(
                                id: i.ToString(CultureInfo.InvariantCulture),
                                recipeName: "Test",
                                name: "Feature",
                                step: new XElement("Feature", new XAttribute("enable", x))))
                    };

                    _recipeManager.Execute(recipe);
                }
            } catch (Exception exception) {
                Services.Notifier.Error(T("Post installation steps failed with error: {0}", exception.Message));
            }

            return(Redirect(redirectUrl));
        }
Esempio n. 3
0
        public void Execute(string extensionId, string recipeName)
        {
            var extensionDescriptor = _extensionManager.GetExtension(extensionId);

            if (extensionDescriptor == null)
            {
                Context.Output.WriteLine(T("Could not discover recipes because extension '{0}' was not found.", extensionId));
                return;
            }

            var recipes = _recipeHarvester.HarvestRecipes(extensionId);

            if (!recipes.Any())
            {
                Context.Output.WriteLine(T("No recipes found for extension '{0}'.", extensionId));
                return;
            }

            var recipe = recipes.FirstOrDefault(r => r.Name.Equals(recipeName, StringComparison.OrdinalIgnoreCase));

            if (recipe == null)
            {
                Context.Output.WriteLine(T("No recipe with name '{0}' was found in extension '{1}'.", recipeName, extensionId));
                return;
            }

            var executionId = _recipeManager.Execute(recipe);

            Context.Output.WriteLine(T("Recipe successfully scheduled with execution ID {0}. Use the 'recipes result' command to check the result of the execution.", executionId).Text);
        }
        public void Import(string recipeText)
        {
            var recipe = _recipeParser.ParseRecipe(recipeText);

            _recipeManager.Execute(recipe);
            UpdateShell();
        }
Esempio n. 5
0
        public void ExecuteRecipe(string extensionId, string recipeName)
        {
            ExtensionDescriptor extensionDescriptor = _extensionManager.GetExtension(extensionId);

            if (extensionDescriptor == null)
            {
                throw new OrchardException(T("Could not discover recipes because module '{0}' was not found.", extensionId));
            }

            IEnumerable <Recipe> recipes = _recipeHarvester.HarvestRecipes(extensionId);

            if (recipes == null)
            {
                throw new OrchardException(T("No recipes found for extension {0}.", extensionId));
            }

            Recipe recipe = recipes.FirstOrDefault(r => r.Name.Equals(recipeName, StringComparison.OrdinalIgnoreCase));

            if (recipe == null)
            {
                throw new OrchardException(T("Invalid recipe name {0}.", recipeName));
            }

            try {
                _recipeManager.Execute(recipe);

                Context.Output.WriteLine(T("Recipe scheduled for execution successfully.").Text);
            }
            catch {
                Context.Output.WriteLine(T("Recipe failed to execute.").Text);
            }
        }
Esempio n. 6
0
        public string Import(string recipeText)
        {
            var recipe      = _recipeParser.ParseRecipe(recipeText);
            var executionId = _recipeManager.Execute(recipe);

            UpdateShell();
            return(executionId);
        }
Esempio n. 7
0
        public string Execute(Recipe recipe)
        {
            var executionId = _recipeManager.Execute(recipe);

            // Only need to update the shell if work was actually done.
            if (executionId != null)
            {
                UpdateShell();
            }

            return(executionId);
        }
        public ActionResult RecipesPOST(string moduleId, string name)
        {
            if (!Services.Authorizer.Authorize(StandardPermissions.SiteOwner, T("Not allowed to manage modules")))
            {
                return(new HttpUnauthorizedResult());
            }

            ModuleEntry module = _extensionManager.AvailableExtensions()
                                 .Where(extensionDescriptor => extensionDescriptor.Id == moduleId && ExtensionIsAllowed(extensionDescriptor))
                                 .Select(extensionDescriptor => new ModuleEntry {
                Descriptor = extensionDescriptor
            }).FirstOrDefault();

            if (module == null)
            {
                return(HttpNotFound());
            }

            Recipe recipe = _recipeHarvester.HarvestRecipes(module.Descriptor.Id).FirstOrDefault(x => !x.IsSetupRecipe && x.Name == name);

            if (recipe == null)
            {
                return(HttpNotFound());
            }

            try
            {
                _recipeManager.Execute(recipe);
            }
            catch (Exception e)
            {
                Logger.Error(e, "Error while executing recipe {0} in {1}", moduleId, name);
                Services.Notifier.Error(T("Recipes {0} contains  unsupported module installation steps.", recipe.Name));
            }

            Services.Notifier.Success(T("The recipe {0} was executed successfully.", recipe.Name));

            return(RedirectToAction("Recipes"));
        }
        public ActionResult InstallPackageDetailsPOST(PackagingInstallViewModel packagingInstallViewModel, string redirectUrl)
        {
            if (_shellSettings.Name != ShellSettings.DefaultName || !Services.Authorizer.Authorize(StandardPermissions.SiteOwner, T("Not authorized to add sources")))
            {
                return(new HttpUnauthorizedResult());
            }

            try {
                IEnumerable <Recipe> recipes = _recipeHarvester.HarvestRecipes(packagingInstallViewModel.ExtensionDescriptor.Id)
                                               .Where(loadedRecipe => packagingInstallViewModel.Recipes.FirstOrDefault(recipeViewModel => recipeViewModel.Execute && recipeViewModel.Recipe.Name.Equals(loadedRecipe.Name)) != null);

                foreach (Recipe recipe in recipes)
                {
                    try {
                        _recipeManager.Execute(recipe);
                    }
                    catch {
                        Services.Notifier.Error(T("Recipes contains {0} unsuported module installation steps.", recipe.Name));
                    }
                }

                // Enable selected features
                if (packagingInstallViewModel.Features.Count > 0)
                {
                    IEnumerable <string> featureIds = packagingInstallViewModel.Features
                                                      .Where(feature => feature.Enable)
                                                      .Select(feature => feature.FeatureDescriptor.Id);

                    // Enable the features and its dependencies
                    _moduleService.EnableFeatures(featureIds, true);
                }
            } catch (Exception exception) {
                Services.Notifier.Error(T("Post installation steps failed with error: {0}", exception.Message));
            }

            return(Redirect(redirectUrl));
        }