Changeset 9195
- Timestamp:
- 01/29/13 14:39:02 (12 years ago)
- Location:
- trunk/sources
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Core/3.3/Interfaces/ILookupParameter.cs
r7259 r9195 26 26 string ActualName { get; set; } 27 27 string TranslatedName { get; } 28 IExecutionContext ExecutionContext { get; set; } 28 29 event EventHandler ActualNameChanged; 29 30 } -
trunk/sources/HeuristicLab.Core/3.3/Interfaces/IParameter.cs
r7259 r9195 27 27 bool Hidden { get; set; } 28 28 IItem ActualValue { get; set; } 29 IExecutionContext ExecutionContext { get; set; }30 29 31 30 event EventHandler HiddenChanged; -
trunk/sources/HeuristicLab.DebugEngine.Views/3.3/OperationContentView.cs
r7966 r9195 61 61 private object GetParameterValue(IParameter param, IExecutionContext context, out string actualName) { 62 62 param = (IParameter)param.Clone(); 63 param.ExecutionContext = context; 63 ILookupParameter lookupParam = param as ILookupParameter; 64 if (lookupParam != null) { 65 actualName = lookupParam.ActualName; 66 lookupParam.ExecutionContext = context; 67 } else 68 actualName = null; 69 64 70 object value = null; 65 71 try { 66 72 value = param.ActualValue; 67 } catch (Exception x) { 73 } 74 catch (Exception x) { 68 75 value = x.Message; 69 76 } 70 ILookupParameter lookupParam = param as ILookupParameter;71 if (lookupParam != null)72 actualName = lookupParam.ActualName;73 else74 actualName = null;75 77 return value; 76 78 } -
trunk/sources/HeuristicLab.Operators/3.3/Operator.cs
r7259 r9195 22 22 using System; 23 23 using System.Drawing; 24 using System.Linq; 24 25 using System.Threading; 25 26 using HeuristicLab.Common; … … 119 120 ExecutionContext = context; 120 121 this.cancellationToken = cancellationToken; 121 foreach (I Parameter param in Parameters)122 foreach (ILookupParameter param in Parameters.OfType<ILookupParameter>()) 122 123 param.ExecutionContext = context; 123 124 IOperation next = Apply(); … … 126 127 } 127 128 finally { 128 foreach (I Parameter param in Parameters)129 foreach (ILookupParameter param in Parameters.OfType<ILookupParameter>()) 129 130 param.ExecutionContext = null; 130 131 ExecutionContext = null; -
trunk/sources/HeuristicLab.Parameters/3.3/LookupParameter.cs
r7259 r9195 21 21 22 22 using System; 23 using System.Threading; 23 24 using HeuristicLab.Common; 24 25 using HeuristicLab.Core; … … 31 32 [Item("LookupParameter", "A parameter whose value is retrieved from or written to a scope.")] 32 33 [StorableClass] 33 public class LookupParameter<T> : Parameter, I LookupParameter<T> where T : class, IItem {34 public class LookupParameter<T> : Parameter, IStatefulItem, ILookupParameter<T> where T : class, IItem { 34 35 [Storable] 35 36 private string actualName; … … 59 60 } 60 61 62 private Lazy<ThreadLocal<IItem>> cachedActualValues; 63 private IItem CachedActualValue { 64 get { return cachedActualValues.Value.Value; } 65 } 66 67 private Lazy<ThreadLocal<IExecutionContext>> executionContexts; 68 public IExecutionContext ExecutionContext { 69 get { return executionContexts.Value.Value; } 70 set { 71 if (value != executionContexts.Value.Value) { 72 executionContexts.Value.Value = value; 73 cachedActualValues.Value.Value = null; 74 } 75 } 76 } 77 61 78 [StorableConstructor] 62 protected LookupParameter(bool deserializing) : base(deserializing) { } 79 protected LookupParameter(bool deserializing) 80 : base(deserializing) { 81 cachedActualValues = new Lazy<ThreadLocal<IItem>>(() => { return new ThreadLocal<IItem>(); }, LazyThreadSafetyMode.ExecutionAndPublication); 82 executionContexts = new Lazy<ThreadLocal<IExecutionContext>>(() => { return new ThreadLocal<IExecutionContext>(); }, LazyThreadSafetyMode.ExecutionAndPublication); 83 } 63 84 protected LookupParameter(LookupParameter<T> original, Cloner cloner) 64 85 : base(original, cloner) { 65 86 actualName = original.actualName; 87 cachedActualValues = new Lazy<ThreadLocal<IItem>>(() => { return new ThreadLocal<IItem>(); }, LazyThreadSafetyMode.ExecutionAndPublication); 88 executionContexts = new Lazy<ThreadLocal<IExecutionContext>>(() => { return new ThreadLocal<IExecutionContext>(); }, LazyThreadSafetyMode.ExecutionAndPublication); 66 89 } 67 90 public LookupParameter() … … 69 92 this.actualName = Name; 70 93 this.Hidden = true; 94 cachedActualValues = new Lazy<ThreadLocal<IItem>>(() => { return new ThreadLocal<IItem>(); }, LazyThreadSafetyMode.ExecutionAndPublication); 95 executionContexts = new Lazy<ThreadLocal<IExecutionContext>>(() => { return new ThreadLocal<IExecutionContext>(); }, LazyThreadSafetyMode.ExecutionAndPublication); 71 96 } 72 97 public LookupParameter(string name) … … 74 99 this.actualName = Name; 75 100 this.Hidden = true; 101 cachedActualValues = new Lazy<ThreadLocal<IItem>>(() => { return new ThreadLocal<IItem>(); }, LazyThreadSafetyMode.ExecutionAndPublication); 102 executionContexts = new Lazy<ThreadLocal<IExecutionContext>>(() => { return new ThreadLocal<IExecutionContext>(); }, LazyThreadSafetyMode.ExecutionAndPublication); 76 103 } 77 104 public LookupParameter(string name, string description) … … 79 106 this.actualName = Name; 80 107 this.Hidden = true; 108 cachedActualValues = new Lazy<ThreadLocal<IItem>>(() => { return new ThreadLocal<IItem>(); }, LazyThreadSafetyMode.ExecutionAndPublication); 109 executionContexts = new Lazy<ThreadLocal<IExecutionContext>>(() => { return new ThreadLocal<IExecutionContext>(); }, LazyThreadSafetyMode.ExecutionAndPublication); 81 110 } 82 111 public LookupParameter(string name, string description, string actualName) … … 84 113 this.actualName = string.IsNullOrWhiteSpace(actualName) ? Name : actualName; 85 114 this.Hidden = true; 115 cachedActualValues = new Lazy<ThreadLocal<IItem>>(() => { return new ThreadLocal<IItem>(); }, LazyThreadSafetyMode.ExecutionAndPublication); 116 executionContexts = new Lazy<ThreadLocal<IExecutionContext>>(() => { return new ThreadLocal<IExecutionContext>(); }, LazyThreadSafetyMode.ExecutionAndPublication); 86 117 } 87 118 … … 132 163 } 133 164 protected override IItem GetActualValue() { 165 if (CachedActualValue != null) return CachedActualValue; 134 166 string name; 135 167 // try to get value from context stack … … 146 178 typeof(T).GetPrettyName()) 147 179 ); 180 cachedActualValues.Value.Value = var.Value; 148 181 return var.Value; 149 182 } … … 156 189 typeof(T).GetPrettyName()) 157 190 ); 191 cachedActualValues.Value.Value = value; 192 158 193 // try to set value in context stack 159 194 string name; … … 175 210 } 176 211 212 public virtual void InitializeState() { 213 } 214 public virtual void ClearState() { 215 if (cachedActualValues.IsValueCreated) { 216 cachedActualValues.Value.Dispose(); 217 cachedActualValues = new Lazy<ThreadLocal<IItem>>(() => { return new ThreadLocal<IItem>(); }, LazyThreadSafetyMode.ExecutionAndPublication); 218 } 219 if (executionContexts.IsValueCreated) { 220 executionContexts.Value.Dispose(); 221 executionContexts = new Lazy<ThreadLocal<IExecutionContext>>(() => { return new ThreadLocal<IExecutionContext>(); }, LazyThreadSafetyMode.ExecutionAndPublication); 222 } 223 } 224 177 225 public event EventHandler ActualNameChanged; 178 226 protected virtual void OnActualNameChanged() { -
trunk/sources/HeuristicLab.Parameters/3.3/Parameter.cs
r7259 r9195 22 22 using System; 23 23 using System.Drawing; 24 using System.Threading;25 24 using HeuristicLab.Common; 26 25 using HeuristicLab.Core; … … 33 32 [Item("Parameter", "A base class for parameters.")] 34 33 [StorableClass] 35 public abstract class Parameter : NamedItem, IParameter , IStatefulItem{34 public abstract class Parameter : NamedItem, IParameter { 36 35 public override Image ItemImage { 37 36 get { … … 67 66 } 68 67 69 private Lazy<ThreadLocal<IItem>> cachedActualValues;70 68 public IItem ActualValue { 71 get { 72 if (cachedActualValues.Value.Value == null) cachedActualValues.Value.Value = GetActualValue(); 73 return cachedActualValues.Value.Value; 74 } 75 set { 76 cachedActualValues.Value.Value = value; 77 SetActualValue(value); 78 } 79 } 80 private Lazy<ThreadLocal<IExecutionContext>> executionContexts; 81 public IExecutionContext ExecutionContext { 82 get { return executionContexts.Value.Value; } 83 set { 84 if (value != executionContexts.Value.Value) { 85 executionContexts.Value.Value = value; 86 cachedActualValues.Value.Value = null; 87 } 88 } 69 get { return GetActualValue(); } 70 set { SetActualValue(value); } 89 71 } 90 72 … … 92 74 protected Parameter(bool deserializing) 93 75 : base(deserializing) { 94 cachedActualValues = new Lazy<ThreadLocal<IItem>>(() => { return new ThreadLocal<IItem>(); }, LazyThreadSafetyMode.ExecutionAndPublication);95 executionContexts = new Lazy<ThreadLocal<IExecutionContext>>(() => { return new ThreadLocal<IExecutionContext>(); }, LazyThreadSafetyMode.ExecutionAndPublication);96 76 } 97 77 protected Parameter(Parameter original, Cloner cloner) … … 99 79 dataType = original.dataType; 100 80 hidden = original.hidden; 101 cachedActualValues = new Lazy<ThreadLocal<IItem>>(() => { return new ThreadLocal<IItem>(); }, LazyThreadSafetyMode.ExecutionAndPublication);102 executionContexts = new Lazy<ThreadLocal<IExecutionContext>>(() => { return new ThreadLocal<IExecutionContext>(); }, LazyThreadSafetyMode.ExecutionAndPublication);103 81 } 104 82 protected Parameter() … … 106 84 dataType = typeof(IItem); 107 85 hidden = false; 108 cachedActualValues = new Lazy<ThreadLocal<IItem>>(() => { return new ThreadLocal<IItem>(); }, LazyThreadSafetyMode.ExecutionAndPublication);109 executionContexts = new Lazy<ThreadLocal<IExecutionContext>>(() => { return new ThreadLocal<IExecutionContext>(); }, LazyThreadSafetyMode.ExecutionAndPublication);110 86 } 111 87 protected Parameter(string name, Type dataType) … … 114 90 this.dataType = dataType; 115 91 hidden = false; 116 cachedActualValues = new Lazy<ThreadLocal<IItem>>(() => { return new ThreadLocal<IItem>(); }, LazyThreadSafetyMode.ExecutionAndPublication);117 executionContexts = new Lazy<ThreadLocal<IExecutionContext>>(() => { return new ThreadLocal<IExecutionContext>(); }, LazyThreadSafetyMode.ExecutionAndPublication);118 92 } 119 93 protected Parameter(string name, string description, Type dataType) … … 122 96 this.dataType = dataType; 123 97 hidden = false; 124 cachedActualValues = new Lazy<ThreadLocal<IItem>>(() => { return new ThreadLocal<IItem>(); }, LazyThreadSafetyMode.ExecutionAndPublication);125 executionContexts = new Lazy<ThreadLocal<IExecutionContext>>(() => { return new ThreadLocal<IExecutionContext>(); }, LazyThreadSafetyMode.ExecutionAndPublication);126 }127 128 public virtual void InitializeState() { }129 public virtual void ClearState() {130 cachedActualValues = new Lazy<ThreadLocal<IItem>>(() => { return new ThreadLocal<IItem>(); }, LazyThreadSafetyMode.ExecutionAndPublication);131 executionContexts = new Lazy<ThreadLocal<IExecutionContext>>(() => { return new ThreadLocal<IExecutionContext>(); }, LazyThreadSafetyMode.ExecutionAndPublication);132 98 } 133 99 -
trunk/sources/HeuristicLab.Parameters/3.3/ScopeParameter.cs
r7259 r9195 21 21 22 22 using System; 23 using System.Threading; 23 24 using HeuristicLab.Common; 24 25 using HeuristicLab.Core; … … 31 32 [Item("ScopeParameter", "A parameter which represents the current scope.")] 32 33 [StorableClass] 33 public class ScopeParameter : Parameter{34 public class ScopeParameter : LookupParameter<IScope> { 34 35 public new IScope ActualValue { 35 36 get { return ExecutionContext.Scope; } 36 37 } 38 37 39 38 40 [StorableConstructor] … … 40 42 protected ScopeParameter(ScopeParameter original, Cloner cloner) : base(original, cloner) { } 41 43 public ScopeParameter() 42 : base("Anonymous" , typeof(IScope)) {44 : base("Anonymous") { 43 45 this.Hidden = true; 44 46 } 45 47 public ScopeParameter(string name) 46 : base(name , typeof(IScope)) {48 : base(name) { 47 49 this.Hidden = true; 48 50 } 49 51 public ScopeParameter(string name, string description) 50 : base(name, description , typeof(IScope)) {52 : base(name, description) { 51 53 this.Hidden = true; 52 54 }
Note: See TracChangeset
for help on using the changeset viewer.