Changeset 3280 for trunk/sources/HeuristicLab.Optimization/3.3/BatchRun.cs
- Timestamp:
- 04/07/10 05:22:33 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Optimization/3.3/BatchRun.cs
r3276 r3280 66 66 } 67 67 68 [Storable] 68 69 private IAlgorithm algorithm; 69 [Storable]70 private IAlgorithm AlgorithmPersistence {71 get { return algorithm; }72 set {73 if (algorithm != null) DeregisterAlgorithmEvents();74 algorithm = value;75 if (algorithm != null) RegisterAlgorithmEvents();76 }77 }78 70 public IAlgorithm Algorithm { 79 71 get { return algorithm; } … … 113 105 public BatchRun() 114 106 : base() { 107 name = ItemName; 108 description = ItemDescription; 115 109 executionState = ExecutionState.Stopped; 116 110 executionTime = TimeSpan.Zero; … … 119 113 stopPending = false; 120 114 } 121 public BatchRun(string name) : base(name) { 115 public BatchRun(string name) 116 : base(name) { 117 description = ItemDescription; 122 118 executionState = ExecutionState.Stopped; 123 119 executionTime = TimeSpan.Zero; … … 126 122 stopPending = false; 127 123 } 128 public BatchRun(string name, string description) : base(name, description) { 124 public BatchRun(string name, string description) 125 : base(name, description) { 129 126 executionState = ExecutionState.Stopped; 130 127 executionTime = TimeSpan.Zero; … … 133 130 stopPending = false; 134 131 } 132 [StorableConstructor] 133 private BatchRun(bool deserializing) 134 : base(deserializing) { 135 stopPending = false; 136 } 137 138 [StorableHook(HookType.AfterDeserialization)] 139 private void Initialize() { 140 if (algorithm != null) RegisterAlgorithmEvents(); 141 } 135 142 136 143 public override IDeepCloneable Clone(Cloner cloner) { 144 if (ExecutionState == ExecutionState.Started) throw new InvalidOperationException(string.Format("Clone not allowed in execution state \"{0}\".", ExecutionState)); 137 145 BatchRun clone = (BatchRun)base.Clone(cloner); 138 146 clone.executionState = executionState; 139 147 clone.executionTime = executionTime; 140 clone. Algorithm = (IAlgorithm)cloner.Clone(algorithm);148 clone.algorithm = (IAlgorithm)cloner.Clone(algorithm); 141 149 clone.repetitions = repetitions; 142 150 clone.runs = (RunCollection)cloner.Clone(runs); 143 151 clone.stopPending = stopPending; 152 clone.Initialize(); 144 153 return clone; 145 154 } … … 234 243 algorithm.Started += new EventHandler(Algorithm_Started); 235 244 algorithm.Stopped += new EventHandler(Algorithm_Stopped); 236 algorithm.Runs.CollectionReset += new CollectionItemsChangedEventHandler< Run>(Algorithm_Runs_CollectionReset);237 algorithm.Runs.ItemsAdded += new CollectionItemsChangedEventHandler< Run>(Algorithm_Runs_ItemsAdded);238 algorithm.Runs.ItemsRemoved += new CollectionItemsChangedEventHandler< Run>(Algorithm_Runs_ItemsRemoved);245 algorithm.Runs.CollectionReset += new CollectionItemsChangedEventHandler<IRun>(Algorithm_Runs_CollectionReset); 246 algorithm.Runs.ItemsAdded += new CollectionItemsChangedEventHandler<IRun>(Algorithm_Runs_ItemsAdded); 247 algorithm.Runs.ItemsRemoved += new CollectionItemsChangedEventHandler<IRun>(Algorithm_Runs_ItemsRemoved); 239 248 } 240 249 private void DeregisterAlgorithmEvents() { … … 245 254 algorithm.Started -= new EventHandler(Algorithm_Started); 246 255 algorithm.Stopped -= new EventHandler(Algorithm_Stopped); 247 algorithm.Runs.CollectionReset -= new CollectionItemsChangedEventHandler< Run>(Algorithm_Runs_CollectionReset);248 algorithm.Runs.ItemsAdded -= new CollectionItemsChangedEventHandler< Run>(Algorithm_Runs_ItemsAdded);249 algorithm.Runs.ItemsRemoved -= new CollectionItemsChangedEventHandler< Run>(Algorithm_Runs_ItemsRemoved);256 algorithm.Runs.CollectionReset -= new CollectionItemsChangedEventHandler<IRun>(Algorithm_Runs_CollectionReset); 257 algorithm.Runs.ItemsAdded -= new CollectionItemsChangedEventHandler<IRun>(Algorithm_Runs_ItemsAdded); 258 algorithm.Runs.ItemsRemoved -= new CollectionItemsChangedEventHandler<IRun>(Algorithm_Runs_ItemsRemoved); 250 259 } 251 260 private void Algorithm_ExceptionOccurred(object sender, EventArgs<Exception> e) { … … 277 286 } 278 287 } 279 private void Algorithm_Runs_CollectionReset(object sender, CollectionItemsChangedEventArgs< Run> e) {288 private void Algorithm_Runs_CollectionReset(object sender, CollectionItemsChangedEventArgs<IRun> e) { 280 289 Runs.RemoveRange(e.OldItems); 281 290 Runs.AddRange(e.Items); 282 291 } 283 private void Algorithm_Runs_ItemsAdded(object sender, CollectionItemsChangedEventArgs< Run> e) {292 private void Algorithm_Runs_ItemsAdded(object sender, CollectionItemsChangedEventArgs<IRun> e) { 284 293 Runs.AddRange(e.Items); 285 294 } 286 private void Algorithm_Runs_ItemsRemoved(object sender, CollectionItemsChangedEventArgs< Run> e) {295 private void Algorithm_Runs_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<IRun> e) { 287 296 Runs.RemoveRange(e.Items); 288 297 }
Note: See TracChangeset
for help on using the changeset viewer.