Free cookie consent management tool by TermsFeed Policy Generator

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

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

#2924:

  • added CLI Framework HeuristicLab.CommandLineInterface
  • added definition language test project HeuristicLab.DefinitionLanguage
  • added test project HeuristicLab.DynamicAssemblyTestApp, for PluginInfrastructure testing
  • changed project HeuristicLab to .NET Core and used it to create a CLI-Tool with the new CLI Framework
  • added Docker support to HeuristicLab
  • added IRunnerHost.cs ... forgot last commit
  • changed DockerRunnerHost and NativeRunnerHost to HeuristicLab-3.3.exe, was a little test project before
  • added new solution file HeuristicLab 3.3 No Views.sln, where all view projects are unloaded at start
File size: 2.0 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.IO;
4using HeuristicLab.CommandLineInterface;
5using HeuristicLab.PluginInfrastructure;
6
7namespace 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}
Note: See TracBrowser for help on using the repository browser.