Free cookie consent management tool by TermsFeed Policy Generator

Changeset 13277


Ignore:
Timestamp:
11/19/15 11:29:17 (9 years ago)
Author:
mkommend
Message:

#2298: Merged r13024, r13080, r13138, and r13218 into stable.

Location:
stable
Files:
14 edited
3 copied

Legend:

Unmodified
Added
Removed
  • stable

  • stable/HeuristicLab.Problems.ExternalEvaluation/3.4/Programmable/MultiObjectiveOptimizationSupportScript.cs

    r13259 r13277  
    3030  [StorableClass]
    3131  public sealed class MultiObjectiveOptimizationSupportScript : OptimizationSupportScript<IMultiObjectiveOptimizationSupport>, IMultiObjectiveOptimizationSupport {
    32 
    33     protected override string CodeTemplate {
    34       get { return Templates.CompiledMultiObjectiveOptimizationSupport; }
    35     }
    36 
    3732    [StorableConstructor]
    3833    private MultiObjectiveOptimizationSupportScript(bool deserializing) : base(deserializing) { }
    3934    private MultiObjectiveOptimizationSupportScript(MultiObjectiveOptimizationSupportScript original, Cloner cloner) : base(original, cloner) { }
    40     public MultiObjectiveOptimizationSupportScript() : base() { }
     35    public MultiObjectiveOptimizationSupportScript() : base(Templates.CompiledMultiObjectiveOptimizationSupport) { }
    4136
    4237    public override IDeepCloneable Clone(Cloner cloner) {
  • stable/HeuristicLab.Problems.ExternalEvaluation/3.4/Programmable/OptimizationSupportScript.cs

    r13259 r13277  
    4646    protected OptimizationSupportScript()
    4747      : base() {
     48      variableStore = new VariableStore();
     49    }
     50
     51    protected OptimizationSupportScript(string code)
     52      : base(code) {
    4853      variableStore = new VariableStore();
    4954    }
  • stable/HeuristicLab.Problems.ExternalEvaluation/3.4/Programmable/SingleObjectiveOptimizationSupportScript.cs

    r13259 r13277  
    3131  [StorableClass]
    3232  public sealed class SingleObjectiveOptimizationSupportScript : OptimizationSupportScript<ISingleObjectiveOptimizationSupport>, ISingleObjectiveOptimizationSupport {
    33 
    34     protected override string CodeTemplate {
    35       get { return Templates.CompiledSingleObjectiveOptimizationSupport; }
    36     }
    37 
    3833    [StorableConstructor]
    3934    private SingleObjectiveOptimizationSupportScript(bool deserializing) : base(deserializing) { }
    4035    private SingleObjectiveOptimizationSupportScript(SingleObjectiveOptimizationSupportScript original, Cloner cloner) : base(original, cloner) { }
    41     public SingleObjectiveOptimizationSupportScript() : base() { }
     36    public SingleObjectiveOptimizationSupportScript() : base(Templates.CompiledSingleObjectiveOptimizationSupport) { }
    4237
    4338    public override IDeepCloneable Clone(Cloner cloner) {
  • stable/HeuristicLab.Problems.Programmable/3.3/MultiObjectiveProblemDefinitionScript.cs

    r13259 r13277  
    3131    public string Filename { get; set; }
    3232
    33     protected override string CodeTemplate {
    34       get { return ScriptTemplates.CompiledMultiObjectiveProblemDefinition; }
    35     }
    36 
    3733    private new IMultiObjectiveProblemDefinition CompiledProblemDefinition {
    3834      get { return (IMultiObjectiveProblemDefinition)base.CompiledProblemDefinition; }
     
    4137    [StorableConstructor]
    4238    private MultiObjectiveProblemDefinitionScript(bool deserializing) : base(deserializing) { }
    43     private MultiObjectiveProblemDefinitionScript(MultiObjectiveProblemDefinitionScript original, Cloner cloner)
    44       : base(original, cloner) { }
    45 
    46     public MultiObjectiveProblemDefinitionScript() {
    47       Code = CodeTemplate;
    48     }
     39    private MultiObjectiveProblemDefinitionScript(MultiObjectiveProblemDefinitionScript original, Cloner cloner) : base(original, cloner) { }
     40    public MultiObjectiveProblemDefinitionScript() : base(ScriptTemplates.CompiledMultiObjectiveProblemDefinition) { }
    4941
    5042    public override IDeepCloneable Clone(Cloner cloner) {
  • stable/HeuristicLab.Problems.Programmable/3.3/ProblemDefinitionScript.cs

    r12009 r13277  
    5353    protected ProblemDefinitionScript()
    5454      : base() {
     55      variableStore = new VariableStore();
     56    }
     57    protected ProblemDefinitionScript(string code)
     58      : base(code) {
    5559      variableStore = new VariableStore();
    5660    }
  • stable/HeuristicLab.Problems.Programmable/3.3/SingleObjectiveProblemDefinitionScript.cs

    r12009 r13277  
    3232    public string Filename { get; set; }
    3333
    34     protected override string CodeTemplate {
    35       get { return ScriptTemplates.CompiledSingleObjectiveProblemDefinition; }
    36     }
    37 
    3834    private new ISingleObjectiveProblemDefinition CompiledProblemDefinition {
    3935      get { return (ISingleObjectiveProblemDefinition)base.CompiledProblemDefinition; }
     
    4339    private SingleObjectiveProblemDefinitionScript(bool deserializing) : base(deserializing) { }
    4440    private SingleObjectiveProblemDefinitionScript(SingleObjectiveProblemDefinitionScript original, Cloner cloner) : base(original, cloner) { }
    45     public SingleObjectiveProblemDefinitionScript()
    46       : base() {
    47       Code = CodeTemplate;
    48     }
     41    public SingleObjectiveProblemDefinitionScript() : base(ScriptTemplates.CompiledSingleObjectiveProblemDefinition) { }
    4942
    5043    public override IDeepCloneable Clone(Cloner cloner) {
  • stable/HeuristicLab.Scripting.Views/3.3/CSharpScriptView.Designer.cs

    r12009 r13277  
    2020#endregion
    2121
    22 using System.Windows.Forms;
    2322
    2423namespace HeuristicLab.Scripting.Views {
     
    4746    /// </summary>
    4847    private void InitializeComponent() {
    49       this.components = new System.ComponentModel.Container();
    50       this.startStopButton = new System.Windows.Forms.Button();
    5148      this.splitContainer2 = new System.Windows.Forms.SplitContainer();
    5249      this.variableStoreView = new HeuristicLab.Scripting.Views.VariableStoreView();
    5350      this.viewHost = new HeuristicLab.MainForm.WindowsForms.ViewHost();
     51      this.infoTabControl.SuspendLayout();
     52      this.outputTabPage.SuspendLayout();
     53      this.errorListTabPage.SuspendLayout();
     54      ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit();
     55      this.splitContainer1.Panel1.SuspendLayout();
     56      this.splitContainer1.Panel2.SuspendLayout();
     57      this.splitContainer1.SuspendLayout();
    5458      ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).BeginInit();
    5559      ((System.ComponentModel.ISupportInitialize)(this.splitContainer2)).BeginInit();
     
    5963      this.SuspendLayout();
    6064      //
    61       // nameTextBox
     65      // executionTimeLabel
    6266      //
    63       this.errorProvider.SetIconAlignment(this.nameTextBox, System.Windows.Forms.ErrorIconAlignment.MiddleLeft);
    64       this.errorProvider.SetIconPadding(this.nameTextBox, 2);
    65       this.nameTextBox.Location = new System.Drawing.Point(60, 0);
    66       this.nameTextBox.Size = new System.Drawing.Size(750, 20);
     67      this.executionTimeLabel.Location = new System.Drawing.Point(409, 3);
    6768      //
    68       // infoLabel
     69      // executionTimeTextBox
    6970      //
    70       this.infoLabel.Location = new System.Drawing.Point(816, 4);
     71      this.executionTimeTextBox.Location = new System.Drawing.Point(498, 0);
    7172      //
    72       // startStopButton
     73      // infoTabControl
    7374      //
    74       this.startStopButton.Image = HeuristicLab.Common.Resources.VSImageLibrary.Play;
    75       this.startStopButton.Location = new System.Drawing.Point(36, 26);
    76       this.startStopButton.Name = "startStopButton";
    77       this.startStopButton.Size = new System.Drawing.Size(24, 24);
    78       this.startStopButton.TabIndex = 1;
    79       this.startStopButton.TextImageRelation = System.Windows.Forms.TextImageRelation.ImageBeforeText;
    80       this.toolTip.SetToolTip(this.startStopButton, "Run (F5)");
    81       this.startStopButton.UseVisualStyleBackColor = true;
    82       this.startStopButton.Click += new System.EventHandler(this.StartStopButtonOnClick);
     75      this.infoTabControl.Size = new System.Drawing.Size(637, 110);
     76      //
     77      // splitContainer1
     78      //
     79      this.splitContainer1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)));
     80      this.splitContainer1.Dock = System.Windows.Forms.DockStyle.Fill;
     81      this.splitContainer1.Location = new System.Drawing.Point(0, 0);
     82      this.splitContainer1.Size = new System.Drawing.Size(637, 543);
     83      this.splitContainer1.SplitterDistance = 427;
    8384      //
    8485      // splitContainer2
     
    101102      this.splitContainer2.SplitterDistance = 637;
    102103      this.splitContainer2.TabIndex = 7;
    103       //
    104       // splitContainer1
    105       //
    106       this.splitContainer1.Location = new System.Drawing.Point(0, 0);
    107       this.splitContainer1.Dock = DockStyle.Fill;
    108104      //
    109105      // variableStoreView
     
    132128      this.viewHost.ViewType = null;
    133129      //
    134       // ScriptView
     130      // CSharpScriptView
    135131      //
    136132      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Inherit;
    137133      this.Controls.Add(this.splitContainer2);
    138       this.Controls.Add(this.startStopButton);
    139       this.Name = "ScriptView";
    140       this.Size = new System.Drawing.Size(835, 602);
     134      this.Name = "CSharpScriptView";
     135      this.Controls.SetChildIndex(this.infoTextLabel, 0);
     136      this.Controls.SetChildIndex(this.compileButton, 0);
    141137      this.Controls.SetChildIndex(this.startStopButton, 0);
    142138      this.Controls.SetChildIndex(this.splitContainer2, 0);
     
    144140      this.Controls.SetChildIndex(this.nameTextBox, 0);
    145141      this.Controls.SetChildIndex(this.infoLabel, 0);
     142      this.infoTabControl.ResumeLayout(false);
     143      this.outputTabPage.ResumeLayout(false);
     144      this.outputTabPage.PerformLayout();
     145      this.errorListTabPage.ResumeLayout(false);
     146      this.splitContainer1.Panel1.ResumeLayout(false);
     147      this.splitContainer1.Panel2.ResumeLayout(false);
     148      this.splitContainer1.Panel2.PerformLayout();
     149      ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).EndInit();
     150      this.splitContainer1.ResumeLayout(false);
     151      ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).EndInit();
    146152      this.splitContainer2.Panel1.ResumeLayout(false);
    147153      this.splitContainer2.Panel2.ResumeLayout(false);
     
    155161    #endregion
    156162
    157     protected System.Windows.Forms.Button startStopButton;
    158163    protected System.Windows.Forms.SplitContainer splitContainer2;
    159164    protected MainForm.WindowsForms.ViewHost viewHost;
  • stable/HeuristicLab.Scripting.Views/3.3/CSharpScriptView.cs

    r12009 r13277  
    2121
    2222using System;
    23 using System.Drawing;
    24 using System.Threading;
    2523using System.Windows.Forms;
    2624using HeuristicLab.Common;
    27 using HeuristicLab.Common.Resources;
    2825using HeuristicLab.MainForm;
    2926
     
    3229  [View("C# Script View")]
    3330  [Content(typeof(CSharpScript), true)]
    34   public partial class CSharpScriptView : ScriptView {
    35     private const string ScriptExecutionStartedMessage = "Script execution started";
    36     private const string ScriptExecutionCanceledMessage = "Script execution canceled";
    37     private const string ScriptExecutionSuccessfulMessage = "Script execution successful";
    38     private const string ScriptExecutionFailedMessage = "Script execution failed";
    39 
    40     protected bool Running { get; set; }
     31  public partial class CSharpScriptView : ExecutableScriptView {
    4132
    4233    public new CSharpScript Content {
     
    5142    protected override void RegisterContentEvents() {
    5243      base.RegisterContentEvents();
    53       Content.ScriptExecutionStarted += ContentOnScriptExecutionStarted;
    54       Content.ScriptExecutionFinished += ContentOnScriptExecutionFinished;
    5544      Content.ConsoleOutputChanged += ContentOnConsoleOutputChanged;
    5645    }
    5746
    5847    protected override void DeregisterContentEvents() {
    59       Content.ScriptExecutionStarted -= ContentOnScriptExecutionStarted;
    60       Content.ScriptExecutionFinished -= ContentOnScriptExecutionFinished;
    6148      Content.ConsoleOutputChanged -= ContentOnConsoleOutputChanged;
    6249      base.DeregisterContentEvents();
     
    6451
    6552    #region Content event handlers
    66     protected virtual void ContentOnScriptExecutionStarted(object sender, EventArgs e) {
    67       if (InvokeRequired)
    68         Invoke((Action<object, EventArgs>)ContentOnScriptExecutionStarted, sender, e);
    69       else {
    70         Locked = true;
    71         ReadOnly = true;
    72         startStopButton.Image = VSImageLibrary.Stop;
    73         toolTip.SetToolTip(startStopButton, "Stop (Shift+F5)");
    74         UpdateInfoTextLabel(ScriptExecutionStartedMessage, SystemColors.ControlText);
    75         infoTabControl.SelectedTab = outputTabPage;
    76       }
    77     }
    78     protected virtual void ContentOnScriptExecutionFinished(object sender, EventArgs<Exception> e) {
    79       if (InvokeRequired)
    80         Invoke((Action<object, EventArgs<Exception>>)ContentOnScriptExecutionFinished, sender, e);
    81       else {
    82         Locked = false;
    83         ReadOnly = false;
    84         startStopButton.Image = VSImageLibrary.Play;
    85         toolTip.SetToolTip(startStopButton, "Run (F5)");
    86 
    87         var ex = e.Value;
    88         if (ex == null) {
    89           UpdateInfoTextLabel(ScriptExecutionSuccessfulMessage, Color.DarkGreen);
    90         } else if (ex is ThreadAbortException) {
    91           // the execution was canceled by the user
    92           UpdateInfoTextLabel(ScriptExecutionCanceledMessage, Color.DarkOrange);
    93         } else {
    94           UpdateInfoTextLabel(ScriptExecutionFailedMessage, Color.DarkRed);
    95           PluginInfrastructure.ErrorHandling.ShowErrorDialog(this, ex);
    96         }
    97 
    98         Running = false;
    99       }
    100     }
    10153    protected virtual void ContentOnConsoleOutputChanged(object sender, EventArgs<string> e) {
    10254      if (InvokeRequired)
     
    11668      }
    11769    }
    118 
    119     protected override void SetEnabledStateOfControls() {
    120       base.SetEnabledStateOfControls();
    121       startStopButton.Enabled = Content != null && (!Locked || Running);
    122     }
    123 
    124     protected virtual void StartStopButtonOnClick(object sender, EventArgs e) {
    125       if (Running) {
    126         Content.Kill();
    127       } else
    128         if (Compile()) {
    129           outputTextBox.Clear();
    130           Running = true;
    131           Content.ExecuteAsync();
    132         }
    133     }
    134 
    135     #region global HotKeys
    136     protected override bool ProcessCmdKey(ref Message msg, Keys keyData) {
    137       switch (keyData) {
    138         case Keys.F5:
    139           if (Content != null && !Locked && !Running) {
    140             if (Compile()) {
    141               outputTextBox.Clear();
    142               Content.ExecuteAsync();
    143               Running = true;
    144             }
    145           }
    146           return true;
    147         case Keys.F5 | Keys.Shift:
    148           if (Running) Content.Kill();
    149           return true;
    150         case Keys.F6:
    151           if (!Running) base.ProcessCmdKey(ref msg, keyData);
    152           return true;
    153       }
    154       return base.ProcessCmdKey(ref msg, keyData);
    155     }
    156     #endregion
    15770  }
    15871}
  • stable/HeuristicLab.Scripting.Views/3.3/ExecutableScriptView.Designer.cs

    r13080 r13277  
    3737      this.SuspendLayout();
    3838      //
    39       // splitContainer1.Panel1
     39      // splitContainer1
    4040      //
    41       this.splitContainer1.Panel1.Controls.Add(this.executionTimeTextBox);
    42       this.splitContainer1.Panel1.Controls.Add(this.executionTimeLabel);
    43       this.splitContainer1.Panel1.Controls.SetChildIndex(this.executionTimeTextBox, 0);
    44       this.splitContainer1.Panel1.Controls.SetChildIndex(this.executionTimeLabel, 0);
     41      //
     42      // splitContainer1.Panel2
     43      //
     44      this.splitContainer1.Panel2.Controls.Add(this.executionTimeLabel);
     45      this.splitContainer1.Panel2.Controls.Add(this.executionTimeTextBox);
     46      this.splitContainer1.Panel2.Controls.SetChildIndex(this.executionTimeTextBox, 0);
     47      this.splitContainer1.Panel2.Controls.SetChildIndex(this.executionTimeLabel, 0);
    4548      //
    4649      // nameTextBox
     
    6366      // executionTimeLabel
    6467      //
    65       this.executionTimeLabel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
     68      this.executionTimeLabel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
    6669      this.executionTimeLabel.AutoSize = true;
    67       this.executionTimeLabel.Location = new System.Drawing.Point(589, 396);
     70      this.executionTimeLabel.Location = new System.Drawing.Point(604, 3);
    6871      this.executionTimeLabel.Name = "executionTimeLabel";
    6972      this.executionTimeLabel.Size = new System.Drawing.Size(83, 13);
     
    7376      // executionTimeTextBox
    7477      //
    75       this.executionTimeTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
    76       this.executionTimeTextBox.Location = new System.Drawing.Point(678, 393);
     78      this.executionTimeTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
     79      this.executionTimeTextBox.Location = new System.Drawing.Point(693, 0);
    7780      this.executionTimeTextBox.Name = "executionTimeTextBox";
    7881      this.executionTimeTextBox.ReadOnly = true;
     
    98101      this.errorListTabPage.ResumeLayout(false);
    99102      this.splitContainer1.Panel1.ResumeLayout(false);
    100       this.splitContainer1.Panel1.PerformLayout();
    101103      this.splitContainer1.Panel2.ResumeLayout(false);
     104      this.splitContainer1.Panel2.PerformLayout();
    102105      ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).EndInit();
    103106      this.splitContainer1.ResumeLayout(false);
  • stable/HeuristicLab.Scripting.Views/3.3/HeuristicLab.Scripting.Views-3.3.csproj

    r11937 r13277  
    9797    <Compile Include="CSharpScriptView.Designer.cs">
    9898      <DependentUpon>CSharpScriptView.cs</DependentUpon>
     99    </Compile>
     100    <Compile Include="ExecutableScriptView.cs">
     101      <SubType>UserControl</SubType>
     102    </Compile>
     103    <Compile Include="ExecutableScriptView.Designer.cs">
     104      <DependentUpon>ExecutableScriptView.cs</DependentUpon>
    99105    </Compile>
    100106    <Compile Include="ScriptView.cs">
  • stable/HeuristicLab.Scripting.Views/3.3/ScriptView.Designer.cs

    r12662 r13277  
    118118      // infoTabControl
    119119      //
     120      this.infoTabControl.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
     121            | System.Windows.Forms.AnchorStyles.Left)
     122            | System.Windows.Forms.AnchorStyles.Right)));
    120123      this.infoTabControl.Controls.Add(this.outputTabPage);
    121124      this.infoTabControl.Controls.Add(this.errorListTabPage);
    122       this.infoTabControl.Dock = System.Windows.Forms.DockStyle.Fill;
    123       this.infoTabControl.Location = new System.Drawing.Point(0, 0);
     125      this.infoTabControl.Location = new System.Drawing.Point(0, 2);
    124126      this.infoTabControl.Name = "infoTabControl";
    125127      this.infoTabControl.SelectedIndex = 0;
    126       this.infoTabControl.Size = new System.Drawing.Size(832, 112);
     128      this.infoTabControl.Size = new System.Drawing.Size(832, 110);
    127129      this.infoTabControl.TabIndex = 1;
    128130      //
     
    133135      this.outputTabPage.Name = "outputTabPage";
    134136      this.outputTabPage.Padding = new System.Windows.Forms.Padding(3);
    135       this.outputTabPage.Size = new System.Drawing.Size(824, 86);
     137      this.outputTabPage.Size = new System.Drawing.Size(824, 84);
    136138      this.outputTabPage.TabIndex = 1;
    137139      this.outputTabPage.Text = "Output";
     
    147149      this.outputTextBox.ReadOnly = true;
    148150      this.outputTextBox.ScrollBars = System.Windows.Forms.ScrollBars.Both;
    149       this.outputTextBox.Size = new System.Drawing.Size(818, 80);
     151      this.outputTextBox.Size = new System.Drawing.Size(818, 78);
    150152      this.outputTextBox.TabIndex = 0;
    151153      this.outputTextBox.WordWrap = false;
  • stable/HeuristicLab.Scripting/3.3/ExecutableScript.cs

    r13080 r13277  
    5252      executionTime = original.executionTime;
    5353    }
    54     public ExecutableScript()
     54    protected ExecutableScript()
    5555      : base() {
    5656      executionTime = TimeSpan.Zero;
    57       Code = CodeTemplate;
    5857    }
    59     public ExecutableScript(string code)
     58    protected ExecutableScript(string code)
    6059      : base(code) {
    6160      executionTime = TimeSpan.Zero;
     
    8584        timer.Elapsed -= timer_Elapsed;
    8685        timer.Stop();
     86        timer.Dispose();
    8787        ExecutionTime += DateTime.UtcNow - lastUpdateTime;
    8888        Running = false;
  • stable/HeuristicLab.Scripting/3.3/HeuristicLab.Scripting-3.3.csproj

    r11920 r13277  
    9292  <ItemGroup>
    9393    <Compile Include="CompilationException.cs" />
     94    <Compile Include="ExecutableScript.cs" />
    9495    <Compile Include="Scripts\CSharp\CSharpScript.cs" />
    9596    <Compile Include="Scripts\Templates\CSharpScriptTemplate.cs" />
  • stable/HeuristicLab.Scripting/3.3/Script.cs

    r12686 r13277  
    3737namespace HeuristicLab.Scripting {
    3838  [StorableClass]
    39   public class Script : NamedItem, IProgrammableItem {
    40     protected virtual string CodeTemplate {
    41       get { return string.Empty; }
    42     }
    43 
     39  public abstract class Script : NamedItem, IProgrammableItem {
    4440    #region Fields & Properties
    4541    public static new Image StaticItemImage {
     
    7773        compileErrors = new CompilerErrorCollection(original.compileErrors);
    7874    }
    79     public Script()
     75    protected Script()
    8076      : base("Script", "An empty script.") {
    81       code = CodeTemplate;
    8277    }
    83     public Script(string code)
     78    protected Script(string code)
    8479      : this() {
    8580      this.code = code;
    86     }
    87 
    88     public override IDeepCloneable Clone(Cloner cloner) {
    89       return new Script(this, cloner);
    9081    }
    9182    #endregion
    9283
    9384    #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       }
    101     }
    102 
    10385    protected virtual CompilerResults DoCompile() {
    10486      var parameters = new CompilerParameters {
     
    11496        .ToArray());
    11597
    116       return CodeProvider.CompileAssemblyFromSource(parameters, code);
     98      var codeProvider = new CSharpCodeProvider(
     99        new Dictionary<string, string> {
     100          { "CompilerVersion", "v4.0"} // support C# 4.0 syntax
     101        });
     102
     103      return codeProvider.CompileAssemblyFromSource(parameters, code);
    117104    }
    118105
  • stable/HeuristicLab.Scripting/3.3/Scripts/CSharp/CSharpScript.cs

    r12708 r13277  
    2323using System.Linq;
    2424using System.Reflection;
    25 using System.Threading;
    2625using HeuristicLab.Common;
    2726using HeuristicLab.Core;
     
    3231  [Creatable(CreatableAttribute.Categories.Scripts, Priority = 100)]
    3332  [StorableClass]
    34   public class CSharpScript : Script, IStorableContent {
    35     #region Constants
    36     protected const string ExecuteMethodName = "Execute";
    37     protected override string CodeTemplate { get { return ScriptTemplates.CSharpScriptTemplate; } }
    38     #endregion
    39 
     33  public class CSharpScript : ExecutableScript, IStorableContent {
    4034    #region Fields & Properties
    4135    private CSharpScriptBase compiledScript;
     
    5044    #endregion
    5145
    52     #region Construction & Initialization
     46    #region Construction & Cloning
    5347    [StorableConstructor]
    5448    protected CSharpScript(bool deserializing) : base(deserializing) { }
     
    5751      variableStore = cloner.Clone(original.variableStore);
    5852    }
    59     public CSharpScript() {
     53    public CSharpScript()
     54      : base(ScriptTemplates.CSharpScriptTemplate) {
    6055      variableStore = new VariableStore();
    61       Code = CodeTemplate;
    6256    }
    6357    public CSharpScript(string code)
     
    8276
    8377    #region Compilation
    84 
    8578    public override Assembly Compile() {
    8679      DeregisterScriptEvents();
     
    9487    #endregion
    9588
    96     private Thread scriptThread;
    97     public virtual void ExecuteAsync() {
     89    protected override void ExecuteCode() {
    9890      if (compiledScript == null) return;
    99       scriptThread = new Thread(() => {
    100         Exception ex = null;
    101         try {
    102           OnScriptExecutionStarted();
    103           compiledScript.Execute(VariableStore);
    104         }
    105         catch (Exception e) {
    106           ex = e;
    107         }
    108         finally {
    109           scriptThread = null;
    110           OnScriptExecutionFinished(ex);
    111         }
    112       });
    113       scriptThread.SetApartmentState(ApartmentState.STA);
    114       scriptThread.Start();
    115     }
    11691
    117     public virtual void Kill() {
    118       if (scriptThread == null) return;
    119       scriptThread.Abort();
     92      compiledScript.Execute(VariableStore);
    12093    }
    12194
    12295    protected virtual void CompiledScriptOnConsoleOutputChanged(object sender, EventArgs<string> e) {
    12396      OnConsoleOutputChanged(e.Value);
    124     }
    125 
    126     public event EventHandler ScriptExecutionStarted;
    127     protected virtual void OnScriptExecutionStarted() {
    128       var handler = ScriptExecutionStarted;
    129       if (handler != null) handler(this, EventArgs.Empty);
    130     }
    131 
    132     public event EventHandler<EventArgs<Exception>> ScriptExecutionFinished;
    133     protected virtual void OnScriptExecutionFinished(Exception e) {
    134       var handler = ScriptExecutionFinished;
    135       if (handler != null) handler(this, new EventArgs<Exception>(e));
    13697    }
    13798
Note: See TracChangeset for help on using the changeset viewer.