- Timestamp:
- 11/30/14 23:25:21 (10 years ago)
- Location:
- branches/OptimizationNetworks/HeuristicLab.Networks/3.3/Programmable
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/OptimizationNetworks/HeuristicLab.Networks/3.3/Programmable/ProgrammableNetwork.cs
r11577 r11602 30 30 [Item("ProgrammableNetwork", "Abstract base class for programmable networks.")] 31 31 [StorableClass] 32 public abstract class ProgrammableNetwork : ProgrammableNode, IProgrammableNetwork { 32 public abstract class ProgrammableNetwork : ProgrammableNode, IProgrammableNetwork, IStorableContent { 33 #region IStorableContent Members 34 public string Filename { get; set; } 35 #endregion 36 33 37 #region Network Members 34 38 [Storable] -
branches/OptimizationNetworks/HeuristicLab.Networks/3.3/Programmable/ProgrammableNetworkCode.cs
r11577 r11602 4 4 using System; 5 5 using System.Threading; 6 7 #region How to use the variable store? 8 // use "Vars" to access variables in the variable store (e.g. Vars.x = 5) 9 // use "Vars[string]" to access variables using runtime strings (e.g. Vars["x"] = 5) 10 // use "Vars.Contains(string)" to check if a variable exists 11 // use "Vars.Clear()" to remove all variables 12 // use "foreach (KeyValuePair<string, object> v in Vars) { ... }" to iterate over all variables 13 // use "Variables" to work with IEnumerable<T> extension methods on the variable store 14 #endregion 6 15 7 16 namespace HeuristicLab.Networks.Programmable { … … 15 24 } 16 25 17 protected override void MessagePort_MessageReceived(object sender, EventArgs<IMessage, CancellationToken> e) { 26 public override void Initialize() { 27 base.Initialize(); 28 // implement initialization here 29 } 30 31 protected override void ProcessMessage(IMessage message, IMessagePort port, CancellationToken token) { 18 32 // implement processing of messages here 19 33 } -
branches/OptimizationNetworks/HeuristicLab.Networks/3.3/Programmable/ProgrammableNetworkItem.cs
r11577 r11602 24 24 using HeuristicLab.Core.Networks; 25 25 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 26 using HeuristicLab.Scripting; 26 27 using Microsoft.CSharp; 27 28 using System; … … 124 125 public virtual bool CanChangeCode { 125 126 get { return false; } 127 } 128 [Storable] 129 private VariableStore variableStore; 130 public VariableStore VariableStore { 131 get { return variableStore; } 126 132 } 127 133 … … 161 167 if (original.compileErrors != null) 162 168 compileErrors = new CompilerErrorCollection(original.compileErrors); 169 variableStore = cloner.Clone(original.variableStore); 163 170 CompiledNetworkItem = cloner.Clone(original.compiledNetworkItem); 164 171 } … … 168 175 description = string.Empty; 169 176 code = CodeTemplate; 177 variableStore = new VariableStore(); 170 178 Compile(); 171 179 } … … 175 183 description = string.Empty; 176 184 code = CodeTemplate; 185 variableStore = new VariableStore(); 177 186 Compile(); 178 187 } … … 182 191 this.description = string.IsNullOrEmpty(description) ? string.Empty : description; 183 192 code = CodeTemplate; 193 variableStore = new VariableStore(); 184 194 Compile(); 185 195 } … … 227 237 } 228 238 public virtual IEnumerable<Assembly> GetAssemblies() { 229 return AppDomain.CurrentDomain.GetAssemblies().Where(a => !a.IsDynamic && File.Exists(a.Location)); 239 var assemblies = AppDomain.CurrentDomain.GetAssemblies() 240 .Where(a => !a.IsDynamic && File.Exists(a.Location)) 241 .ToList(); 242 assemblies.Add(typeof(Microsoft.CSharp.RuntimeBinder.Binder).Assembly); // for dlr functionality 243 return assemblies; 230 244 } 231 245 #endregion … … 347 361 348 362 protected ProgrammableNetworkItem Context { get; private set; } 363 private Variables variables; 364 protected Variables Variables { 365 get { 366 if (variables == null) variables = new Variables(Context.variableStore); 367 return variables; 368 } 369 } 370 protected dynamic Vars { 371 get { return Variables; } 372 } 349 373 350 374 protected CompiledProgrammableNetworkItem(CompiledProgrammableNetworkItem original, Cloner cloner) … … 359 383 } 360 384 361 public virtual void Initialize() { } 385 public virtual void Initialize() { 386 Variables.Clear(); 387 } 362 388 363 389 public override string ToString() { -
branches/OptimizationNetworks/HeuristicLab.Networks/3.3/Programmable/ProgrammableNetworkItemCode.cs
r11577 r11602 1 1 using HeuristicLab.Common; 2 2 using HeuristicLab.Core; 3 4 #region How to use the variable store? 5 // use "Vars" to access variables in the variable store (e.g. Vars.x = 5) 6 // use "Vars[string]" to access variables using runtime strings (e.g. Vars["x"] = 5) 7 // use "Vars.Contains(string)" to check if a variable exists 8 // use "Vars.Clear()" to remove all variables 9 // use "foreach (KeyValuePair<string, object> v in Vars) { ... }" to iterate over all variables 10 // use "Variables" to work with IEnumerable<T> extension methods on the variable store 11 #endregion 3 12 4 13 namespace HeuristicLab.Networks.Programmable { … … 11 20 return new MyProgrammableNetworkItem(this, cloner); 12 21 } 22 23 public override void Initialize() { 24 base.Initialize(); 25 // implement initialization here 26 } 13 27 } 14 28 } -
branches/OptimizationNetworks/HeuristicLab.Networks/3.3/Programmable/ProgrammableNode.cs
r11577 r11602 126 126 } 127 127 128 protected virtual void MessagePort_MessageReceived(object sender, EventArgs<IMessage, CancellationToken> e) { } 128 private void MessagePort_MessageReceived(object sender, EventArgs<IMessage, CancellationToken> e) { 129 ProcessMessage(e.Value, (IMessagePort)sender, e.Value2); 130 } 131 protected virtual void ProcessMessage(IMessage message, IMessagePort port, CancellationToken token) { } 129 132 130 133 #region Events -
branches/OptimizationNetworks/HeuristicLab.Networks/3.3/Programmable/ProgrammableNodeCode.cs
r11577 r11602 4 4 using System; 5 5 using System.Threading; 6 7 #region How to use the variable store? 8 // use "Vars" to access variables in the variable store (e.g. Vars.x = 5) 9 // use "Vars[string]" to access variables using runtime strings (e.g. Vars["x"] = 5) 10 // use "Vars.Contains(string)" to check if a variable exists 11 // use "Vars.Clear()" to remove all variables 12 // use "foreach (KeyValuePair<string, object> v in Vars) { ... }" to iterate over all variables 13 // use "Variables" to work with IEnumerable<T> extension methods on the variable store 14 #endregion 6 15 7 16 namespace HeuristicLab.Networks.Programmable { … … 15 24 } 16 25 17 protected override void MessagePort_MessageReceived(object sender, EventArgs<IMessage, CancellationToken> e) { 26 public override void Initialize() { 27 base.Initialize(); 28 // implement initialization here 29 } 30 31 protected override void ProcessMessage(IMessage message, IMessagePort port, CancellationToken token) { 18 32 // implement processing of messages here 19 33 }
Note: See TracChangeset
for help on using the changeset viewer.