public bool ExecuteNextStep(string executionId)
        {
            var nextRecipeStep = _recipeStepQueue.Dequeue(executionId);

            if (nextRecipeStep == null)
            {
                _recipeJournal.ExecutionComplete(executionId);
                _recipeExecuteEventHandler.ExecutionComplete(executionId);
                return(false);
            }
            _recipeJournal.WriteJournalEntry(executionId, string.Format("Executing step {0}.", nextRecipeStep.Name));
            var recipeContext = new RecipeContext {
                RecipeStep = nextRecipeStep, Executed = false, ExecutionId = executionId
            };

            try {
                _recipeExecuteEventHandler.RecipeStepExecuting(executionId, recipeContext);
                foreach (var recipeHandler in _recipeHandlers)
                {
                    recipeHandler.ExecuteRecipeStep(recipeContext);
                }
                _recipeExecuteEventHandler.RecipeStepExecuted(executionId, recipeContext);
            }
            catch (Exception exception) {
                Logger.Error(exception, "Recipe execution {0} was cancelled because a step failed to execute", executionId);
                while (_recipeStepQueue.Dequeue(executionId) != null)
                {
                    ;
                }
                _recipeJournal.ExecutionFailed(executionId);
                var message = T("Recipe execution with id {0} was cancelled because the \"{1}\" step failed to execute. The following exception was thrown: {2}. Refer to the error logs for more information.",
                                executionId, nextRecipeStep.Name, exception.Message);
                _recipeJournal.WriteJournalEntry(executionId, message.ToString());

                throw new OrchardCoreException(message);
            }

            if (!recipeContext.Executed)
            {
                Logger.Error("Could not execute recipe step '{0}' because the recipe handler was not found.", recipeContext.RecipeStep.Name);
                while (_recipeStepQueue.Dequeue(executionId) != null)
                {
                    ;
                }
                _recipeJournal.ExecutionFailed(executionId);
                var message = T("Recipe execution with id {0} was cancelled because the recipe handler for step \"{1}\" was not found. Refer to the error logs for more information.",
                                executionId, nextRecipeStep.Name);
                _recipeJournal.WriteJournalEntry(executionId, message.ToString());

                throw new OrchardCoreException(message);
            }

            return(true);
        }
Exemple #2
0
        public bool ExecuteNextStep(string executionId)
        {
            var nextRecipeStep = _recipeStepQueue.Dequeue(executionId);

            if (nextRecipeStep == null)
            {
                Logger.Information("No more recipe steps left to execute.");
                _recipeExecuteEventHandler.ExecutionComplete(executionId);
                return(false);
            }

            Logger.Information("Executing recipe step '{0}'.", nextRecipeStep.Name);

            var recipeContext = new RecipeContext {
                RecipeStep = nextRecipeStep, Executed = false, ExecutionId = executionId
            };

            try {
                _recipeExecuteEventHandler.RecipeStepExecuting(executionId, recipeContext);

                foreach (var recipeHandler in _recipeHandlers)
                {
                    recipeHandler.ExecuteRecipeStep(recipeContext);
                }

                UpdateStepResultRecord(executionId, nextRecipeStep.RecipeName, nextRecipeStep.Id, nextRecipeStep.Name, isSuccessful: true);
                _recipeExecuteEventHandler.RecipeStepExecuted(executionId, recipeContext);
            }
            catch (Exception ex) {
                UpdateStepResultRecord(executionId, nextRecipeStep.RecipeName, nextRecipeStep.Id, nextRecipeStep.Name, isSuccessful: false, errorMessage: ex.Message);
                Logger.Error(ex, "Recipe execution failed because the step '{0}' failed.", nextRecipeStep.Name);
                while (_recipeStepQueue.Dequeue(executionId) != null)
                {
                    ;
                }
                var message = T("Recipe execution with ID {0} failed because the step '{1}' failed to execute. The following exception was thrown:\n{2}\nRefer to the error logs for more information.", executionId, nextRecipeStep.Name, ex.Message);
                throw new OrchardCoreException(message);
            }

            if (!recipeContext.Executed)
            {
                Logger.Error("Recipe execution failed because no matching handler for recipe step '{0}' was found.", recipeContext.RecipeStep.Name);
                while (_recipeStepQueue.Dequeue(executionId) != null)
                {
                    ;
                }
                var message = T("Recipe execution with ID {0} failed because no matching handler for recipe step '{1}' was found. Refer to the error logs for more information.", executionId, nextRecipeStep.Name);
                throw new OrchardCoreException(message);
            }

            return(true);
        }