Free cookie consent management tool by TermsFeed Policy Generator

Changeset 18030


Ignore:
Timestamp:
07/26/21 14:28:29 (3 years ago)
Author:
dpiringe
Message:

#3026

  • added check for missing path property
  • added functionality for relative .hl file paths
Location:
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/JsonTemplateGenerator.cs

    r17843 r18030  
    3232      JArray resultItems = new JArray();
    3333      IList<IJsonItem> jsonItems = new List<IJsonItem>();
     34     
    3435      string templateName = Path.GetFileName(templatePath);
    3536      string templateDirectory = Path.GetDirectoryName(templatePath);
     
    4546      #region Serialize HL File
    4647      ProtoBufSerializer serializer = new ProtoBufSerializer();
     48      // get absolute path for serialization
    4749      string hlFilePath = Path.Combine(templateDirectory, $"{templateName}.hl");
    4850      serializer.Serialize(optimizer, hlFilePath);
     51      // overwrite string for relative path
     52      hlFilePath = Path.Combine($".{Path.DirectorySeparatorChar}", $"{templateName}.hl");
    4953      #endregion
    5054
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/JsonTemplateInstantiator.cs

    r18026 r18030  
    33using System.IO;
    44using System.Linq;
     5using System.Text.RegularExpressions;
    56using HEAL.Attic;
    67using HeuristicLab.Optimization;
     
    5152
    5253      // extract metadata information
    53       string hLFileLocation = Path.GetFullPath(Template[Constants.Metadata][Constants.HLFileLocation].ToString());
     54      string relativePath = Template[Constants.Metadata][Constants.HLFileLocation].ToString(); // get relative path
     55      // convert to absolute path
     56      string hLFileLocation = Regex.Replace(relativePath, @"^(\.)", $"{Path.GetDirectoryName(templateFile)}");
    5457
    5558      #region Deserialize HL File
     
    108111      foreach (JObject obj in Config) {
    109112        // build item from config object
    110         string path = obj.Property("Path").Value.ToString(); // TODO: catch exception if path is not available
     113        var prop = obj.Property("Path");
     114        if (prop == null)
     115          throw new ArgumentException("Path property is missing.");
     116        string path = prop.Value.ToString();
    111117        // override default value
    112118        if (Objects.TryGetValue(path, out IJsonItem param)) {
Note: See TracChangeset for help on using the changeset viewer.