public async Task ExecuteAsync(string executionId, RecipeStepDescriptor recipeStep) { _logger.LogInformation("Executing recipe step '{0}'.", recipeStep.Name); var recipeContext = new RecipeContext { RecipeStep = recipeStep, Executed = false, ExecutionId = executionId }; await _eventBus.NotifyAsync <IRecipeEventHandler>(e => e.RecipeStepExecutingAsync(executionId, recipeStep)); await _recipeHandlers.InvokeAsync(rh => rh.ExecuteRecipeStepAsync(recipeContext), _logger); await UpdateStepResultRecordAsync(recipeContext, true); await _eventBus.NotifyAsync <IRecipeEventHandler>(e => e.RecipeStepExecutedAsync(executionId, recipeStep)); }
public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlanResult result) { var allContentState = step as AllContentDeploymentStep; if (allContentState == null) { return; } var data = new JArray(); var descriptor = new RecipeStepDescriptor { Name = "Data", Step = data }; foreach (var contentItem in await _session.QueryAsync <ContentItem, ContentItemIndex>(x => x.Published).List()) { data.Add(contentItem.Content); } return; }
public async Task <string> ExecuteAsync(string executionId, RecipeDescriptor recipeDescriptor) { await _eventBus.NotifyAsync <IRecipeEventHandler>(x => x.RecipeExecutingAsync(executionId, recipeDescriptor)); try { RecipeResult result = new RecipeResult { ExecutionId = executionId }; List <RecipeStepResult> stepResults = new List <RecipeStepResult>(); using (StreamReader file = File.OpenText(recipeDescriptor.RecipeFileInfo.PhysicalPath)) { using (var reader = new JsonTextReader(file)) { VariablesMethodProvider variablesMethodProvider = null; // Go to Steps, then iterate. while (reader.Read()) { if (reader.Path == "variables") { reader.Read(); var variables = JObject.Load(reader); variablesMethodProvider = new VariablesMethodProvider(variables); } if (reader.Path == "steps" && reader.TokenType == JsonToken.StartArray) { int stepId = 0; while (reader.Read() && reader.Depth > 1) { if (reader.Depth == 2) { var child = JToken.Load(reader); var recipeStep = new RecipeStepDescriptor { Id = (stepId++).ToString(), Name = child.Value <string>("name"), Step = child }; var shellContext = _orchardHost.GetOrCreateShellContext(_shellSettings); using (var scope = shellContext.CreateServiceScope()) { if (!shellContext.IsActivated) { var eventBus = scope.ServiceProvider.GetService <IEventBus>(); await eventBus.NotifyAsync <IOrchardShellEvents>(x => x.ActivatingAsync()); await eventBus.NotifyAsync <IOrchardShellEvents>(x => x.ActivatedAsync()); shellContext.IsActivated = true; } var recipeStepExecutor = scope.ServiceProvider.GetRequiredService <IRecipeStepExecutor>(); var scriptingManager = scope.ServiceProvider.GetRequiredService <IScriptingManager>(); if (variablesMethodProvider != null) { variablesMethodProvider.ScriptingManager = scriptingManager; scriptingManager.GlobalMethodProviders.Add(variablesMethodProvider); } if (_applicationLifetime.ApplicationStopping.IsCancellationRequested) { throw new OrchardException(T["Recipe cancelled, application is restarting"]); } EvaluateJsonTree(scriptingManager, recipeStep.Step); await recipeStepExecutor.ExecuteAsync(executionId, recipeStep); } // The recipe execution might have invalidated the shell by enabling new features, // so the deferred tasks need to run on an updated shell context if necessary. shellContext = _orchardHost.GetOrCreateShellContext(_shellSettings); using (var scope = shellContext.CreateServiceScope()) { var recipeStepExecutor = scope.ServiceProvider.GetRequiredService <IRecipeStepExecutor>(); var deferredTaskEngine = scope.ServiceProvider.GetService <IDeferredTaskEngine>(); // The recipe might have added some deferred tasks to process if (deferredTaskEngine != null && deferredTaskEngine.HasPendingTasks) { var taskContext = new DeferredTaskContext(scope.ServiceProvider); await deferredTaskEngine.ExecuteTasksAsync(taskContext); } } } } } } } } await _eventBus.NotifyAsync <IRecipeEventHandler>(x => x.RecipeExecutedAsync(executionId, recipeDescriptor)); return(executionId); } catch (Exception) { await _eventBus.NotifyAsync <IRecipeEventHandler>(x => x.ExecutionFailedAsync(executionId, recipeDescriptor)); throw; } }