Changeset 3865 for trunk/sources/HeuristicLab.Problems.ExternalEvaluation
- Timestamp:
- 05/27/10 20:27:41 (15 years ago)
- Location:
- trunk/sources/HeuristicLab.Problems.ExternalEvaluation/3.3
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.ExternalEvaluation/3.3/Drivers/ExternalEvaluationDriver.cs
r3864 r3865 31 31 public bool IsInitialized { get; protected set; } 32 32 33 protected ExternalEvaluationDriver() 34 : base() { 35 name = ItemName; 36 description = ItemDescription; 37 } 38 33 39 #region IExternalEvaluationDriver Members 34 40 -
trunk/sources/HeuristicLab.Problems.ExternalEvaluation/3.3/Drivers/ExternalEvaluationProcessDriver.cs
r3864 r3865 23 23 using System.Diagnostics; 24 24 using System.IO; 25 using HeuristicLab.Common; 25 26 using HeuristicLab.Core; 26 27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; … … 30 31 [StorableClass] 31 32 public class ExternalEvaluationProcessDriver : ExternalEvaluationDriver { 33 public override bool CanChangeName { get { return false; } } 34 public override bool CanChangeDescription { get { return false; } } 35 32 36 private Process process; 33 37 [Storable] 34 38 private string executable; 39 public string Executable { 40 get { return executable; } 41 set { 42 if (IsInitialized) throw new InvalidOperationException("ExternalEvaluationProcessDriver cannot change the executable path as it has already been started."); 43 string oldExecutable = executable; 44 executable = value; 45 if (!oldExecutable.Equals(executable)) OnExecutableChanged(); 46 } 47 } 35 48 [Storable] 36 49 private string arguments; 50 public string Arguments { 51 get { return arguments; } 52 set { 53 if (IsInitialized) throw new InvalidOperationException("ExternalEvaluationProcessDriver cannot change the arguments as it has already been started."); 54 string oldArguments = arguments; 55 arguments = value; 56 if (!oldArguments.Equals(arguments)) OnArgumentsChanged(); 57 } 58 } 37 59 private ExternalEvaluationStreamDriver driver; 38 60 … … 44 66 } 45 67 68 public override IDeepCloneable Clone(Cloner cloner) { 69 ExternalEvaluationProcessDriver clone = (ExternalEvaluationProcessDriver)base.Clone(cloner); 70 clone.executable = executable; 71 clone.arguments = arguments; 72 return clone; 73 } 74 46 75 #region IExternalDriver Members 47 76 48 77 public override void Start() { 49 base.Start(); 50 process = new Process(); 51 process.StartInfo = new ProcessStartInfo(executable, arguments); 52 process.StartInfo.UseShellExecute = false; 53 process.StartInfo.RedirectStandardInput = true; 54 process.StartInfo.RedirectStandardOutput = true; 55 process.Start(); 56 Stream processStdOut = process.StandardOutput.BaseStream; 57 Stream processStdIn = process.StandardInput.BaseStream; 58 driver = new ExternalEvaluationStreamDriver(processStdOut, processStdIn); 59 driver.Start(); 78 if (!String.IsNullOrEmpty(executable.Trim())) { 79 base.Start(); 80 process = new Process(); 81 process.StartInfo = new ProcessStartInfo(executable, arguments); 82 process.StartInfo.UseShellExecute = false; 83 process.StartInfo.RedirectStandardInput = true; 84 process.StartInfo.RedirectStandardOutput = true; 85 process.EnableRaisingEvents = true; // required to be notified of exit 86 process.Start(); 87 Stream processStdOut = process.StandardOutput.BaseStream; 88 Stream processStdIn = process.StandardInput.BaseStream; 89 OnProcessStarted(); 90 process.Exited += new EventHandler(process_Exited); 91 driver = new ExternalEvaluationStreamDriver(processStdOut, processStdIn); 92 driver.Start(); 93 } else throw new InvalidOperationException("Cannot start ExternalEvaluationProcessDriver because executable is not defined."); 60 94 } 61 95 … … 70 104 public override void Stop() { 71 105 base.Stop(); 72 if (!process.HasExited) { 73 driver.Stop(); 106 if (process != null) { 74 107 if (!process.HasExited) { 75 process.CloseMainWindow(); 76 process.WaitForExit(1000); 77 process.Close(); 108 driver.Stop(); 109 if (!process.HasExited) { 110 process.CloseMainWindow(); 111 process.WaitForExit(1000); 112 process.Close(); 113 // for some reasons the event process_Exited does not fire 114 OnProcessExited(); 115 } 78 116 } 117 process = null; 79 118 } 80 process = null;81 119 } 82 120 83 121 #endregion 122 123 #region Event handlers (process) 124 private void process_Exited(object sender, EventArgs e) { 125 if (IsInitialized) { 126 if (driver.IsInitialized) driver.Stop(); 127 IsInitialized = false; 128 process = null; 129 } 130 OnProcessExited(); 131 } 132 #endregion 133 134 #region Events 135 public event EventHandler ExecutableChanged; 136 protected void OnExecutableChanged() { 137 EventHandler handler = ExecutableChanged; 138 if (handler != null) handler(this, EventArgs.Empty); 139 } 140 141 public event EventHandler ArgumentsChanged; 142 protected void OnArgumentsChanged() { 143 EventHandler handler = ArgumentsChanged; 144 if (handler != null) handler(this, EventArgs.Empty); 145 } 146 147 public event EventHandler ProcessStarted; 148 private void OnProcessStarted() { 149 EventHandler handler = ProcessStarted; 150 if (handler != null) handler(this, EventArgs.Empty); 151 } 152 153 public event EventHandler ProcessExited; 154 private void OnProcessExited() { 155 EventHandler handler = ProcessExited; 156 if (handler != null) handler(this, EventArgs.Empty); 157 } 158 #endregion 84 159 } 85 160 } -
trunk/sources/HeuristicLab.Problems.ExternalEvaluation/3.3/Drivers/ExternalEvaluationStreamDriver.cs
r3862 r3865 30 30 [StorableClass] 31 31 public class ExternalEvaluationStreamDriver : ExternalEvaluationDriver { 32 public override bool CanChangeName { get { return false; } } 33 public override bool CanChangeDescription { get { return false; } } 34 32 35 private CodedInputStream inputStream; 33 36 private Stream input; -
trunk/sources/HeuristicLab.Problems.ExternalEvaluation/3.3/Properties/AssemblyInfo.frame
r3862 r3865 7 7 // associated with an assembly. 8 8 [assembly: AssemblyTitle("HeuristicLab.Problems.ExternalEvaluation")] 9 [assembly: AssemblyDescription("Plugin sfor Problems that are evaluated outside of HeuristicLab.")]9 [assembly: AssemblyDescription("Plugin for Problems that are evaluated outside of HeuristicLab.")] 10 10 [assembly: AssemblyConfiguration("")] 11 11 [assembly: AssemblyCompany("")]
Note: See TracChangeset
for help on using the changeset viewer.