Free cookie consent management tool by TermsFeed Policy Generator

Changeset 17406


Ignore:
Timestamp:
01/27/20 10:33:01 (5 years ago)
Author:
dpiringe
Message:

#3026

  • added interfaces IJsonItem and IJsonItemValidator
  • replaced every reference JsonItem with IJsonItem
Location:
branches/3026_IntegrationIntoSymSpace
Files:
3 added
27 edited

Legend:

Unmodified
Added
Removed
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/ViewModels/JsonItemVM.cs

    r17405 r17406  
    1111
    1212  public class JsonItemVM {
    13     public JsonItem Item { get; set; }
     13    public IJsonItem Item { get; set; }
    1414
    1515    private IList<JsonItemVM> children = new List<JsonItemVM>();
     
    3232    public event OnChildAddedHandler OnChildAdded;
    3333
    34     public JsonItemVM(JsonItem item) {
     34    public JsonItemVM(IJsonItem item) {
    3535      this.Item = item;
    3636    }
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/Views/ExportJsonDialog.Designer.cs

    r17405 r17406  
    8888      // jsonItemBindingSource
    8989      //
    90       this.jsonItemBindingSource.DataSource = typeof(HeuristicLab.JsonInterface.JsonItem);
     90      this.jsonItemBindingSource.DataSource = typeof(HeuristicLab.JsonInterface.IJsonItem);
    9191      //
    9292      // ExportJsonDialog
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/Views/ExportJsonDialog.cs

    r17405 r17406  
    1818    private static SaveFileDialog saveFileDialog;
    1919    private IDictionary<int, UserControl> ctrlCollection = new Dictionary<int, UserControl>();
    20     private JsonItem root;
     20    private IJsonItem root;
    2121    private IOptimizer optimizer;
    2222    private IList<JsonItemVM> vms;
     
    6767    }
    6868
    69     private JsonItemVM BuildTreeNode(TreeNode node, JsonItem item) {
     69    private JsonItemVM BuildTreeNode(TreeNode node, IJsonItem item) {
    7070      JsonItemVM vm = new JsonItemVM(item);
    7171
     
    8989    }
    9090
    91     private bool IsDrawableItem(JsonItem item) {
     91    private bool IsDrawableItem(IJsonItem item) {
    9292      bool b = false;
    9393      if (item.Children != null) {
     
    111111
    112112    private UserControl GenerateControl(JsonItemVM vm) {
    113       JsonItem item = vm.Item;
     113      IJsonItem item = vm.Item;
    114114      UserControl control = null;
    115115      if (!(item is UnsupportedJsonItem)) {
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/AlgorithmConverter.cs

    r17405 r17406  
    1313    public override Type ConvertableType => typeof(IAlgorithm);
    1414
    15     public override void InjectData(IItem item, JsonItem data, IJsonItemConverter root) {
     15    public override void InjectData(IItem item, IJsonItem data, IJsonItemConverter root) {
    1616      base.InjectData(item, data, root);
    1717      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();
    1919      root.Inject(algorithm.Problem, problemData, root);
    2020
    2121    }
    2222
    23     public override void Populate(IItem value, JsonItem item, IJsonItemConverter root) {
     23    public override void Populate(IItem value, IJsonItem item, IJsonItemConverter root) {
    2424      base.Populate(value, item, root);
    2525      IAlgorithm algorithm = value as IAlgorithm;
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/BaseConverter.cs

    r17404 r17406  
    1414    public abstract Type ConvertableType { get; }
    1515
    16     public void Inject(IItem item, JsonItem data, IJsonItemConverter root) {
     16    public void Inject(IItem item, IJsonItem data, IJsonItemConverter root) {
    1717
    1818      InjectData(item, data, root);
    1919    }
    2020
    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 };
    2323      Populate(value, data, root);
    2424      return data;
    2525    }
    2626   
    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?
    2929
    3030    #region Helper
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/ConstrainedValueParameterConverter.cs

    r17404 r17406  
    1212    public override Type ConvertableType => typeof(IConstrainedValueParameter<>);
    1313
    14     public override void InjectData(IParameter parameter, JsonItem data, IJsonItemConverter root) {
     14    public override void InjectData(IParameter parameter, IJsonItem data, IJsonItemConverter root) {
    1515      foreach(var x in GetValidValues(parameter))
    1616        if(x.ToString() == CastValue<string>(data.Value))
     
    2525    }
    2626
    27     public override void Populate(IParameter value, JsonItem item, IJsonItemConverter root) {
     27    public override void Populate(IParameter value, IJsonItem item, IJsonItemConverter root) {
    2828      item.AddChilds(GetParameterizedChilds(value));
    2929      item.Name = value.Name;
     
    4040    }
    4141
    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>();
    4444      var values = ((dynamic)value).ValidValues;
    4545      foreach(var x in values) {
    4646        if (x is IParameterizedItem) {
    47           JsonItem tmp = JsonItemConverter.Extract(x);
     47          IJsonItem tmp = JsonItemConverter.Extract(x);
    4848          if(!(tmp is UnsupportedJsonItem))
    4949            list.Add(tmp);
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/EnumTypeConverter.cs

    r17394 r17406  
    1212    public override Type ConvertableType => typeof(EnumValue<>);
    1313
    14     public override void InjectData(IItem item, JsonItem data, IJsonItemConverter root) =>
     14    public override void InjectData(IItem item, IJsonItem data, IJsonItemConverter root) =>
    1515      ((dynamic)item).Value = Enum.Parse(
    1616        item.GetType().GenericTypeArguments.First(),
    1717        CastValue<string>(data.Value));
    1818
    19     public override void Populate(IItem value, JsonItem item, IJsonItemConverter root) {
     19    public override void Populate(IItem value, IJsonItem item, IJsonItemConverter root) {
    2020      object val = ((dynamic)value).Value;
    2121      Type enumType = val.GetType();
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/LookupParameterConverter.cs

    r17394 r17406  
    1111    public override Type ConvertableType => typeof(ILookupParameter);
    1212
    13     public override void Populate(IParameter value, JsonItem item, IJsonItemConverter root) {
     13    public override void Populate(IParameter value, IJsonItem item, IJsonItemConverter root) {
    1414      item.Name = value.Name;
    1515      item.ActualName = ((ILookupParameter)value).ActualName;
    1616    }
    1717
    18     public override void InjectData(IParameter parameter, JsonItem data, IJsonItemConverter root) =>
     18    public override void InjectData(IParameter parameter, IJsonItem data, IJsonItemConverter root) =>
    1919      ((ILookupParameter)parameter).ActualName = data.ActualName as string;
    2020  }
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/MultiCheckedOperatorConverter.cs

    r17394 r17406  
    1212    public override Type ConvertableType => typeof(ICheckedMultiOperator<>);
    1313
    14     public override void Populate(IItem value, JsonItem item, IJsonItemConverter root) {
     14    public override void Populate(IItem value, IJsonItem item, IJsonItemConverter root) {
    1515      base.Populate(value, item, root);
    1616
     
    2525    }
    2626
    27     public override void InjectData(IItem item, JsonItem data, IJsonItemConverter root) {
     27    public override void InjectData(IItem item, IJsonItem data, IJsonItemConverter root) {
    2828      base.InjectData(item, data, root);
    2929
     
    3333    }
    3434
    35     private bool GetOperatorState(string name, JsonItem data) {
     35    private bool GetOperatorState(string name, IJsonItem data) {
    3636      foreach(var op in data.Children) {
    3737        if (op.Name == name && op.Value is bool) return (bool)op.Value;
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/ParameterBaseConverter.cs

    r17394 r17406  
    88namespace HeuristicLab.JsonInterface {
    99  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) =>
    1111      Populate(value as IParameter, item, root);
    1212
    13     public abstract void Populate(IParameter value, JsonItem item, IJsonItemConverter root);
     13    public abstract void Populate(IParameter value, IJsonItem item, IJsonItemConverter root);
    1414
    15     public override void InjectData(IItem item, JsonItem data, IJsonItemConverter root) =>
     15    public override void InjectData(IItem item, IJsonItem data, IJsonItemConverter root) =>
    1616      InjectData(item as IParameter, data, root);
    1717
    18     public abstract void InjectData(IParameter parameter, JsonItem data, IJsonItemConverter root);
     18    public abstract void InjectData(IParameter parameter, IJsonItem data, IJsonItemConverter root);
    1919  }
    2020}
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/ParameterizedItemConverter.cs

    r17404 r17406  
    1111    public override Type ConvertableType => typeof(IParameterizedItem);
    1212
    13     public override void InjectData(IItem item, JsonItem data, IJsonItemConverter root) {
     13    public override void InjectData(IItem item, IJsonItem data, IJsonItemConverter root) {
    1414      IParameterizedItem pItem = item as IParameterizedItem;
    1515
     
    2121    }
    2222
    23     public override void Populate(IItem value, JsonItem item, IJsonItemConverter root) {
     23    public override void Populate(IItem value, IJsonItem item, IJsonItemConverter root) {
    2424      var parameterizedItem = value as IParameterizedItem;
    2525
    2626      foreach (var param in parameterizedItem.Parameters) {
    2727        if (!param.Hidden) {
    28           JsonItem tmp = root.Extract(param, root);
     28          IJsonItem tmp = root.Extract(param, root);
    2929          if(!(tmp is UnsupportedJsonItem))
    3030            item.AddChilds(tmp);
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/RegressionProblemDataConverter.cs

    r17394 r17406  
    1414    public override Type ConvertableType => HEAL.Attic.Mapper.StaticCache.GetType(new Guid("EE612297-B1AF-42D2-BF21-AF9A2D42791C"));
    1515
    16     public override void Populate(IItem value, JsonItem item, IJsonItemConverter root) {     
     16    public override void Populate(IItem value, IJsonItem item, IJsonItemConverter root) {     
    1717      dynamic val = (dynamic)value;
    1818      object dataset = (object)val.Dataset;
     
    4040    }
    4141
    42     public override void InjectData(IItem item, JsonItem data, IJsonItemConverter root) {
     42    public override void InjectData(IItem item, IJsonItem data, IJsonItemConverter root) {
    4343      // TODO: inject data
    4444      throw new NotImplementedException();
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/StringValueConverter.cs

    r17394 r17406  
    1212    public override Type ConvertableType => typeof(StringValue);
    1313
    14     public override void InjectData(IItem item, JsonItem data, IJsonItemConverter root) =>
     14    public override void InjectData(IItem item, IJsonItem data, IJsonItemConverter root) =>
    1515      ((StringValue)item).Value = CastValue<string>(data.Value);
    1616
    17     public override void Populate(IItem value, JsonItem item, IJsonItemConverter root) =>
     17    public override void Populate(IItem value, IJsonItem item, IJsonItemConverter root) =>
    1818      item.Value = ((StringValue)value).Value;
    1919  }
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/ValueLookupParameterConverter.cs

    r17394 r17406  
    1111    public override Type ConvertableType => typeof(IValueLookupParameter);
    1212
    13     public override void Populate(IParameter value, JsonItem item, IJsonItemConverter root) {
     13    public override void Populate(IParameter value, IJsonItem item, IJsonItemConverter root) {
    1414      IValueLookupParameter param = value as IValueLookupParameter;
    1515     
     
    2020      IEnumerable<object> actualRange = null;
    2121      if(param.Value != null) {
    22         JsonItem tmp = root.Extract(param.Value, root);
     22        IJsonItem tmp = root.Extract(param.Value, root);
    2323        tmp.Parent = item;
    2424        actualValue = tmp.Value;
     
    3131    }
    3232
    33     public override void InjectData(IParameter parameter, JsonItem data, IJsonItemConverter root) {
     33    public override void InjectData(IParameter parameter, IJsonItem data, IJsonItemConverter root) {
    3434      IValueLookupParameter param = parameter as IValueLookupParameter;
    3535      param.ActualName = CastValue<string>(data.ActualName);
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/ValueParameterConverter.cs

    r17404 r17406  
    1111    public override Type ConvertableType => typeof(IValueParameter);
    1212
    13     public override void InjectData(IParameter parameter, JsonItem data, IJsonItemConverter root) {
     13    public override void InjectData(IParameter parameter, IJsonItem data, IJsonItemConverter root) {
    1414      if (parameter.ActualValue == null && data.Value != null)
    1515        parameter.ActualValue = Instantiate(parameter.DataType);
     
    1717    }
    1818
    19     public override void Populate(IParameter value, JsonItem item, IJsonItemConverter root) {
     19    public override void Populate(IParameter value, IJsonItem item, IJsonItemConverter root) {
    2020      item.Name = value.Name;
    2121      if (value.ActualValue != null) {
    22         JsonItem tmp = root.Extract(value.ActualValue, root);
     22        IJsonItem tmp = root.Extract(value.ActualValue, root);
    2323        if(!(tmp is UnsupportedJsonItem)) {
    2424          if (tmp.Name == "[OverridableParamName]") {
    2525            tmp.Name = value.Name;
    26             JsonItem.Merge(item, tmp);
     26            JsonItem.Merge(item as JsonItem, tmp as JsonItem);
    2727          } else
    2828            item.AddChilds(tmp);
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/ValueRangeConverter.cs

    r17394 r17406  
    2727    private const BindingFlags Flags = BindingFlags.NonPublic | BindingFlags.Instance;
    2828
    29     public override void Populate(IItem value, JsonItem item, IJsonItemConverter root) {
     29    public override void Populate(IItem value, IJsonItem item, IJsonItemConverter root) {
    3030      var field = value.GetType().GetField("values", Flags);
    3131      Tuple<T,T> tuple = (Tuple<T,T>)field.GetValue(value);
     
    3535    }
    3636
    37     public override void InjectData(IItem item, JsonItem data, IJsonItemConverter root) {
     37    public override void InjectData(IItem item, IJsonItem data, IJsonItemConverter root) {
    3838      object[] arr = (object[])data.Value;
    3939      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  
    3434    where T : struct
    3535  {
    36     public override void InjectData(IItem item, JsonItem data, IJsonItemConverter root) =>
     36    public override void InjectData(IItem item, IJsonItem data, IJsonItemConverter root) =>
    3737      CopyArrayData(((ArrayType)item), CastValue<T[]>(data.Value));
    3838
    39     public override void Populate(IItem value, JsonItem item, IJsonItemConverter root) {
     39    public override void Populate(IItem value, IJsonItem item, IJsonItemConverter root) {
    4040      item.Name = "[OverridableParamName]";
    4141      item.Value = ((ArrayType)value).CloneAsArray();
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/ValueTypeMatrixConverter.cs

    r17394 r17406  
    3333    where T : struct
    3434  {
    35     public override void InjectData(IItem item, JsonItem data, IJsonItemConverter root) =>
     35    public override void InjectData(IItem item, IJsonItem data, IJsonItemConverter root) =>
    3636      CopyMatrixData(item as MatrixType, data.Value);
    3737
    38     public override void Populate(IItem value, JsonItem item, IJsonItemConverter root) {
     38    public override void Populate(IItem value, IJsonItem item, IJsonItemConverter root) {
    3939      item.Name = "[OverridableParamName]";
    4040      item.Value = ((MatrixType)value).CloneAsMatrix();
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/ValueTypeValueConverter.cs

    r17394 r17406  
    3838    where T : struct {
    3939
    40     public override void InjectData(IItem item, JsonItem data, IJsonItemConverter root) =>
     40    public override void InjectData(IItem item, IJsonItem data, IJsonItemConverter root) =>
    4141      ((ValueType)item).Value = CastValue<T>(data.Value);
    4242
    43     public override void Populate(IItem value, JsonItem item, IJsonItemConverter root) {
     43    public override void Populate(IItem value, IJsonItem item, IJsonItemConverter root) {
    4444      item.Name = "[OverridableParamName]";
    4545      item.Value = ((ValueType)value).Value;
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/HeuristicLab.JsonInterface.csproj

    r17405 r17406  
    6666    <Compile Include="Converters\ValueLookupParameterConverter.cs" />
    6767    <Compile Include="Converters\ValueRangeConverter.cs" />
     68    <Compile Include="Interfaces\IJsonItem.cs" />
     69    <Compile Include="Interfaces\IJsonItemValidator.cs" />
    6870    <Compile Include="ResultItem.cs" />
    6971    <Compile Include="SingleLineArrayJsonWriter.cs" />
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Interfaces/IJsonItemConverter.cs

    r17394 r17406  
    1515    /// <param name="item">The IItem which get the data injected.</param>
    1616    /// <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);
    1818
    1919    /// <summary>
     
    2323    /// <param name="value">The IItem to extract infos.</param>
    2424    /// <returns>JsonItem with infos to reinitialise the IItem.</returns>
    25     JsonItem Extract(IItem value, IJsonItemConverter root);
     25    IJsonItem Extract(IItem value, IJsonItemConverter root);
    2626
    2727    Type ConvertableType { get; }
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/JCGenerator.cs

    r17405 r17406  
    1717    private JObject Template { get; set; }
    1818    private JArray JArrayItems { get; set; }
    19     private IList<JsonItem> JsonItems { get; set; }
     19    private IList<IJsonItem> JsonItems { get; set; }
    2020    private IOptimizer Optimizer { get; set; }
    2121
     
    2424      // data container
    2525      JArrayItems = new JArray();
    26       JsonItems = new List<JsonItem>();
     26      JsonItems = new List<IJsonItem>();
    2727
    2828      ProtoBufSerializer serializer = new ProtoBufSerializer();
     
    4040    }
    4141
    42     public string GenerateTemplate(IEnumerable<JsonItem> items) {
     42    public string GenerateTemplate(IEnumerable<IJsonItem> items) {
    4343      ProtoBufSerializer serializer = new ProtoBufSerializer();
    4444      serializer.Serialize(Optimizer, @"C:\Workspace\template.hl");
     
    6161    }
    6262
    63     public string GenerateTemplate(JsonItem rootItem, IOptimizer optimizer) {
     63    public string GenerateTemplate(IJsonItem rootItem, IOptimizer optimizer) {
    6464      // data container
    6565      Template = JObject.Parse(Constants.Template);
    66       JsonItems = new List<JsonItem>();
     66      JsonItems = new List<IJsonItem>();
    6767
    6868      // extract JsonItem, save the name in the metadata section of the
     
    9292    }
    9393
    94     public IEnumerable<JsonItem> FetchJsonItems(IOptimizer optimizer) {
     94    public IEnumerable<IJsonItem> FetchJsonItems(IOptimizer optimizer) {
    9595      // data container
    9696      Template = JObject.Parse(Constants.Template);
    97       JsonItems = new List<JsonItem>();
     97      JsonItems = new List<IJsonItem>();
    9898      Optimizer = optimizer;
    9999
     
    110110
    111111    private void AddIItem(IItem item) {
    112       JsonItem jsonItem = JsonItemConverter.Extract(item);
     112      IJsonItem jsonItem = JsonItemConverter.Extract(item);
    113113      Template[Constants.Metadata][Constants.Optimizer] = item.ItemName;
    114114      PopulateJsonItems(jsonItem);
     
    116116
    117117    // 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;
    120120     
    121121      if (item.Value != null || item.Range != null || item is ResultItem || item.ActualName != null) {
     
    130130    }
    131131
    132     private static JObject Serialize(JsonItem item) =>
     132    private static JObject Serialize(IJsonItem item) =>
    133133      JObject.FromObject(item, Settings());
    134134
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/JsonItem.cs

    r17404 r17406  
    1414  /// Main data class for json interface.
    1515  /// </summary>
    16   public class JsonItem {
    17     public class JsonItemValidator {
     16  public class JsonItem : IJsonItem {
     17
     18    public class JsonItemValidator : IJsonItemValidator {
    1819      private IDictionary<int, bool> Cache = new Dictionary<int, bool>();
    1920      private JsonItem Root { get; set; }
     
    2223      }
    2324
    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>();
    2627        return ValidateHelper(Root, ref faultyItems);
    2728      }
    2829
    29       private bool ValidateHelper(JsonItem item, ref IList<JsonItem> faultyItems) {
     30      private bool ValidateHelper(JsonItem item, ref IList<IJsonItem> faultyItems) {
    3031        int hash = item.GetHashCode();
    3132        if (Cache.TryGetValue(hash, out bool r))
     
    3839        Cache.Add(hash, res);
    3940        foreach (var child in item.Children)
    40           res = res && ValidateHelper(child, ref faultyItems);
     41          res = res && ValidateHelper(child as JsonItem, ref faultyItems);
    4142        return res;
    4243      }
     
    4748    public virtual string Path {
    4849      get {
    49         JsonItem tmp = Parent;
     50        IJsonItem tmp = Parent;
    5051        StringBuilder builder = new StringBuilder(this.Name);
    5152        while(tmp != null) {
     
    5859
    5960    [JsonIgnore]
    60     public virtual IList<JsonItem> Children { get; protected set; }
     61    public virtual IList<IJsonItem> Children { get; protected set; }
    6162
    6263    [JsonIgnore]
    63     public virtual JsonItem Parent { get; set; }
     64    public virtual IJsonItem Parent { get; set; }
    6465
    6566    public virtual object Value { get; set; }
     
    7273    public JsonItem() { }
    7374
    74     public JsonItem(IEnumerable<JsonItem> childs) {
     75    public JsonItem(IEnumerable<IJsonItem> childs) {
    7576      AddChilds(childs);
    7677    }
    7778    #endregion
    78 
    7979
    8080    #region Public Static Methods
     
    8686      if(target.Children != null) {
    8787        if (from.Children != null)
    88           ((List<JsonItem>)from.Children).AddRange(target.Children);
     88          ((List<IJsonItem>)from.Children).AddRange(target.Children);
    8989      } else {
    9090        target.Children = from.Children;
     
    9494
    9595    #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>);
    9898
    99     public void AddChilds(IEnumerable<JsonItem> childs) {
     99    public void AddChilds(IEnumerable<IJsonItem> childs) {
    100100      if (Children == null)
    101         Children = new List<JsonItem>();
     101        Children = new List<IJsonItem>();
    102102      foreach (var child in childs) {
    103103        Children.Add(child);
     
    106106    }
    107107
    108     public virtual JsonItemValidator GetValidator() => new JsonItemValidator(this);
     108    public virtual IJsonItemValidator GetValidator() => new JsonItemValidator(this);
    109109    #endregion
    110110
     
    154154
    155155    #region BuildJsonItemMethods
    156     public static JsonItem BuildJsonItem(JObject obj) {
     156    public static IJsonItem BuildJsonItem(JObject obj) {
    157157      object val = obj[nameof(Value)]?.ToObject<object>();
    158158      if (val is JContainer jContainer) // for resolving array values
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/JsonItemConverter.cs

    r17394 r17406  
    2020      = new Dictionary<Type, IJsonItemConverter>();
    2121
    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>();
    2424
    2525    public int Priority => throw new NotImplementedException();
     
    5151    }
    5252   
    53     public void Inject(IItem item, JsonItem data, IJsonItemConverter root) {
     53    public void Inject(IItem item, IJsonItem data, IJsonItemConverter root) {
    5454      if(!Cache.ContainsKey(item.GetHashCode())) {
    5555        IJsonItemConverter converter = GetConverter(item.GetType());
     
    5858    }
    5959
    60     public JsonItem Extract(IItem item, IJsonItemConverter root) {
     60    public IJsonItem Extract(IItem item, IJsonItemConverter root) {
    6161      int hash = item.GetHashCode();
    62       if (Cache.TryGetValue(hash, out JsonItem val))
     62      if (Cache.TryGetValue(hash, out IJsonItem val))
    6363        return val;
    6464      else {
    6565        IJsonItemConverter converter = GetConverter(item.GetType());
    6666        if (converter == null) return new UnsupportedJsonItem();
    67         JsonItem tmp = GetConverter(item.GetType()).Extract(item, root);
     67        IJsonItem tmp = GetConverter(item.GetType()).Extract(item, root);
    6868        Cache.Add(hash, tmp);
    6969        return tmp;
     
    7171    }
    7272   
    73     public static void Inject(IItem item, JsonItem data) {
     73    public static void Inject(IItem item, IJsonItem data) {
    7474      IJsonItemConverter c = JsonItemConverterFactory.Create();
    7575      c.Inject(item, data, c);
    7676    }
    7777
    78     public static JsonItem Extract(IItem item) {
     78    public static IJsonItem Extract(IItem item) {
    7979      IJsonItemConverter c = JsonItemConverterFactory.Create();
    8080      return c.Extract(item, c);
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/JsonTemplateInstantiator.cs

    r17395 r17406  
    2121      public JToken Template { get; set; }
    2222      public JArray Config { get; set; }
    23       public IDictionary<string, JsonItem> Objects { get; set; }
     23      public IDictionary<string, IJsonItem> Objects { get; set; }
    2424    }
    2525
     
    3232    public static IOptimizer Instantiate(string templateFile, string configFile = "") {
    3333      InstData instData = new InstData() {
    34         Objects = new Dictionary<string, JsonItem>()
     34        Objects = new Dictionary<string, IJsonItem>()
    3535      };
    3636
     
    5656
    5757      // get algorthm data and object
    58       JsonItem optimizerData = instData.Objects[optimizerName];
     58      IJsonItem optimizerData = instData.Objects[optimizerName];
    5959
    6060      // inject configuration
     
    7070       
    7171        // rebuilds object tree
    72         JsonItem parent = null;
     72        IJsonItem parent = null;
    7373        StringBuilder partialPath = new StringBuilder();
    7474        for(int i = 0; i < pathParts.Length-1; ++i) {
    7575          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)) {
    7878            tmp = value;
    7979          } else {
     
    8686        }
    8787
    88         JsonItem data = JsonItem.BuildJsonItem(item);
     88        IJsonItem data = JsonItem.BuildJsonItem(item);
    8989        parent.AddChilds(data);
    9090        instData.Objects.Add(data.Path, data);
     
    9595      foreach (JObject obj in instData.Config) {
    9696        // build item from config object
    97         JsonItem item = JsonItem.BuildJsonItem(obj);
     97        IJsonItem item = JsonItem.BuildJsonItem(obj);
    9898        // override default value
    99         if (instData.Objects.TryGetValue(item.Path, out JsonItem param)) {
     99        if (instData.Objects.TryGetValue(item.Path, out IJsonItem param)) {
    100100          param.Value = item.Value;
    101101          // override ActualName (for LookupParameters)
     
    106106    }
    107107
    108     private static JsonItem GetData(string key, InstData instData)
     108    private static IJsonItem GetData(string key, InstData instData)
    109109    {
    110       if (instData.Objects.TryGetValue(key, out JsonItem value))
     110      if (instData.Objects.TryGetValue(key, out IJsonItem value))
    111111        return value;
    112112      else
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/SingleLineArrayJsonWriter.cs

    r17394 r17406  
    1919      base.Formatting = Formatting.Indented;
    2020      base.WritePropertyName(name);
    21       isRangeArray = name == nameof(JsonItem.Range) || name == nameof(JsonItem.Value);
     21      isRangeArray = name == nameof(IJsonItem.Range) || name == nameof(IJsonItem.Value);
    2222    }
    2323
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/UnsupportedJsonItem.cs

    r17394 r17406  
    1818
    1919    [JsonIgnore]
    20     public override IList<JsonItem> Children {
     20    public override IList<IJsonItem> Children {
    2121      get => throw new NotSupportedException();
    2222      protected set => throw new NotSupportedException();
     
    2424
    2525    [JsonIgnore]
    26     public override JsonItem Parent {
     26    public override IJsonItem Parent {
    2727      get => throw new NotSupportedException();
    2828      set => throw new NotSupportedException();
Note: See TracChangeset for help on using the changeset viewer.