Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
01/28/20 14:53:45 (4 years ago)
Author:
dpiringe
Message:

#3026:

  • deleted JsonItemArrayControl and JsonItemDefaultControl
  • redesigned architecture for JsonItem: now there are different types of JsonItem (IntJsonItem, BoolJsonItem, ...) -> for better type safety and expandability
  • fixed bug in BaseConverter for GetMinValue and GetMaxValue for IntValue, but ignored for other value types (DoubleValue, DateTimeValue, ...) because the redesign of JsonItem-Architecture can make these two methods obsolet soon
  • fixed bug in JsonItemConverter to prevent null pointer exceptions
  • refactored value and range converters -> removed complicated generic ValueTypeValueConverter and ValueRangeConverter and implemented the necessary methods directly in concrete classes (improves readability and removes the need of reflection)
  • redesigned view handling in OptimizerIntegration -> dynamically seaches for JsonItemVMBase implementations, which are connected with a view
    • this enables better scaling with more user controls
  • JsonItemVMBase implements MVVM architecture
File:
1 edited

Legend:

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

    r17406 r17410  
    2222      public JArray Config { get; set; }
    2323      public IDictionary<string, IJsonItem> Objects { get; set; }
     24      public IOptimizer Optimizer { get; set; }
    2425    }
    2526
     
    4748      ProtoBufSerializer serializer = new ProtoBufSerializer();
    4849      IOptimizer optimizer = (IOptimizer)serializer.Deserialize(hLFileLocation);
     50      instData.Optimizer = optimizer;
    4951
    5052      // collect all parameterizedItems from template
     
    6567
    6668    #region Helper
     69
     70    private static object GetValueFromJObject(JObject obj) {
     71      object val = obj[nameof(IJsonItem.Value)]?.ToObject<object>();
     72      if (val is JContainer jContainer) // for resolving array values
     73        val = jContainer.ToObject<object[]>();
     74
     75      return val;
     76    }
     77
    6778    private static void CollectParameterizedItems(InstData instData) {
     79      //JCGenerator generator = new JCGenerator();
     80      //IEnumerable<IJsonItem> items = generator.FetchJsonItems(instData.Optimizer);
     81      IJsonItem root = JsonItemConverter.Extract(instData.Optimizer);
     82      instData.Objects.Add(root.Path, root);
     83
     84      foreach (JObject obj in instData.Template[Constants.Parameters]) {
     85        string[] pathParts = obj.Property("Path").Value.ToString().Split('.');
     86        IJsonItem tmp = root;
     87        IJsonItem old = null;
     88        for(int i = 1; i < pathParts.Length; ++i) {
     89          foreach(var c in tmp.Children) {
     90            if (c.Name == pathParts[i])
     91              tmp = c;
     92          }
     93          if (old == tmp)
     94            throw new Exception($"Invalid path '{string.Join(".", pathParts)}'");
     95          else old = tmp;
     96        }
     97        tmp.Value = GetValueFromJObject(obj);
     98        tmp.Range = obj[nameof(IJsonItem.Range)]?.ToObject<object[]>();
     99        tmp.ActualName = obj[nameof(IJsonItem.ActualName)]?.ToString();
     100        instData.Objects.Add(tmp.Path, tmp);
     101      }
     102
     103
     104      /*
    68105      foreach (JObject item in instData.Template[Constants.Parameters]) {
    69106        string[] pathParts = item.Property("Path").Value.ToString().Split('.');
     
    89126        parent.AddChilds(data);
    90127        instData.Objects.Add(data.Path, data);
    91       }
     128      }*/
    92129    }
    93130   
     
    95132      foreach (JObject obj in instData.Config) {
    96133        // build item from config object
    97         IJsonItem item = JsonItem.BuildJsonItem(obj);
     134        //IJsonItem item = JsonItem.BuildJsonItem(obj);
     135        string path = obj.Property("Path").Value.ToString();
    98136        // override default value
    99         if (instData.Objects.TryGetValue(item.Path, out IJsonItem param)) {
    100           param.Value = item.Value;
     137        if (instData.Objects.TryGetValue(path, out IJsonItem param)) {
     138          param.Value = GetValueFromJObject(obj);
    101139          // override ActualName (for LookupParameters)
    102140          if (param.ActualName != null)
    103             param.ActualName = item.ActualName;
    104         } else throw new InvalidDataException($"No parameter with path='{item.Path}' defined!");
     141            param.ActualName = obj[nameof(IJsonItem.ActualName)]?.ToString();
     142        } else throw new InvalidDataException($"No parameter with path='{path}' defined!");
    105143      }
    106144    }
Note: See TracChangeset for help on using the changeset viewer.