Changeset 5183 for branches/ParallelEngine/HeuristicLab.Operators
- Timestamp:
- 12/30/10 02:13:02 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ParallelEngine/HeuristicLab.Operators/3.3/Operator.cs
r5178 r5183 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 55 57 /// <summary>58 /// Flag whether the current instance has been canceled.59 /// </summary>60 56 private bool canceled; 61 /// <inheritdoc/>62 57 protected bool Canceled { 63 58 get { return canceled; } … … 72 67 [Storable] 73 68 private bool breakpoint; 74 /// <inheritdoc/>75 /// <remarks>Calls <see cref="OnBreakpointChanged"/> in the setter.</remarks>76 69 public bool Breakpoint { 77 70 get { return breakpoint; } … … 86 79 87 80 [StorableConstructor] 88 protected Operator(bool deserializing) : base(deserializing) { } 81 protected Operator(bool deserializing) 82 : base(deserializing) { 83 executionContexts = new Lazy<ThreadLocal<IExecutionContext>>(() => { return new ThreadLocal<IExecutionContext>(); }, LazyThreadSafetyMode.ExecutionAndPublication); 84 canceled = false; 85 } 89 86 protected Operator(Operator original, Cloner cloner) 90 87 : base(original, cloner) { 88 executionContexts = new Lazy<ThreadLocal<IExecutionContext>>(() => { return new ThreadLocal<IExecutionContext>(); }, LazyThreadSafetyMode.ExecutionAndPublication); 91 89 this.canceled = original.canceled; 92 90 this.breakpoint = original.breakpoint; 93 this.executionContext = cloner.Clone<IExecutionContext>(original.executionContext);94 91 } 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 92 protected Operator() 100 93 : base() { 94 executionContexts = new Lazy<ThreadLocal<IExecutionContext>>(() => { return new ThreadLocal<IExecutionContext>(); }, LazyThreadSafetyMode.ExecutionAndPublication); 101 95 canceled = false; 102 96 breakpoint = false; … … 104 98 protected Operator(string name) 105 99 : base(name) { 100 executionContexts = new Lazy<ThreadLocal<IExecutionContext>>(() => { return new ThreadLocal<IExecutionContext>(); }, LazyThreadSafetyMode.ExecutionAndPublication); 106 101 canceled = false; 107 102 breakpoint = false; … … 109 104 protected Operator(string name, ParameterCollection parameters) 110 105 : base(name, parameters) { 106 executionContexts = new Lazy<ThreadLocal<IExecutionContext>>(() => { return new ThreadLocal<IExecutionContext>(); }, LazyThreadSafetyMode.ExecutionAndPublication); 111 107 canceled = false; 112 108 breakpoint = false; … … 114 110 protected Operator(string name, string description) 115 111 : base(name, description) { 112 executionContexts = new Lazy<ThreadLocal<IExecutionContext>>(() => { return new ThreadLocal<IExecutionContext>(); }, LazyThreadSafetyMode.ExecutionAndPublication); 116 113 canceled = false; 117 114 breakpoint = false; … … 119 116 protected Operator(string name, string description, ParameterCollection parameters) 120 117 : base(name, description, parameters) { 118 executionContexts = new Lazy<ThreadLocal<IExecutionContext>>(() => { return new ThreadLocal<IExecutionContext>(); }, LazyThreadSafetyMode.ExecutionAndPublication); 121 119 canceled = false; 122 120 breakpoint = false; 123 121 } 124 122 125 /// <inheritdoc/>126 123 public virtual IOperation Execute(IExecutionContext context) { 127 124 try { … … 140 137 } 141 138 } 142 /// <inheritdoc/>143 /// <remarks>Sets property <see cref="Canceled"/> to <c>true</c>.</remarks>144 139 public void Abort() { 145 140 Canceled = true; 146 141 } 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 142 public abstract IOperation Apply(); 153 143 154 protected virtual void OnExecutionContextChanged() { }155 144 protected virtual void OnCanceledChanged() { } 156 /// <inheritdoc/>157 145 public event EventHandler BreakpointChanged; 158 /// <summary>159 /// Fires a new <c>BreakpointChanged</c> event.160 /// </summary>161 146 protected virtual void OnBreakpointChanged() { 162 147 if (BreakpointChanged != null) { … … 164 149 } 165 150 } 166 /// <inheritdoc/>167 151 public event EventHandler Executed; 168 /// <summary>169 /// Fires a new <c>Executed</c> event.170 /// </summary>171 152 protected virtual void OnExecuted() { 172 153 if (Executed != null) {
Note: See TracChangeset
for help on using the changeset viewer.