Changeset 17406
- Timestamp:
- 01/27/20 10:33:01 (5 years ago)
- Location:
- branches/3026_IntegrationIntoSymSpace
- Files:
-
- 3 added
- 27 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/ViewModels/JsonItemVM.cs
r17405 r17406 11 11 12 12 public class JsonItemVM { 13 public JsonItem Item { get; set; }13 public IJsonItem Item { get; set; } 14 14 15 15 private IList<JsonItemVM> children = new List<JsonItemVM>(); … … 32 32 public event OnChildAddedHandler OnChildAdded; 33 33 34 public JsonItemVM( JsonItem item) {34 public JsonItemVM(IJsonItem item) { 35 35 this.Item = item; 36 36 } -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/Views/ExportJsonDialog.Designer.cs
r17405 r17406 88 88 // jsonItemBindingSource 89 89 // 90 this.jsonItemBindingSource.DataSource = typeof(HeuristicLab.JsonInterface. JsonItem);90 this.jsonItemBindingSource.DataSource = typeof(HeuristicLab.JsonInterface.IJsonItem); 91 91 // 92 92 // ExportJsonDialog -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/Views/ExportJsonDialog.cs
r17405 r17406 18 18 private static SaveFileDialog saveFileDialog; 19 19 private IDictionary<int, UserControl> ctrlCollection = new Dictionary<int, UserControl>(); 20 private JsonItem root;20 private IJsonItem root; 21 21 private IOptimizer optimizer; 22 22 private IList<JsonItemVM> vms; … … 67 67 } 68 68 69 private JsonItemVM BuildTreeNode(TreeNode node, JsonItem item) {69 private JsonItemVM BuildTreeNode(TreeNode node, IJsonItem item) { 70 70 JsonItemVM vm = new JsonItemVM(item); 71 71 … … 89 89 } 90 90 91 private bool IsDrawableItem( JsonItem item) {91 private bool IsDrawableItem(IJsonItem item) { 92 92 bool b = false; 93 93 if (item.Children != null) { … … 111 111 112 112 private UserControl GenerateControl(JsonItemVM vm) { 113 JsonItem item = vm.Item;113 IJsonItem item = vm.Item; 114 114 UserControl control = null; 115 115 if (!(item is UnsupportedJsonItem)) { -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/AlgorithmConverter.cs
r17405 r17406 13 13 public override Type ConvertableType => typeof(IAlgorithm); 14 14 15 public override void InjectData(IItem item, JsonItem data, IJsonItemConverter root) {15 public override void InjectData(IItem item, IJsonItem data, IJsonItemConverter root) { 16 16 base.InjectData(item, data, root); 17 17 IAlgorithm algorithm = item as IAlgorithm; 18 JsonItem problemData = data.Children.Where(x => x.Name == algorithm.Problem.Name).First();18 IJsonItem problemData = data.Children.Where(x => x.Name == algorithm.Problem.Name).First(); 19 19 root.Inject(algorithm.Problem, problemData, root); 20 20 21 21 } 22 22 23 public override void Populate(IItem value, JsonItem item, IJsonItemConverter root) {23 public override void Populate(IItem value, IJsonItem item, IJsonItemConverter root) { 24 24 base.Populate(value, item, root); 25 25 IAlgorithm algorithm = value as IAlgorithm; -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/BaseConverter.cs
r17404 r17406 14 14 public abstract Type ConvertableType { get; } 15 15 16 public void Inject(IItem item, JsonItem data, IJsonItemConverter root) {16 public void Inject(IItem item, IJsonItem data, IJsonItemConverter root) { 17 17 18 18 InjectData(item, data, root); 19 19 } 20 20 21 public JsonItem Extract(IItem value, IJsonItemConverter root) {22 JsonItem data = new JsonItem() { Name = value.ItemName };21 public IJsonItem Extract(IItem value, IJsonItemConverter root) { 22 IJsonItem data = new JsonItem() { Name = value.ItemName }; 23 23 Populate(value, data, root); 24 24 return data; 25 25 } 26 26 27 public abstract void InjectData(IItem item, JsonItem data, IJsonItemConverter root);28 public abstract void Populate(IItem value, JsonItem item, IJsonItemConverter root); // TODO: populate?27 public abstract void InjectData(IItem item, IJsonItem data, IJsonItemConverter root); 28 public abstract void Populate(IItem value, IJsonItem item, IJsonItemConverter root); // TODO: populate? 29 29 30 30 #region Helper -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/ConstrainedValueParameterConverter.cs
r17404 r17406 12 12 public override Type ConvertableType => typeof(IConstrainedValueParameter<>); 13 13 14 public override void InjectData(IParameter parameter, JsonItem data, IJsonItemConverter root) {14 public override void InjectData(IParameter parameter, IJsonItem data, IJsonItemConverter root) { 15 15 foreach(var x in GetValidValues(parameter)) 16 16 if(x.ToString() == CastValue<string>(data.Value)) … … 25 25 } 26 26 27 public override void Populate(IParameter value, JsonItem item, IJsonItemConverter root) {27 public override void Populate(IParameter value, IJsonItem item, IJsonItemConverter root) { 28 28 item.AddChilds(GetParameterizedChilds(value)); 29 29 item.Name = value.Name; … … 40 40 } 41 41 42 private IList< JsonItem> GetParameterizedChilds(IParameter value) {43 List< JsonItem> list = new List<JsonItem>();42 private IList<IJsonItem> GetParameterizedChilds(IParameter value) { 43 List<IJsonItem> list = new List<IJsonItem>(); 44 44 var values = ((dynamic)value).ValidValues; 45 45 foreach(var x in values) { 46 46 if (x is IParameterizedItem) { 47 JsonItem tmp = JsonItemConverter.Extract(x);47 IJsonItem tmp = JsonItemConverter.Extract(x); 48 48 if(!(tmp is UnsupportedJsonItem)) 49 49 list.Add(tmp); -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/EnumTypeConverter.cs
r17394 r17406 12 12 public override Type ConvertableType => typeof(EnumValue<>); 13 13 14 public override void InjectData(IItem item, JsonItem data, IJsonItemConverter root) =>14 public override void InjectData(IItem item, IJsonItem data, IJsonItemConverter root) => 15 15 ((dynamic)item).Value = Enum.Parse( 16 16 item.GetType().GenericTypeArguments.First(), 17 17 CastValue<string>(data.Value)); 18 18 19 public override void Populate(IItem value, JsonItem item, IJsonItemConverter root) {19 public override void Populate(IItem value, IJsonItem item, IJsonItemConverter root) { 20 20 object val = ((dynamic)value).Value; 21 21 Type enumType = val.GetType(); -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/LookupParameterConverter.cs
r17394 r17406 11 11 public override Type ConvertableType => typeof(ILookupParameter); 12 12 13 public override void Populate(IParameter value, JsonItem item, IJsonItemConverter root) {13 public override void Populate(IParameter value, IJsonItem item, IJsonItemConverter root) { 14 14 item.Name = value.Name; 15 15 item.ActualName = ((ILookupParameter)value).ActualName; 16 16 } 17 17 18 public override void InjectData(IParameter parameter, JsonItem data, IJsonItemConverter root) =>18 public override void InjectData(IParameter parameter, IJsonItem data, IJsonItemConverter root) => 19 19 ((ILookupParameter)parameter).ActualName = data.ActualName as string; 20 20 } -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/MultiCheckedOperatorConverter.cs
r17394 r17406 12 12 public override Type ConvertableType => typeof(ICheckedMultiOperator<>); 13 13 14 public override void Populate(IItem value, JsonItem item, IJsonItemConverter root) {14 public override void Populate(IItem value, IJsonItem item, IJsonItemConverter root) { 15 15 base.Populate(value, item, root); 16 16 … … 25 25 } 26 26 27 public override void InjectData(IItem item, JsonItem data, IJsonItemConverter root) {27 public override void InjectData(IItem item, IJsonItem data, IJsonItemConverter root) { 28 28 base.InjectData(item, data, root); 29 29 … … 33 33 } 34 34 35 private bool GetOperatorState(string name, JsonItem data) {35 private bool GetOperatorState(string name, IJsonItem data) { 36 36 foreach(var op in data.Children) { 37 37 if (op.Name == name && op.Value is bool) return (bool)op.Value; -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/ParameterBaseConverter.cs
r17394 r17406 8 8 namespace HeuristicLab.JsonInterface { 9 9 public abstract class ParameterBaseConverter : BaseConverter { 10 public override void Populate(IItem value, JsonItem item, IJsonItemConverter root) =>10 public override void Populate(IItem value, IJsonItem item, IJsonItemConverter root) => 11 11 Populate(value as IParameter, item, root); 12 12 13 public abstract void Populate(IParameter value, JsonItem item, IJsonItemConverter root);13 public abstract void Populate(IParameter value, IJsonItem item, IJsonItemConverter root); 14 14 15 public override void InjectData(IItem item, JsonItem data, IJsonItemConverter root) =>15 public override void InjectData(IItem item, IJsonItem data, IJsonItemConverter root) => 16 16 InjectData(item as IParameter, data, root); 17 17 18 public abstract void InjectData(IParameter parameter, JsonItem data, IJsonItemConverter root);18 public abstract void InjectData(IParameter parameter, IJsonItem data, IJsonItemConverter root); 19 19 } 20 20 } -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/ParameterizedItemConverter.cs
r17404 r17406 11 11 public override Type ConvertableType => typeof(IParameterizedItem); 12 12 13 public override void InjectData(IItem item, JsonItem data, IJsonItemConverter root) {13 public override void InjectData(IItem item, IJsonItem data, IJsonItemConverter root) { 14 14 IParameterizedItem pItem = item as IParameterizedItem; 15 15 … … 21 21 } 22 22 23 public override void Populate(IItem value, JsonItem item, IJsonItemConverter root) {23 public override void Populate(IItem value, IJsonItem item, IJsonItemConverter root) { 24 24 var parameterizedItem = value as IParameterizedItem; 25 25 26 26 foreach (var param in parameterizedItem.Parameters) { 27 27 if (!param.Hidden) { 28 JsonItem tmp = root.Extract(param, root);28 IJsonItem tmp = root.Extract(param, root); 29 29 if(!(tmp is UnsupportedJsonItem)) 30 30 item.AddChilds(tmp); -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/RegressionProblemDataConverter.cs
r17394 r17406 14 14 public override Type ConvertableType => HEAL.Attic.Mapper.StaticCache.GetType(new Guid("EE612297-B1AF-42D2-BF21-AF9A2D42791C")); 15 15 16 public override void Populate(IItem value, JsonItem item, IJsonItemConverter root) {16 public override void Populate(IItem value, IJsonItem item, IJsonItemConverter root) { 17 17 dynamic val = (dynamic)value; 18 18 object dataset = (object)val.Dataset; … … 40 40 } 41 41 42 public override void InjectData(IItem item, JsonItem data, IJsonItemConverter root) {42 public override void InjectData(IItem item, IJsonItem data, IJsonItemConverter root) { 43 43 // TODO: inject data 44 44 throw new NotImplementedException(); -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/StringValueConverter.cs
r17394 r17406 12 12 public override Type ConvertableType => typeof(StringValue); 13 13 14 public override void InjectData(IItem item, JsonItem data, IJsonItemConverter root) =>14 public override void InjectData(IItem item, IJsonItem data, IJsonItemConverter root) => 15 15 ((StringValue)item).Value = CastValue<string>(data.Value); 16 16 17 public override void Populate(IItem value, JsonItem item, IJsonItemConverter root) =>17 public override void Populate(IItem value, IJsonItem item, IJsonItemConverter root) => 18 18 item.Value = ((StringValue)value).Value; 19 19 } -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/ValueLookupParameterConverter.cs
r17394 r17406 11 11 public override Type ConvertableType => typeof(IValueLookupParameter); 12 12 13 public override void Populate(IParameter value, JsonItem item, IJsonItemConverter root) {13 public override void Populate(IParameter value, IJsonItem item, IJsonItemConverter root) { 14 14 IValueLookupParameter param = value as IValueLookupParameter; 15 15 … … 20 20 IEnumerable<object> actualRange = null; 21 21 if(param.Value != null) { 22 JsonItem tmp = root.Extract(param.Value, root);22 IJsonItem tmp = root.Extract(param.Value, root); 23 23 tmp.Parent = item; 24 24 actualValue = tmp.Value; … … 31 31 } 32 32 33 public override void InjectData(IParameter parameter, JsonItem data, IJsonItemConverter root) {33 public override void InjectData(IParameter parameter, IJsonItem data, IJsonItemConverter root) { 34 34 IValueLookupParameter param = parameter as IValueLookupParameter; 35 35 param.ActualName = CastValue<string>(data.ActualName); -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/ValueParameterConverter.cs
r17404 r17406 11 11 public override Type ConvertableType => typeof(IValueParameter); 12 12 13 public override void InjectData(IParameter parameter, JsonItem data, IJsonItemConverter root) {13 public override void InjectData(IParameter parameter, IJsonItem data, IJsonItemConverter root) { 14 14 if (parameter.ActualValue == null && data.Value != null) 15 15 parameter.ActualValue = Instantiate(parameter.DataType); … … 17 17 } 18 18 19 public override void Populate(IParameter value, JsonItem item, IJsonItemConverter root) {19 public override void Populate(IParameter value, IJsonItem item, IJsonItemConverter root) { 20 20 item.Name = value.Name; 21 21 if (value.ActualValue != null) { 22 JsonItem tmp = root.Extract(value.ActualValue, root);22 IJsonItem tmp = root.Extract(value.ActualValue, root); 23 23 if(!(tmp is UnsupportedJsonItem)) { 24 24 if (tmp.Name == "[OverridableParamName]") { 25 25 tmp.Name = value.Name; 26 JsonItem.Merge(item , tmp);26 JsonItem.Merge(item as JsonItem, tmp as JsonItem); 27 27 } else 28 28 item.AddChilds(tmp); -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/ValueRangeConverter.cs
r17394 r17406 27 27 private const BindingFlags Flags = BindingFlags.NonPublic | BindingFlags.Instance; 28 28 29 public override void Populate(IItem value, JsonItem item, IJsonItemConverter root) {29 public override void Populate(IItem value, IJsonItem item, IJsonItemConverter root) { 30 30 var field = value.GetType().GetField("values", Flags); 31 31 Tuple<T,T> tuple = (Tuple<T,T>)field.GetValue(value); … … 35 35 } 36 36 37 public override void InjectData(IItem item, JsonItem data, IJsonItemConverter root) {37 public override void InjectData(IItem item, IJsonItem data, IJsonItemConverter root) { 38 38 object[] arr = (object[])data.Value; 39 39 Tuple<T,T> tuple = new Tuple<T,T>(Instantiate<T>(arr[0]), Instantiate<T>(arr[1])); -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/ValueTypeArrayConverter.cs
r17394 r17406 34 34 where T : struct 35 35 { 36 public override void InjectData(IItem item, JsonItem data, IJsonItemConverter root) =>36 public override void InjectData(IItem item, IJsonItem data, IJsonItemConverter root) => 37 37 CopyArrayData(((ArrayType)item), CastValue<T[]>(data.Value)); 38 38 39 public override void Populate(IItem value, JsonItem item, IJsonItemConverter root) {39 public override void Populate(IItem value, IJsonItem item, IJsonItemConverter root) { 40 40 item.Name = "[OverridableParamName]"; 41 41 item.Value = ((ArrayType)value).CloneAsArray(); -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/ValueTypeMatrixConverter.cs
r17394 r17406 33 33 where T : struct 34 34 { 35 public override void InjectData(IItem item, JsonItem data, IJsonItemConverter root) =>35 public override void InjectData(IItem item, IJsonItem data, IJsonItemConverter root) => 36 36 CopyMatrixData(item as MatrixType, data.Value); 37 37 38 public override void Populate(IItem value, JsonItem item, IJsonItemConverter root) {38 public override void Populate(IItem value, IJsonItem item, IJsonItemConverter root) { 39 39 item.Name = "[OverridableParamName]"; 40 40 item.Value = ((MatrixType)value).CloneAsMatrix(); -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/ValueTypeValueConverter.cs
r17394 r17406 38 38 where T : struct { 39 39 40 public override void InjectData(IItem item, JsonItem data, IJsonItemConverter root) =>40 public override void InjectData(IItem item, IJsonItem data, IJsonItemConverter root) => 41 41 ((ValueType)item).Value = CastValue<T>(data.Value); 42 42 43 public override void Populate(IItem value, JsonItem item, IJsonItemConverter root) {43 public override void Populate(IItem value, IJsonItem item, IJsonItemConverter root) { 44 44 item.Name = "[OverridableParamName]"; 45 45 item.Value = ((ValueType)value).Value; -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/HeuristicLab.JsonInterface.csproj
r17405 r17406 66 66 <Compile Include="Converters\ValueLookupParameterConverter.cs" /> 67 67 <Compile Include="Converters\ValueRangeConverter.cs" /> 68 <Compile Include="Interfaces\IJsonItem.cs" /> 69 <Compile Include="Interfaces\IJsonItemValidator.cs" /> 68 70 <Compile Include="ResultItem.cs" /> 69 71 <Compile Include="SingleLineArrayJsonWriter.cs" /> -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Interfaces/IJsonItemConverter.cs
r17394 r17406 15 15 /// <param name="item">The IItem which get the data injected.</param> 16 16 /// <param name="data">The JsonItem with the saved values.</param> 17 void Inject(IItem item, JsonItem data, IJsonItemConverter root);17 void Inject(IItem item, IJsonItem data, IJsonItemConverter root); 18 18 19 19 /// <summary> … … 23 23 /// <param name="value">The IItem to extract infos.</param> 24 24 /// <returns>JsonItem with infos to reinitialise the IItem.</returns> 25 JsonItem Extract(IItem value, IJsonItemConverter root);25 IJsonItem Extract(IItem value, IJsonItemConverter root); 26 26 27 27 Type ConvertableType { get; } -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/JCGenerator.cs
r17405 r17406 17 17 private JObject Template { get; set; } 18 18 private JArray JArrayItems { get; set; } 19 private IList< JsonItem> JsonItems { get; set; }19 private IList<IJsonItem> JsonItems { get; set; } 20 20 private IOptimizer Optimizer { get; set; } 21 21 … … 24 24 // data container 25 25 JArrayItems = new JArray(); 26 JsonItems = new List< JsonItem>();26 JsonItems = new List<IJsonItem>(); 27 27 28 28 ProtoBufSerializer serializer = new ProtoBufSerializer(); … … 40 40 } 41 41 42 public string GenerateTemplate(IEnumerable< JsonItem> items) {42 public string GenerateTemplate(IEnumerable<IJsonItem> items) { 43 43 ProtoBufSerializer serializer = new ProtoBufSerializer(); 44 44 serializer.Serialize(Optimizer, @"C:\Workspace\template.hl"); … … 61 61 } 62 62 63 public string GenerateTemplate( JsonItem rootItem, IOptimizer optimizer) {63 public string GenerateTemplate(IJsonItem rootItem, IOptimizer optimizer) { 64 64 // data container 65 65 Template = JObject.Parse(Constants.Template); 66 JsonItems = new List< JsonItem>();66 JsonItems = new List<IJsonItem>(); 67 67 68 68 // extract JsonItem, save the name in the metadata section of the … … 92 92 } 93 93 94 public IEnumerable< JsonItem> FetchJsonItems(IOptimizer optimizer) {94 public IEnumerable<IJsonItem> FetchJsonItems(IOptimizer optimizer) { 95 95 // data container 96 96 Template = JObject.Parse(Constants.Template); 97 JsonItems = new List< JsonItem>();97 JsonItems = new List<IJsonItem>(); 98 98 Optimizer = optimizer; 99 99 … … 110 110 111 111 private void AddIItem(IItem item) { 112 JsonItem jsonItem = JsonItemConverter.Extract(item);112 IJsonItem jsonItem = JsonItemConverter.Extract(item); 113 113 Template[Constants.Metadata][Constants.Optimizer] = item.ItemName; 114 114 PopulateJsonItems(jsonItem); … … 116 116 117 117 // serializes ParameterizedItems and saves them in list "JsonItems". 118 private void PopulateJsonItems( JsonItem item) {119 IEnumerable< JsonItem> tmpParameter = item.Children;118 private void PopulateJsonItems(IJsonItem item) { 119 IEnumerable<IJsonItem> tmpParameter = item.Children; 120 120 121 121 if (item.Value != null || item.Range != null || item is ResultItem || item.ActualName != null) { … … 130 130 } 131 131 132 private static JObject Serialize( JsonItem item) =>132 private static JObject Serialize(IJsonItem item) => 133 133 JObject.FromObject(item, Settings()); 134 134 -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/JsonItem.cs
r17404 r17406 14 14 /// Main data class for json interface. 15 15 /// </summary> 16 public class JsonItem { 17 public class JsonItemValidator { 16 public class JsonItem : IJsonItem { 17 18 public class JsonItemValidator : IJsonItemValidator { 18 19 private IDictionary<int, bool> Cache = new Dictionary<int, bool>(); 19 20 private JsonItem Root { get; set; } … … 22 23 } 23 24 24 public bool Validate(ref IList< JsonItem> faultyItems) {25 faultyItems = new List< JsonItem>();25 public bool Validate(ref IList<IJsonItem> faultyItems) { 26 faultyItems = new List<IJsonItem>(); 26 27 return ValidateHelper(Root, ref faultyItems); 27 28 } 28 29 29 private bool ValidateHelper(JsonItem item, ref IList< JsonItem> faultyItems) {30 private bool ValidateHelper(JsonItem item, ref IList<IJsonItem> faultyItems) { 30 31 int hash = item.GetHashCode(); 31 32 if (Cache.TryGetValue(hash, out bool r)) … … 38 39 Cache.Add(hash, res); 39 40 foreach (var child in item.Children) 40 res = res && ValidateHelper(child , ref faultyItems);41 res = res && ValidateHelper(child as JsonItem, ref faultyItems); 41 42 return res; 42 43 } … … 47 48 public virtual string Path { 48 49 get { 49 JsonItem tmp = Parent;50 IJsonItem tmp = Parent; 50 51 StringBuilder builder = new StringBuilder(this.Name); 51 52 while(tmp != null) { … … 58 59 59 60 [JsonIgnore] 60 public virtual IList< JsonItem> Children { get; protected set; }61 public virtual IList<IJsonItem> Children { get; protected set; } 61 62 62 63 [JsonIgnore] 63 public virtual JsonItem Parent { get; set; }64 public virtual IJsonItem Parent { get; set; } 64 65 65 66 public virtual object Value { get; set; } … … 72 73 public JsonItem() { } 73 74 74 public JsonItem(IEnumerable< JsonItem> childs) {75 public JsonItem(IEnumerable<IJsonItem> childs) { 75 76 AddChilds(childs); 76 77 } 77 78 #endregion 78 79 79 80 80 #region Public Static Methods … … 86 86 if(target.Children != null) { 87 87 if (from.Children != null) 88 ((List< JsonItem>)from.Children).AddRange(target.Children);88 ((List<IJsonItem>)from.Children).AddRange(target.Children); 89 89 } else { 90 90 target.Children = from.Children; … … 94 94 95 95 #region Public Methods 96 public void AddChilds(params JsonItem[] childs) =>97 AddChilds(childs as IEnumerable< JsonItem>);96 public void AddChilds(params IJsonItem[] childs) => 97 AddChilds(childs as IEnumerable<IJsonItem>); 98 98 99 public void AddChilds(IEnumerable< JsonItem> childs) {99 public void AddChilds(IEnumerable<IJsonItem> childs) { 100 100 if (Children == null) 101 Children = new List< JsonItem>();101 Children = new List<IJsonItem>(); 102 102 foreach (var child in childs) { 103 103 Children.Add(child); … … 106 106 } 107 107 108 public virtual JsonItemValidator GetValidator() => new JsonItemValidator(this);108 public virtual IJsonItemValidator GetValidator() => new JsonItemValidator(this); 109 109 #endregion 110 110 … … 154 154 155 155 #region BuildJsonItemMethods 156 public static JsonItem BuildJsonItem(JObject obj) {156 public static IJsonItem BuildJsonItem(JObject obj) { 157 157 object val = obj[nameof(Value)]?.ToObject<object>(); 158 158 if (val is JContainer jContainer) // for resolving array values -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/JsonItemConverter.cs
r17394 r17406 20 20 = new Dictionary<Type, IJsonItemConverter>(); 21 21 22 private IDictionary<int, JsonItem> Cache { get; set; }23 = new Dictionary<int, JsonItem>();22 private IDictionary<int, IJsonItem> Cache { get; set; } 23 = new Dictionary<int, IJsonItem>(); 24 24 25 25 public int Priority => throw new NotImplementedException(); … … 51 51 } 52 52 53 public void Inject(IItem item, JsonItem data, IJsonItemConverter root) {53 public void Inject(IItem item, IJsonItem data, IJsonItemConverter root) { 54 54 if(!Cache.ContainsKey(item.GetHashCode())) { 55 55 IJsonItemConverter converter = GetConverter(item.GetType()); … … 58 58 } 59 59 60 public JsonItem Extract(IItem item, IJsonItemConverter root) {60 public IJsonItem Extract(IItem item, IJsonItemConverter root) { 61 61 int hash = item.GetHashCode(); 62 if (Cache.TryGetValue(hash, out JsonItem val))62 if (Cache.TryGetValue(hash, out IJsonItem val)) 63 63 return val; 64 64 else { 65 65 IJsonItemConverter converter = GetConverter(item.GetType()); 66 66 if (converter == null) return new UnsupportedJsonItem(); 67 JsonItem tmp = GetConverter(item.GetType()).Extract(item, root);67 IJsonItem tmp = GetConverter(item.GetType()).Extract(item, root); 68 68 Cache.Add(hash, tmp); 69 69 return tmp; … … 71 71 } 72 72 73 public static void Inject(IItem item, JsonItem data) {73 public static void Inject(IItem item, IJsonItem data) { 74 74 IJsonItemConverter c = JsonItemConverterFactory.Create(); 75 75 c.Inject(item, data, c); 76 76 } 77 77 78 public static JsonItem Extract(IItem item) {78 public static IJsonItem Extract(IItem item) { 79 79 IJsonItemConverter c = JsonItemConverterFactory.Create(); 80 80 return c.Extract(item, c); -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/JsonTemplateInstantiator.cs
r17395 r17406 21 21 public JToken Template { get; set; } 22 22 public JArray Config { get; set; } 23 public IDictionary<string, JsonItem> Objects { get; set; }23 public IDictionary<string, IJsonItem> Objects { get; set; } 24 24 } 25 25 … … 32 32 public static IOptimizer Instantiate(string templateFile, string configFile = "") { 33 33 InstData instData = new InstData() { 34 Objects = new Dictionary<string, JsonItem>()34 Objects = new Dictionary<string, IJsonItem>() 35 35 }; 36 36 … … 56 56 57 57 // get algorthm data and object 58 JsonItem optimizerData = instData.Objects[optimizerName];58 IJsonItem optimizerData = instData.Objects[optimizerName]; 59 59 60 60 // inject configuration … … 70 70 71 71 // rebuilds object tree 72 JsonItem parent = null;72 IJsonItem parent = null; 73 73 StringBuilder partialPath = new StringBuilder(); 74 74 for(int i = 0; i < pathParts.Length-1; ++i) { 75 75 partialPath.Append(pathParts[i]); 76 JsonItem tmp = null;77 if (instData.Objects.TryGetValue(partialPath.ToString(), out JsonItem value)) {76 IJsonItem tmp = null; 77 if (instData.Objects.TryGetValue(partialPath.ToString(), out IJsonItem value)) { 78 78 tmp = value; 79 79 } else { … … 86 86 } 87 87 88 JsonItem data = JsonItem.BuildJsonItem(item);88 IJsonItem data = JsonItem.BuildJsonItem(item); 89 89 parent.AddChilds(data); 90 90 instData.Objects.Add(data.Path, data); … … 95 95 foreach (JObject obj in instData.Config) { 96 96 // build item from config object 97 JsonItem item = JsonItem.BuildJsonItem(obj);97 IJsonItem item = JsonItem.BuildJsonItem(obj); 98 98 // override default value 99 if (instData.Objects.TryGetValue(item.Path, out JsonItem param)) {99 if (instData.Objects.TryGetValue(item.Path, out IJsonItem param)) { 100 100 param.Value = item.Value; 101 101 // override ActualName (for LookupParameters) … … 106 106 } 107 107 108 private static JsonItem GetData(string key, InstData instData)108 private static IJsonItem GetData(string key, InstData instData) 109 109 { 110 if (instData.Objects.TryGetValue(key, out JsonItem value))110 if (instData.Objects.TryGetValue(key, out IJsonItem value)) 111 111 return value; 112 112 else -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/SingleLineArrayJsonWriter.cs
r17394 r17406 19 19 base.Formatting = Formatting.Indented; 20 20 base.WritePropertyName(name); 21 isRangeArray = name == nameof( JsonItem.Range) || name == nameof(JsonItem.Value);21 isRangeArray = name == nameof(IJsonItem.Range) || name == nameof(IJsonItem.Value); 22 22 } 23 23 -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/UnsupportedJsonItem.cs
r17394 r17406 18 18 19 19 [JsonIgnore] 20 public override IList< JsonItem> Children {20 public override IList<IJsonItem> Children { 21 21 get => throw new NotSupportedException(); 22 22 protected set => throw new NotSupportedException(); … … 24 24 25 25 [JsonIgnore] 26 public override JsonItem Parent {26 public override IJsonItem Parent { 27 27 get => throw new NotSupportedException(); 28 28 set => throw new NotSupportedException();
Note: See TracChangeset
for help on using the changeset viewer.