Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/17/19 10:40:41 (5 years ago)
Author:
dpiringe
Message:

#2924:

  • some changes in CLIApplication.cs to reduce unnecessary allocation of string objects
  • renamed AppTest to ConsoleOptimizer and fixed race condition
  • replaced enum RunnerJob with class RunnerMessage for more control of saved data
  • changed usage of BinaryFormatter with HEAL.Attic, following types are now Storable:
    • ConsoleOptimizer
    • InspectApplication
    • ApplicationBase
    • ApplicationRunner
    • AssemblyInfo
    • Runner
    • UniPath
    • RunnerMessage
  • switched QuietMode from ApplicationRunner to IRunner
  • DockerRunnerHost can now automatically build docker images for linux and windows containers (also identifies which container type is active) -> removes the condition to have the image preinstalled
    • to achieve this, there are two new folders DockerLinuxBuild and DockerWindowsBuild included in build output, which include Dockerfiles to build images for linux and windows container
  • added NuGet package System.CodeDom to project HeuristicLab.Scripting-3.3
  • added method Send(RunnerMessage) to IRunnerHost and transferred methods Pause and Resume to IRunner
  • added internal reference of RunnerHost in Runner
  • added abstract method SendMessage(RunnerMessage) in RunnerHost which gets called from method Send(RunnerMessage)
  • because of a Google.Protobuf "bug", RunnerMessages cannot get serialized/deserialized directly on stream -> workaround with a byte array, which gets written and read
    • additionally, the length of the array gets sent first (length as integer -> 4 bytes)
    • static method in RunnerMessage to read a message from a stream
    • the method SendMessage(RunnerMessage) in RunnerHost implements this functionality
Location:
branches/2924_DotNetCoreMigration/HeuristicLab.DynamicAssemblyTestApp
Files:
2 edited
1 moved

Legend:

Unmodified
Added
Removed
  • branches/2924_DotNetCoreMigration/HeuristicLab.DynamicAssemblyTestApp/ConsoleOptimizer.cs

    r17012 r17013  
    22using System.IO;
    33using System.Threading;
     4using HEAL.Attic;
    45using HeuristicLab.Common;
    56using HeuristicLab.Core;
     
    89
    910namespace HeuristicLab.DynamicAssemblyTestApp {
    10   [Serializable]
     11  [StorableType("33B32897-258B-4E29-8E2E-0A9A8AE67B1D")]
    1112  [Application("CLIOptimize", "")]
    12   public class AppTest : ApplicationBase {
     13  public class ConsoleOptimizer : ApplicationBase {
    1314
    1415    #region Vars
    15     [NonSerialized]
    1616    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;
    2020    private static object locker = new object();
    2121    #endregion
    2222
    2323    #region Properties
     24    [Storable]
    2425    public UniPath InputFilePath { get; set; } = null;
     26    [Storable]
    2527    public UniPath OutputPath { get; set; } = null;
    2628    #endregion
    2729
    2830    #region Constructors
    29     public AppTest() { }
    30     public AppTest(UniPath inputFilePath, UniPath outputPath) {
     31    public ConsoleOptimizer() { }
     32    public ConsoleOptimizer(UniPath inputFilePath, UniPath outputPath) {
    3133      InputFilePath = inputFilePath;
    3234      OutputPath = outputPath;
     
    3436    #endregion
    3537
     38
    3639    public override void Run(ICommandLineArgument[] args) {
    37       Init();
    3840      lock (locker) {
     41        Init();
     42        executable.Started += Executable_Started;
    3943        executable.Stopped += Executable_Stopped;
     44        startedSignal.Reset();
    4045        executable.StartAsync();
     46        startedSignal.WaitOne();
    4147      }
    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();
    4356    }
    4457
    4558    public override void OnCancel() {
     59      base.OnCancel();
     60      startedSignal.WaitOne();
    4661      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();
    5064      }
    5165    }
     
    5367    public override void OnPause() {
    5468      base.OnPause();
     69      startedSignal.WaitOne();
    5570      lock (locker) {
    56         if (executable != null) executable.Pause();
     71        if (isFinished) throw new InvalidOperationException("Executable has already finished!");
     72        executable.Pause();
    5773      }
    5874    }
     
    6076    public override void OnResume() {
    6177      base.OnResume();
     78      startedSignal.WaitOne();
    6279      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();
    6584      }
    6685    }
     
    7998    private void Executable_Stopped(object sender, EventArgs e) {
    8099      lock (locker) {
     100        isFinished = true;
    81101        IOptimizer optimizer = executable as IOptimizer;
    82102        if (optimizer != null) PrintResults(optimizer);
    83103        ContentManager.Save((IStorableContent)executable, OutputPath.ToString() + Path.DirectorySeparatorChar + "result.hl", true);
    84104      }
    85       autoResetEvent.Set();
     105      stoppedSignal.Set();
    86106    }
    87107
  • branches/2924_DotNetCoreMigration/HeuristicLab.DynamicAssemblyTestApp/HeuristicLab.DynamicAssemblyTestApp.csproj

    r16991 r17013  
    1919  </ItemGroup>
    2020
     21  <ItemGroup>
     22    <Reference Include="HEAL.Attic">
     23      <HintPath>..\bin\HEAL.Attic.dll</HintPath>
     24    </Reference>
     25  </ItemGroup>
     26
    2127</Project>
  • branches/2924_DotNetCoreMigration/HeuristicLab.DynamicAssemblyTestApp/InspectApplication.cs

    r16998 r17013  
    11using System;
     2using HEAL.Attic;
    23using HeuristicLab.Common;
    34using HeuristicLab.Core;
     
    67
    78namespace HeuristicLab.DynamicAssemblyTestApp {
    8   [Serializable]
     9  [StorableType("61621E70-8A67-43A2-8EB2-233FC01E493B")]
    910  [Application("CLIInspect", "")]
    1011  public class InspectApplication : ApplicationBase {
     12    [Storable]
    1113    public UniPath InputFilePath { get; set; }
    1214
Note: See TracChangeset for help on using the changeset viewer.