1 | using System;
|
---|
2 | using System.IO;
|
---|
3 | using HeuristicLab.CommandLineInterface;
|
---|
4 | using HeuristicLab.PluginInfrastructure;
|
---|
5 |
|
---|
6 | namespace 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 | }
|
---|