Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2924_DotNetCoreMigration/HeuristicLab.PluginInfrastructure/3.3/Utils/UniPath.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.Runtime.InteropServices;
3using System.Text.RegularExpressions;
4using HEAL.Attic;
5
6namespace HeuristicLab.PluginInfrastructure {
7  [StorableType("8911C8DC-FDA0-4CF6-A0CD-C67E72094D62")]
8  public class UniPath {
9
10    #region Vars
11    [Storable]
12    private string fullPath = "";
13    #endregion
14
15    #region Constructors
16    [StorableConstructor]
17    private UniPath(StorableConstructorFlag _) { }
18    public UniPath(string path) {
19      fullPath = Path.GetFullPath(path);
20    }
21    #endregion
22
23    private bool IsWindowsAbsolutePath(string path) => Regex.IsMatch(path, @"^[A-Z]:");
24
25    private string Rebuild(char split, string startStr, string seperator) {
26      string[] splits = fullPath.Split(split);
27      string tmp = startStr;
28      int i = 1;
29      while (i < (splits.Length - 1)) {
30        tmp += splits[i] + seperator;
31        ++i;
32      }
33      tmp += splits[i];
34      return tmp;
35    }
36
37    public override string ToString() {
38      bool isWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
39      if (isWindows) {
40        if (IsWindowsAbsolutePath(fullPath))
41          return fullPath;
42        else return Rebuild('/', @"C:\", @"\");
43      } else {
44        if (IsWindowsAbsolutePath(fullPath))
45          return Rebuild('\\', "/", "/");
46        else return fullPath;
47      }
48    }
49  }
50}
Note: See TracBrowser for help on using the repository browser.