Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
02/01/21 14:37:18 (4 years ago)
Author:
dpiringe
Message:

#3026

  • removed the option to set the value for JsonItems via exporter
    • reworked some base controls
    • added new controls for JsonItem specific properties (e.g. ArrayResizable)
    • deleted a lot of obsolet controls
  • removed the Enable checkbox in the detail view of JsonItems
  • exporter now clones the IOptimizer object
  • added a check + message for unsupported exports
  • list of JsonItems now includes unsupported JsonItems (disabled and marked with 'unsupported')
  • refactored the converter type check
    • now every converter has to specify its supported type(s)
File:
1 edited

Legend:

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

    r17689 r17828  
    1212  public class JsonTemplateGenerator {
    1313
    14     public static void GenerateTemplate(string path, IOptimizer optimizer) =>
    15       GenerateTemplate(path, optimizer.Name, optimizer);
     14    /// <summary>
     15    /// static Function to generate a template.
     16    /// </summary>
     17    /// <param name="templatePath">the path for the template files</param>
     18    /// <param name="optimizer">the optimizer object to serialize</param>
     19    /// <param name="rootItem">Root JsonItem for serialization, considers only active JsonItems for serialization</param>
     20    public static void GenerateTemplate(string templatePath, IOptimizer optimizer, IJsonItem rootItem) {
     21      // clear all runs
     22      optimizer.Runs.Clear();
    1623
    17     public static void GenerateTemplate(string path, string templateName, IOptimizer optimizer) =>
    18       GenerateTemplate(path, templateName, optimizer, JsonItemConverter.Extract(optimizer));
     24      // validation
     25      ValidationResult validationResult = rootItem.GetValidator().Validate();
     26      if (!validationResult.Success)
     27        throw validationResult.GenerateException();
    1928
    20     public static void GenerateTemplate(string path, string templateName, IOptimizer optimizer, IJsonItem rootItem) {
    2129      #region Init
    2230      JObject template = JObject.Parse(Constants.Template);
     
    2432      JArray resultItems = new JArray();
    2533      IList<IJsonItem> jsonItems = new List<IJsonItem>();
    26       string fullPath = Path.GetFullPath(path);
     34      string templateName = Path.GetFileName(templatePath);
     35      string templateDirectory = Path.GetDirectoryName(templatePath);
     36
    2737      #endregion
    2838
     
    3545      #region Serialize HL File
    3646      ProtoBufSerializer serializer = new ProtoBufSerializer();
    37       string hlFilePath = Path.Combine(fullPath, templateName + ".hl");
     47      string hlFilePath = Path.Combine(templateDirectory, $"{templateName}.hl");
    3848      serializer.Serialize(optimizer, hlFilePath);
    3949      #endregion
     
    5666
    5767      #region Serialize and write to file
    58       File.WriteAllText(fullPath + @"\" + templateName + ".json", SingleLineArrayJsonWriter.Serialize(template));
     68      File.WriteAllText(Path.Combine(templateDirectory, $"{templateName}.json"), SingleLineArrayJsonWriter.Serialize(template));
    5969      #endregion
    6070    }
Note: See TracChangeset for help on using the changeset viewer.