Changeset 14029 for branches/crossvalidation-2434/HeuristicLab.Scripting
- Timestamp:
- 07/08/16 14:40:02 (8 years ago)
- Location:
- branches/crossvalidation-2434
- Files:
-
- 1 deleted
- 6 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/crossvalidation-2434
- Property svn:mergeinfo changed
-
branches/crossvalidation-2434/HeuristicLab.Scripting/3.3/HeuristicLab.Scripting-3.3.csproj
r11882 r14029 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" /> -
branches/crossvalidation-2434/HeuristicLab.Scripting/3.3/Plugin.cs.frame
r12753 r14029 23 23 24 24 namespace HeuristicLab.Scripting { 25 [Plugin("HeuristicLab.Scripting", "3.3.1 2.$WCREV$")]25 [Plugin("HeuristicLab.Scripting", "3.3.13.$WCREV$")] 26 26 [PluginFile("HeuristicLab.Scripting-3.3.dll", PluginFileType.Assembly)] 27 27 [PluginDependency("HeuristicLab.Collections", "3.3")] -
branches/crossvalidation-2434/HeuristicLab.Scripting/3.3/Properties/AssemblyInfo.cs.frame
r12753 r14029 55 55 // [assembly: AssemblyVersion("1.0.*")] 56 56 [assembly: AssemblyVersion("3.3.0.0")] 57 [assembly: AssemblyFileVersion("3.3.1 2.$WCREV$")]57 [assembly: AssemblyFileVersion("3.3.13.$WCREV$")] -
branches/crossvalidation-2434/HeuristicLab.Scripting/3.3/Script.cs
r12616 r14029 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 -
branches/crossvalidation-2434/HeuristicLab.Scripting/3.3/Scripts/CSharp/CSharpScript.cs
r12504 r14029 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.