Exemple #1
0
 public void Start(CancellationToken cancellationToken)
 {
     if ((ExecutionState != ExecutionState.Prepared) && (ExecutionState != ExecutionState.Paused))
     {
         throw new InvalidOperationException(string.Format("Start not allowed in execution state \"{0}\".", ExecutionState));
     }
     if (Optimizer == null)
     {
         return;
     }
     batchRunAction = BatchRunAction.Start;
     if (Optimizer.ExecutionState == ExecutionState.Stopped)
     {
         Optimizer.Prepare();
     }
     for (int i = repetitionsCounter; i < repetitions; i++)
     {
         // a race-condition may occur when the optimizer has changed the state by itself in the meantime
         try { Optimizer.Start(cancellationToken); } catch (InvalidOperationException) { }
         if (ExecutionState == ExecutionState.Paused || ExecutionState == ExecutionState.Stopped)
         {
             break;
         }
         Optimizer.Prepare();
         if (ExecutionState == ExecutionState.Paused || ExecutionState == ExecutionState.Stopped)
         {
             break;
         }
     }
 }
Exemple #2
0
        private void OnStopped()
        {
            batchRunAction = BatchRunAction.None;
            ExecutionState = ExecutionState.Stopped;
            EventHandler handler = Stopped;

            if (handler != null)
            {
                handler(this, EventArgs.Empty);
            }
        }
Exemple #3
0
 private BatchRun(BatchRun original, Cloner cloner)
     : base(original, cloner)
 {
     executionState     = original.executionState;
     executionTime      = original.executionTime;
     runsExecutionTime  = original.runsExecutionTime;
     optimizer          = cloner.Clone(original.optimizer);
     repetitions        = original.repetitions;
     repetitionsCounter = original.repetitionsCounter;
     runs           = cloner.Clone(original.runs);
     batchRunAction = original.batchRunAction;
     Initialize();
 }
Exemple #4
0
 public void Pause()
 {
     if (ExecutionState != ExecutionState.Started)
     {
         throw new InvalidOperationException(string.Format("Pause not allowed in execution state \"{0}\".", ExecutionState));
     }
     if (Optimizer == null)
     {
         return;
     }
     batchRunAction = BatchRunAction.Pause;
     if (Optimizer.ExecutionState != ExecutionState.Started)
     {
         return;
     }
     // a race-condition may occur when the optimizer has changed the state by itself in the meantime
     try { Optimizer.Pause(); } catch (InvalidOperationException) { } catch (NotSupportedException) { }
 }
Exemple #5
0
 public void Stop()
 {
     if ((ExecutionState != ExecutionState.Started) && (ExecutionState != ExecutionState.Paused))
     {
         throw new InvalidOperationException(string.Format("Stop not allowed in execution state \"{0}\".", ExecutionState));
     }
     if (Optimizer == null)
     {
         return;
     }
     batchRunAction = BatchRunAction.Stop;
     if (Optimizer.ExecutionState != ExecutionState.Started && Optimizer.ExecutionState != ExecutionState.Paused)
     {
         OnStopped();
         return;
     }
     // a race-condition may occur when the optimizer has changed the state by itself in the meantime
     try { Optimizer.Stop(); } catch (InvalidOperationException) { }
 }
Exemple #6
0
 public void Prepare(bool clearRuns)
 {
     if ((ExecutionState != ExecutionState.Prepared) && (ExecutionState != ExecutionState.Paused) && (ExecutionState != ExecutionState.Stopped))
     {
         throw new InvalidOperationException(string.Format("Prepare not allowed in execution state \"{0}\".", ExecutionState));
     }
     if (Optimizer != null)
     {
         ExecutionTime      = TimeSpan.Zero;
         RepetitionsCounter = 0;
         if (clearRuns)
         {
             runs.Clear();
         }
         batchRunAction = BatchRunAction.Prepare;
         // a race-condition may occur when the optimizer has changed the state by itself in the meantime
         try { Optimizer.Prepare(clearRuns); } catch (InvalidOperationException) { }
     }
     else
     {
         ExecutionState = ExecutionState.Stopped;
     }
 }
Exemple #7
0
 private void OnStopped() {
   batchRunAction = BatchRunAction.None;
   ExecutionState = ExecutionState.Stopped;
   EventHandler handler = Stopped;
   if (handler != null) handler(this, EventArgs.Empty);
 }
Exemple #8
0
 public void Stop() {
   if ((ExecutionState != ExecutionState.Started) && (ExecutionState != ExecutionState.Paused))
     throw new InvalidOperationException(string.Format("Stop not allowed in execution state \"{0}\".", ExecutionState));
   if (Optimizer == null) return;
   batchRunAction = BatchRunAction.Stop;
   if (Optimizer.ExecutionState != ExecutionState.Started && Optimizer.ExecutionState != ExecutionState.Paused) {
     OnStopped();
     return;
   }
   // a race-condition may occur when the optimizer has changed the state by itself in the meantime
   try { Optimizer.Stop(); }
   catch (InvalidOperationException) { }
 }
Exemple #9
0
 public void Prepare(bool clearRuns) {
   if ((ExecutionState != ExecutionState.Prepared) && (ExecutionState != ExecutionState.Paused) && (ExecutionState != ExecutionState.Stopped))
     throw new InvalidOperationException(string.Format("Prepare not allowed in execution state \"{0}\".", ExecutionState));
   if (Optimizer != null) {
     ExecutionTime = TimeSpan.Zero;
     RepetitionsCounter = 0;
     if (clearRuns) runs.Clear();
     batchRunAction = BatchRunAction.Prepare;
     // a race-condition may occur when the optimizer has changed the state by itself in the meantime
     try { Optimizer.Prepare(clearRuns); }
     catch (InvalidOperationException) { }
   } else {
     ExecutionState = ExecutionState.Stopped;
   }
 }
Exemple #10
0
 private BatchRun(BatchRun original, Cloner cloner)
   : base(original, cloner) {
   executionState = original.executionState;
   executionTime = original.executionTime;
   runsExecutionTime = original.runsExecutionTime;
   optimizer = cloner.Clone(original.optimizer);
   repetitions = original.repetitions;
   repetitionsCounter = original.repetitionsCounter;
   runs = cloner.Clone(original.runs);
   batchRunAction = original.batchRunAction;
   Initialize();
 }