Free cookie consent management tool by TermsFeed Policy Generator

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

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

#2924:

  • removed a blank line in InspectCommand.cs
  • removed BuildCommand.cs and project HeuristicLab.DefinitionLanguage, because it was only a test
  • removed reference BuildCommand in ApplicationCommand
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(InspectCommand)
18    }
19  )]
20  class ApplicationCommand : ICommand {
21
22    [Option(Description = "Sets the path for the binaries.")]
23    public string BasePath { get; set; }
24
25    [Option(Shortcut = "i", Description = "Sets the isolation type. Possible types are: NATIVE or DOCKER.")]
26    public IsolationType Isolation { get; set; }
27
28    [Option]
29    private bool StartAsRunnerHost { get; set; }
30
31    public void Execute() {
32      if (StartAsRunnerHost) {
33        StartupRunnerHost();
34      } else {
35        SetupIsolation();
36      }
37    }
38
39    private void StartupRunnerHost() {
40      Stream stdin = Console.OpenStandardInput();
41      var message = (TransportRunnerMessage)RunnerMessage.ReadMessageFromStream(stdin);
42      IRunner runner = message.Runner;
43
44      if (runner != null)
45        runner.Run();
46      else
47        Console.Error.WriteLine("Cannot deserialize data from stdin to a type of RunnerConfig!");
48    }
49
50    private void SetupIsolation() {
51      switch (Isolation) {
52        case IsolationType.Native: Settings.Host = new NativeRunnerHost(); break;
53        case IsolationType.Docker: Settings.Host = new DockerRunnerHost(); break;
54        default: throw new ArgumentException("Invalid value for isolation.", "Isolation");
55      }
56
57      if (BasePath != null && !Directory.Exists(BasePath))
58        throw new DirectoryNotFoundException("Path for binaries is not a directory or does not exists.");
59      else BasePath = Directory.GetCurrentDirectory();
60
61      IPluginLoader validator = PluginLoaderFactory.Create();
62      Settings.assemblyInfos = validator.Validate(BasePath);
63    }
64  }
65}
Note: See TracBrowser for help on using the repository browser.