- Timestamp:
- 06/17/19 10:40:41 (5 years ago)
- Location:
- branches/2924_DotNetCoreMigration/HeuristicLab.DynamicAssemblyTestApp
- Files:
-
- 2 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
branches/2924_DotNetCoreMigration/HeuristicLab.DynamicAssemblyTestApp/ConsoleOptimizer.cs
r17012 r17013 2 2 using System.IO; 3 3 using System.Threading; 4 using HEAL.Attic; 4 5 using HeuristicLab.Common; 5 6 using HeuristicLab.Core; … … 8 9 9 10 namespace HeuristicLab.DynamicAssemblyTestApp { 10 [S erializable]11 [StorableType("33B32897-258B-4E29-8E2E-0A9A8AE67B1D")] 11 12 [Application("CLIOptimize", "")] 12 public class AppTest: ApplicationBase {13 public class ConsoleOptimizer : ApplicationBase { 13 14 14 15 #region Vars 15 [NonSerialized]16 16 private IExecutable executable; 17 [NonSerialized]18 private static AutoResetEvent autoResetEvent = new AutoResetEvent(false);19 [NonSerialized]17 private readonly ManualResetEvent stoppedSignal = new ManualResetEvent(false); 18 private readonly ManualResetEvent startedSignal = new ManualResetEvent(false); 19 private bool isFinished = false; 20 20 private static object locker = new object(); 21 21 #endregion 22 22 23 23 #region Properties 24 [Storable] 24 25 public UniPath InputFilePath { get; set; } = null; 26 [Storable] 25 27 public UniPath OutputPath { get; set; } = null; 26 28 #endregion 27 29 28 30 #region Constructors 29 public AppTest() { }30 public AppTest(UniPath inputFilePath, UniPath outputPath) {31 public ConsoleOptimizer() { } 32 public ConsoleOptimizer(UniPath inputFilePath, UniPath outputPath) { 31 33 InputFilePath = inputFilePath; 32 34 OutputPath = outputPath; … … 34 36 #endregion 35 37 38 36 39 public override void Run(ICommandLineArgument[] args) { 37 Init();38 40 lock (locker) { 41 Init(); 42 executable.Started += Executable_Started; 39 43 executable.Stopped += Executable_Stopped; 44 startedSignal.Reset(); 40 45 executable.StartAsync(); 46 startedSignal.WaitOne(); 41 47 } 42 autoResetEvent.WaitOne(); 48 stoppedSignal.WaitOne(); 49 50 startedSignal.Close(); 51 stoppedSignal.Close(); 52 } 53 54 private void Executable_Started(object sender, EventArgs e) { 55 startedSignal.Set(); 43 56 } 44 57 45 58 public override void OnCancel() { 59 base.OnCancel(); 60 startedSignal.WaitOne(); 46 61 lock (locker) { 47 base.OnCancel(); 48 if (executable != null) 49 executable.Stop(); 62 if (isFinished) throw new InvalidOperationException("Executable has already finished!"); 63 executable.Stop(); 50 64 } 51 65 } … … 53 67 public override void OnPause() { 54 68 base.OnPause(); 69 startedSignal.WaitOne(); 55 70 lock (locker) { 56 if (executable != null) executable.Pause(); 71 if (isFinished) throw new InvalidOperationException("Executable has already finished!"); 72 executable.Pause(); 57 73 } 58 74 } … … 60 76 public override void OnResume() { 61 77 base.OnResume(); 78 startedSignal.WaitOne(); 62 79 lock (locker) { 63 if (executable != null) 64 executable.StartAsync(); 80 if (isFinished) throw new InvalidOperationException("Executable has already finished!"); 81 startedSignal.Reset(); 82 executable.StartAsync(); 83 startedSignal.WaitOne(); 65 84 } 66 85 } … … 79 98 private void Executable_Stopped(object sender, EventArgs e) { 80 99 lock (locker) { 100 isFinished = true; 81 101 IOptimizer optimizer = executable as IOptimizer; 82 102 if (optimizer != null) PrintResults(optimizer); 83 103 ContentManager.Save((IStorableContent)executable, OutputPath.ToString() + Path.DirectorySeparatorChar + "result.hl", true); 84 104 } 85 autoResetEvent.Set();105 stoppedSignal.Set(); 86 106 } 87 107 -
branches/2924_DotNetCoreMigration/HeuristicLab.DynamicAssemblyTestApp/HeuristicLab.DynamicAssemblyTestApp.csproj
r16991 r17013 19 19 </ItemGroup> 20 20 21 <ItemGroup> 22 <Reference Include="HEAL.Attic"> 23 <HintPath>..\bin\HEAL.Attic.dll</HintPath> 24 </Reference> 25 </ItemGroup> 26 21 27 </Project> -
branches/2924_DotNetCoreMigration/HeuristicLab.DynamicAssemblyTestApp/InspectApplication.cs
r16998 r17013 1 1 using System; 2 using HEAL.Attic; 2 3 using HeuristicLab.Common; 3 4 using HeuristicLab.Core; … … 6 7 7 8 namespace HeuristicLab.DynamicAssemblyTestApp { 8 [S erializable]9 [StorableType("61621E70-8A67-43A2-8EB2-233FC01E493B")] 9 10 [Application("CLIInspect", "")] 10 11 public class InspectApplication : ApplicationBase { 12 [Storable] 11 13 public UniPath InputFilePath { get; set; } 12 14
Note: See TracChangeset
for help on using the changeset viewer.