Free cookie consent management tool by TermsFeed Policy Generator

Changeset 10892


Ignore:
Timestamp:
05/26/14 16:41:12 (11 years ago)
Author:
abeham
Message:

#2136: merged r10510, r10511, r10512, r10566, r10577, r10642, r10727, r10731, r10747, r10761, r10857, r10865 to stable

Location:
stable
Files:
2 deleted
9 edited
7 copied

Legend:

Unmodified
Added
Removed
  • stable

  • stable/HeuristicLab 3.3.sln

    r10891 r10892  
    381381Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HeuristicLab.Problems.DataAnalysis.Trading.Views-3.4", "HeuristicLab.Problems.DataAnalysis.Trading.Views\3.4\HeuristicLab.Problems.DataAnalysis.Trading.Views-3.4.csproj", "{CB3D0A1E-1BE8-476B-A53C-2B189E30064F}"
    382382EndProject
    383 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HeuristicLab.Scripting-3.3", "HeuristicLab.HLScript\3.3\HeuristicLab.Scripting-3.3.csproj", "{21977CC3-1757-4B3B-87BD-FF817AAA900F}"
    384 EndProject
    385 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HeuristicLab.Scripting.Views-3.3", "HeuristicLab.HLScript.Views\3.3\HeuristicLab.Scripting.Views-3.3.csproj", "{0C2917C8-7AA8-4E18-800A-C4D064F992ED}"
     383Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HeuristicLab.Scripting-3.3", "HeuristicLab.Scripting\3.3\HeuristicLab.Scripting-3.3.csproj", "{21977CC3-1757-4B3B-87BD-FF817AAA900F}"
     384EndProject
     385Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HeuristicLab.Scripting.Views-3.3", "HeuristicLab.Scripting.Views\3.3\HeuristicLab.Scripting.Views-3.3.csproj", "{0C2917C8-7AA8-4E18-800A-C4D064F992ED}"
    386386EndProject
    387387Global
  • stable/HeuristicLab.Scripting.Views/3.3/CSharpScriptView.cs

    r10731 r10892  
    2121
    2222using System;
    23 using System.Drawing;
    2423using System.Windows.Forms;
    2524using HeuristicLab.Common;
     
    9594      base.OnContentChanged();
    9695      if (Content == null) {
    97         codeEditor.UserCode = string.Empty;
    9896        variableStoreView.Content = null;
    9997      } else {
    100         codeEditor.UserCode = Content.Code;
    101         foreach (var asm in Content.GetAssemblies())
    102           codeEditor.AddAssembly(asm);
    10398        variableStoreView.Content = Content.VariableStore;
    104         if (Content.CompileErrors == null) {
    105           compilationLabel.ForeColor = SystemColors.ControlDarkDark;
    106           compilationLabel.Text = "Not compiled";
    107         } else if (Content.CompileErrors.HasErrors) {
    108           compilationLabel.ForeColor = Color.DarkRed;
    109           compilationLabel.Text = "Compilation failed";
    110         } else {
    111           compilationLabel.ForeColor = Color.DarkGreen;
    112           compilationLabel.Text = "Compilation successful";
    113         }
    11499      }
    115100    }
     
    117102    protected override void SetEnabledStateOfControls() {
    118103      base.SetEnabledStateOfControls();
    119       compileButton.Enabled = Content != null && !Locked && !ReadOnly;
    120104      startStopButton.Enabled = Content != null && (!Locked || Running);
    121       codeEditor.Enabled = Content != null && !Locked && !ReadOnly;
    122105    }
    123106
  • stable/HeuristicLab.Scripting.Views/3.3/HeuristicLab.Scripting.Views-3.3.csproj

    r10510 r10892  
    8686  <ItemGroup>
    8787    <None Include="Plugin.cs.frame" />
     88    <Compile Include="CSharpScriptView.cs">
     89      <SubType>UserControl</SubType>
     90    </Compile>
     91    <Compile Include="CSharpScriptView.Designer.cs">
     92      <DependentUpon>CSharpScriptView.cs</DependentUpon>
     93    </Compile>
    8894    <Compile Include="ScriptView.cs">
    8995      <SubType>UserControl</SubType>
  • stable/HeuristicLab.Scripting.Views/3.3/ScriptView.Designer.cs

    r10506 r10892  
    4646    private void InitializeComponent() {
    4747      this.components = new System.ComponentModel.Container();
     48      System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(ScriptView));
    4849      this.compilationLabel = new System.Windows.Forms.Label();
    49       this.startStopButton = new System.Windows.Forms.Button();
     50      this.imageList = new System.Windows.Forms.ImageList(this.components);
     51      this.compileButton = new System.Windows.Forms.Button();
     52      this.infoTabControl = new System.Windows.Forms.TabControl();
     53      this.outputTabPage = new System.Windows.Forms.TabPage();
     54      this.outputTextBox = new System.Windows.Forms.TextBox();
     55      this.errorListTabPage = new System.Windows.Forms.TabPage();
    5056      this.errorListView = new System.Windows.Forms.ListView();
    5157      this.iconColumnHeader = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
     
    5561      this.columnColumnHeader = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
    5662      this.descriptionColumnHeader = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
    57       this.imageList = new System.Windows.Forms.ImageList(this.components);
    5863      this.codeEditor = new HeuristicLab.CodeEditor.CodeEditor();
    5964      this.splitContainer1 = new System.Windows.Forms.SplitContainer();
    60       this.splitContainer2 = new System.Windows.Forms.SplitContainer();
    61       this.infoTabControl = new System.Windows.Forms.TabControl();
    62       this.outputTabPage = new System.Windows.Forms.TabPage();
    63       this.outputTextBox = new System.Windows.Forms.TextBox();
    64       this.errorListTabPage = new System.Windows.Forms.TabPage();
    65       this.variableStoreView = new HeuristicLab.Scripting.Views.VariableStoreView();
    66       this.viewHost = new HeuristicLab.MainForm.WindowsForms.ViewHost();
    67       this.compileButton = new System.Windows.Forms.Button();
    6865      ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).BeginInit();
     66      this.infoTabControl.SuspendLayout();
     67      this.outputTabPage.SuspendLayout();
     68      this.errorListTabPage.SuspendLayout();
    6969      ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit();
    7070      this.splitContainer1.Panel1.SuspendLayout();
    7171      this.splitContainer1.Panel2.SuspendLayout();
    7272      this.splitContainer1.SuspendLayout();
    73       ((System.ComponentModel.ISupportInitialize)(this.splitContainer2)).BeginInit();
    74       this.splitContainer2.Panel1.SuspendLayout();
    75       this.splitContainer2.Panel2.SuspendLayout();
    76       this.splitContainer2.SuspendLayout();
    77       this.infoTabControl.SuspendLayout();
    78       this.outputTabPage.SuspendLayout();
    79       this.errorListTabPage.SuspendLayout();
    8073      this.SuspendLayout();
    8174      //
     
    8477      this.errorProvider.SetIconAlignment(this.nameTextBox, System.Windows.Forms.ErrorIconAlignment.MiddleLeft);
    8578      this.errorProvider.SetIconPadding(this.nameTextBox, 2);
    86       this.nameTextBox.Location = new System.Drawing.Point(60, 0);
    87       this.nameTextBox.Size = new System.Drawing.Size(750, 20);
     79      this.nameTextBox.Location = new System.Drawing.Point(69, 0);
     80      this.nameTextBox.Size = new System.Drawing.Size(741, 20);
    8881      //
    8982      // infoLabel
     
    10194      this.compilationLabel.Text = "Not compiled";
    10295      //
    103       // startStopButton
    104       //
    105       this.startStopButton.Image = HeuristicLab.Common.Resources.VSImageLibrary.Play;
    106       this.startStopButton.Location = new System.Drawing.Point(36, 26);
    107       this.startStopButton.Name = "startStopButton";
    108       this.startStopButton.Size = new System.Drawing.Size(24, 24);
    109       this.startStopButton.TabIndex = 1;
    110       this.startStopButton.TextImageRelation = System.Windows.Forms.TextImageRelation.ImageBeforeText;
    111       this.toolTip.SetToolTip(this.startStopButton, "Run (F5)");
    112       this.startStopButton.UseVisualStyleBackColor = true;
    113       this.startStopButton.Click += new System.EventHandler(this.startStopButton_Click);
     96      // imageList
     97      //
     98      this.imageList.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit;
     99      this.imageList.ImageSize = new System.Drawing.Size(16, 16);
     100      this.imageList.TransparentColor = System.Drawing.Color.Transparent;
     101      //
     102      // compileButton
     103      //
     104      this.compileButton.Image = HeuristicLab.Common.Resources.VSImageLibrary.Script;
     105      this.compileButton.Location = new System.Drawing.Point(6, 26);
     106      this.compileButton.Name = "compileButton";
     107      this.compileButton.Size = new System.Drawing.Size(24, 24);
     108      this.compileButton.TabIndex = 8;
     109      this.compileButton.TextImageRelation = System.Windows.Forms.TextImageRelation.ImageBeforeText;
     110      this.toolTip.SetToolTip(this.compileButton, "Compile (F6)");
     111      this.compileButton.UseVisualStyleBackColor = true;
     112      this.compileButton.Click += new System.EventHandler(this.CompileButtonOnClick);
     113      //
     114      // infoTabControl
     115      //
     116      this.infoTabControl.Controls.Add(this.outputTabPage);
     117      this.infoTabControl.Controls.Add(this.errorListTabPage);
     118      this.infoTabControl.Dock = System.Windows.Forms.DockStyle.Fill;
     119      this.infoTabControl.Location = new System.Drawing.Point(0, 0);
     120      this.infoTabControl.Name = "infoTabControl";
     121      this.infoTabControl.SelectedIndex = 0;
     122      this.infoTabControl.Size = new System.Drawing.Size(832, 112);
     123      this.infoTabControl.TabIndex = 1;
     124      //
     125      // outputTabPage
     126      //
     127      this.outputTabPage.Controls.Add(this.outputTextBox);
     128      this.outputTabPage.Location = new System.Drawing.Point(4, 22);
     129      this.outputTabPage.Name = "outputTabPage";
     130      this.outputTabPage.Padding = new System.Windows.Forms.Padding(3);
     131      this.outputTabPage.Size = new System.Drawing.Size(824, 86);
     132      this.outputTabPage.TabIndex = 1;
     133      this.outputTabPage.Text = "Output";
     134      this.outputTabPage.UseVisualStyleBackColor = true;
     135      //
     136      // outputTextBox
     137      //
     138      this.outputTextBox.Dock = System.Windows.Forms.DockStyle.Fill;
     139      this.outputTextBox.Font = new System.Drawing.Font("Consolas", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
     140      this.outputTextBox.Location = new System.Drawing.Point(3, 3);
     141      this.outputTextBox.Multiline = true;
     142      this.outputTextBox.Name = "outputTextBox";
     143      this.outputTextBox.ReadOnly = true;
     144      this.outputTextBox.ScrollBars = System.Windows.Forms.ScrollBars.Both;
     145      this.outputTextBox.Size = new System.Drawing.Size(818, 80);
     146      this.outputTextBox.TabIndex = 0;
     147      this.outputTextBox.WordWrap = false;
     148      //
     149      // errorListTabPage
     150      //
     151      this.errorListTabPage.Controls.Add(this.errorListView);
     152      this.errorListTabPage.Location = new System.Drawing.Point(4, 22);
     153      this.errorListTabPage.Name = "errorListTabPage";
     154      this.errorListTabPage.Padding = new System.Windows.Forms.Padding(3);
     155      this.errorListTabPage.Size = new System.Drawing.Size(824, 86);
     156      this.errorListTabPage.TabIndex = 0;
     157      this.errorListTabPage.Text = "Error List";
     158      this.errorListTabPage.UseVisualStyleBackColor = true;
    114159      //
    115160      // errorListView
     
    128173      this.errorListView.Location = new System.Drawing.Point(3, 3);
    129174      this.errorListView.Name = "errorListView";
    130       this.errorListView.Size = new System.Drawing.Size(623, 79);
     175      this.errorListView.Size = new System.Drawing.Size(818, 80);
    131176      this.errorListView.SmallImageList = this.imageList;
    132177      this.errorListView.TabIndex = 0;
     
    158203      this.descriptionColumnHeader.Text = "Description";
    159204      //
    160       // imageList
    161       //
    162       this.imageList.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit;
    163       this.imageList.ImageSize = new System.Drawing.Size(16, 16);
    164       this.imageList.TransparentColor = System.Drawing.Color.Transparent;
    165       //
    166205      // codeEditor
    167206      //
     
    170209      this.codeEditor.Name = "codeEditor";
    171210      this.codeEditor.Prefix = "";
    172       this.codeEditor.Size = new System.Drawing.Size(637, 428);
     211      this.codeEditor.Size = new System.Drawing.Size(832, 430);
    173212      this.codeEditor.Suffix = "";
    174213      this.codeEditor.TabIndex = 0;
    175214      this.codeEditor.UserCode = "";
    176       this.codeEditor.TextEditorTextChanged += new System.EventHandler(this.codeEditor_TextEditorTextChanged);
     215      this.codeEditor.TextEditorTextChanged += new System.EventHandler(this.CodeEditorOnTextEditorTextChanged);
    177216      //
    178217      // splitContainer1
     
    181220            | System.Windows.Forms.AnchorStyles.Left)
    182221            | System.Windows.Forms.AnchorStyles.Right)));
    183       this.splitContainer1.Location = new System.Drawing.Point(3, 56);
     222      this.splitContainer1.Location = new System.Drawing.Point(0, 56);
    184223      this.splitContainer1.Name = "splitContainer1";
     224      this.splitContainer1.Orientation = System.Windows.Forms.Orientation.Horizontal;
    185225      //
    186226      // splitContainer1.Panel1
    187227      //
    188       this.splitContainer1.Panel1.Controls.Add(this.splitContainer2);
     228      this.splitContainer1.Panel1.Controls.Add(this.codeEditor);
    189229      //
    190230      // splitContainer1.Panel2
    191231      //
    192       this.splitContainer1.Panel2.Controls.Add(this.variableStoreView);
    193       this.splitContainer1.Panel2.Controls.Add(this.viewHost);
    194       this.splitContainer1.Size = new System.Drawing.Size(829, 543);
    195       this.splitContainer1.SplitterDistance = 637;
    196       this.splitContainer1.TabIndex = 7;
    197       //
    198       // splitContainer2
    199       //
    200       this.splitContainer2.Dock = System.Windows.Forms.DockStyle.Fill;
    201       this.splitContainer2.Location = new System.Drawing.Point(0, 0);
    202       this.splitContainer2.Name = "splitContainer2";
    203       this.splitContainer2.Orientation = System.Windows.Forms.Orientation.Horizontal;
    204       //
    205       // splitContainer2.Panel1
    206       //
    207       this.splitContainer2.Panel1.Controls.Add(this.codeEditor);
    208       //
    209       // splitContainer2.Panel2
    210       //
    211       this.splitContainer2.Panel2.Controls.Add(this.infoTabControl);
    212       this.splitContainer2.Size = new System.Drawing.Size(637, 543);
    213       this.splitContainer2.SplitterDistance = 428;
    214       this.splitContainer2.TabIndex = 5;
    215       //
    216       // infoTabControl
    217       //
    218       this.infoTabControl.Controls.Add(this.outputTabPage);
    219       this.infoTabControl.Controls.Add(this.errorListTabPage);
    220       this.infoTabControl.Dock = System.Windows.Forms.DockStyle.Fill;
    221       this.infoTabControl.Location = new System.Drawing.Point(0, 0);
    222       this.infoTabControl.Name = "infoTabControl";
    223       this.infoTabControl.SelectedIndex = 0;
    224       this.infoTabControl.Size = new System.Drawing.Size(637, 111);
    225       this.infoTabControl.TabIndex = 1;
    226       //
    227       // outputTabPage
    228       //
    229       this.outputTabPage.Controls.Add(this.outputTextBox);
    230       this.outputTabPage.Location = new System.Drawing.Point(4, 22);
    231       this.outputTabPage.Name = "outputTabPage";
    232       this.outputTabPage.Padding = new System.Windows.Forms.Padding(3);
    233       this.outputTabPage.Size = new System.Drawing.Size(629, 85);
    234       this.outputTabPage.TabIndex = 1;
    235       this.outputTabPage.Text = "Output";
    236       this.outputTabPage.UseVisualStyleBackColor = true;
    237       //
    238       // outputTextBox
    239       //
    240       this.outputTextBox.Dock = System.Windows.Forms.DockStyle.Fill;
    241       this.outputTextBox.Font = new System.Drawing.Font("Consolas", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
    242       this.outputTextBox.Location = new System.Drawing.Point(3, 3);
    243       this.outputTextBox.Multiline = true;
    244       this.outputTextBox.Name = "outputTextBox";
    245       this.outputTextBox.ReadOnly = true;
    246       this.outputTextBox.ScrollBars = System.Windows.Forms.ScrollBars.Both;
    247       this.outputTextBox.Size = new System.Drawing.Size(623, 79);
    248       this.outputTextBox.TabIndex = 0;
    249       this.outputTextBox.WordWrap = false;
    250       //
    251       // errorListTabPage
    252       //
    253       this.errorListTabPage.Controls.Add(this.errorListView);
    254       this.errorListTabPage.Location = new System.Drawing.Point(4, 22);
    255       this.errorListTabPage.Name = "errorListTabPage";
    256       this.errorListTabPage.Padding = new System.Windows.Forms.Padding(3);
    257       this.errorListTabPage.Size = new System.Drawing.Size(629, 85);
    258       this.errorListTabPage.TabIndex = 0;
    259       this.errorListTabPage.Text = "Error List";
    260       this.errorListTabPage.UseVisualStyleBackColor = true;
    261       //
    262       // variableStoreView
    263       //
    264       this.variableStoreView.Caption = "ItemCollection View";
    265       this.variableStoreView.Content = null;
    266       this.variableStoreView.Dock = System.Windows.Forms.DockStyle.Fill;
    267       this.variableStoreView.Location = new System.Drawing.Point(0, 0);
    268       this.variableStoreView.Name = "variableStoreView";
    269       this.variableStoreView.ReadOnly = false;
    270       this.variableStoreView.Size = new System.Drawing.Size(188, 543);
    271       this.variableStoreView.TabIndex = 0;
    272       //
    273       // viewHost
    274       //
    275       this.viewHost.Caption = "View";
    276       this.viewHost.Content = null;
    277       this.viewHost.Dock = System.Windows.Forms.DockStyle.Fill;
    278       this.viewHost.Enabled = false;
    279       this.viewHost.Location = new System.Drawing.Point(0, 0);
    280       this.viewHost.Name = "viewHost";
    281       this.viewHost.ReadOnly = false;
    282       this.viewHost.Size = new System.Drawing.Size(188, 543);
    283       this.viewHost.TabIndex = 0;
    284       this.viewHost.ViewsLabelVisible = true;
    285       this.viewHost.ViewType = null;
    286       //
    287       // compileButton
    288       //
    289       this.compileButton.Image = HeuristicLab.Common.Resources.VSImageLibrary.Script;
    290       this.compileButton.Location = new System.Drawing.Point(6, 26);
    291       this.compileButton.Name = "compileButton";
    292       this.compileButton.Size = new System.Drawing.Size(24, 24);
    293       this.compileButton.TabIndex = 8;
    294       this.compileButton.TextImageRelation = System.Windows.Forms.TextImageRelation.ImageBeforeText;
    295       this.toolTip.SetToolTip(this.compileButton, "Compile (F6)");
    296       this.compileButton.UseVisualStyleBackColor = true;
    297       this.compileButton.Click += new System.EventHandler(this.compileButton_Click);
     232      this.splitContainer1.Panel2.Controls.Add(this.infoTabControl);
     233      this.splitContainer1.Size = new System.Drawing.Size(832, 546);
     234      this.splitContainer1.SplitterDistance = 430;
     235      this.splitContainer1.TabIndex = 9;
    298236      //
    299237      // ScriptView
    300238      //
    301239      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Inherit;
     240      this.Controls.Add(this.splitContainer1);
    302241      this.Controls.Add(this.compileButton);
    303       this.Controls.Add(this.splitContainer1);
    304       this.Controls.Add(this.startStopButton);
    305242      this.Controls.Add(this.compilationLabel);
    306243      this.Name = "ScriptView";
    307244      this.Size = new System.Drawing.Size(835, 602);
    308245      this.Controls.SetChildIndex(this.compilationLabel, 0);
    309       this.Controls.SetChildIndex(this.startStopButton, 0);
     246      this.Controls.SetChildIndex(this.compileButton, 0);
    310247      this.Controls.SetChildIndex(this.splitContainer1, 0);
    311248      this.Controls.SetChildIndex(this.nameLabel, 0);
    312249      this.Controls.SetChildIndex(this.nameTextBox, 0);
    313250      this.Controls.SetChildIndex(this.infoLabel, 0);
    314       this.Controls.SetChildIndex(this.compileButton, 0);
    315251      ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).EndInit();
     252      this.infoTabControl.ResumeLayout(false);
     253      this.outputTabPage.ResumeLayout(false);
     254      this.outputTabPage.PerformLayout();
     255      this.errorListTabPage.ResumeLayout(false);
    316256      this.splitContainer1.Panel1.ResumeLayout(false);
    317257      this.splitContainer1.Panel2.ResumeLayout(false);
    318258      ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).EndInit();
    319259      this.splitContainer1.ResumeLayout(false);
    320       this.splitContainer2.Panel1.ResumeLayout(false);
    321       this.splitContainer2.Panel2.ResumeLayout(false);
    322       ((System.ComponentModel.ISupportInitialize)(this.splitContainer2)).EndInit();
    323       this.splitContainer2.ResumeLayout(false);
    324       this.infoTabControl.ResumeLayout(false);
    325       this.outputTabPage.ResumeLayout(false);
    326       this.outputTabPage.PerformLayout();
    327       this.errorListTabPage.ResumeLayout(false);
    328260      this.ResumeLayout(false);
    329261      this.PerformLayout();
     
    333265    #endregion
    334266
    335     private System.Windows.Forms.Label compilationLabel;
    336     private System.Windows.Forms.Button startStopButton;
    337     private System.Windows.Forms.ListView errorListView;
    338     private System.Windows.Forms.ColumnHeader descriptionColumnHeader;
    339     private System.Windows.Forms.ColumnHeader lineColumnHeader;
    340     private System.Windows.Forms.ColumnHeader columnColumnHeader;
    341     private CodeEditor.CodeEditor codeEditor;
    342     private System.Windows.Forms.SplitContainer splitContainer1;
    343     private System.Windows.Forms.SplitContainer splitContainer2;
    344     private MainForm.WindowsForms.ViewHost viewHost;
    345     private VariableStoreView variableStoreView;
    346     private System.Windows.Forms.ColumnHeader errorNumberColumnHeader;
    347     private System.Windows.Forms.ColumnHeader categoryColumnHeader;
    348     private System.Windows.Forms.TabControl infoTabControl;
    349     private System.Windows.Forms.TabPage errorListTabPage;
    350     private System.Windows.Forms.TabPage outputTabPage;
    351     private System.Windows.Forms.TextBox outputTextBox;
    352     private System.Windows.Forms.Button compileButton;
    353     private System.Windows.Forms.ColumnHeader iconColumnHeader;
    354     private System.Windows.Forms.ImageList imageList;
     267    protected System.Windows.Forms.Label compilationLabel;
     268    protected System.Windows.Forms.Button compileButton;
     269    protected System.Windows.Forms.ImageList imageList;
     270    protected System.Windows.Forms.TabControl infoTabControl;
     271    protected System.Windows.Forms.TabPage outputTabPage;
     272    protected System.Windows.Forms.TextBox outputTextBox;
     273    protected System.Windows.Forms.TabPage errorListTabPage;
     274    protected System.Windows.Forms.ListView errorListView;
     275    protected System.Windows.Forms.ColumnHeader iconColumnHeader;
     276    protected System.Windows.Forms.ColumnHeader categoryColumnHeader;
     277    protected System.Windows.Forms.ColumnHeader errorNumberColumnHeader;
     278    protected System.Windows.Forms.ColumnHeader lineColumnHeader;
     279    protected System.Windows.Forms.ColumnHeader columnColumnHeader;
     280    protected System.Windows.Forms.ColumnHeader descriptionColumnHeader;
     281    protected CodeEditor.CodeEditor codeEditor;
     282    protected System.Windows.Forms.SplitContainer splitContainer1;
    355283  }
    356284}
  • stable/HeuristicLab.Scripting.Views/3.3/ScriptView.cs

    r10506 r10892  
    2626using System.Linq;
    2727using System.Windows.Forms;
    28 using HeuristicLab.Common;
    2928using HeuristicLab.Common.Resources;
    3029using HeuristicLab.Core.Views;
     
    3635  [Content(typeof(Script), true)]
    3736  public partial class ScriptView : NamedItemView {
    38     private bool running;
    39 
    4037    public new Script Content {
    4138      get { return (Script)base.Content; }
    42       set { base.Content = (Script)value; }
     39      set { base.Content = value; }
    4340    }
    4441
     
    4643      InitializeComponent();
    4744      errorListView.SmallImageList.Images.AddRange(new Image[] { VSImageLibrary.Warning, VSImageLibrary.Error });
    48       AdjustErrorListViewColumnSizes();
    4945    }
    5046
    5147    protected override void RegisterContentEvents() {
    5248      base.RegisterContentEvents();
    53       Content.CodeChanged += Content_CodeChanged;
    54       Content.ScriptExecutionStarted += Content_ScriptExecutionStarted;
    55       Content.ScriptExecutionFinished += Content_ScriptExecutionFinished;
    56       Content.ConsoleOutputChanged += Content_ConsoleOutputChanged;
     49      Content.CodeChanged += ContentOnCodeChanged;
    5750    }
    5851
    5952    protected override void DeregisterContentEvents() {
    60       Content.CodeChanged -= Content_CodeChanged;
    61       Content.ScriptExecutionStarted -= Content_ScriptExecutionStarted;
    62       Content.ScriptExecutionFinished -= Content_ScriptExecutionFinished;
    63       Content.ConsoleOutputChanged -= Content_ConsoleOutputChanged;
     53      Content.CodeChanged -= ContentOnCodeChanged;
    6454      base.DeregisterContentEvents();
    6555    }
    6656
    67     #region Content event handlers
    68     private void Content_CodeChanged(object sender, EventArgs e) {
     57    protected virtual void ContentOnCodeChanged(object sender, EventArgs e) {
    6958      codeEditor.UserCode = Content.Code;
    7059    }
    71     private void Content_ScriptExecutionStarted(object sender, EventArgs e) {
    72       if (InvokeRequired)
    73         Invoke((Action<object, EventArgs>)Content_ScriptExecutionStarted, sender, e);
    74       else {
    75         Locked = true;
    76         ReadOnly = true;
    77         startStopButton.Image = VSImageLibrary.Stop;
    78         infoTabControl.SelectedTab = outputTabPage;
    79       }
    80     }
    81     private void Content_ScriptExecutionFinished(object sender, EventArgs<Exception> e) {
    82       if (InvokeRequired)
    83         Invoke((Action<object, EventArgs<Exception>>)Content_ScriptExecutionFinished, sender, e);
    84       else {
    85         Locked = false;
    86         ReadOnly = false;
    87         startStopButton.Image = VSImageLibrary.Play;
    88         running = false;
    89         var ex = e.Value;
    90         if (ex != null)
    91           PluginInfrastructure.ErrorHandling.ShowErrorDialog(this, ex);
    92       }
    93     }
    94     private void Content_ConsoleOutputChanged(object sender, EventArgs<string> e) {
    95       if (InvokeRequired)
    96         Invoke((Action<object, EventArgs<string>>)Content_ConsoleOutputChanged, sender, e);
    97       else {
    98         outputTextBox.AppendText(e.Value);
    99       }
    100     }
    101     #endregion
    10260
    10361    protected override void OnContentChanged() {
     
    10563      if (Content == null) {
    10664        codeEditor.UserCode = string.Empty;
    107         variableStoreView.Content = null;
    10865      } else {
    10966        codeEditor.UserCode = Content.Code;
    11067        foreach (var asm in Content.GetAssemblies())
    11168          codeEditor.AddAssembly(asm);
    112         variableStoreView.Content = Content.VariableStore;
    11369        if (Content.CompileErrors == null) {
    11470          compilationLabel.ForeColor = SystemColors.ControlDarkDark;
     
    12783      base.SetEnabledStateOfControls();
    12884      compileButton.Enabled = Content != null && !Locked && !ReadOnly;
    129       startStopButton.Enabled = Content != null && (!Locked || running);
    13085      codeEditor.Enabled = Content != null && !Locked && !ReadOnly;
    13186    }
    13287
    133     #region Child Control event handlers
    134     private void compileButton_Click(object sender, EventArgs e) {
     88    protected virtual void CompileButtonOnClick(object sender, EventArgs e) {
    13589      Compile();
    13690    }
    13791
    138     private void startStopButton_Click(object sender, EventArgs e) {
    139       if (running) {
    140         Content.Kill();
    141       } else
    142         if (Compile()) {
    143           outputTextBox.Clear();
    144           Content.Execute();
    145           running = true;
    146         }
    147     }
    148 
    149     private void codeEditor_TextEditorTextChanged(object sender, EventArgs e) {
     92    protected virtual void CodeEditorOnTextEditorTextChanged(object sender, EventArgs e) {
     93      if (Content == null) return;
    15094      Content.Code = codeEditor.UserCode;
    15195    }
    152     #endregion
    153 
    154     #region global HotKeys
    15596    protected override bool ProcessCmdKey(ref Message msg, Keys keyData) {
    15697      switch (keyData) {
    157         case Keys.F5:
    158           if (Content != null && !Locked) {
    159             if (Compile()) {
    160               outputTextBox.Clear();
    161               Content.Execute();
    162               running = true;
    163             } else
    164               infoTabControl.SelectedTab = errorListTabPage;
    165           }
    166           break;
    167         case Keys.F5 | Keys.Shift:
    168           if (running) Content.Kill();
    169           break;
    17098        case Keys.F6:
    171           if (!Compile() || Content.CompileErrors.HasWarnings)
    172             infoTabControl.SelectedTab = errorListTabPage;
    173           break;
     99          if (Content != null && !Locked)
     100            Compile();
     101          return true;
    174102      }
    175103      return base.ProcessCmdKey(ref msg, keyData);
    176104    }
    177     #endregion
    178105
    179     #region Auxiliary functions
    180     private bool Compile() {
     106    public virtual bool Compile() {
    181107      ReadOnly = true;
    182108      Locked = true;
     
    188114        return true;
    189115      } catch {
    190         outputTextBox.AppendText("Compilation failed.");
    191         return false;
     116        if (Content.CompileErrors.HasErrors) {
     117          outputTextBox.AppendText("Compilation failed.");
     118          return false;
     119        } else {
     120          outputTextBox.AppendText("Compilation succeeded.");
     121          return true;
     122        }
    192123      } finally {
    193124        ShowCompilationResults();
     125        if (Content.CompileErrors.Count > 0)
     126          infoTabControl.SelectedTab = errorListTabPage;
    194127        ReadOnly = false;
    195128        Locked = false;
     
    197130      }
    198131    }
    199     #endregion
    200132
    201     private void ShowCompilationResults() {
     133    protected virtual void ShowCompilationResults() {
    202134      if (Content.CompileErrors.Count == 0) return;
    203135      var msgs = Content.CompileErrors.OfType<CompilerError>()
     
    220152    }
    221153
    222     private void AdjustErrorListViewColumnSizes() {
     154    protected virtual void AdjustErrorListViewColumnSizes() {
    223155      foreach (ColumnHeader ch in errorListView.Columns)
    224         // adjusts the column width to the width of the column
    225         // header or the column content, whichever is greater
     156        // adjusts the column width to the width of the column header
    226157        ch.Width = -2;
    227158    }
  • stable/HeuristicLab.Scripting.Views/3.3/VariableStoreView.cs

    r10506 r10892  
    2121
    2222using System;
    23 using System.Collections;
    2423using System.Collections.Generic;
    2524using System.Drawing;
     
    220219
    221220        if (items.Count > 0) {
    222           DataObject data = new DataObject();
     221          var data = new DataObject();
    223222          if (items.Count == 1) data.SetData(HeuristicLab.Common.Constants.DragDropDataFormat, items[0]);
    224223          else data.SetData(HeuristicLab.Common.Constants.DragDropDataFormat, items);
    225224          if (ReadOnly) {
    226             DoDragDrop(data, DragDropEffects.Copy | DragDropEffects.Link);
     225            DoDragDrop(data, DragDropEffects.Copy);
    227226          } else {
    228             DragDropEffects result = DoDragDrop(data, DragDropEffects.Copy | DragDropEffects.Link | DragDropEffects.Move);
     227            var result = DoDragDrop(data, DragDropEffects.Copy | DragDropEffects.Link | DragDropEffects.Move);
    229228            if ((result & DragDropEffects.Move) == DragDropEffects.Move) {
    230229              foreach (string item in items) Content.Remove(item);
     
    235234    }
    236235    protected virtual void variableListView_DragEnter(object sender, DragEventArgs e) {
    237       validDragOperation = false;
    238       if (!Locked && !ReadOnly && (e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat) is object)) {
    239         validDragOperation = true;
    240       } else if (!Locked && !ReadOnly && (e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat) is IEnumerable)) {
    241         validDragOperation = true;
    242         IEnumerable items = (IEnumerable)e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat);
    243         foreach (object item in items)
    244           validDragOperation = validDragOperation && (item is object);
    245       }
     236      validDragOperation = !Locked && !ReadOnly && e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat) != null;
    246237    }
    247238    protected virtual void variableListView_DragOver(object sender, DragEventArgs e) {
     
    257248    protected virtual void variableListView_DragDrop(object sender, DragEventArgs e) {
    258249      if (e.Effect != DragDropEffects.None) {
    259         if (e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat) is IEnumerable) {
    260           IEnumerable<object> items = ((IEnumerable)e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat)).Cast<object>();
    261           if (e.Effect.HasFlag(DragDropEffects.Copy)) {
    262             var cloner = new Cloner();
    263             var clonedItems = new List<object>();
    264             foreach (var item in items) {
    265               var dc = item as IDeepCloneable;
    266               clonedItems.Add(dc != null ? cloner.Clone(dc) : item);
    267             }
    268             items = clonedItems;
    269           }
    270           foreach (var item in items) {
    271             string name = GenerateNewVariableName();
    272             Content.Add(name, item);
    273             var listViewItem = variableListView.FindItemWithText(name);
    274             listViewItem.BeginEdit();
    275           }
    276         } else {
    277           object item = e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat);
    278           if (e.Effect.HasFlag(DragDropEffects.Copy)) {
    279             var cloner = new Cloner();
    280             var dc = item as IDeepCloneable;
    281             if (dc != null) item = cloner.Clone(dc);
    282           }
    283           string name = GenerateNewVariableName();
    284           Content.Add(name, item);
    285           var listViewItem = variableListView.FindItemWithText(name);
    286           listViewItem.BeginEdit();
    287         }
     250        object item = e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat);
     251        if (e.Effect.HasFlag(DragDropEffects.Copy)) {
     252          var cloner = new Cloner();
     253          var dc = item as IDeepCloneable;
     254          if (dc != null) item = cloner.Clone(dc);
     255        }
     256        string name = GenerateNewVariableName();
     257        Content.Add(name, item);
     258        var listViewItem = variableListView.FindItemWithText(name);
     259        listViewItem.BeginEdit();
    288260      }
    289261    }
     
    423395      string toolTipText = string.Join(Environment.NewLine, lines);
    424396      if (!serializable)
    425         toolTipText += Environment.NewLine + "CAUTION: Type is not serializable!";
     397        toolTipText = "Caution: Type is not serializable!" + Environment.NewLine + toolTipText;
    426398      return toolTipText;
    427399    }
  • stable/HeuristicLab.Scripting/3.3/CSharpScript.cs

    r10731 r10892  
    6262
    6363    #region Fields & Properties
    64     protected CSharpScriptBase CompiledScript;
     64    private CSharpScriptBase compiledScript;
    6565
    6666    public string Filename { get; set; }
     
    8282    public CSharpScript() {
    8383      variableStore = new VariableStore();
     84      Code = CodeTemplate;
    8485    }
    8586    public CSharpScript(string code)
     
    9495
    9596    protected virtual void RegisterScriptEvents() {
    96       if (CompiledScript != null)
    97         CompiledScript.ConsoleOutputChanged += CompiledScriptOnConsoleOutputChanged;
     97      if (compiledScript != null)
     98        compiledScript.ConsoleOutputChanged += CompiledScriptOnConsoleOutputChanged;
    9899    }
    99100
    100101    protected virtual void DeregisterScriptEvents() {
    101       if (CompiledScript != null)
    102         CompiledScript.ConsoleOutputChanged -= CompiledScriptOnConsoleOutputChanged;
     102      if (compiledScript != null)
     103        compiledScript.ConsoleOutputChanged -= CompiledScriptOnConsoleOutputChanged;
    103104    }
    104105
     
    106107
    107108    public override Assembly Compile() {
    108       CompiledScript = null;
     109      DeregisterScriptEvents();
     110      compiledScript = null;
    109111      var assembly = base.Compile();
    110112      var types = assembly.GetTypes();
    111       DeregisterScriptEvents();
    112       CompiledScript = (CSharpScriptBase)Activator.CreateInstance(types.First(x => typeof(CSharpScriptBase).IsAssignableFrom(x)));
     113      compiledScript = (CSharpScriptBase)Activator.CreateInstance(types.Single(x => typeof(CSharpScriptBase).IsAssignableFrom(x)));
    113114      RegisterScriptEvents();
    114115      return assembly;
     
    116117    #endregion
    117118
    118     protected Thread ScriptThread;
     119    private Thread scriptThread;
    119120    public virtual void Execute() {
    120       if (CompiledScript == null) return;
    121       var executeMethod = typeof(CSharpScriptBase).GetMethod(ExecuteMethodName, BindingFlags.NonPublic | BindingFlags.Instance);
    122       if (executeMethod != null) {
    123         ScriptThread = new Thread(() => {
    124           Exception ex = null;
    125           try {
    126             OnScriptExecutionStarted();
    127             executeMethod.Invoke(CompiledScript, new object[] { VariableStore });
    128           } catch (ThreadAbortException) {
    129             // the execution was cancelled by the user
    130           } catch (TargetInvocationException e) {
    131             ex = e.InnerException;
    132           } finally {
    133             OnScriptExecutionFinished(ex);
    134           }
    135         });
    136         ScriptThread.Start();
    137       }
     121      if (compiledScript == null) return;
     122      scriptThread = new Thread(() => {
     123        Exception ex = null;
     124        try {
     125          OnScriptExecutionStarted();
     126          compiledScript.Execute(VariableStore);
     127        } catch (ThreadAbortException) {
     128          // the execution was cancelled by the user
     129        } catch (Exception e) {
     130          ex = e;
     131        } finally {
     132          OnScriptExecutionFinished(ex);
     133        }
     134      });
     135      scriptThread.Start();
    138136    }
    139137
    140138    public virtual void Kill() {
    141       if (ScriptThread.IsAlive)
    142         ScriptThread.Abort();
     139      if (scriptThread.IsAlive)
     140        scriptThread.Abort();
    143141    }
    144142
  • stable/HeuristicLab.Scripting/3.3/CSharpScriptBase.cs

    r10731 r10892  
    5252
    5353    protected class EventWriter : TextWriter {
    54       private readonly CSharpScriptBase usb;
     54      private readonly CSharpScriptBase script;
    5555
    56       public EventWriter(CSharpScriptBase usb) {
    57         this.usb = usb;
     56      public EventWriter(CSharpScriptBase script) {
     57        this.script = script;
    5858      }
    5959
     
    6464      #region Write/WriteLine Overrides
    6565      #region Write
    66       public override void Write(bool value) { usb.OnConsoleOutputChanged(value.ToString()); }
    67       public override void Write(char value) { usb.OnConsoleOutputChanged(value.ToString()); }
    68       public override void Write(char[] buffer) { usb.OnConsoleOutputChanged(new string(buffer)); }
    69       public override void Write(char[] buffer, int index, int count) { usb.OnConsoleOutputChanged(new string(buffer, index, count)); }
    70       public override void Write(decimal value) { usb.OnConsoleOutputChanged(value.ToString()); }
    71       public override void Write(double value) { usb.OnConsoleOutputChanged(value.ToString()); }
    72       public override void Write(float value) { usb.OnConsoleOutputChanged(value.ToString()); }
    73       public override void Write(int value) { usb.OnConsoleOutputChanged(value.ToString()); }
    74       public override void Write(long value) { usb.OnConsoleOutputChanged(value.ToString()); }
    75       public override void Write(object value) { usb.OnConsoleOutputChanged(value.ToString()); }
    76       public override void Write(string value) { usb.OnConsoleOutputChanged(value); }
    77       public override void Write(string format, object arg0) { usb.OnConsoleOutputChanged(string.Format(format, arg0)); }
    78       public override void Write(string format, object arg0, object arg1) { usb.OnConsoleOutputChanged(string.Format(format, arg0, arg0)); }
    79       public override void Write(string format, object arg0, object arg1, object arg2) { usb.OnConsoleOutputChanged(string.Format(format, arg0, arg1, arg2)); }
    80       public override void Write(string format, params object[] arg) { usb.OnConsoleOutputChanged(string.Format(format, arg)); }
    81       public override void Write(uint value) { usb.OnConsoleOutputChanged(value.ToString()); }
    82       public override void Write(ulong value) { usb.OnConsoleOutputChanged(value.ToString()); }
     66      public override void Write(bool value) { script.OnConsoleOutputChanged(value.ToString()); }
     67      public override void Write(char value) { script.OnConsoleOutputChanged(value.ToString()); }
     68      public override void Write(char[] buffer) { script.OnConsoleOutputChanged(new string(buffer)); }
     69      public override void Write(char[] buffer, int index, int count) { script.OnConsoleOutputChanged(new string(buffer, index, count)); }
     70      public override void Write(decimal value) { script.OnConsoleOutputChanged(value.ToString()); }
     71      public override void Write(double value) { script.OnConsoleOutputChanged(value.ToString()); }
     72      public override void Write(float value) { script.OnConsoleOutputChanged(value.ToString()); }
     73      public override void Write(int value) { script.OnConsoleOutputChanged(value.ToString()); }
     74      public override void Write(long value) { script.OnConsoleOutputChanged(value.ToString()); }
     75      public override void Write(object value) { script.OnConsoleOutputChanged(value.ToString()); }
     76      public override void Write(string value) { script.OnConsoleOutputChanged(value); }
     77      public override void Write(string format, object arg0) { script.OnConsoleOutputChanged(string.Format(format, arg0)); }
     78      public override void Write(string format, object arg0, object arg1) { script.OnConsoleOutputChanged(string.Format(format, arg0, arg0)); }
     79      public override void Write(string format, object arg0, object arg1, object arg2) { script.OnConsoleOutputChanged(string.Format(format, arg0, arg1, arg2)); }
     80      public override void Write(string format, params object[] arg) { script.OnConsoleOutputChanged(string.Format(format, arg)); }
     81      public override void Write(uint value) { script.OnConsoleOutputChanged(value.ToString()); }
     82      public override void Write(ulong value) { script.OnConsoleOutputChanged(value.ToString()); }
    8383      #endregion
    8484
    8585      #region WriteLine
    86       public override void WriteLine() { usb.OnConsoleOutputChanged(Environment.NewLine); }
    87       public override void WriteLine(bool value) { usb.OnConsoleOutputChanged(value + Environment.NewLine); }
    88       public override void WriteLine(char value) { usb.OnConsoleOutputChanged(value + Environment.NewLine); }
    89       public override void WriteLine(char[] buffer) { usb.OnConsoleOutputChanged(new string(buffer) + Environment.NewLine); }
    90       public override void WriteLine(char[] buffer, int index, int count) { usb.OnConsoleOutputChanged(new string(buffer, index, count) + Environment.NewLine); }
    91       public override void WriteLine(decimal value) { usb.OnConsoleOutputChanged(value + Environment.NewLine); }
    92       public override void WriteLine(double value) { usb.OnConsoleOutputChanged(value + Environment.NewLine); }
    93       public override void WriteLine(float value) { usb.OnConsoleOutputChanged(value + Environment.NewLine); }
    94       public override void WriteLine(int value) { usb.OnConsoleOutputChanged(value + Environment.NewLine); }
    95       public override void WriteLine(long value) { usb.OnConsoleOutputChanged(value + Environment.NewLine); }
    96       public override void WriteLine(object value) { usb.OnConsoleOutputChanged(value + Environment.NewLine); }
    97       public override void WriteLine(string value) { usb.OnConsoleOutputChanged(value + Environment.NewLine); }
    98       public override void WriteLine(string format, object arg0) { usb.OnConsoleOutputChanged(string.Format(format, arg0) + Environment.NewLine); }
    99       public override void WriteLine(string format, object arg0, object arg1) { usb.OnConsoleOutputChanged(string.Format(format, arg0, arg1) + Environment.NewLine); }
    100       public override void WriteLine(string format, object arg0, object arg1, object arg2) { usb.OnConsoleOutputChanged(string.Format(format, arg0, arg1, arg2) + Environment.NewLine); }
    101       public override void WriteLine(string format, params object[] arg) { usb.OnConsoleOutputChanged(string.Format(format, arg) + Environment.NewLine); }
    102       public override void WriteLine(uint value) { usb.OnConsoleOutputChanged(value + Environment.NewLine); }
    103       public override void WriteLine(ulong value) { usb.OnConsoleOutputChanged(value + Environment.NewLine); }
     86      public override void WriteLine() { script.OnConsoleOutputChanged(Environment.NewLine); }
     87      public override void WriteLine(bool value) { script.OnConsoleOutputChanged(value + Environment.NewLine); }
     88      public override void WriteLine(char value) { script.OnConsoleOutputChanged(value + Environment.NewLine); }
     89      public override void WriteLine(char[] buffer) { script.OnConsoleOutputChanged(new string(buffer) + Environment.NewLine); }
     90      public override void WriteLine(char[] buffer, int index, int count) { script.OnConsoleOutputChanged(new string(buffer, index, count) + Environment.NewLine); }
     91      public override void WriteLine(decimal value) { script.OnConsoleOutputChanged(value + Environment.NewLine); }
     92      public override void WriteLine(double value) { script.OnConsoleOutputChanged(value + Environment.NewLine); }
     93      public override void WriteLine(float value) { script.OnConsoleOutputChanged(value + Environment.NewLine); }
     94      public override void WriteLine(int value) { script.OnConsoleOutputChanged(value + Environment.NewLine); }
     95      public override void WriteLine(long value) { script.OnConsoleOutputChanged(value + Environment.NewLine); }
     96      public override void WriteLine(object value) { script.OnConsoleOutputChanged(value + Environment.NewLine); }
     97      public override void WriteLine(string value) { script.OnConsoleOutputChanged(value + Environment.NewLine); }
     98      public override void WriteLine(string format, object arg0) { script.OnConsoleOutputChanged(string.Format(format, arg0) + Environment.NewLine); }
     99      public override void WriteLine(string format, object arg0, object arg1) { script.OnConsoleOutputChanged(string.Format(format, arg0, arg1) + Environment.NewLine); }
     100      public override void WriteLine(string format, object arg0, object arg1, object arg2) { script.OnConsoleOutputChanged(string.Format(format, arg0, arg1, arg2) + Environment.NewLine); }
     101      public override void WriteLine(string format, params object[] arg) { script.OnConsoleOutputChanged(string.Format(format, arg) + Environment.NewLine); }
     102      public override void WriteLine(uint value) { script.OnConsoleOutputChanged(value + Environment.NewLine); }
     103      public override void WriteLine(ulong value) { script.OnConsoleOutputChanged(value + Environment.NewLine); }
    104104      #endregion
    105105      #endregion
  • stable/HeuristicLab.Scripting/3.3/HeuristicLab.Scripting-3.3.csproj

    r10506 r10892  
    8585  </ItemGroup>
    8686  <ItemGroup>
     87    <Compile Include="CSharpScript.cs" />
     88    <Compile Include="Variables.cs" />
    8789    <Compile Include="VariableStore.cs" />
    8890    <None Include="Plugin.cs.frame" />
    8991    <Compile Include="Script.cs" />
    90     <Compile Include="UserScriptBase.cs" />
     92    <Compile Include="CSharpScriptBase.cs" />
    9193    <Compile Include="Plugin.cs" />
    9294    <Compile Include="Properties\AssemblyInfo.cs" />
  • stable/HeuristicLab.Scripting/3.3/Script.cs

    r10506 r10892  
    2929using System.Reflection;
    3030using System.Text;
    31 using System.Text.RegularExpressions;
    32 using System.Threading;
    3331using HeuristicLab.Common;
    3432using HeuristicLab.Common.Resources;
     
    3836
    3937namespace HeuristicLab.Scripting {
    40   [Item("Script", "An empty C# script.")]
    41   [Creatable("Scripts")]
    4238  [StorableClass]
    43   public sealed class Script : NamedItem, IStorableContent {
    44     #region Constants
    45     private const string ExecuteMethodName = "Execute";
    46     private const string CodeTemplate =
    47 @"// use 'vars' to access global variables in the variable store
    48 
    49 using System;
    50 using System.Linq;
    51 using System.Collections.Generic;
    52 using HeuristicLab.Common;
    53 using HeuristicLab.Core;
    54 using HeuristicLab.Data;
    55 
    56 public class UserScript : HeuristicLab.Scripting.UserScriptBase {
    57   public override void Main() {
    58     // type your code here
    59   }
    60 
    61   // further classes and methods
    62 
    63 }";
    64     #endregion
     39  public class Script : NamedItem {
     40    protected virtual string CodeTemplate {
     41      get { return string.Empty; }
     42    }
    6543
    6644    #region Fields & Properties
    67     private UserScriptBase compiledScript;
    68 
    69     public string Filename { get; set; }
    70 
    7145    public static new Image StaticItemImage {
    7246      get { return VSImageLibrary.Script; }
    73     }
    74 
    75     [Storable]
    76     private VariableStore variableStore;
    77     public VariableStore VariableStore {
    78       get { return variableStore; }
    7947    }
    8048
     
    8654        if (value == code) return;
    8755        code = value;
    88         compiledScript = null;
    8956        OnCodeChanged();
    9057      }
    91     }
    92 
    93     private string compilationUnitCode;
    94     public string CompilationUnitCode {
    95       get { return compilationUnitCode; }
    9658    }
    9759
     
    10870    #region Construction & Initialization
    10971    [StorableConstructor]
    110     private Script(bool deserializing) : base(deserializing) { }
    111     private Script(Script original, Cloner cloner)
     72    protected Script(bool deserializing) : base(deserializing) { }
     73    protected Script(Script original, Cloner cloner)
    11274      : base(original, cloner) {
    11375      code = original.code;
    114       variableStore = new VariableStore();
    115       compilationUnitCode = original.compilationUnitCode;
    11676      if (original.compileErrors != null)
    11777        compileErrors = new CompilerErrorCollection(original.compileErrors);
    11878    }
    119 
    12079    public Script()
    121       : base("Script", "A HeuristicLab script.") {
    122       code = CodeTemplate;
    123       variableStore = new VariableStore();
     80      : base("Script", "An empty script.") {
     81      code = string.Empty;
     82    }
     83    public Script(string code)
     84      : this() {
     85      this.code = code;
    12486    }
    12587
     
    12991    #endregion
    13092
    131     private void RegisterScriptEvents() {
    132       if (compiledScript == null) return;
    133       compiledScript.ConsoleOutputChanged += compiledScript_ConsoleOutputChanged;
     93    #region Compilation
     94    protected virtual CSharpCodeProvider CodeProvider {
     95      get {
     96        return new CSharpCodeProvider(
     97          new Dictionary<string, string> {
     98                {"CompilerVersion", "v4.0"}, // support C# 4.0 syntax
     99              });
     100      }
    134101    }
    135102
    136     private void DeregisterScriptEvents() {
    137       if (compiledScript == null) return;
    138       compiledScript.ConsoleOutputChanged -= compiledScript_ConsoleOutputChanged;
    139     }
    140 
    141     #region Compilation
    142     private CSharpCodeProvider codeProvider =
    143       new CSharpCodeProvider(
    144         new Dictionary<string, string> {
    145           { "CompilerVersion", "v4.0" },  // support C# 4.0 syntax
    146         });
    147 
    148     private CompilerResults DoCompile() {
     103    protected virtual CompilerResults DoCompile() {
    149104      var parameters = new CompilerParameters {
    150105        GenerateExecutable = false,
     
    159114      var unit = CreateCompilationUnit();
    160115      var writer = new StringWriter();
    161       codeProvider.GenerateCodeFromCompileUnit(
     116      CodeProvider.GenerateCodeFromCompileUnit(
    162117        unit,
    163118        writer,
     
    166121          IndentString = "  ",
    167122        });
    168       compilationUnitCode = writer.ToString();
    169       return codeProvider.CompileAssemblyFromDom(parameters, unit);
     123      return CodeProvider.CompileAssemblyFromDom(parameters, unit);
    170124    }
    171125
    172     public void Compile() {
     126    public virtual Assembly Compile() {
    173127      var results = DoCompile();
    174       compiledScript = null;
    175128      CompileErrors = results.Errors;
    176129      if (results.Errors.HasErrors) {
     
    181134            .AppendLine(error.ErrorText);
    182135        }
    183         throw new Exception(string.Format(
    184           "Compilation of \"{0}\" failed:{1}{2}",
    185           Name, Environment.NewLine,
    186           sb.ToString()));
     136        throw new Exception(string.Format("Compilation of \"{0}\" failed:{1}{2}",
     137          Name, Environment.NewLine, sb.ToString()));
    187138      } else {
    188         var assembly = results.CompiledAssembly;
    189         var types = assembly.GetTypes();
    190         DeregisterScriptEvents();
    191         compiledScript = (UserScriptBase)Activator.CreateInstance(types[0]);
    192         RegisterScriptEvents();
     139        return results.CompiledAssembly;
    193140      }
    194141    }
    195142
    196     public IEnumerable<Assembly> GetAssemblies() {
     143    public virtual IEnumerable<Assembly> GetAssemblies() {
    197144      var assemblies = new List<Assembly>();
    198145      foreach (var a in AppDomain.CurrentDomain.GetAssemblies()) {
     
    210157    }
    211158
    212     private readonly Regex SafeTypeNameCharRegex = new Regex("[_a-zA-Z0-9]+");
    213     private readonly Regex SafeTypeNameRegex = new Regex("[_a-zA-Z][_a-zA-Z0-9]*");
    214 
    215     private CodeCompileUnit CreateCompilationUnit() {
     159    protected virtual CodeCompileUnit CreateCompilationUnit() {
    216160      var unit = new CodeSnippetCompileUnit(code);
    217161      return unit;
    218162    }
    219 
    220     public string CompiledTypeName {
    221       get {
    222         var sb = new StringBuilder();
    223         var strings = SafeTypeNameCharRegex.Matches(Name)
    224                                            .Cast<Match>()
    225                                            .Select(m => m.Value);
    226         foreach (string s in strings)
    227           sb.Append(s);
    228         return SafeTypeNameRegex.Match(sb.ToString()).Value;
    229       }
    230     }
    231163    #endregion
    232164
    233     private Thread scriptThread;
    234     public void Execute() {
    235       if (compiledScript == null) return;
    236       var executeMethod = typeof(UserScriptBase).GetMethod(ExecuteMethodName, BindingFlags.NonPublic | BindingFlags.Instance);
    237       if (executeMethod != null) {
    238         scriptThread = new Thread(() => {
    239           Exception ex = null;
    240           try {
    241             OnScriptExecutionStarted();
    242             executeMethod.Invoke(compiledScript, new[] { VariableStore });
    243           } catch (ThreadAbortException) {
    244             // the execution was cancelled by the user
    245           } catch (TargetInvocationException e) {
    246             ex = e.InnerException;
    247           } finally {
    248             OnScriptExecutionFinished(ex);
    249           }
    250         });
    251         scriptThread.Start();
    252       }
    253     }
    254 
    255     public void Kill() {
    256       if (scriptThread.IsAlive)
    257         scriptThread.Abort();
    258     }
    259 
    260     private void compiledScript_ConsoleOutputChanged(object sender, EventArgs<string> e) {
    261       OnConsoleOutputChanged(e.Value);
    262     }
    263 
    264165    public event EventHandler CodeChanged;
    265     private void OnCodeChanged() {
     166    protected virtual void OnCodeChanged() {
    266167      var handler = CodeChanged;
    267168      if (handler != null) handler(this, EventArgs.Empty);
     
    269170
    270171    public event EventHandler CompileErrorsChanged;
    271     private void OnCompileErrorsChanged() {
     172    protected virtual void OnCompileErrorsChanged() {
    272173      var handler = CompileErrorsChanged;
    273174      if (handler != null) handler(this, EventArgs.Empty);
    274175    }
    275 
    276     public event EventHandler ScriptExecutionStarted;
    277     private void OnScriptExecutionStarted() {
    278       var handler = ScriptExecutionStarted;
    279       if (handler != null) handler(this, EventArgs.Empty);
    280     }
    281 
    282     public event EventHandler<EventArgs<Exception>> ScriptExecutionFinished;
    283     private void OnScriptExecutionFinished(Exception e) {
    284       var handler = ScriptExecutionFinished;
    285       if (handler != null) handler(this, new EventArgs<Exception>(e));
    286     }
    287 
    288     public event EventHandler<EventArgs<string>> ConsoleOutputChanged;
    289     private void OnConsoleOutputChanged(string args) {
    290       var handler = ConsoleOutputChanged;
    291       if (handler != null) handler(this, new EventArgs<string>(args));
    292     }
    293176  }
    294177}
  • stable/HeuristicLab.Scripting/3.3/UserScriptBase.cs

    r10512 r10892  
    5252      var handler = ConsoleOutputChanged;
    5353      if (handler != null) handler(null, new EventArgs<string>(args));
    54     }
    55 
    56     protected class Variables : DynamicObject, IEnumerable<KeyValuePair<string, object>> {
    57       private readonly VariableStore variableStore;
    58 
    59       public ICollection<string> Keys {
    60         get { return variableStore.Keys; }
    61       }
    62 
    63       public ICollection<object> Values {
    64         get { return variableStore.Values; }
    65       }
    66 
    67       public Variables(VariableStore variableStore) {
    68         this.variableStore = variableStore;
    69       }
    70 
    71       public override bool TryGetMember(GetMemberBinder binder, out object result) {
    72         return variableStore.TryGetValue(binder.Name, out result);
    73       }
    74 
    75       public override bool TrySetMember(SetMemberBinder binder, object value) {
    76         variableStore[binder.Name] = value;
    77         return true;
    78       }
    79 
    80       public bool Contains(string variableName) {
    81         return variableStore.ContainsKey(variableName);
    82       }
    83 
    84       public IEnumerator<KeyValuePair<string, object>> GetEnumerator() {
    85         return variableStore.GetEnumerator();
    86       }
    87 
    88       IEnumerator IEnumerable.GetEnumerator() {
    89         return GetEnumerator();
    90       }
    9154    }
    9255
  • stable/HeuristicLab.Scripting/3.3/Variables.cs

    r10566 r10892  
    66  public class Variables : DynamicObject, IEnumerable<KeyValuePair<string, object>> {
    77    private readonly VariableStore variableStore;
    8 
    9     public ICollection<string> Keys {
    10       get { return variableStore.Keys; }
    11     }
    12 
    13     public ICollection<object> Values {
    14       get { return variableStore.Values; }
    15     }
    168
    179    public Variables(VariableStore variableStore) {
     
    3224    }
    3325
     26    public void Clear() {
     27      variableStore.Clear();
     28    }
     29
    3430    public IEnumerator<KeyValuePair<string, object>> GetEnumerator() {
    3531      return variableStore.GetEnumerator();
Note: See TracChangeset for help on using the changeset viewer.