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:
4 edited
1 copied

Legend:

Unmodified
Added
Removed
  • stable

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