Changeset 13277
- Timestamp:
- 11/19/15 11:29:17 (9 years ago)
- Location:
- stable
- Files:
-
- 14 edited
- 3 copied
Legend:
- Unmodified
- Added
- Removed
-
stable
- Property svn:mergeinfo changed
/trunk/sources merged: 13024,13080,13138,13218
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Problems.ExternalEvaluation/3.4/Programmable/MultiObjectiveOptimizationSupportScript.cs
r13259 r13277 30 30 [StorableClass] 31 31 public sealed class MultiObjectiveOptimizationSupportScript : OptimizationSupportScript<IMultiObjectiveOptimizationSupport>, IMultiObjectiveOptimizationSupport { 32 33 protected override string CodeTemplate {34 get { return Templates.CompiledMultiObjectiveOptimizationSupport; }35 }36 37 32 [StorableConstructor] 38 33 private MultiObjectiveOptimizationSupportScript(bool deserializing) : base(deserializing) { } 39 34 private MultiObjectiveOptimizationSupportScript(MultiObjectiveOptimizationSupportScript original, Cloner cloner) : base(original, cloner) { } 40 public MultiObjectiveOptimizationSupportScript() : base( ) { }35 public MultiObjectiveOptimizationSupportScript() : base(Templates.CompiledMultiObjectiveOptimizationSupport) { } 41 36 42 37 public override IDeepCloneable Clone(Cloner cloner) { -
stable/HeuristicLab.Problems.ExternalEvaluation/3.4/Programmable/OptimizationSupportScript.cs
r13259 r13277 46 46 protected OptimizationSupportScript() 47 47 : base() { 48 variableStore = new VariableStore(); 49 } 50 51 protected OptimizationSupportScript(string code) 52 : base(code) { 48 53 variableStore = new VariableStore(); 49 54 } -
stable/HeuristicLab.Problems.ExternalEvaluation/3.4/Programmable/SingleObjectiveOptimizationSupportScript.cs
r13259 r13277 31 31 [StorableClass] 32 32 public sealed class SingleObjectiveOptimizationSupportScript : OptimizationSupportScript<ISingleObjectiveOptimizationSupport>, ISingleObjectiveOptimizationSupport { 33 34 protected override string CodeTemplate {35 get { return Templates.CompiledSingleObjectiveOptimizationSupport; }36 }37 38 33 [StorableConstructor] 39 34 private SingleObjectiveOptimizationSupportScript(bool deserializing) : base(deserializing) { } 40 35 private SingleObjectiveOptimizationSupportScript(SingleObjectiveOptimizationSupportScript original, Cloner cloner) : base(original, cloner) { } 41 public SingleObjectiveOptimizationSupportScript() : base( ) { }36 public SingleObjectiveOptimizationSupportScript() : base(Templates.CompiledSingleObjectiveOptimizationSupport) { } 42 37 43 38 public override IDeepCloneable Clone(Cloner cloner) { -
stable/HeuristicLab.Problems.Programmable/3.3/MultiObjectiveProblemDefinitionScript.cs
r13259 r13277 31 31 public string Filename { get; set; } 32 32 33 protected override string CodeTemplate {34 get { return ScriptTemplates.CompiledMultiObjectiveProblemDefinition; }35 }36 37 33 private new IMultiObjectiveProblemDefinition CompiledProblemDefinition { 38 34 get { return (IMultiObjectiveProblemDefinition)base.CompiledProblemDefinition; } … … 41 37 [StorableConstructor] 42 38 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) { } 49 41 50 42 public override IDeepCloneable Clone(Cloner cloner) { -
stable/HeuristicLab.Problems.Programmable/3.3/ProblemDefinitionScript.cs
r12009 r13277 53 53 protected ProblemDefinitionScript() 54 54 : base() { 55 variableStore = new VariableStore(); 56 } 57 protected ProblemDefinitionScript(string code) 58 : base(code) { 55 59 variableStore = new VariableStore(); 56 60 } -
stable/HeuristicLab.Problems.Programmable/3.3/SingleObjectiveProblemDefinitionScript.cs
r12009 r13277 32 32 public string Filename { get; set; } 33 33 34 protected override string CodeTemplate {35 get { return ScriptTemplates.CompiledSingleObjectiveProblemDefinition; }36 }37 38 34 private new ISingleObjectiveProblemDefinition CompiledProblemDefinition { 39 35 get { return (ISingleObjectiveProblemDefinition)base.CompiledProblemDefinition; } … … 43 39 private SingleObjectiveProblemDefinitionScript(bool deserializing) : base(deserializing) { } 44 40 private SingleObjectiveProblemDefinitionScript(SingleObjectiveProblemDefinitionScript original, Cloner cloner) : base(original, cloner) { } 45 public SingleObjectiveProblemDefinitionScript() 46 : base() { 47 Code = CodeTemplate; 48 } 41 public SingleObjectiveProblemDefinitionScript() : base(ScriptTemplates.CompiledSingleObjectiveProblemDefinition) { } 49 42 50 43 public override IDeepCloneable Clone(Cloner cloner) { -
stable/HeuristicLab.Scripting.Views/3.3/CSharpScriptView.Designer.cs
r12009 r13277 20 20 #endregion 21 21 22 using System.Windows.Forms;23 22 24 23 namespace HeuristicLab.Scripting.Views { … … 47 46 /// </summary> 48 47 private void InitializeComponent() { 49 this.components = new System.ComponentModel.Container();50 this.startStopButton = new System.Windows.Forms.Button();51 48 this.splitContainer2 = new System.Windows.Forms.SplitContainer(); 52 49 this.variableStoreView = new HeuristicLab.Scripting.Views.VariableStoreView(); 53 50 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(); 54 58 ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).BeginInit(); 55 59 ((System.ComponentModel.ISupportInitialize)(this.splitContainer2)).BeginInit(); … … 59 63 this.SuspendLayout(); 60 64 // 61 // nameTextBox65 // executionTimeLabel 62 66 // 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); 67 68 // 68 // infoLabel69 // executionTimeTextBox 69 70 // 70 this. infoLabel.Location = new System.Drawing.Point(816, 4);71 this.executionTimeTextBox.Location = new System.Drawing.Point(498, 0); 71 72 // 72 // startStopButton73 // infoTabControl 73 74 // 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.s tartStopButton.TabIndex = 1;79 this.s tartStopButton.TextImageRelation = System.Windows.Forms.TextImageRelation.ImageBeforeText;80 this. toolTip.SetToolTip(this.startStopButton, "Run (F5)");81 this.s tartStopButton.UseVisualStyleBackColor = true;82 this.s tartStopButton.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; 83 84 // 84 85 // splitContainer2 … … 101 102 this.splitContainer2.SplitterDistance = 637; 102 103 this.splitContainer2.TabIndex = 7; 103 //104 // splitContainer1105 //106 this.splitContainer1.Location = new System.Drawing.Point(0, 0);107 this.splitContainer1.Dock = DockStyle.Fill;108 104 // 109 105 // variableStoreView … … 132 128 this.viewHost.ViewType = null; 133 129 // 134 // ScriptView130 // CSharpScriptView 135 131 // 136 132 this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Inherit; 137 133 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); 141 137 this.Controls.SetChildIndex(this.startStopButton, 0); 142 138 this.Controls.SetChildIndex(this.splitContainer2, 0); … … 144 140 this.Controls.SetChildIndex(this.nameTextBox, 0); 145 141 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(); 146 152 this.splitContainer2.Panel1.ResumeLayout(false); 147 153 this.splitContainer2.Panel2.ResumeLayout(false); … … 155 161 #endregion 156 162 157 protected System.Windows.Forms.Button startStopButton;158 163 protected System.Windows.Forms.SplitContainer splitContainer2; 159 164 protected MainForm.WindowsForms.ViewHost viewHost; -
stable/HeuristicLab.Scripting.Views/3.3/CSharpScriptView.cs
r12009 r13277 21 21 22 22 using System; 23 using System.Drawing;24 using System.Threading;25 23 using System.Windows.Forms; 26 24 using HeuristicLab.Common; 27 using HeuristicLab.Common.Resources;28 25 using HeuristicLab.MainForm; 29 26 … … 32 29 [View("C# Script View")] 33 30 [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 { 41 32 42 33 public new CSharpScript Content { … … 51 42 protected override void RegisterContentEvents() { 52 43 base.RegisterContentEvents(); 53 Content.ScriptExecutionStarted += ContentOnScriptExecutionStarted;54 Content.ScriptExecutionFinished += ContentOnScriptExecutionFinished;55 44 Content.ConsoleOutputChanged += ContentOnConsoleOutputChanged; 56 45 } 57 46 58 47 protected override void DeregisterContentEvents() { 59 Content.ScriptExecutionStarted -= ContentOnScriptExecutionStarted;60 Content.ScriptExecutionFinished -= ContentOnScriptExecutionFinished;61 48 Content.ConsoleOutputChanged -= ContentOnConsoleOutputChanged; 62 49 base.DeregisterContentEvents(); … … 64 51 65 52 #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 user92 UpdateInfoTextLabel(ScriptExecutionCanceledMessage, Color.DarkOrange);93 } else {94 UpdateInfoTextLabel(ScriptExecutionFailedMessage, Color.DarkRed);95 PluginInfrastructure.ErrorHandling.ShowErrorDialog(this, ex);96 }97 98 Running = false;99 }100 }101 53 protected virtual void ContentOnConsoleOutputChanged(object sender, EventArgs<string> e) { 102 54 if (InvokeRequired) … … 116 68 } 117 69 } 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 } else128 if (Compile()) {129 outputTextBox.Clear();130 Running = true;131 Content.ExecuteAsync();132 }133 }134 135 #region global HotKeys136 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 #endregion157 70 } 158 71 } -
stable/HeuristicLab.Scripting.Views/3.3/ExecutableScriptView.Designer.cs
r13080 r13277 37 37 this.SuspendLayout(); 38 38 // 39 // splitContainer1 .Panel139 // splitContainer1 40 40 // 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); 45 48 // 46 49 // nameTextBox … … 63 66 // executionTimeLabel 64 67 // 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))); 66 69 this.executionTimeLabel.AutoSize = true; 67 this.executionTimeLabel.Location = new System.Drawing.Point( 589, 396);70 this.executionTimeLabel.Location = new System.Drawing.Point(604, 3); 68 71 this.executionTimeLabel.Name = "executionTimeLabel"; 69 72 this.executionTimeLabel.Size = new System.Drawing.Size(83, 13); … … 73 76 // executionTimeTextBox 74 77 // 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(6 78, 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); 77 80 this.executionTimeTextBox.Name = "executionTimeTextBox"; 78 81 this.executionTimeTextBox.ReadOnly = true; … … 98 101 this.errorListTabPage.ResumeLayout(false); 99 102 this.splitContainer1.Panel1.ResumeLayout(false); 100 this.splitContainer1.Panel1.PerformLayout();101 103 this.splitContainer1.Panel2.ResumeLayout(false); 104 this.splitContainer1.Panel2.PerformLayout(); 102 105 ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).EndInit(); 103 106 this.splitContainer1.ResumeLayout(false); -
stable/HeuristicLab.Scripting.Views/3.3/HeuristicLab.Scripting.Views-3.3.csproj
r11937 r13277 97 97 <Compile Include="CSharpScriptView.Designer.cs"> 98 98 <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> 99 105 </Compile> 100 106 <Compile Include="ScriptView.cs"> -
stable/HeuristicLab.Scripting.Views/3.3/ScriptView.Designer.cs
r12662 r13277 118 118 // infoTabControl 119 119 // 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))); 120 123 this.infoTabControl.Controls.Add(this.outputTabPage); 121 124 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); 124 126 this.infoTabControl.Name = "infoTabControl"; 125 127 this.infoTabControl.SelectedIndex = 0; 126 this.infoTabControl.Size = new System.Drawing.Size(832, 11 2);128 this.infoTabControl.Size = new System.Drawing.Size(832, 110); 127 129 this.infoTabControl.TabIndex = 1; 128 130 // … … 133 135 this.outputTabPage.Name = "outputTabPage"; 134 136 this.outputTabPage.Padding = new System.Windows.Forms.Padding(3); 135 this.outputTabPage.Size = new System.Drawing.Size(824, 8 6);137 this.outputTabPage.Size = new System.Drawing.Size(824, 84); 136 138 this.outputTabPage.TabIndex = 1; 137 139 this.outputTabPage.Text = "Output"; … … 147 149 this.outputTextBox.ReadOnly = true; 148 150 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); 150 152 this.outputTextBox.TabIndex = 0; 151 153 this.outputTextBox.WordWrap = false; -
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.