Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2924_DotNetCoreMigration/HeuristicLab/3.3/OptimizeCommand.cs

Last change on this file 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: 1.4 KB
Line 
1using System.IO;
2using System.Linq;
3using HeuristicLab.CommandLineInterface;
4using HeuristicLab.PluginInfrastructure;
5
6namespace HeuristicLab {
7  [Command(Description = "Command to run a .hl-file.")]
8  class OptimizeCommand : ICommand {
9    [Option(Shortcut = "q", Description = "Disables console output.")]
10    public bool Quiet { get; set; }
11
12    [Option(Shortcut = "o", Description = "Sets the output directory for the result.")]
13    public string Output { get; set; }
14
15    [Value(0)]
16    public string Input { get; set; }
17
18    public void Execute() {
19      if (Input == null || !File.Exists(Input))
20        throw new FileNotFoundException("Path to .hl file empty or wrong!");
21      if (Output != null && !Directory.Exists(Output))
22        throw new DirectoryNotFoundException("Output directory does not exist!");
23      if (Settings.Host != null) {
24        Settings.Host.QuietMode = Quiet;
25        IRunner runner = new ApplicationRunner() {
26          AssembliesToLoad = Settings.assemblyInfos,
27          StartApplication =
28            ApplicationManager.Manager.GetInstances<IApplication>(
29              new UniPath(Input),
30              new UniPath(Output ?? Input.Replace(Path.GetFileName(Input), ""))
31            ).Where(x => x.Name.Equals("CLIOptimize"))
32             .First()
33        };
34        Settings.Host.Run(runner);
35      }
36    }
37  }
38}
Note: See TracBrowser for help on using the repository browser.