Changeset 13277 for stable/HeuristicLab.Scripting
- Timestamp:
- 11/19/15 11:29:17 (9 years ago)
- Location:
- stable
- Files:
-
- 4 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
stable
- Property svn:mergeinfo changed
/trunk/sources merged: 13024,13080,13138,13218
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Scripting/3.3/ExecutableScript.cs
r13080 r13277 52 52 executionTime = original.executionTime; 53 53 } 54 p ublicExecutableScript()54 protected ExecutableScript() 55 55 : base() { 56 56 executionTime = TimeSpan.Zero; 57 Code = CodeTemplate;58 57 } 59 p ublicExecutableScript(string code)58 protected ExecutableScript(string code) 60 59 : base(code) { 61 60 executionTime = TimeSpan.Zero; … … 85 84 timer.Elapsed -= timer_Elapsed; 86 85 timer.Stop(); 86 timer.Dispose(); 87 87 ExecutionTime += DateTime.UtcNow - lastUpdateTime; 88 88 Running = false; -
stable/HeuristicLab.Scripting/3.3/HeuristicLab.Scripting-3.3.csproj
r11920 r13277 92 92 <ItemGroup> 93 93 <Compile Include="CompilationException.cs" /> 94 <Compile Include="ExecutableScript.cs" /> 94 95 <Compile Include="Scripts\CSharp\CSharpScript.cs" /> 95 96 <Compile Include="Scripts\Templates\CSharpScriptTemplate.cs" /> -
stable/HeuristicLab.Scripting/3.3/Script.cs
r12686 r13277 37 37 namespace HeuristicLab.Scripting { 38 38 [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 { 44 40 #region Fields & Properties 45 41 public static new Image StaticItemImage { … … 77 73 compileErrors = new CompilerErrorCollection(original.compileErrors); 78 74 } 79 p ublicScript()75 protected Script() 80 76 : base("Script", "An empty script.") { 81 code = CodeTemplate;82 77 } 83 p ublicScript(string code)78 protected Script(string code) 84 79 : this() { 85 80 this.code = code; 86 }87 88 public override IDeepCloneable Clone(Cloner cloner) {89 return new Script(this, cloner);90 81 } 91 82 #endregion 92 83 93 84 #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 syntax99 });100 }101 }102 103 85 protected virtual CompilerResults DoCompile() { 104 86 var parameters = new CompilerParameters { … … 114 96 .ToArray()); 115 97 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); 117 104 } 118 105 -
stable/HeuristicLab.Scripting/3.3/Scripts/CSharp/CSharpScript.cs
r12708 r13277 23 23 using System.Linq; 24 24 using System.Reflection; 25 using System.Threading;26 25 using HeuristicLab.Common; 27 26 using HeuristicLab.Core; … … 32 31 [Creatable(CreatableAttribute.Categories.Scripts, Priority = 100)] 33 32 [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 { 40 34 #region Fields & Properties 41 35 private CSharpScriptBase compiledScript; … … 50 44 #endregion 51 45 52 #region Construction & Initialization46 #region Construction & Cloning 53 47 [StorableConstructor] 54 48 protected CSharpScript(bool deserializing) : base(deserializing) { } … … 57 51 variableStore = cloner.Clone(original.variableStore); 58 52 } 59 public CSharpScript() { 53 public CSharpScript() 54 : base(ScriptTemplates.CSharpScriptTemplate) { 60 55 variableStore = new VariableStore(); 61 Code = CodeTemplate;62 56 } 63 57 public CSharpScript(string code) … … 82 76 83 77 #region Compilation 84 85 78 public override Assembly Compile() { 86 79 DeregisterScriptEvents(); … … 94 87 #endregion 95 88 96 private Thread scriptThread; 97 public virtual void ExecuteAsync() { 89 protected override void ExecuteCode() { 98 90 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 }116 91 117 public virtual void Kill() { 118 if (scriptThread == null) return; 119 scriptThread.Abort(); 92 compiledScript.Execute(VariableStore); 120 93 } 121 94 122 95 protected virtual void CompiledScriptOnConsoleOutputChanged(object sender, EventArgs<string> e) { 123 96 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));136 97 } 137 98
Note: See TracChangeset
for help on using the changeset viewer.