[3226] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[7259] | 3 | * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[3226] | 4 | *
|
---|
| 5 | * This file is part of HeuristicLab.
|
---|
| 6 | *
|
---|
| 7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
| 8 | * it under the terms of the GNU General Public License as published by
|
---|
| 9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
| 10 | * (at your option) any later version.
|
---|
| 11 | *
|
---|
| 12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 15 | * GNU General Public License for more details.
|
---|
| 16 | *
|
---|
| 17 | * You should have received a copy of the GNU General Public License
|
---|
| 18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 19 | */
|
---|
| 20 | #endregion
|
---|
| 21 |
|
---|
| 22 | using System;
|
---|
[4533] | 23 | using System.Collections.Generic;
|
---|
[3226] | 24 | using System.Drawing;
|
---|
[3716] | 25 | using HeuristicLab.Collections;
|
---|
[3265] | 26 | using HeuristicLab.Common;
|
---|
[3226] | 27 | using HeuristicLab.Core;
|
---|
[3716] | 28 | using HeuristicLab.Data;
|
---|
[3226] | 29 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 30 |
|
---|
| 31 | namespace HeuristicLab.Optimization {
|
---|
| 32 | /// <summary>
|
---|
[5300] | 33 | /// A run in which an optimizer is executed a given number of times.
|
---|
[3226] | 34 | /// </summary>
|
---|
[5300] | 35 | [Item("Batch Run", "A run in which an optimizer is executed a given number of times.")]
|
---|
[3226] | 36 | [Creatable("Testing & Analysis")]
|
---|
| 37 | [StorableClass]
|
---|
[4419] | 38 | public sealed class BatchRun : NamedItem, IOptimizer, IStorableContent {
|
---|
| 39 | public string Filename { get; set; }
|
---|
| 40 |
|
---|
[7201] | 41 | public static new Image StaticItemImage {
|
---|
| 42 | get { return HeuristicLab.Common.Resources.VSImageLibrary.Event; }
|
---|
| 43 | }
|
---|
[3226] | 44 | public override Image ItemImage {
|
---|
[3351] | 45 | get {
|
---|
[6534] | 46 | if (ExecutionState == ExecutionState.Prepared) return HeuristicLab.Common.Resources.VSImageLibrary.BatchRunPrepared;
|
---|
| 47 | else if (ExecutionState == ExecutionState.Started) return HeuristicLab.Common.Resources.VSImageLibrary.BatchRunStarted;
|
---|
| 48 | else if (ExecutionState == ExecutionState.Paused) return HeuristicLab.Common.Resources.VSImageLibrary.BatchRunPaused;
|
---|
| 49 | else if (ExecutionState == ExecutionState.Stopped) return HeuristicLab.Common.Resources.VSImageLibrary.BatchRunStopped;
|
---|
[7201] | 50 | else return base.ItemImage;
|
---|
[3351] | 51 | }
|
---|
[3226] | 52 | }
|
---|
| 53 |
|
---|
[3265] | 54 | [Storable]
|
---|
| 55 | private ExecutionState executionState;
|
---|
| 56 | public ExecutionState ExecutionState {
|
---|
| 57 | get { return executionState; }
|
---|
| 58 | private set {
|
---|
| 59 | if (executionState != value) {
|
---|
| 60 | executionState = value;
|
---|
| 61 | OnExecutionStateChanged();
|
---|
[3351] | 62 | OnItemImageChanged();
|
---|
[3265] | 63 | }
|
---|
| 64 | }
|
---|
| 65 | }
|
---|
| 66 |
|
---|
| 67 | [Storable]
|
---|
| 68 | private TimeSpan executionTime;
|
---|
| 69 | public TimeSpan ExecutionTime {
|
---|
| 70 | get {
|
---|
[5300] | 71 | if ((Optimizer != null) && (Optimizer.ExecutionState != ExecutionState.Stopped))
|
---|
| 72 | return executionTime + Optimizer.ExecutionTime;
|
---|
[3265] | 73 | else
|
---|
| 74 | return executionTime;
|
---|
| 75 | }
|
---|
| 76 | private set {
|
---|
| 77 | executionTime = value;
|
---|
| 78 | OnExecutionTimeChanged();
|
---|
| 79 | }
|
---|
| 80 | }
|
---|
| 81 |
|
---|
[3280] | 82 | [Storable]
|
---|
[5300] | 83 | private IOptimizer optimizer;
|
---|
| 84 | public IOptimizer Optimizer {
|
---|
| 85 | get { return optimizer; }
|
---|
[3226] | 86 | set {
|
---|
[5300] | 87 | if (optimizer != value) {
|
---|
| 88 | if (optimizer != null) {
|
---|
| 89 | DeregisterOptimizerEvents();
|
---|
| 90 | IEnumerable<IRun> runs = optimizer.Runs;
|
---|
| 91 | optimizer = null; //necessary to avoid removing the runs from the old optimizer
|
---|
[4115] | 92 | Runs.RemoveRange(runs);
|
---|
| 93 | }
|
---|
[5300] | 94 | optimizer = value;
|
---|
| 95 | if (optimizer != null) {
|
---|
| 96 | RegisterOptimizerEvents();
|
---|
| 97 | Runs.AddRange(optimizer.Runs);
|
---|
[4115] | 98 | }
|
---|
[5300] | 99 | OnOptimizerChanged();
|
---|
[3716] | 100 | Prepare();
|
---|
[3226] | 101 | }
|
---|
| 102 | }
|
---|
| 103 | }
|
---|
[5300] | 104 | // BackwardsCompatibility3.3
|
---|
| 105 | #region Backwards compatible code (remove with 3.4)
|
---|
[5409] | 106 | [Storable(AllowOneWay = true)]
|
---|
[5300] | 107 | private IAlgorithm algorithm {
|
---|
| 108 | set { optimizer = value; }
|
---|
| 109 | }
|
---|
| 110 | #endregion
|
---|
[3226] | 111 |
|
---|
| 112 | [Storable]
|
---|
| 113 | private int repetitions;
|
---|
| 114 | public int Repetitions {
|
---|
| 115 | get { return repetitions; }
|
---|
| 116 | set {
|
---|
| 117 | if (repetitions != value) {
|
---|
| 118 | repetitions = value;
|
---|
| 119 | OnRepetitionsChanged();
|
---|
[5300] | 120 | if ((Optimizer != null) && (Optimizer.ExecutionState == ExecutionState.Stopped))
|
---|
[3275] | 121 | Prepare();
|
---|
[3226] | 122 | }
|
---|
| 123 | }
|
---|
| 124 | }
|
---|
[3716] | 125 | [Storable]
|
---|
| 126 | private int repetitionsCounter;
|
---|
[3226] | 127 |
|
---|
| 128 | [Storable]
|
---|
[3260] | 129 | private RunCollection runs;
|
---|
| 130 | public RunCollection Runs {
|
---|
| 131 | get { return runs; }
|
---|
[3716] | 132 | private set {
|
---|
| 133 | if (value == null) throw new ArgumentNullException();
|
---|
| 134 | if (runs != value) {
|
---|
| 135 | if (runs != null) DeregisterRunsEvents();
|
---|
| 136 | runs = value;
|
---|
| 137 | if (runs != null) RegisterRunsEvents();
|
---|
| 138 | }
|
---|
| 139 | }
|
---|
[3226] | 140 | }
|
---|
| 141 |
|
---|
[5419] | 142 | public IEnumerable<IOptimizer> NestedOptimizers {
|
---|
| 143 | get {
|
---|
| 144 | if (Optimizer == null) yield break;
|
---|
| 145 |
|
---|
| 146 | yield return Optimizer;
|
---|
| 147 | foreach (IOptimizer opt in Optimizer.NestedOptimizers)
|
---|
| 148 | yield return opt;
|
---|
| 149 | }
|
---|
| 150 | }
|
---|
| 151 |
|
---|
[6767] | 152 | private bool batchRunStarted = false;
|
---|
| 153 | private bool batchRunPaused = false;
|
---|
| 154 | private bool batchRunStopped = false;
|
---|
[3226] | 155 |
|
---|
| 156 | public BatchRun()
|
---|
| 157 | : base() {
|
---|
[3280] | 158 | name = ItemName;
|
---|
| 159 | description = ItemDescription;
|
---|
[3265] | 160 | executionState = ExecutionState.Stopped;
|
---|
| 161 | executionTime = TimeSpan.Zero;
|
---|
[3226] | 162 | repetitions = 10;
|
---|
[3716] | 163 | repetitionsCounter = 0;
|
---|
| 164 | Runs = new RunCollection();
|
---|
[3226] | 165 | }
|
---|
[3280] | 166 | public BatchRun(string name)
|
---|
| 167 | : base(name) {
|
---|
| 168 | description = ItemDescription;
|
---|
[3265] | 169 | executionState = ExecutionState.Stopped;
|
---|
| 170 | executionTime = TimeSpan.Zero;
|
---|
[3226] | 171 | repetitions = 10;
|
---|
[3716] | 172 | repetitionsCounter = 0;
|
---|
| 173 | Runs = new RunCollection();
|
---|
[3226] | 174 | }
|
---|
[3280] | 175 | public BatchRun(string name, string description)
|
---|
| 176 | : base(name, description) {
|
---|
[3265] | 177 | executionState = ExecutionState.Stopped;
|
---|
| 178 | executionTime = TimeSpan.Zero;
|
---|
[3226] | 179 | repetitions = 10;
|
---|
[3716] | 180 | repetitionsCounter = 0;
|
---|
| 181 | Runs = new RunCollection();
|
---|
[3226] | 182 | }
|
---|
[3280] | 183 | [StorableConstructor]
|
---|
[6767] | 184 | private BatchRun(bool deserializing) : base(deserializing) { }
|
---|
[3280] | 185 | [StorableHook(HookType.AfterDeserialization)]
|
---|
[4722] | 186 | private void AfterDeserialization() {
|
---|
| 187 | Initialize();
|
---|
[3280] | 188 | }
|
---|
| 189 |
|
---|
[4722] | 190 | private BatchRun(BatchRun original, Cloner cloner)
|
---|
| 191 | : base(original, cloner) {
|
---|
| 192 | executionState = original.executionState;
|
---|
| 193 | executionTime = original.executionTime;
|
---|
[5300] | 194 | optimizer = cloner.Clone(original.optimizer);
|
---|
[4722] | 195 | repetitions = original.repetitions;
|
---|
| 196 | repetitionsCounter = original.repetitionsCounter;
|
---|
| 197 | runs = cloner.Clone(original.runs);
|
---|
[6767] | 198 | batchRunStarted = original.batchRunStarted;
|
---|
| 199 | batchRunPaused = original.batchRunPaused;
|
---|
| 200 | batchRunStopped = original.batchRunStopped;
|
---|
[4722] | 201 | Initialize();
|
---|
| 202 | }
|
---|
[3226] | 203 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
[3280] | 204 | if (ExecutionState == ExecutionState.Started) throw new InvalidOperationException(string.Format("Clone not allowed in execution state \"{0}\".", ExecutionState));
|
---|
[4722] | 205 | return new BatchRun(this, cloner);
|
---|
[3226] | 206 | }
|
---|
| 207 |
|
---|
[4722] | 208 | private void Initialize() {
|
---|
[5300] | 209 | if (optimizer != null) RegisterOptimizerEvents();
|
---|
[4722] | 210 | if (runs != null) RegisterRunsEvents();
|
---|
| 211 | }
|
---|
| 212 |
|
---|
[3226] | 213 | public void Prepare() {
|
---|
[3275] | 214 | Prepare(false);
|
---|
[3226] | 215 | }
|
---|
[3275] | 216 | public void Prepare(bool clearRuns) {
|
---|
[3265] | 217 | if ((ExecutionState != ExecutionState.Prepared) && (ExecutionState != ExecutionState.Paused) && (ExecutionState != ExecutionState.Stopped))
|
---|
| 218 | throw new InvalidOperationException(string.Format("Prepare not allowed in execution state \"{0}\".", ExecutionState));
|
---|
[5300] | 219 | if (Optimizer != null) {
|
---|
[3716] | 220 | repetitionsCounter = 0;
|
---|
| 221 | if (clearRuns) runs.Clear();
|
---|
[5300] | 222 | Optimizer.Prepare(clearRuns);
|
---|
[6471] | 223 | } else {
|
---|
| 224 | ExecutionState = ExecutionState.Stopped;
|
---|
[3261] | 225 | }
|
---|
[3226] | 226 | }
|
---|
[3265] | 227 | public void Start() {
|
---|
| 228 | if ((ExecutionState != ExecutionState.Prepared) && (ExecutionState != ExecutionState.Paused))
|
---|
| 229 | throw new InvalidOperationException(string.Format("Start not allowed in execution state \"{0}\".", ExecutionState));
|
---|
[6767] | 230 | if (Optimizer == null) return;
|
---|
| 231 |
|
---|
| 232 | batchRunStarted = true;
|
---|
| 233 | batchRunPaused = false;
|
---|
| 234 | batchRunStopped = false;
|
---|
[6816] | 235 | if (Optimizer.ExecutionState == ExecutionState.Stopped) Optimizer.Prepare();
|
---|
[6767] | 236 | Optimizer.Start();
|
---|
[3265] | 237 | }
|
---|
| 238 | public void Pause() {
|
---|
| 239 | if (ExecutionState != ExecutionState.Started)
|
---|
| 240 | throw new InvalidOperationException(string.Format("Pause not allowed in execution state \"{0}\".", ExecutionState));
|
---|
[6767] | 241 | if (Optimizer == null) return;
|
---|
| 242 | if (Optimizer.ExecutionState != ExecutionState.Started) return;
|
---|
| 243 |
|
---|
| 244 | batchRunStarted = false;
|
---|
| 245 | batchRunPaused = true;
|
---|
| 246 | batchRunStopped = false;
|
---|
| 247 | Optimizer.Pause();
|
---|
[3265] | 248 | }
|
---|
[3226] | 249 | public void Stop() {
|
---|
[3265] | 250 | if ((ExecutionState != ExecutionState.Started) && (ExecutionState != ExecutionState.Paused))
|
---|
| 251 | throw new InvalidOperationException(string.Format("Stop not allowed in execution state \"{0}\".", ExecutionState));
|
---|
[6767] | 252 | if (Optimizer == null) return;
|
---|
| 253 | if (Optimizer.ExecutionState != ExecutionState.Started && Optimizer.ExecutionState != ExecutionState.Paused) return;
|
---|
| 254 | batchRunStarted = false;
|
---|
| 255 | batchRunPaused = false;
|
---|
| 256 | batchRunStopped = true;
|
---|
| 257 | Optimizer.Stop();
|
---|
[3226] | 258 | }
|
---|
| 259 |
|
---|
| 260 | #region Events
|
---|
[3265] | 261 | public event EventHandler ExecutionStateChanged;
|
---|
| 262 | private void OnExecutionStateChanged() {
|
---|
| 263 | EventHandler handler = ExecutionStateChanged;
|
---|
| 264 | if (handler != null) handler(this, EventArgs.Empty);
|
---|
| 265 | }
|
---|
| 266 | public event EventHandler ExecutionTimeChanged;
|
---|
| 267 | private void OnExecutionTimeChanged() {
|
---|
| 268 | EventHandler handler = ExecutionTimeChanged;
|
---|
| 269 | if (handler != null) handler(this, EventArgs.Empty);
|
---|
| 270 | }
|
---|
[5300] | 271 | public event EventHandler OptimizerChanged;
|
---|
| 272 | private void OnOptimizerChanged() {
|
---|
| 273 | EventHandler handler = OptimizerChanged;
|
---|
[3265] | 274 | if (handler != null) handler(this, EventArgs.Empty);
|
---|
[3226] | 275 | }
|
---|
| 276 | public event EventHandler RepetitionsChanged;
|
---|
| 277 | private void OnRepetitionsChanged() {
|
---|
[3265] | 278 | EventHandler handler = RepetitionsChanged;
|
---|
| 279 | if (handler != null) handler(this, EventArgs.Empty);
|
---|
[3226] | 280 | }
|
---|
| 281 | public event EventHandler Prepared;
|
---|
| 282 | private void OnPrepared() {
|
---|
[3265] | 283 | ExecutionState = ExecutionState.Prepared;
|
---|
| 284 | EventHandler handler = Prepared;
|
---|
| 285 | if (handler != null) handler(this, EventArgs.Empty);
|
---|
[3226] | 286 | }
|
---|
| 287 | public event EventHandler Started;
|
---|
| 288 | private void OnStarted() {
|
---|
[3265] | 289 | ExecutionState = ExecutionState.Started;
|
---|
| 290 | EventHandler handler = Started;
|
---|
| 291 | if (handler != null) handler(this, EventArgs.Empty);
|
---|
[3226] | 292 | }
|
---|
[3265] | 293 | public event EventHandler Paused;
|
---|
| 294 | private void OnPaused() {
|
---|
| 295 | ExecutionState = ExecutionState.Paused;
|
---|
| 296 | EventHandler handler = Paused;
|
---|
| 297 | if (handler != null) handler(this, EventArgs.Empty);
|
---|
| 298 | }
|
---|
[3226] | 299 | public event EventHandler Stopped;
|
---|
| 300 | private void OnStopped() {
|
---|
[3265] | 301 | ExecutionState = ExecutionState.Stopped;
|
---|
| 302 | EventHandler handler = Stopped;
|
---|
| 303 | if (handler != null) handler(this, EventArgs.Empty);
|
---|
[3226] | 304 | }
|
---|
[3265] | 305 | public event EventHandler<EventArgs<Exception>> ExceptionOccurred;
|
---|
[3226] | 306 | private void OnExceptionOccurred(Exception exception) {
|
---|
[3265] | 307 | EventHandler<EventArgs<Exception>> handler = ExceptionOccurred;
|
---|
| 308 | if (handler != null) handler(this, new EventArgs<Exception>(exception));
|
---|
[3226] | 309 | }
|
---|
| 310 |
|
---|
[5300] | 311 | private void RegisterOptimizerEvents() {
|
---|
| 312 | optimizer.ExceptionOccurred += new EventHandler<EventArgs<Exception>>(Optimizer_ExceptionOccurred);
|
---|
| 313 | optimizer.ExecutionTimeChanged += new EventHandler(Optimizer_ExecutionTimeChanged);
|
---|
| 314 | optimizer.Paused += new EventHandler(Optimizer_Paused);
|
---|
| 315 | optimizer.Prepared += new EventHandler(Optimizer_Prepared);
|
---|
| 316 | optimizer.Started += new EventHandler(Optimizer_Started);
|
---|
| 317 | optimizer.Stopped += new EventHandler(Optimizer_Stopped);
|
---|
| 318 | optimizer.Runs.CollectionReset += new CollectionItemsChangedEventHandler<IRun>(Optimizer_Runs_CollectionReset);
|
---|
| 319 | optimizer.Runs.ItemsAdded += new CollectionItemsChangedEventHandler<IRun>(Optimizer_Runs_ItemsAdded);
|
---|
| 320 | optimizer.Runs.ItemsRemoved += new CollectionItemsChangedEventHandler<IRun>(Optimizer_Runs_ItemsRemoved);
|
---|
[3261] | 321 | }
|
---|
[5300] | 322 | private void DeregisterOptimizerEvents() {
|
---|
| 323 | optimizer.ExceptionOccurred -= new EventHandler<EventArgs<Exception>>(Optimizer_ExceptionOccurred);
|
---|
| 324 | optimizer.ExecutionTimeChanged -= new EventHandler(Optimizer_ExecutionTimeChanged);
|
---|
| 325 | optimizer.Paused -= new EventHandler(Optimizer_Paused);
|
---|
| 326 | optimizer.Prepared -= new EventHandler(Optimizer_Prepared);
|
---|
| 327 | optimizer.Started -= new EventHandler(Optimizer_Started);
|
---|
| 328 | optimizer.Stopped -= new EventHandler(Optimizer_Stopped);
|
---|
| 329 | optimizer.Runs.CollectionReset -= new CollectionItemsChangedEventHandler<IRun>(Optimizer_Runs_CollectionReset);
|
---|
| 330 | optimizer.Runs.ItemsAdded -= new CollectionItemsChangedEventHandler<IRun>(Optimizer_Runs_ItemsAdded);
|
---|
| 331 | optimizer.Runs.ItemsRemoved -= new CollectionItemsChangedEventHandler<IRun>(Optimizer_Runs_ItemsRemoved);
|
---|
[3226] | 332 | }
|
---|
[5300] | 333 | private void Optimizer_ExceptionOccurred(object sender, EventArgs<Exception> e) {
|
---|
[3261] | 334 | OnExceptionOccurred(e.Value);
|
---|
[3226] | 335 | }
|
---|
[5300] | 336 | private void Optimizer_ExecutionTimeChanged(object sender, EventArgs e) {
|
---|
[3265] | 337 | OnExecutionTimeChanged();
|
---|
| 338 | }
|
---|
[5300] | 339 | private void Optimizer_Paused(object sender, EventArgs e) {
|
---|
[6767] | 340 | if (ExecutionState == ExecutionState.Started) {
|
---|
| 341 | batchRunStarted = false;
|
---|
| 342 | batchRunPaused = true;
|
---|
| 343 | batchRunStopped = false;
|
---|
| 344 | OnPaused();
|
---|
| 345 | }
|
---|
[3265] | 346 | }
|
---|
[5300] | 347 | private void Optimizer_Prepared(object sender, EventArgs e) {
|
---|
[6767] | 348 | if (ExecutionState == ExecutionState.Stopped || !batchRunStarted) {
|
---|
[3276] | 349 | OnPrepared();
|
---|
[6767] | 350 | }
|
---|
[3265] | 351 | }
|
---|
[5300] | 352 | private void Optimizer_Started(object sender, EventArgs e) {
|
---|
[3276] | 353 | if (ExecutionState != ExecutionState.Started)
|
---|
| 354 | OnStarted();
|
---|
[3261] | 355 | }
|
---|
[5300] | 356 | private void Optimizer_Stopped(object sender, EventArgs e) {
|
---|
[3716] | 357 | repetitionsCounter++;
|
---|
[3265] | 358 |
|
---|
[6767] | 359 | if (batchRunStopped) OnStopped();
|
---|
| 360 | else if (repetitionsCounter >= repetitions) OnStopped();
|
---|
| 361 | else if (batchRunPaused) OnPaused();
|
---|
| 362 | else if (batchRunStarted) {
|
---|
[5300] | 363 | Optimizer.Prepare();
|
---|
| 364 | Optimizer.Start();
|
---|
[6767] | 365 | } else OnStopped();
|
---|
[3226] | 366 | }
|
---|
[5300] | 367 | private void Optimizer_Runs_CollectionReset(object sender, CollectionItemsChangedEventArgs<IRun> e) {
|
---|
[3275] | 368 | Runs.RemoveRange(e.OldItems);
|
---|
| 369 | Runs.AddRange(e.Items);
|
---|
| 370 | }
|
---|
[5300] | 371 | private void Optimizer_Runs_ItemsAdded(object sender, CollectionItemsChangedEventArgs<IRun> e) {
|
---|
[3275] | 372 | Runs.AddRange(e.Items);
|
---|
| 373 | }
|
---|
[5300] | 374 | private void Optimizer_Runs_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<IRun> e) {
|
---|
[3275] | 375 | Runs.RemoveRange(e.Items);
|
---|
| 376 | }
|
---|
[3716] | 377 |
|
---|
| 378 | private void RegisterRunsEvents() {
|
---|
| 379 | runs.CollectionReset += new CollectionItemsChangedEventHandler<IRun>(Runs_CollectionReset);
|
---|
[4115] | 380 | runs.ItemsAdded += new CollectionItemsChangedEventHandler<IRun>(Runs_ItemsAdded);
|
---|
[3716] | 381 | runs.ItemsRemoved += new CollectionItemsChangedEventHandler<IRun>(Runs_ItemsRemoved);
|
---|
| 382 | }
|
---|
[4115] | 383 |
|
---|
[3716] | 384 | private void DeregisterRunsEvents() {
|
---|
| 385 | runs.CollectionReset -= new CollectionItemsChangedEventHandler<IRun>(Runs_CollectionReset);
|
---|
[4115] | 386 | runs.ItemsAdded -= new CollectionItemsChangedEventHandler<IRun>(Runs_ItemsAdded);
|
---|
[3716] | 387 | runs.ItemsRemoved -= new CollectionItemsChangedEventHandler<IRun>(Runs_ItemsRemoved);
|
---|
| 388 | }
|
---|
| 389 | private void Runs_CollectionReset(object sender, CollectionItemsChangedEventArgs<IRun> e) {
|
---|
| 390 | foreach (IRun run in e.OldItems) {
|
---|
| 391 | IItem item;
|
---|
| 392 | run.Results.TryGetValue("Execution Time", out item);
|
---|
| 393 | TimeSpanValue executionTime = item as TimeSpanValue;
|
---|
| 394 | if (executionTime != null) ExecutionTime -= executionTime.Value;
|
---|
| 395 | }
|
---|
[5300] | 396 | if (Optimizer != null) Optimizer.Runs.RemoveRange(e.OldItems);
|
---|
[3716] | 397 | foreach (IRun run in e.Items) {
|
---|
| 398 | IItem item;
|
---|
| 399 | run.Results.TryGetValue("Execution Time", out item);
|
---|
| 400 | TimeSpanValue executionTime = item as TimeSpanValue;
|
---|
| 401 | if (executionTime != null) ExecutionTime += executionTime.Value;
|
---|
| 402 | }
|
---|
| 403 | }
|
---|
[4115] | 404 | private void Runs_ItemsAdded(object sender, CollectionItemsChangedEventArgs<IRun> e) {
|
---|
| 405 | foreach (IRun run in e.Items) {
|
---|
| 406 | IItem item;
|
---|
| 407 | run.Results.TryGetValue("Execution Time", out item);
|
---|
| 408 | TimeSpanValue executionTime = item as TimeSpanValue;
|
---|
| 409 | if (executionTime != null) ExecutionTime += executionTime.Value;
|
---|
| 410 | }
|
---|
| 411 | }
|
---|
[3716] | 412 | private void Runs_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<IRun> e) {
|
---|
| 413 | foreach (IRun run in e.Items) {
|
---|
| 414 | IItem item;
|
---|
| 415 | run.Results.TryGetValue("Execution Time", out item);
|
---|
| 416 | TimeSpanValue executionTime = item as TimeSpanValue;
|
---|
| 417 | if (executionTime != null) ExecutionTime -= executionTime.Value;
|
---|
| 418 | }
|
---|
[5300] | 419 | if (Optimizer != null) Optimizer.Runs.RemoveRange(e.Items);
|
---|
[3716] | 420 | }
|
---|
[3226] | 421 | #endregion
|
---|
| 422 | }
|
---|
| 423 | }
|
---|