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