Changeset 10114 for branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.SolutionCaching/3.3/RunCollectionModifiers
- Timestamp:
- 11/07/13 16:30:39 (11 years ago)
- Location:
- branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.SolutionCaching/3.3/RunCollectionModifiers
- Files:
-
- 2 added
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.SolutionCaching/3.3/RunCollectionModifiers/RunCollectionModifierExecutable.cs
r10113 r10114 23 23 using System.Collections.Generic; 24 24 using System.Linq; 25 using System.Text;26 25 using System.Threading; 27 26 using System.Threading.Tasks; 28 27 using HeuristicLab.Common; 29 28 using HeuristicLab.Core; 30 using HeuristicLab.Hive;31 29 using HeuristicLab.Optimization; 32 30 using HeuristicLab.Parameters; 33 31 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 34 32 35 namespace HeuristicLab.Analysis.SolutionCaching .RunCollectionModifiers{36 [Item("RunCollectionModifier Task", "An item that runs RunCollectionModifiers on RunCollections with Hive support.")]33 namespace HeuristicLab.Analysis.SolutionCaching { 34 [Item("RunCollectionModifierExecutable", "An executable that runs RunCollectionModifiers on RunCollections.")] 37 35 [StorableClass] 38 public class RunCollectionModifierTask : ParameterizedNamedItem, ITask { 39 public virtual bool IsParallelizable { 40 get { return false; } 41 } 42 43 public virtual bool ComputeInParallel { 44 get { return false; } 45 set { 46 throw new NotSupportedException("Parallelization is not supported for RunCollectionModifierTasks."); 47 } 48 } 49 36 public class RunCollectionModifierExecutable : ParameterizedNamedItem, IExecutable { 50 37 [Storable] 51 38 protected ExecutionState executionState; … … 101 88 102 89 #region Constructors and Cloning 103 public RunCollectionModifier Task() {90 public RunCollectionModifierExecutable() { 104 91 Parameters.Add(new ValueParameter<ItemList<IRunCollectionModifier>>("RunCollectionModifiers", "List of RunCollectionModifiers that are executed. ", new ItemList<IRunCollectionModifier>())); 105 92 executionStack = new Stack<IRunCollectionModifier>(); … … 108 95 } 109 96 [StorableConstructor] 110 protected RunCollectionModifier Task(bool deserializing) : base(deserializing) { }111 protected RunCollectionModifier Task(RunCollectionModifierTaskoriginal, Cloner cloner)97 protected RunCollectionModifierExecutable(bool deserializing) : base(deserializing) { } 98 protected RunCollectionModifierExecutable(RunCollectionModifierExecutable original, Cloner cloner) 112 99 : base(original, cloner) { 113 100 executionTime = original.executionTime; … … 121 108 } 122 109 public override IDeepCloneable Clone(Cloner cloner) { 123 return new RunCollectionModifier Task(this, cloner);110 return new RunCollectionModifierExecutable(this, cloner); 124 111 } 125 112 #endregion … … 134 121 executionStack.Push(runCollectionModifier); 135 122 } 136 137 executionState = ExecutionState.Prepared;138 123 } 139 124 … … 151 136 } 152 137 catch (AggregateException remaining) { 153 if (remaining.InnerExceptions.Count == 1) On TaskFailed(remaining.InnerExceptions[0]);154 else On TaskFailed(remaining);138 if (remaining.InnerExceptions.Count == 1) OnExceptionOccuted(remaining.InnerExceptions[0]); 139 else OnExceptionOccuted(remaining); 155 140 } 156 141 } … … 158 143 cancellationTokenSource = null; 159 144 if (stopPending) executionStack.Clear(); 160 if (executionStack.Count == 0) On TaskStopped();161 else On TaskPaused();145 if (executionStack.Count == 0) OnStopped(); 146 else OnPaused(); 162 147 }); 163 148 } … … 166 151 if (ExecutionState == ExecutionState.Paused) { 167 152 executionStack.Clear(); 168 On TaskStopped();153 OnStopped(); 169 154 } else { 170 155 stopPending = true; … … 179 164 protected virtual void RunModifiers(object state) { 180 165 CancellationToken ct = (CancellationToken)state; 181 On TaskStarted();166 OnStarted(); 182 167 183 168 IRunCollectionModifier next; … … 197 182 198 183 #region Events 199 public event EventHandler TaskStarted; 200 protected virtual void OnTaskStarted() { 184 public event EventHandler Prepared; 185 protected virtual void OnPrepared() { 186 ExecutionState = ExecutionState.Prepared; 187 EventHandler handler = Prepared; 188 if (handler != null) handler(this, EventArgs.Empty); 189 } 190 public event EventHandler Started; 191 protected virtual void OnStarted() { 201 192 executionState = ExecutionState.Started; 202 EventHandler handler = TaskStarted; 203 if (handler != null) handler(this, EventArgs.Empty); 204 } 205 206 public event EventHandler TaskStopped; 207 protected virtual void OnTaskStopped() { 193 EventHandler handler = Started; 194 if (handler != null) handler(this, EventArgs.Empty); 195 } 196 public event EventHandler Stopped; 197 protected virtual void OnStopped() { 208 198 executionState = ExecutionState.Stopped; 209 EventHandler handler = TaskStopped; 210 if (handler != null) handler(this, EventArgs.Empty); 211 } 212 213 public event EventHandler TaskPaused; 214 protected virtual void OnTaskPaused() { 199 EventHandler handler = Stopped; 200 if (handler != null) handler(this, EventArgs.Empty); 201 } 202 public event EventHandler Paused; 203 protected virtual void OnPaused() { 215 204 executionState = ExecutionState.Paused; 216 EventHandler handler = TaskPaused; 217 if (handler != null) handler(this, EventArgs.Empty); 218 } 219 220 public event EventHandler TaskFailed; 221 protected virtual void OnTaskFailed(Exception e) { 205 EventHandler handler = Paused; 206 if (handler != null) handler(this, EventArgs.Empty); 207 } 208 public event EventHandler<EventArgs<Exception>> ExceptionOccurred; 209 protected virtual void OnExceptionOccuted(Exception e) { 222 210 var eventArgs = new EventArgs<Exception>(e); 223 211 Log.LogException(e); 224 EventHandler handler = TaskFailed;212 EventHandler<EventArgs<Exception>> handler = ExceptionOccurred; 225 213 if (handler != null) handler(this, eventArgs); 226 214 } 227 228 215 public event EventHandler ExecutionTimeChanged; 229 216 protected virtual void OnExecutionTimeChanged() { … … 231 218 if (handler != null) handler(this, EventArgs.Empty); 232 219 } 233 234 220 public event EventHandler ExecutionStateChanged; 235 221 protected virtual void OnExecutionStateChanged() { … … 237 223 if (handler != null) handler(this, EventArgs.Empty); 238 224 } 239 240 public event EventHandler ComputeInParallelChanged; //not needed241 225 #endregion 242 226 }
Note: See TracChangeset
for help on using the changeset viewer.