示例#1
0
        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");
                }
            });
        }
示例#2
0
 public IPlanExecution Create(BackupPlan plan, PlanExecutionEvents events) => new ManualPlanExecution(planExecutionHelper, plan, events);
示例#3
0
 public ManualPlanExecution(PlanExecutionHelper planExecutionHelper, BackupPlan backupPlan, PlanExecutionEvents events)
 {
     this.planExecutionHelper = planExecutionHelper;
     this.backupPlan          = backupPlan;
     this.events = events;
 }
示例#4
0
 public InvalidPlanExecution(PlanExecutionEvents events, string reason)
 {
     this.events = events;
     this.reason = reason;
 }