diff --git a/src/Orchard.Web/Modules/Orchard.Recipes/Commands/RecipesCommands.cs b/src/Orchard.Web/Modules/Orchard.Recipes/Commands/RecipesCommands.cs index c0a9589da..28c5292e7 100644 --- a/src/Orchard.Web/Modules/Orchard.Recipes/Commands/RecipesCommands.cs +++ b/src/Orchard.Web/Modules/Orchard.Recipes/Commands/RecipesCommands.cs @@ -12,25 +12,31 @@ namespace Orchard.Recipes.Commands { private readonly IRecipeHarvester _recipeHarvester; private readonly IRecipeManager _recipeManager; private readonly IExtensionManager _extensionManager; + private readonly IRecipeResultAccessor _recipeResultAccessor; - public RecipesCommands(IRecipeHarvester recipeHarvester, IRecipeManager recipeManager, IExtensionManager extensionManager) { + public RecipesCommands( + IRecipeHarvester recipeHarvester, + IRecipeManager recipeManager, + IExtensionManager extensionManager, + IRecipeResultAccessor recipeResultAccessor) { _recipeHarvester = recipeHarvester; _recipeManager = recipeManager; _extensionManager = extensionManager; + _recipeResultAccessor = recipeResultAccessor; } - [CommandHelp("recipes harvest \r\n\t" + "Display list of available recipes for an extension")] + [CommandHelp("recipes harvest \r\n\t" + "Displays a list of available recipes for a specific extension.")] [CommandName("recipes harvest")] - public void HarvestRecipes(string extensionId) { - ExtensionDescriptor extensionDescriptor = _extensionManager.GetExtension(extensionId); + public void Harvest(string extensionId) { + var extensionDescriptor = _extensionManager.GetExtension(extensionId); if (extensionDescriptor == null) { - Context.Output.WriteLine(T("Could not discover recipes because module '{0}' was not found.", extensionId)); + Context.Output.WriteLine(T("Could not discover recipes because extension '{0}' was not found.", extensionId)); return; } - IEnumerable recipes = _recipeHarvester.HarvestRecipes(extensionId); + var recipes = _recipeHarvester.HarvestRecipes(extensionId); if (recipes.Count() == 0) { - Context.Output.WriteLine(T("No recipes found for extension {0}.", extensionId)); + Context.Output.WriteLine(T("No recipes found for extension '{0}'.", extensionId)); return; } @@ -38,7 +44,7 @@ namespace Orchard.Recipes.Commands { Context.Output.WriteLine(T("--------------------------")); Context.Output.WriteLine(); - foreach (Recipe recipe in recipes) { + foreach (var recipe in recipes) { Context.Output.WriteLine(T("Recipe: {0}", recipe.Name)); Context.Output.WriteLine(T(" Version: {0}", recipe.Version)); Context.Output.WriteLine(T(" Tags: {0}", recipe.Tags)); @@ -48,29 +54,49 @@ namespace Orchard.Recipes.Commands { } } - [CommandHelp("recipes execute \r\n\t" + "Executes a recipe from a module")] + [CommandHelp("recipes execute \r\n\t" + "Executes a specific recipe for a specific extension.")] [CommandName("recipes execute")] - public void ExecuteRecipe(string extensionId, string recipeName) { - ExtensionDescriptor extensionDescriptor = _extensionManager.GetExtension(extensionId); + public void Execute(string extensionId, string recipeName) { + var extensionDescriptor = _extensionManager.GetExtension(extensionId); if (extensionDescriptor == null) { - Context.Output.WriteLine(T("Could not discover recipes because module '{0}' was not found.", extensionId)); + Context.Output.WriteLine(T("Could not discover recipes because extension '{0}' was not found.", extensionId)); return; } - IEnumerable recipes = _recipeHarvester.HarvestRecipes(extensionId); - if (recipes.Count() == 0) { - Context.Output.WriteLine(T("No recipes found for extension {0}.", extensionId)); + var recipes = _recipeHarvester.HarvestRecipes(extensionId); + if (!recipes.Any()) { + Context.Output.WriteLine(T("No recipes found for extension '{0}'.", extensionId)); return; } - Recipe recipe = recipes.FirstOrDefault(r => r.Name.Equals(recipeName, StringComparison.OrdinalIgnoreCase)); + var recipe = recipes.FirstOrDefault(r => r.Name.Equals(recipeName, StringComparison.OrdinalIgnoreCase)); if (recipe == null) { - Context.Output.WriteLine(T("Invalid recipe name {0}.", recipeName)); + Context.Output.WriteLine(T("No recipe with name '{0}' was found in extension '{1}'.", recipeName, extensionId)); return; } - _recipeManager.Execute(recipe); - Context.Output.WriteLine(T("Recipe scheduled for execution successfully.").Text); + 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); + } + + [CommandHelp("recipes result \r\n\t" + "Prints the status/result of a specific recipe execution.")] + [CommandName("recipes result")] + public void Result(string executionId) { + var result = _recipeResultAccessor.GetResult(executionId); + + Context.Output.WriteLine(T("Result of recipe execution:")); + Context.Output.WriteLine(T("---------------------------")); + Context.Output.WriteLine(T(" Execution ID: {0}", executionId)); + Context.Output.WriteLine(T(" Completed: {0}", result.IsCompleted)); + Context.Output.WriteLine(T(" Successful: {0}", result.IsSuccessful)); + + foreach (var step in result.Steps) { + Context.Output.WriteLine(T(" Step: {0}", step.StepName)); + Context.Output.WriteLine(T(" Completed: {0}", step.IsCompleted)); + Context.Output.WriteLine(T(" Successful: {0}", step.IsSuccessful)); + if (!String.IsNullOrEmpty(step.ErrorMessage)) + Context.Output.WriteLine(T(" Error message: {0}", step.ErrorMessage)); + } } } } \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Setup/Commands/SetupCommand.cs b/src/Orchard.Web/Modules/Orchard.Setup/Commands/SetupCommand.cs index c0c139b14..e56c2cd61 100644 --- a/src/Orchard.Web/Modules/Orchard.Setup/Commands/SetupCommand.cs +++ b/src/Orchard.Web/Modules/Orchard.Setup/Commands/SetupCommand.cs @@ -39,16 +39,16 @@ namespace Orchard.Setup.Commands { [CommandHelp("setup /SiteName: /AdminUsername: /AdminPassword: /DatabaseProvider: " + "/DatabaseConnectionString: /DatabaseTablePrefix: /EnabledFeatures: " + "/Recipe:" + - "\r\n\tRun first time setup for the site or for a given tenant")] + "\r\n\tRuns first time setup for the site or for a given tenant.")] [CommandName("setup")] [OrchardSwitches("SiteName,AdminUsername,AdminPassword,DatabaseProvider,DatabaseConnectionString,DatabaseTablePrefix,EnabledFeatures,Recipe")] public void Setup() { IEnumerable enabledFeatures = null; - if (!string.IsNullOrEmpty(EnabledFeatures)) { + if (!String.IsNullOrEmpty(EnabledFeatures)) { enabledFeatures = EnabledFeatures .Split(',') .Select(s => s.Trim()) - .Where(s => !string.IsNullOrEmpty(s)); + .Where(s => !String.IsNullOrEmpty(s)); } Recipe = String.IsNullOrEmpty(Recipe) ? "Default" : Recipe; @@ -63,13 +63,9 @@ namespace Orchard.Setup.Commands { Recipe = Recipe, }; - _setupService.Setup(setupContext); + var executionId = _setupService.Setup(setupContext); - Context.Output.WriteLine(T("Site \"{0}\" successfully setup to run data provider \"{1}\" (with table prefix \"{2}\") and configured by recipe \"{3}\"", - setupContext.SiteName, - setupContext.DatabaseProvider, - setupContext.DatabaseTablePrefix, - setupContext.Recipe)); + Context.Output.WriteLine(T("Setup of site '{0}' was started with recipe execution ID {1}. Use the 'recipes result' command to check the result of the execution.", setupContext.SiteName, executionId)); } } }