Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2924_DotNetCoreMigration/HeuristicLab.PluginInfrastructure/3.3/Isolation/ApplicationRunner.cs @ 16993

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

#2924:

  • added IEnumerable<T> GetInstances<T>(params object[] args) where T: class and IEnumerable<object> GetInstances(Type type, params object[] args) method to IApplicationManager and implemented them in LightweightApplicationManager -> to instantiate types with specific constructor arguments
  • added RunnerState State { get; } property in IRunnerHost, was already in RunnerHost
  • added user authentication for NativeRunnerHost
  • added optional check for a running docker daemon and available image for type DockerRunnerHost + Exception DockerException
  • added caching of the saved IApplication in ApplicationRunner to prevent a new instance every get call
  • removed System.ServiceModel.Primitives NuGet package
  • lots of formatting
File size: 1.6 KB
RevLine 
[16984]1using System;
2using System.IO;
3
4namespace HeuristicLab.PluginInfrastructure {
5  [Serializable]
6  public class ApplicationRunner : Runner {
7    /// <summary>
8    /// Arguments for the StartApplication.
9    /// </summary>
10    public ICommandLineArgument[] Args { get; set; }
11
12    /// <summary>
13    /// The application which should run in child process.
14    /// </summary>
15    public IApplication StartApplication {
16      get {
[16993]17        if (application == null) {
18          using (var memStream = new MemoryStream(serializedStartApplication)) {
19            application = (IApplication)formatter.Deserialize(memStream);
20          }
[16984]21        }
[16993]22        return application;
[16984]23      }
24      set {
25        using (var ms = new MemoryStream()) {
26          formatter.Serialize(ms, value);
27          serializedStartApplication = ms.ToArray();
28        }
29      }
30    }
31    // Encapsulated application is necessary, because it is not possible to
32    // instantly deserialize the application, before all assemblies are loaded.
33    private byte[] serializedStartApplication = new byte[0];
[16993]34    // cache application to prevent new instances every get call of StartApplication
35    private IApplication application;
[16984]36
37    protected override void Execute() {
38      StartApplication.Run(Args);
39    }
40
41    protected override void OnRunnerJob(RunnerJob runnerJob) {
42      switch (runnerJob) {
43        case RunnerJob.Cancel: StartApplication.OnCancel(); break;
[16993]44        case RunnerJob.Pause: StartApplication.OnPause(); break;
[16984]45        case RunnerJob.Resume: StartApplication.OnResume(); break;
46      }
47    }
48  }
49}
Note: See TracBrowser for help on using the repository browser.