Changeset 11602
- Timestamp:
- 11/30/14 23:25:21 (10 years ago)
- Location:
- branches/OptimizationNetworks
- Files:
-
- 9 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 } -
branches/OptimizationNetworks/HeuristicLab.Scripting.Views/3.3/ProgrammableItemView.Designer.cs
r11577 r11602 46 46 private void InitializeComponent() { 47 47 this.components = new System.ComponentModel.Container(); 48 this.splitContainer = new System.Windows.Forms.SplitContainer();48 this.splitContainer2 = new System.Windows.Forms.SplitContainer(); 49 49 this.codeGroupBox = new System.Windows.Forms.GroupBox(); 50 50 this.codeEditor = new HeuristicLab.CodeEditor.CodeEditor(); … … 61 61 this.compilationLabel = new System.Windows.Forms.Label(); 62 62 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(); 67 69 this.codeGroupBox.SuspendLayout(); 68 70 this.errorsGroupBox.SuspendLayout(); 71 ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit(); 72 this.splitContainer1.Panel1.SuspendLayout(); 73 this.splitContainer1.Panel2.SuspendLayout(); 74 this.splitContainer1.SuspendLayout(); 69 75 this.SuspendLayout(); 70 76 // 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; 90 94 // 91 95 // codeGroupBox … … 95 99 this.codeGroupBox.Location = new System.Drawing.Point(0, 0); 96 100 this.codeGroupBox.Name = "codeGroupBox"; 97 this.codeGroupBox.Size = new System.Drawing.Size( 486, 382);101 this.codeGroupBox.Size = new System.Drawing.Size(357, 382); 98 102 this.codeGroupBox.TabIndex = 0; 99 103 this.codeGroupBox.TabStop = false; … … 108 112 this.codeEditor.Name = "codeEditor"; 109 113 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); 111 116 this.codeEditor.Suffix = ""; 112 117 this.codeEditor.TabIndex = 0; … … 120 125 this.errorsGroupBox.Location = new System.Drawing.Point(0, 0); 121 126 this.errorsGroupBox.Name = "errorsGroupBox"; 122 this.errorsGroupBox.Size = new System.Drawing.Size( 486, 68);127 this.errorsGroupBox.Size = new System.Drawing.Size(357, 68); 123 128 this.errorsGroupBox.TabIndex = 0; 124 129 this.errorsGroupBox.TabStop = false; … … 142 147 this.errorsListView.Location = new System.Drawing.Point(6, 19); 143 148 this.errorsListView.Name = "errorsListView"; 144 this.errorsListView.Size = new System.Drawing.Size( 474, 43);149 this.errorsListView.Size = new System.Drawing.Size(345, 43); 145 150 this.errorsListView.SmallImageList = this.imageList; 146 151 this.errorsListView.TabIndex = 0; … … 200 205 this.compilationLabel.Text = "Not compiled"; 201 206 // 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 // 202 237 // ProgrammableItemView 203 238 // 239 this.Controls.Add(this.splitContainer1); 204 240 this.Controls.Add(this.compilationLabel); 205 241 this.Controls.Add(this.compileButton); 206 this.Controls.Add(this.splitContainer);207 242 this.Name = "ProgrammableItemView"; 208 243 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); 213 248 this.codeGroupBox.ResumeLayout(false); 214 249 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); 215 254 this.ResumeLayout(false); 216 255 this.PerformLayout(); … … 220 259 #endregion 221 260 222 protected System.Windows.Forms.SplitContainer splitContainer ;261 protected System.Windows.Forms.SplitContainer splitContainer2; 223 262 protected System.Windows.Forms.GroupBox errorsGroupBox; 224 263 protected System.Windows.Forms.Button compileButton; … … 235 274 protected System.Windows.Forms.GroupBox codeGroupBox; 236 275 protected System.Windows.Forms.ToolTip toolTip; 276 protected System.Windows.Forms.SplitContainer splitContainer1; 277 protected VariableStoreView variableStoreView; 237 278 238 279 } -
branches/OptimizationNetworks/HeuristicLab.Scripting.Views/3.3/ProgrammableItemView.cs
r11577 r11602 60 60 if (Content == null) { 61 61 codeEditor.UserCode = string.Empty; 62 variableStoreView.Content = null; 62 63 } else { 63 64 codeEditor.UserCode = Content.Code; 64 65 foreach (var asm in Content.GetAssemblies()) 65 66 codeEditor.AddAssembly(asm); 67 variableStoreView.Content = Content.VariableStore; 66 68 } 67 69 ShowCompilationResults(); … … 74 76 codeEditor.Enabled = Content != null && !Locked; 75 77 codeEditor.ReadOnly = ReadOnly || Locked || ((Content != null) && !Content.CanChangeCode); 78 variableStoreView.ReadOnly = (Content != null) && !Content.CanChangeCode; 76 79 } 77 80 -
branches/OptimizationNetworks/HeuristicLab.Scripting/3.3/IProgrammableItem.cs
r11577 r11602 31 31 CompilerErrorCollection CompileErrors { get; } 32 32 bool CanChangeCode { get; } 33 VariableStore VariableStore { get; } 33 34 34 35 void Compile();
Note: See TracChangeset
for help on using the changeset viewer.