Free cookie consent management tool by TermsFeed Policy Generator

Changeset 18039 for branches


Ignore:
Timestamp:
08/03/21 10:53:47 (3 years ago)
Author:
dpiringe
Message:

#3026

  • fixed the possibility for duplicated result entries in template generation
  • added a check for duplicated result entries in Runner to prevent an Key already exists exception (a user could manually manipulate the template file to generate this type of exception, thats the reason for a second check)
  • fixed the relative to absolute path transformation in JsonTemplateInstantiator
Location:
branches/3026_IntegrationIntoSymSpace
Files:
3 edited

Legend:

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

    r18026 r18039  
    6666        foreach(var result in filteredResults) {
    6767          var formatter = GetResultFormatter(result.Item1.ResultFormatterType);
    68           obj.Add(result.Item1.Name, formatter.Format(result.Item2));
     68          if(!obj.ContainsKey(result.Item1.Name)) // to prevent duplicates
     69            obj.Add(result.Item1.Name, formatter.Format(result.Item2));
    6970        }
    7071      }
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/AlgorithmConverter.cs

    r17843 r18039  
    2828      IAlgorithm algorithm = value as IAlgorithm;
    2929      foreach (var res in algorithm.Results) {
    30         item.AddChildren(root.Extract(res, root));
    31         /*
    32         item.AddChildren(new ResultJsonItem() {
    33           Name = res.Name,
    34           Description = res.Description
    35         });*/
     30        var resultItem = root.Extract(res, root);
     31        // fetch all result parameter items
     32        var resultParameterItems =
     33          item.Where(x => x
     34          .GetType()
     35          .GetInterfaces()
     36          .Any(y => y == typeof(IResultJsonItem)));
     37        // check for duplicates (to prevent double result items,
     38        // which can occur with result parameters)
     39        if(!resultParameterItems.Any(x => x.Name == resultItem.Name))
     40          item.AddChildren(resultItem);
    3641      }
    3742      item.AddChildren(root.Extract(algorithm.Problem, root));
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/JsonTemplateInstantiator.cs

    r18030 r18039  
    2424  /// </summary>
    2525  public class JsonTemplateInstantiator {
     26
     27    #region Constants
     28    private const string RelativePathCurrentDirectoryRegex = @"^(\.)";
     29    #endregion
    2630
    2731    #region Private Properties
     
    5256
    5357      // extract metadata information
    54       string relativePath = Template[Constants.Metadata][Constants.HLFileLocation].ToString(); // get relative path
     58      string relativePath = Template[Constants.Metadata][Constants.HLFileLocation].ToString().Trim(); // get relative path
    5559      // convert to absolute path
    56       string hLFileLocation = Regex.Replace(relativePath, @"^(\.)", $"{Path.GetDirectoryName(templateFile)}");
     60      if (Regex.IsMatch(relativePath, RelativePathCurrentDirectoryRegex))
     61        relativePath = relativePath.Remove(0, 2); // remove first 2 chars -> indicates the current directory
     62
     63      string hLFileLocation = $"{Path.GetDirectoryName(templateFile)}{Path.DirectorySeparatorChar}{relativePath}";
    5764
    5865      #region Deserialize HL File
Note: See TracChangeset for help on using the changeset viewer.