Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2924_DotNetCoreMigration/HeuristicLab/3.3/ApplicationCommand.cs @ 17013

Last change on this file since 17013 was 17013, checked in by dpiringe, 5 years ago

#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
File size: 2.0 KB
Line 
1using System;
2using System.IO;
3using HeuristicLab.CommandLineInterface;
4using HeuristicLab.PluginInfrastructure;
5
6namespace HeuristicLab {
7
8  public enum IsolationType {
9    Docker,
10    Native
11  }
12
13  [CommandLineInterface.Application(
14    "HL", "1.0.0.0",
15    SubCommands = new Type[] {
16      typeof(OptimizeCommand),
17      typeof(BuildCommand),
18      typeof(InspectCommand)
19    }
20  )]
21  class ApplicationCommand : ICommand {
22
23    [Option(Description = "Sets the path for the binaries.")]
24    public string BasePath { get; set; }
25
26    [Option(Shortcut = "i", Description = "Sets the isolation type. Possible types are: NATIVE or DOCKER.")]
27    public IsolationType Isolation { get; set; }
28
29    [Option]
30    private bool StartAsRunnerHost { get; set; }
31
32    public void Execute() {
33      if (StartAsRunnerHost) {
34        StartupRunnerHost();
35      } else {
36        SetupIsolation();
37      }
38    }
39
40    private void StartupRunnerHost() {
41      Stream stdin = Console.OpenStandardInput();
42      var message = (TransportRunnerMessage)RunnerMessage.ReadMessageFromStream(stdin);
43      IRunner runner = message.Runner;
44
45      if (runner != null)
46        runner.Run();
47      else
48        Console.Error.WriteLine("Cannot deserialize data from stdin to a type of RunnerConfig!");
49    }
50
51    private void SetupIsolation() {
52      switch (Isolation) {
53        case IsolationType.Native: Settings.Host = new NativeRunnerHost(); break;
54        case IsolationType.Docker: Settings.Host = new DockerRunnerHost(); break;
55        default: throw new ArgumentException("Invalid value for isolation.", "Isolation");
56      }
57
58      if (BasePath != null && !Directory.Exists(BasePath))
59        throw new DirectoryNotFoundException("Path for binaries is not a directory or does not exists.");
60      else BasePath = Directory.GetCurrentDirectory();
61
62      IPluginLoader validator = PluginLoaderFactory.Create();
63      Settings.assemblyInfos = validator.Validate(BasePath);
64    }
65  }
66}
Note: See TracBrowser for help on using the repository browser.