Free cookie consent management tool by TermsFeed Policy Generator

Changeset 11602


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

#2205: Continued working on programmable network items

  • added VariableStore to all programmable network items
Location:
branches/OptimizationNetworks
Files:
9 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    }
  • branches/OptimizationNetworks/HeuristicLab.Scripting.Views/3.3/ProgrammableItemView.Designer.cs

    r11577 r11602  
    4646    private void InitializeComponent() {
    4747      this.components = new System.ComponentModel.Container();
    48       this.splitContainer = new System.Windows.Forms.SplitContainer();
     48      this.splitContainer2 = new System.Windows.Forms.SplitContainer();
    4949      this.codeGroupBox = new System.Windows.Forms.GroupBox();
    5050      this.codeEditor = new HeuristicLab.CodeEditor.CodeEditor();
     
    6161      this.compilationLabel = new System.Windows.Forms.Label();
    6262      this.toolTip = new System.Windows.Forms.ToolTip(this.components);
    63       ((System.ComponentModel.ISupportInitialize)(this.splitContainer)).BeginInit();
    64       this.splitContainer.Panel1.SuspendLayout();
    65       this.splitContainer.Panel2.SuspendLayout();
    66       this.splitContainer.SuspendLayout();
     63      this.splitContainer1 = new System.Windows.Forms.SplitContainer();
     64      this.variableStoreView = new HeuristicLab.Scripting.Views.VariableStoreView();
     65      ((System.ComponentModel.ISupportInitialize)(this.splitContainer2)).BeginInit();
     66      this.splitContainer2.Panel1.SuspendLayout();
     67      this.splitContainer2.Panel2.SuspendLayout();
     68      this.splitContainer2.SuspendLayout();
    6769      this.codeGroupBox.SuspendLayout();
    6870      this.errorsGroupBox.SuspendLayout();
     71      ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit();
     72      this.splitContainer1.Panel1.SuspendLayout();
     73      this.splitContainer1.Panel2.SuspendLayout();
     74      this.splitContainer1.SuspendLayout();
    6975      this.SuspendLayout();
    7076      //
    71       // splitContainer
    72       //
    73       this.splitContainer.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    74             | System.Windows.Forms.AnchorStyles.Left)
    75             | System.Windows.Forms.AnchorStyles.Right)));
    76       this.splitContainer.Location = new System.Drawing.Point(0, 33);
    77       this.splitContainer.Name = "splitContainer";
    78       this.splitContainer.Orientation = System.Windows.Forms.Orientation.Horizontal;
    79       //
    80       // splitContainer.Panel1
    81       //
    82       this.splitContainer.Panel1.Controls.Add(this.codeGroupBox);
    83       //
    84       // splitContainer.Panel2
    85       //
    86       this.splitContainer.Panel2.Controls.Add(this.errorsGroupBox);
    87       this.splitContainer.Size = new System.Drawing.Size(486, 454);
    88       this.splitContainer.SplitterDistance = 382;
    89       this.splitContainer.TabIndex = 3;
     77      // splitContainer2
     78      //
     79      this.splitContainer2.Dock = System.Windows.Forms.DockStyle.Fill;
     80      this.splitContainer2.Location = new System.Drawing.Point(0, 0);
     81      this.splitContainer2.Name = "splitContainer2";
     82      this.splitContainer2.Orientation = System.Windows.Forms.Orientation.Horizontal;
     83      //
     84      // splitContainer2.Panel1
     85      //
     86      this.splitContainer2.Panel1.Controls.Add(this.codeGroupBox);
     87      //
     88      // splitContainer2.Panel2
     89      //
     90      this.splitContainer2.Panel2.Controls.Add(this.errorsGroupBox);
     91      this.splitContainer2.Size = new System.Drawing.Size(357, 454);
     92      this.splitContainer2.SplitterDistance = 382;
     93      this.splitContainer2.TabIndex = 3;
    9094      //
    9195      // codeGroupBox
     
    9599      this.codeGroupBox.Location = new System.Drawing.Point(0, 0);
    96100      this.codeGroupBox.Name = "codeGroupBox";
    97       this.codeGroupBox.Size = new System.Drawing.Size(486, 382);
     101      this.codeGroupBox.Size = new System.Drawing.Size(357, 382);
    98102      this.codeGroupBox.TabIndex = 0;
    99103      this.codeGroupBox.TabStop = false;
     
    108112      this.codeEditor.Name = "codeEditor";
    109113      this.codeEditor.Prefix = "";
    110       this.codeEditor.Size = new System.Drawing.Size(474, 357);
     114      this.codeEditor.ReadOnly = false;
     115      this.codeEditor.Size = new System.Drawing.Size(345, 357);
    111116      this.codeEditor.Suffix = "";
    112117      this.codeEditor.TabIndex = 0;
     
    120125      this.errorsGroupBox.Location = new System.Drawing.Point(0, 0);
    121126      this.errorsGroupBox.Name = "errorsGroupBox";
    122       this.errorsGroupBox.Size = new System.Drawing.Size(486, 68);
     127      this.errorsGroupBox.Size = new System.Drawing.Size(357, 68);
    123128      this.errorsGroupBox.TabIndex = 0;
    124129      this.errorsGroupBox.TabStop = false;
     
    142147      this.errorsListView.Location = new System.Drawing.Point(6, 19);
    143148      this.errorsListView.Name = "errorsListView";
    144       this.errorsListView.Size = new System.Drawing.Size(474, 43);
     149      this.errorsListView.Size = new System.Drawing.Size(345, 43);
    145150      this.errorsListView.SmallImageList = this.imageList;
    146151      this.errorsListView.TabIndex = 0;
     
    200205      this.compilationLabel.Text = "Not compiled";
    201206      //
     207      // splitContainer1
     208      //
     209      this.splitContainer1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
     210            | System.Windows.Forms.AnchorStyles.Left)
     211            | System.Windows.Forms.AnchorStyles.Right)));
     212      this.splitContainer1.Location = new System.Drawing.Point(0, 33);
     213      this.splitContainer1.Name = "splitContainer1";
     214      //
     215      // splitContainer1.Panel1
     216      //
     217      this.splitContainer1.Panel1.Controls.Add(this.splitContainer2);
     218      //
     219      // splitContainer1.Panel2
     220      //
     221      this.splitContainer1.Panel2.Controls.Add(this.variableStoreView);
     222      this.splitContainer1.Size = new System.Drawing.Size(486, 454);
     223      this.splitContainer1.SplitterDistance = 357;
     224      this.splitContainer1.TabIndex = 4;
     225      //
     226      // variableStoreView
     227      //
     228      this.variableStoreView.Caption = "ItemCollection View";
     229      this.variableStoreView.Content = null;
     230      this.variableStoreView.Dock = System.Windows.Forms.DockStyle.Fill;
     231      this.variableStoreView.Location = new System.Drawing.Point(0, 0);
     232      this.variableStoreView.Name = "variableStoreView";
     233      this.variableStoreView.ReadOnly = false;
     234      this.variableStoreView.Size = new System.Drawing.Size(125, 454);
     235      this.variableStoreView.TabIndex = 0;
     236      //
    202237      // ProgrammableItemView
    203238      //
     239      this.Controls.Add(this.splitContainer1);
    204240      this.Controls.Add(this.compilationLabel);
    205241      this.Controls.Add(this.compileButton);
    206       this.Controls.Add(this.splitContainer);
    207242      this.Name = "ProgrammableItemView";
    208243      this.Size = new System.Drawing.Size(486, 487);
    209       this.splitContainer.Panel1.ResumeLayout(false);
    210       this.splitContainer.Panel2.ResumeLayout(false);
    211       ((System.ComponentModel.ISupportInitialize)(this.splitContainer)).EndInit();
    212       this.splitContainer.ResumeLayout(false);
     244      this.splitContainer2.Panel1.ResumeLayout(false);
     245      this.splitContainer2.Panel2.ResumeLayout(false);
     246      ((System.ComponentModel.ISupportInitialize)(this.splitContainer2)).EndInit();
     247      this.splitContainer2.ResumeLayout(false);
    213248      this.codeGroupBox.ResumeLayout(false);
    214249      this.errorsGroupBox.ResumeLayout(false);
     250      this.splitContainer1.Panel1.ResumeLayout(false);
     251      this.splitContainer1.Panel2.ResumeLayout(false);
     252      ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).EndInit();
     253      this.splitContainer1.ResumeLayout(false);
    215254      this.ResumeLayout(false);
    216255      this.PerformLayout();
     
    220259    #endregion
    221260
    222     protected System.Windows.Forms.SplitContainer splitContainer;
     261    protected System.Windows.Forms.SplitContainer splitContainer2;
    223262    protected System.Windows.Forms.GroupBox errorsGroupBox;
    224263    protected System.Windows.Forms.Button compileButton;
     
    235274    protected System.Windows.Forms.GroupBox codeGroupBox;
    236275    protected System.Windows.Forms.ToolTip toolTip;
     276    protected System.Windows.Forms.SplitContainer splitContainer1;
     277    protected VariableStoreView variableStoreView;
    237278
    238279  }
  • branches/OptimizationNetworks/HeuristicLab.Scripting.Views/3.3/ProgrammableItemView.cs

    r11577 r11602  
    6060      if (Content == null) {
    6161        codeEditor.UserCode = string.Empty;
     62        variableStoreView.Content = null;
    6263      } else {
    6364        codeEditor.UserCode = Content.Code;
    6465        foreach (var asm in Content.GetAssemblies())
    6566          codeEditor.AddAssembly(asm);
     67        variableStoreView.Content = Content.VariableStore;
    6668      }
    6769      ShowCompilationResults();
     
    7476      codeEditor.Enabled = Content != null && !Locked;
    7577      codeEditor.ReadOnly = ReadOnly || Locked || ((Content != null) && !Content.CanChangeCode);
     78      variableStoreView.ReadOnly = (Content != null) && !Content.CanChangeCode;
    7679    }
    7780
  • branches/OptimizationNetworks/HeuristicLab.Scripting/3.3/IProgrammableItem.cs

    r11577 r11602  
    3131    CompilerErrorCollection CompileErrors { get; }
    3232    bool CanChangeCode { get; }
     33    VariableStore VariableStore { get; }
    3334
    3435    void Compile();
Note: See TracChangeset for help on using the changeset viewer.