- Timestamp:
- 11/19/19 16:33:01 (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/JCGenerator.cs
r17349 r17353 2 2 using System.Collections.Generic; 3 3 using System.Linq; 4 using HeuristicLab.Common; 4 5 using HeuristicLab.Core; 5 6 using HeuristicLab.Data; … … 9 10 10 11 namespace HeuristicLab.JsonInterface { 12 /// <summary> 13 /// Static class to generate json interface templates. 14 /// </summary> 11 15 public static class JCGenerator { 12 13 16 private struct GenData { 14 17 public JObject Template { get; set; } … … 16 19 public JArray JsonItems { get; set; } 17 20 } 18 19 21 20 22 public static string GenerateTemplate(IAlgorithm algorithm) { 21 23 // data container … … 30 32 // which have parameters aswell 31 33 AddInstantiableIItem(Constants.Algorithm, algorithm, genData); 32 IsConvertable(algorithm, true);33 if (algorithm.Problem != null && IsConvertable(algorithm.Problem, true)) // 1.2. only when an problem exists34 //IsConvertable(algorithm, true); 35 if (algorithm.Problem != null) // 1.2. only when an problem exists 34 36 AddInstantiableIItem(Constants.Problem, algorithm.Problem, genData); 35 37 … … 43 45 44 46 #region Helper 45 private static bool IsConvertable(object obj, bool throwException ) {47 private static bool IsConvertable(object obj, bool throwException = false) { 46 48 bool tmp = ConvertableAttribute.IsConvertable(obj); 47 49 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!"); 49 51 return tmp; 50 52 } 53 51 54 private static void AddInstantiableIItem(string metaDataTagName, IItem item, GenData genData) { 52 55 JsonItem jsonItem = JsonItemConverter.Extract(item); … … 78 81 obj.Property(nameof(JsonItem.Type))?.Remove(); 79 82 80 genData.TypeList.Add(item.Path, item.Type); 83 if(!genData.TypeList.ContainsKey(item.Path)) 84 genData.TypeList.Add(item.Path, item.Type); 81 85 return obj; 82 86 } … … 87 91 TransformNodes(x => { 88 92 var p = x.ToObject<JsonItem>(); 93 x.Property(nameof(JsonItem.Type))?.Remove(); 94 x.Property(nameof(JsonItem.Parameters))?.Remove(); 95 /* 89 96 if ((p.Value == null || (p.Value != null && p.Value.GetType() == typeof(string) && p.Range == null) && p.ActualName == null)) { 90 97 objToRemove.Add(x); … … 92 99 x.Property(nameof(JsonItem.Type))?.Remove(); 93 100 x.Property(nameof(JsonItem.Parameters))?.Remove(); 94 } 101 }*/ 95 102 }, token[Constants.FreeParameters]); 96 foreach (var x in objToRemove) x.Remove();103 //foreach (var x in objToRemove) x.Remove(); 97 104 } 98 105 … … 109 116 if (p.Value == null) objToRemove.Add(x); 110 117 }, token[Constants.StaticParameters]); 111 foreach (var x in objToRemove) x.Remove();118 //foreach (var x in objToRemove) x.Remove(); 112 119 } 113 120
Note: See TracChangeset
for help on using the changeset viewer.