Changeset 5193 for trunk/sources/HeuristicLab.Operators
- Timestamp:
- 01/03/11 00:46:55 (14 years ago)
- Location:
- trunk/sources
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources
- Property svn:mergeinfo changed
/branches/ParallelEngine (added) merged: 5175-5178,5183,5185,5187-5188
- Property svn:mergeinfo changed
-
trunk/sources/HeuristicLab.Operators/3.3/Operator.cs
r4722 r5193 22 22 using System; 23 23 using System.Drawing; 24 using System.Threading; 24 25 using HeuristicLab.Common; 25 26 using HeuristicLab.Core; … … 28 29 namespace HeuristicLab.Operators { 29 30 /// <summary> 30 /// The base class for alloperators.31 /// Base class for operators. 31 32 /// </summary> 32 33 [Item("Operator", "Base class for operators.")] … … 43 44 } 44 45 45 [Storable] 46 private IExecutionContext executionContext; 46 private Lazy<ThreadLocal<IExecutionContext>> executionContexts; 47 47 protected IExecutionContext ExecutionContext { 48 get { return executionContext ; }48 get { return executionContexts.Value.Value; } 49 49 private set { 50 if (value != executionContext) { 51 executionContext = value; 52 OnExecutionContextChanged(); 50 if (value != executionContexts.Value.Value) { 51 executionContexts.Value.Value = value; 53 52 } 54 53 } 55 54 } 56 57 /// <summary> 58 /// Flag whether the current instance has been canceled. 59 /// </summary> 60 private bool canceled; 61 /// <inheritdoc/> 62 protected bool Canceled { 63 get { return canceled; } 64 private set { 65 if (value != canceled) { 66 canceled = value; 67 OnCanceledChanged(); 68 } 69 } 55 private CancellationToken cancellationToken; 56 protected CancellationToken CancellationToken { 57 get { return cancellationToken; } 70 58 } 71 59 72 60 [Storable] 73 61 private bool breakpoint; 74 /// <inheritdoc/>75 /// <remarks>Calls <see cref="OnBreakpointChanged"/> in the setter.</remarks>76 62 public bool Breakpoint { 77 63 get { return breakpoint; } … … 86 72 87 73 [StorableConstructor] 88 protected Operator(bool deserializing) : base(deserializing) { } 74 protected Operator(bool deserializing) 75 : base(deserializing) { 76 executionContexts = new Lazy<ThreadLocal<IExecutionContext>>(() => { return new ThreadLocal<IExecutionContext>(); }, LazyThreadSafetyMode.ExecutionAndPublication); 77 } 89 78 protected Operator(Operator original, Cloner cloner) 90 79 : base(original, cloner) { 91 this.canceled = original.canceled;80 executionContexts = new Lazy<ThreadLocal<IExecutionContext>>(() => { return new ThreadLocal<IExecutionContext>(); }, LazyThreadSafetyMode.ExecutionAndPublication); 92 81 this.breakpoint = original.breakpoint; 93 this.executionContext = cloner.Clone<IExecutionContext>(original.executionContext);94 82 } 95 /// <summary>96 /// Initializes a new instance of <see cref="OperatorBase"/> setting the breakpoint flag and97 /// the canceled flag to <c>false</c> and the name of the operator to the type name.98 /// </summary>99 83 protected Operator() 100 84 : base() { 101 canceled = false;85 executionContexts = new Lazy<ThreadLocal<IExecutionContext>>(() => { return new ThreadLocal<IExecutionContext>(); }, LazyThreadSafetyMode.ExecutionAndPublication); 102 86 breakpoint = false; 103 87 } 104 88 protected Operator(string name) 105 89 : base(name) { 106 canceled = false;90 executionContexts = new Lazy<ThreadLocal<IExecutionContext>>(() => { return new ThreadLocal<IExecutionContext>(); }, LazyThreadSafetyMode.ExecutionAndPublication); 107 91 breakpoint = false; 108 92 } 109 93 protected Operator(string name, ParameterCollection parameters) 110 94 : base(name, parameters) { 111 canceled = false;95 executionContexts = new Lazy<ThreadLocal<IExecutionContext>>(() => { return new ThreadLocal<IExecutionContext>(); }, LazyThreadSafetyMode.ExecutionAndPublication); 112 96 breakpoint = false; 113 97 } 114 98 protected Operator(string name, string description) 115 99 : base(name, description) { 116 canceled = false;100 executionContexts = new Lazy<ThreadLocal<IExecutionContext>>(() => { return new ThreadLocal<IExecutionContext>(); }, LazyThreadSafetyMode.ExecutionAndPublication); 117 101 breakpoint = false; 118 102 } 119 103 protected Operator(string name, string description, ParameterCollection parameters) 120 104 : base(name, description, parameters) { 121 canceled = false;105 executionContexts = new Lazy<ThreadLocal<IExecutionContext>>(() => { return new ThreadLocal<IExecutionContext>(); }, LazyThreadSafetyMode.ExecutionAndPublication); 122 106 breakpoint = false; 123 107 } 124 108 125 /// <inheritdoc/> 126 public virtual IOperation Execute(IExecutionContext context) { 109 public virtual IOperation Execute(IExecutionContext context, CancellationToken cancellationToken) { 127 110 try { 128 Canceled = false;129 111 ExecutionContext = context; 112 this.cancellationToken = cancellationToken; 130 113 foreach (IParameter param in Parameters) 131 114 param.ExecutionContext = context; … … 140 123 } 141 124 } 142 /// <inheritdoc/>143 /// <remarks>Sets property <see cref="Canceled"/> to <c>true</c>.</remarks>144 public void Abort() {145 Canceled = true;146 }147 /// <summary>148 /// Performs the current operator on the specified <paramref name="scope"/>.149 /// </summary>150 /// <param name="scope">The scope where to execute the operator</param>151 /// <returns><c>null</c>.</returns>152 125 public abstract IOperation Apply(); 153 126 154 protected virtual void OnExecutionContextChanged() { }155 protected virtual void OnCanceledChanged() { }156 /// <inheritdoc/>157 127 public event EventHandler BreakpointChanged; 158 /// <summary>159 /// Fires a new <c>BreakpointChanged</c> event.160 /// </summary>161 128 protected virtual void OnBreakpointChanged() { 162 129 if (BreakpointChanged != null) { … … 164 131 } 165 132 } 166 /// <inheritdoc/>167 133 public event EventHandler Executed; 168 /// <summary>169 /// Fires a new <c>Executed</c> event.170 /// </summary>171 134 protected virtual void OnExecuted() { 172 135 if (Executed != null) {
Note: See TracChangeset
for help on using the changeset viewer.