public async Task ExecuteAsync(BackupPlan plan, PlanExecutionEvents events) { await Task.Run(() => { try { events.OnIsRunning(true); var placeholders = new Placeholders(); systemOperations.LoadSystemPlaceholders(placeholders); int stepsFinished = 0; events.OnProgress(0); int planProgress = 0; foreach (var step in plan.Steps) { var stepExecution = serviceProvider.Get <IStepExecution>(s => s.Type == step.StepType); if (stepExecution != null) { var stepEvents = new StepExecutionEvents(); stepEvents.ProgressUpdated += (o, e) => events.OnProgress(planProgress + e.Progress / plan.Steps.Count()); stepEvents.StatusTextUpdated += (o, e) => events.OnStatusText(e.StatusText); stepExecution.Execute(step, placeholders, stepEvents); stepsFinished++; planProgress = stepsFinished * 100 / plan.Steps.Count(); events.OnProgress(planProgress); } else { events.OnHasErrors(true, $"Unknown execution step '{step.StepType}'"); break; } } } catch (Exception ex) { events.OnHasErrors(true, ex.Message); } finally { events.OnIsRunning(false); events.OnStatusText("Finished successfully"); } }); }
public IPlanExecution Create(BackupPlan plan, PlanExecutionEvents events) => new ManualPlanExecution(planExecutionHelper, plan, events);
public ManualPlanExecution(PlanExecutionHelper planExecutionHelper, BackupPlan backupPlan, PlanExecutionEvents events) { this.planExecutionHelper = planExecutionHelper; this.backupPlan = backupPlan; this.events = events; }
public InvalidPlanExecution(PlanExecutionEvents events, string reason) { this.events = events; this.reason = reason; }