Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/19/19 16:33:01 (4 years ago)
Author:
dpiringe
Message:

#3026:

  • relocated GetMaxValue and GetMinValue from ValueTypeValueConverter into BaseConverter
  • fixed a bug in ConstrainedValueParameterConverter (from GetType().Name to ToString())
  • printing now PrettyNames for types
  • added comments
  • added StorableConverter.cs (not finished, maybe not a good converter)
  • added ValueRangeConverter.cs for DoubleRange and IntRange
  • added ParameterConverter.cs for default parameter conversion
File:
1 edited

Legend:

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

    r17349 r17353  
    22using System.Collections.Generic;
    33using System.Linq;
     4using HeuristicLab.Common;
    45using HeuristicLab.Core;
    56using HeuristicLab.Data;
     
    910
    1011namespace HeuristicLab.JsonInterface {
     12  /// <summary>
     13  /// Static class to generate json interface templates.
     14  /// </summary>
    1115  public static class JCGenerator {
    12 
    1316    private struct GenData {
    1417      public JObject Template { get; set; }
     
    1619      public JArray JsonItems { get; set; }
    1720    }
    18 
    19 
     21   
    2022    public static string GenerateTemplate(IAlgorithm algorithm) {
    2123      // data container
     
    3032      // which have parameters aswell
    3133      AddInstantiableIItem(Constants.Algorithm, algorithm, genData);
    32       IsConvertable(algorithm, true);
    33       if (algorithm.Problem != null && IsConvertable(algorithm.Problem, true)) // 1.2. only when an problem exists
     34      //IsConvertable(algorithm, true);
     35      if (algorithm.Problem != null) // 1.2. only when an problem exists
    3436        AddInstantiableIItem(Constants.Problem, algorithm.Problem, genData);
    3537
     
    4345   
    4446    #region Helper
    45     private static bool IsConvertable(object obj, bool throwException) {
     47    private static bool IsConvertable(object obj, bool throwException = false) {
    4648      bool tmp = ConvertableAttribute.IsConvertable(obj);
    4749      if (throwException && tmp)
    48         throw new NotSupportedException($"Type {obj.GetType().Name} is not convertable!");
     50        throw new NotSupportedException($"Type {obj.GetType().GetPrettyName(false)} is not convertable!");
    4951      return tmp;
    5052    }
     53
    5154    private static void AddInstantiableIItem(string metaDataTagName, IItem item, GenData genData) {
    5255      JsonItem jsonItem = JsonItemConverter.Extract(item);
     
    7881      obj.Property(nameof(JsonItem.Type))?.Remove();
    7982
    80       genData.TypeList.Add(item.Path, item.Type);
     83      if(!genData.TypeList.ContainsKey(item.Path))
     84        genData.TypeList.Add(item.Path, item.Type);
    8185      return obj;
    8286    }
     
    8791      TransformNodes(x => {
    8892        var p = x.ToObject<JsonItem>();
     93        x.Property(nameof(JsonItem.Type))?.Remove();
     94        x.Property(nameof(JsonItem.Parameters))?.Remove();
     95        /*
    8996        if ((p.Value == null || (p.Value != null && p.Value.GetType() == typeof(string) && p.Range == null) && p.ActualName == null)) {
    9097          objToRemove.Add(x);
     
    9299          x.Property(nameof(JsonItem.Type))?.Remove();
    93100          x.Property(nameof(JsonItem.Parameters))?.Remove();
    94         }
     101        }*/
    95102      }, token[Constants.FreeParameters]);
    96       foreach (var x in objToRemove) x.Remove();
     103      //foreach (var x in objToRemove) x.Remove();
    97104    }
    98105
     
    109116        if (p.Value == null) objToRemove.Add(x);
    110117      }, token[Constants.StaticParameters]);
    111       foreach (var x in objToRemove) x.Remove();
     118      //foreach (var x in objToRemove) x.Remove();
    112119    }
    113120
Note: See TracChangeset for help on using the changeset viewer.