Free cookie consent management tool by TermsFeed Policy Generator

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:
2 edited

Legend:

Unmodified
Added
Removed
  • stable

  • 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.