Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/30/14 23:25:21 (10 years ago)
Author:
swagner
Message:

#2205: Continued working on programmable network items

  • added VariableStore to all programmable network items
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  
    3030  [Item("ProgrammableNetwork", "Abstract base class for programmable networks.")]
    3131  [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
    3337    #region Network Members
    3438    [Storable]
  • branches/OptimizationNetworks/HeuristicLab.Networks/3.3/Programmable/ProgrammableNetworkCode.cs

    r11577 r11602  
    44using System;
    55using 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
    615
    716namespace HeuristicLab.Networks.Programmable {
     
    1524    }
    1625
    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) {
    1832      // implement processing of messages here
    1933    }
  • branches/OptimizationNetworks/HeuristicLab.Networks/3.3/Programmable/ProgrammableNetworkItem.cs

    r11577 r11602  
    2424using HeuristicLab.Core.Networks;
    2525using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     26using HeuristicLab.Scripting;
    2627using Microsoft.CSharp;
    2728using System;
     
    124125    public virtual bool CanChangeCode {
    125126      get { return false; }
     127    }
     128    [Storable]
     129    private VariableStore variableStore;
     130    public VariableStore VariableStore {
     131      get { return variableStore; }
    126132    }
    127133
     
    161167      if (original.compileErrors != null)
    162168        compileErrors = new CompilerErrorCollection(original.compileErrors);
     169      variableStore = cloner.Clone(original.variableStore);
    163170      CompiledNetworkItem = cloner.Clone(original.compiledNetworkItem);
    164171    }
     
    168175      description = string.Empty;
    169176      code = CodeTemplate;
     177      variableStore = new VariableStore();
    170178      Compile();
    171179    }
     
    175183      description = string.Empty;
    176184      code = CodeTemplate;
     185      variableStore = new VariableStore();
    177186      Compile();
    178187    }
     
    182191      this.description = string.IsNullOrEmpty(description) ? string.Empty : description;
    183192      code = CodeTemplate;
     193      variableStore = new VariableStore();
    184194      Compile();
    185195    }
     
    227237    }
    228238    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;
    230244    }
    231245    #endregion
     
    347361
    348362      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      }
    349373
    350374      protected CompiledProgrammableNetworkItem(CompiledProgrammableNetworkItem original, Cloner cloner)
     
    359383      }
    360384
    361       public virtual void Initialize() { }
     385      public virtual void Initialize() {
     386        Variables.Clear();
     387      }
    362388
    363389      public override string ToString() {
  • branches/OptimizationNetworks/HeuristicLab.Networks/3.3/Programmable/ProgrammableNetworkItemCode.cs

    r11577 r11602  
    11using HeuristicLab.Common;
    22using 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
    312
    413namespace HeuristicLab.Networks.Programmable {
     
    1120      return new MyProgrammableNetworkItem(this, cloner);
    1221    }
     22
     23    public override void Initialize() {
     24      base.Initialize();
     25      // implement initialization here
     26    }
    1327  }
    1428}
  • branches/OptimizationNetworks/HeuristicLab.Networks/3.3/Programmable/ProgrammableNode.cs

    r11577 r11602  
    126126      }
    127127
    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) { }
    129132
    130133      #region Events
  • branches/OptimizationNetworks/HeuristicLab.Networks/3.3/Programmable/ProgrammableNodeCode.cs

    r11577 r11602  
    44using System;
    55using 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
    615
    716namespace HeuristicLab.Networks.Programmable {
     
    1524    }
    1625
    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) {
    1832      // implement processing of messages here
    1933    }
Note: See TracChangeset for help on using the changeset viewer.