Free cookie consent management tool by TermsFeed Policy Generator

Changeset 17283


Ignore:
Timestamp:
10/01/19 14:36:32 (5 years ago)
Author:
dpiringe
Message:

#3026: renamed Component to JsonItem

Location:
branches/3026_IntegrationIntoSymSpace/HeuristicLab.Manufacture
Files:
18 edited
1 moved

Legend:

Unmodified
Added
Removed
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.Manufacture/Converters/BaseConverter.cs

    r17281 r17283  
    1010  public abstract class BaseConverter : IJsonItemConverter
    1111  {
    12     public Component Extract(IItem value) {
    13       Component data = ExtractData(value);
     12    public JsonItem Extract(IItem value) {
     13      JsonItem data = ExtractData(value);
    1414      data.Name = String.IsNullOrEmpty(data.Name) ? value.ItemName : data.Name;
    1515      return data;
    1616    }
    1717
    18     public void Inject(IItem item, Component data) {
     18    public void Inject(IItem item, JsonItem data) {
    1919      if(data.Reference != null) {
    20         Component.Merge(data, data.Reference);
     20        JsonItem.Merge(data, data.Reference);
    2121      }
    2222      InjectData(item, data);
    2323    }
    2424
    25     public abstract void InjectData(IItem item, Component data);
    26     public abstract Component ExtractData(IItem value);
     25    public abstract void InjectData(IItem item, JsonItem data);
     26    public abstract JsonItem ExtractData(IItem value);
    2727
    2828    #region Helper
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.Manufacture/Converters/ConstrainedValueParameterConverter.cs

    r17281 r17283  
    88namespace HeuristicLab.Manufacture {
    99  public class ConstrainedValueParameterConverter : ParameterBaseConverter {
    10     public override void InjectData(IParameter parameter, Component data) {
     10    public override void InjectData(IParameter parameter, JsonItem data) {
    1111      foreach (var x in parameter.Cast<dynamic>().ValidValues)
    1212        if (x.GetType().Name == CastValue<string>(data.Default))
     
    1717    }
    1818
    19     public override Component ExtractData(IParameter value) =>
    20       new Component() {
     19    public override JsonItem ExtractData(IParameter value) =>
     20      new JsonItem() {
    2121        Name = value.Name,
    2222        Default = value.ActualValue?.GetType().Name,
     
    3333    }
    3434    // id = kombi aus path + default
    35     private IList<Component> GetParameterizedChilds(IParameter value) {
    36       List<Component> list = new List<Component>();
     35    private IList<JsonItem> GetParameterizedChilds(IParameter value) {
     36      List<JsonItem> list = new List<JsonItem>();
    3737      var values = value.Cast<dynamic>().ValidValues;
    3838      foreach(var x in values) {
    3939        if (x is IParameterizedItem) {
    40           Component tmp = JsonItemConverter.Extract(x);
     40          JsonItem tmp = JsonItemConverter.Extract(x);
    4141          tmp.PrependPath(value.Name);
    4242          list.Add(tmp);
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.Manufacture/Converters/DummyConverter.cs

    r17281 r17283  
    88namespace HeuristicLab.Manufacture {
    99  public class DummyConverter : BaseConverter {
    10     public override void InjectData(IItem item, Component data) {
     10    public override void InjectData(IItem item, JsonItem data) {
    1111      // do nothing because the instance already exists and
    1212      // there are no values to inject
    1313    }
    1414
    15     public override Component ExtractData(IItem value) =>
    16       new Component() { Default = value.GetType().Name };
     15    public override JsonItem ExtractData(IItem value) =>
     16      new JsonItem() { Default = value.GetType().Name };
    1717  }
    1818}
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.Manufacture/Converters/EnumTypeConverter.cs

    r17281 r17283  
    99namespace HeuristicLab.Manufacture {
    1010  public class EnumTypeConverter : BaseConverter {
    11     public override void InjectData(IItem item, Component data) =>
     11    public override void InjectData(IItem item, JsonItem data) =>
    1212      item.Cast<dynamic>().Value = Enum.Parse(
    1313        item.GetType().GenericTypeArguments.First(),
    1414        CastValue<string>(data.Default));
    1515
    16     public override Component ExtractData(IItem value) {
    17       Component data = new Component();
     16    public override JsonItem ExtractData(IItem value) {
     17      JsonItem data = new JsonItem();
    1818      object val = ((dynamic)value).Value;
    1919      Type enumType = val.GetType();
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.Manufacture/Converters/LookupParameterConverter.cs

    r17281 r17283  
    88namespace HeuristicLab.Manufacture {
    99  public class LookupParameterConverter : ParameterBaseConverter {
    10     public override Component ExtractData(IParameter value) {
    11       return new Component() { Name = value.Name };
     10    public override JsonItem ExtractData(IParameter value) {
     11      return new JsonItem() { Name = value.Name };
    1212    }
    1313
    14     public override void InjectData(IParameter parameter, Component data) {
     14    public override void InjectData(IParameter parameter, JsonItem data) {
    1515     
    1616    }
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.Manufacture/Converters/MultiCheckedOperatorConverter.cs

    r17281 r17283  
    88namespace HeuristicLab.Manufacture {
    99  public class MultiCheckedOperatorConverter : ParameterizedItemConverter {
    10     public override Component ExtractData(IItem value) {
    11       Component data = base.ExtractData(value);
     10    public override JsonItem ExtractData(IItem value) {
     11      JsonItem data = base.ExtractData(value);
    1212
    1313      data.Default = value.GetType().Name;
    14       data.Operators = new List<Component>();
    15       /*
    16       if (data.ParameterizedItems == null)
    17         data.ParameterizedItems = new List<Component>();
    18       data.ParameterizedItems.Add(data);
    19       */
     14      data.Operators = new List<JsonItem>();
    2015      dynamic val = value.Cast<dynamic>();
    2116      foreach (var op in val.Operators) {
    22         data.Operators.Add(new Component() {
     17        data.Operators.Add(new JsonItem() {
    2318          Name = op.Name,
    2419          Default = val.Operators.ItemChecked(op),
     
    3025    }
    3126
    32     public override void InjectData(IItem item, Component data) {
     27    public override void InjectData(IItem item, JsonItem data) {
    3328      base.InjectData(item, data);
    3429
     
    3934    }
    4035
    41     private bool GetOperatorState(string name, Component data) {
     36    private bool GetOperatorState(string name, JsonItem data) {
    4237      foreach(var op in data.Operators) {
    4338        if (op.Name == name) return op.Default.Cast<bool>();
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.Manufacture/Converters/ParameterBaseConverter.cs

    r17281 r17283  
    88namespace HeuristicLab.Manufacture {
    99  public abstract class ParameterBaseConverter : BaseConverter {
    10     public override Component ExtractData(IItem value) {
     10    public override JsonItem ExtractData(IItem value) {
    1111      IParameter param = value.Cast<IParameter>();
    12       Component comp = ExtractData(param);
     12      JsonItem comp = ExtractData(param);
    1313      //comp.Path = value.Cast<IParameter>().ActualValue?.ItemName;
    1414      /*comp.Path = value.Cast<IParameter>().Name + "." + comp.Path;
     
    2020      return comp;
    2121    }
    22     public abstract Component ExtractData(IParameter value);
     22    public abstract JsonItem ExtractData(IParameter value);
    2323
    24     public override void InjectData(IItem item, Component data) => InjectData(item.Cast<IParameter>(), data);
     24    public override void InjectData(IItem item, JsonItem data) => InjectData(item.Cast<IParameter>(), data);
    2525
    26     public abstract void InjectData(IParameter parameter, Component data);
     26    public abstract void InjectData(IParameter parameter, JsonItem data);
    2727  }
    2828}
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.Manufacture/Converters/ParameterizedItemConverter.cs

    r17281 r17283  
    22using System.Collections.Generic;
    33using System.Linq;
    4 using System.Text;
     4using System.Text;JsonItem obj
    55using System.Threading.Tasks;
    66using HeuristicLab.Core;
     
    99{
    1010  public class ParameterizedItemConverter : BaseConverter {
    11     public override void InjectData(IItem item, Component data) {
     11    public override void InjectData(IItem item, JsonItem data) {
    1212      IParameterizedItem pItem = item.Cast<IParameterizedItem>();
    1313
     
    1919    }
    2020
    21     public override Component ExtractData(IItem value) {
    22       Component obj = new Component();
    23       obj.Name = value.ItemName;
    24       obj.Type = value.GetType().AssemblyQualifiedName;
    25       obj.Path = value.ItemName;
     21    public override JsonItem ExtractData(IItem value) {
     22      JsonItem item = new JsonItem();
     23      item.Name = value.ItemName;
     24      item.Type = value.GetType().AssemblyQualifiedName;
     25      item.Path = value.ItemName;
    2626
    2727      foreach (var param in value.Cast<IParameterizedItem>().Parameters) {
    28         Component data = JsonItemConverter.Extract(param);
     28        JsonItem data = JsonItemConverter.Extract(param);
    2929        data.Name = param.Name;
    3030        data.Path = param.Name;
    31         data.PrependPath(obj.Path);
     31        data.PrependPath(item.Path);
    3232        data.UpdatePaths();
    3333       
    34         if (obj.Parameters == null)
    35           obj.Parameters = new List<Component>();
    36         obj.Parameters.Add(data);
     34        if (item.Parameters == null)
     35          item.Parameters = new List<JsonItem>();
     36        item.Parameters.Add(data);
    3737      }
    38       return obj;
     38      return item;
    3939    }
    4040  }
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.Manufacture/Converters/StringValueConverter.cs

    r17281 r17283  
    99namespace HeuristicLab.Manufacture {
    1010  public class StringValueConverter : BaseConverter {
    11     public override void InjectData(IItem item, Component data) =>
     11    public override void InjectData(IItem item, JsonItem data) =>
    1212      item.Cast<StringValue>().Value = CastValue<string>(data.Default);
    1313
    14     public override Component ExtractData(IItem value) =>
    15       new Component() {
     14    public override JsonItem ExtractData(IItem value) =>
     15      new JsonItem() {
    1616        Default = value.Cast<StringValue>().Value
    1717      };
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.Manufacture/Converters/ValueParameterConverter.cs

    r17281 r17283  
    99  public class ValueParameterConverter : ParameterBaseConverter {
    1010
    11     public override void InjectData(IParameter parameter, Component data) =>
     11    public override void InjectData(IParameter parameter, JsonItem data) =>
    1212      JsonItemConverter.Inject(parameter.ActualValue, data);
    1313
    14     public override Component ExtractData(IParameter value) {
    15       Component data = null;
     14    public override JsonItem ExtractData(IParameter value) {
     15      JsonItem data = null;
    1616      if (value.ActualValue == null)
    17         data = new Component();
     17        data = new JsonItem();
    1818      else
    1919        data = JsonItemConverter.Extract(value.ActualValue);
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.Manufacture/Converters/ValueTypeArrayConverter.cs

    r17281 r17283  
    1313    where T : struct
    1414  {
    15     public override void InjectData(IItem item, Component data) =>
     15    public override void InjectData(IItem item, JsonItem data) =>
    1616      CopyArrayData(item.Cast<ArrayType>(), CastValue<T[]>(data.Default));
    1717
    18     public override Component ExtractData(IItem value) =>
    19       new Component() {
     18    public override JsonItem ExtractData(IItem value) =>
     19      new JsonItem() {
    2020        Default = value.Cast<ArrayType>().CloneAsArray()
    2121      };
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.Manufacture/Converters/ValueTypeMatrixConverter.cs

    r17281 r17283  
    1313    where T : struct
    1414  {
    15     public override void InjectData(IItem item, Component data) =>
     15    public override void InjectData(IItem item, JsonItem data) =>
    1616      CopyMatrixData(item.Cast<MatrixType>(), CastValue<T[,]>(data.Default));
    1717
    18     public override Component ExtractData(IItem value) =>
    19       new Component() {
     18    public override JsonItem ExtractData(IItem value) =>
     19      new JsonItem() {
    2020        Default = value.Cast<MatrixType>().CloneAsMatrix()
    2121      };
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.Manufacture/Converters/ValueTypeValueConverter.cs

    r17281 r17283  
    1212    where T : struct {
    1313
    14     public override void InjectData(IItem item, Component data) =>
     14    public override void InjectData(IItem item, JsonItem data) =>
    1515      item.Cast<ValueType>().Value = CastValue<T>(data.Default);
    1616
    17     public override Component ExtractData(IItem value) =>
    18       new Component() {
     17    public override JsonItem ExtractData(IItem value) =>
     18      new JsonItem() {
    1919        Default = value.Cast<ValueType>().Value,
    2020        Range = new object[] { GetMinValue(), GetMaxValue() }
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.Manufacture/HeuristicLab.Manufacture.csproj

    r17282 r17283  
    7171    <Compile Include="Program.cs" />
    7272    <Compile Include="Properties\AssemblyInfo.cs" />
    73     <Compile Include="Component.cs" />
     73    <Compile Include="JsonItem.cs" />
    7474    <Compile Include="Interfaces\IJsonItemConverter.cs" />
    7575    <Compile Include="JsonItemConverter.cs" />
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.Manufacture/Interfaces/IJsonItemConverter.cs

    r17281 r17283  
    1010  public interface IJsonItemConverter {
    1111    /// <summary>
    12     /// Extracts all infos out of an IItem to create a Component.
     12    /// Extracts all infos out of an IItem to create a JsonItem.
    1313    /// (For template generation.)
    1414    /// </summary>
    1515    /// <param name="value">The IItem to extract infos.</param>
    16     /// <returns>Component with infos to reinitialise the IItem.</returns>
    17     Component Extract(IItem value);
     16    /// <returns>JsonItem with infos to reinitialise the IItem.</returns>
     17    JsonItem Extract(IItem value);
    1818
    1919    /// <summary>
    20     /// Injects the saved infos from the Component into the IItem.
     20    /// Injects the saved infos from the JsonItem into the IItem.
    2121    /// (Sets the necessary values.)
    2222    /// </summary>
    2323    /// <param name="item">The IItem which get the data injected.</param>
    24     /// <param name="data">The Component with the saved values.</param>
    25     void Inject(IItem item, Component data);
     24    /// <param name="data">The JsonItem with the saved values.</param>
     25    void Inject(IItem item, JsonItem data);
    2626  }
    2727}
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.Manufacture/JCGenerator.cs

    r17281 r17283  
    2727
    2828    JArray jsonItems = new JArray();
    29     private void PopulateJsonItems(Component component) {
    30       if (component.Parameters != null) {
    31         if(component.Range == null)
    32           jsonItems.Add(Serialize(component));
    33         foreach (var p in component.Parameters)
     29    private void PopulateJsonItems(JsonItem item) {
     30      if (item.Parameters != null) {
     31        if(item.Range == null)
     32          jsonItems.Add(Serialize(item));
     33        foreach (var p in item.Parameters)
    3434          if(p.Parameters != null)
    3535            PopulateJsonItems(p);
     
    3737    }
    3838
    39     private JObject Serialize(Component component) {
    40       JObject obj = JObject.FromObject(component, Settings());
     39    private JObject Serialize(JsonItem item) {
     40      JObject obj = JObject.FromObject(item, Settings());
    4141      obj["StaticParameters"] = obj["Parameters"];
    4242      obj["FreeParameters"] = obj["Parameters"];
     
    4949      obj.Property("Type")?.Remove();
    5050
    51       TypeList.Add(component.Path, component.Type);
     51      TypeList.Add(item.Path, item.Type);
    5252      return obj;
    5353    }
     
    5555    public string GenerateTemplate(IAlgorithm algorithm, IProblem problem, params string[] freeParameters) {
    5656      algorithm.Problem = problem;
    57       Component algorithmData = JsonItemConverter.Extract(algorithm);
    58       Component problemData = JsonItemConverter.Extract(problem);
     57      JsonItem algorithmData = JsonItemConverter.Extract(algorithm);
     58      JsonItem problemData = JsonItemConverter.Extract(problem);
    5959      PopulateJsonItems(algorithmData);
    6060      PopulateJsonItems(problemData);
     
    7474      IList<JObject> objToRemove = new List<JObject>();
    7575      TransformNodes(x => {
    76         var p = x.ToObject<Component>();
     76        var p = x.ToObject<JsonItem>();
    7777
    7878        /*bool isSelected = false;
     
    9696      IList<JObject> objToRemove = new List<JObject>();
    9797      TransformNodes(x => {
    98         var p = x.ToObject<Component>();
     98        var p = x.ToObject<JsonItem>();
    9999        x.Property("Range")?.Remove();
    100100        x.Property("Operators")?.Remove();
     
    105105      foreach (var x in objToRemove) x.Remove();
    106106    }
    107 
    108107
    109108    private JsonSerializer Settings() => new JsonSerializer() {
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.Manufacture/JCInstantiator.cs

    r17281 r17283  
    2222      TypeList = Config["Types"].ToObject<Dictionary<string, string>>();
    2323
    24       Component algorithmData = GetData(Config["Metadata"]["Algorithm"].ToString());
     24      JsonItem algorithmData = GetData(Config["Metadata"]["Algorithm"].ToString());
    2525      ResolveReferences(algorithmData);
    2626      IAlgorithm algorithm = CreateObject<IAlgorithm>(algorithmData);
    2727     
    28       Component problemData = GetData(Config["Metadata"]["Problem"].ToString());
     28      JsonItem problemData = GetData(Config["Metadata"]["Problem"].ToString());
    2929      ResolveReferences(problemData);
    3030      IProblem problem = CreateObject<IProblem>(problemData);
     
    3737    }
    3838
    39     private void ResolveReferences(Component data) {
     39    private void ResolveReferences(JsonItem data) {
    4040      foreach (var p in data.Parameters)
    4141        if (p.Default is string && p.Reference == null)
     
    4343    }
    4444
    45     private Component GetData(string key)
     45    private JsonItem GetData(string key)
    4646    {
    4747      foreach(JObject item in Config["Objects"])
    4848      {
    49         Component data = BuildComponent(item);
     49        JsonItem data = BuildJsonItem(item);
    5050        if (data.Name == key) return data;
    5151      }
     
    5353    }
    5454
    55     private T CreateObject<T>(Component data) {
     55    private T CreateObject<T>(JsonItem data) {
    5656      if (TypeList.TryGetValue(data.Name, out string typeName)) {
    5757        Type type = Type.GetType(typeName);
     
    6060    }
    6161
    62     private Component BuildComponent(JObject obj) =>
    63       new Component() {
    64         Name = obj[nameof(Component.Name)]?.ToString(),
    65         Default = obj[nameof(Component.Default)]?.ToObject<object>(),
    66         Range = obj[nameof(Component.Range)]?.ToObject<object[]>(),
    67         Type = obj[nameof(Component.Type)]?.ToObject<string>(),
     62    private JsonItem BuildJsonItem(JObject obj) =>
     63      new JsonItem() {
     64        Name = obj[nameof(JsonItem.Name)]?.ToString(),
     65        Default = obj[nameof(JsonItem.Default)]?.ToObject<object>(),
     66        Range = obj[nameof(JsonItem.Range)]?.ToObject<object[]>(),
     67        Type = obj[nameof(JsonItem.Type)]?.ToObject<string>(),
    6868        Parameters = PopulateParameters(obj),
    6969        Operators = PopulateOperators(obj)
    7070      };
    7171
    72     private IList<Component> PopulateParameters(JObject obj) {
    73       IList<Component> list = new List<Component>();
     72    private IList<JsonItem> PopulateParameters(JObject obj) {
     73      IList<JsonItem> list = new List<JsonItem>();
    7474      if (obj["StaticParameters"] != null)
    7575        foreach (JObject param in obj["StaticParameters"])
    76           list.Add(BuildComponent(param));
     76          list.Add(BuildJsonItem(param));
    7777
    7878      if (obj["FreeParameters"] != null) {
    7979        foreach (JObject param in obj["FreeParameters"]) {
    80           Component tmp = BuildComponent(param);
    81           Component comp = null;
     80          JsonItem tmp = BuildJsonItem(param);
     81          JsonItem comp = null;
    8282          foreach (var p in list) // TODO: nicht notwendig, da immer alle params im static block sind
    8383            if (p.Name == tmp.Name) comp = p;
    8484          if (comp != null)
    85             Component.Merge(comp, tmp);
     85            JsonItem.Merge(comp, tmp);
    8686          else list.Add(tmp);
    8787        }
     
    9090    }
    9191
    92     private IList<Component> PopulateOperators(JObject obj) {
    93       IList<Component> list = new List<Component>();
     92    private IList<JsonItem> PopulateOperators(JObject obj) {
     93      IList<JsonItem> list = new List<JsonItem>();
    9494      if (obj[nameof(Operators)] != null)
    9595        foreach (JObject sp in obj[nameof(Operators)]) {
    96           Component tmp = BuildComponent(sp);
     96          JsonItem tmp = BuildJsonItem(sp);
    9797          list.Add(tmp);
    9898        }
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.Manufacture/JsonItem.cs

    r17282 r17283  
    1010namespace HeuristicLab.Manufacture {
    1111  //JsonItem
    12   public class Component {
     12  public class JsonItem {
    1313    private IList<object> range;
    1414    private object defaultValue;
     
    3535    }
    3636
    37     public IList<Component> Parameters { get; set; }
    38     public IList<Component> Operators { get; set; }
     37    public IList<JsonItem> Parameters { get; set; }
     38    public IList<JsonItem> Operators { get; set; }
    3939   
    4040    public override bool Equals(object obj) =>
    41       (obj is Component ? (obj.Cast<Component>().Name == this.Name) : false);
     41      (obj is JsonItem ? (obj.Cast<JsonItem>().Name == this.Name) : false);
    4242     
    4343    public override int GetHashCode() => Name.GetHashCode();
    4444
    4545    [JsonIgnore]
    46     public Component Reference { get; set; }
     46    public JsonItem Reference { get; set; }
    4747   
    48     public static void Merge(Component target, Component from) {
     48    public static void Merge(JsonItem target, JsonItem from) {
    4949      target.Name = from.Name ?? target.Name;
    5050      target.Type = from.Type ?? target.Type;
     
    5959    public bool FulfillConstraints() => FulfillConstraints(this);
    6060
    61     public static bool FulfillConstraints(Component data) =>
     61    public static bool FulfillConstraints(JsonItem data) =>
    6262      data.Range != null && data.Default != null && (
    6363      IsInRangeList(data.Range, data.Default) ||
     
    9191    }
    9292
    93     private void PrependPathHelper(IEnumerable<Component> components, string str) {
    94       if (components != null) {
    95         foreach (var p in components)
     93    private void PrependPathHelper(IEnumerable<JsonItem> items, string str) {
     94      if (items != null) {
     95        foreach (var p in items)
    9696          p.PrependPath(str);
    9797      }
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.Manufacture/JsonItemConverter.cs

    r17282 r17283  
    2222    }
    2323
    24 
    2524    public static void Register<T>(IJsonItemConverter converter, int priority) => Register(typeof(T), converter, priority);
    2625
     
    4342    }
    4443
    45     internal static void Inject(IItem item, Component data) =>
     44    internal static void Inject(IItem item, JsonItem data) =>
    4645      Get(item.GetType()).Inject(item, data);
    4746
    48     internal static Component Extract(IItem item) =>
     47    internal static JsonItem Extract(IItem item) =>
    4948      Get(item.GetType()).Extract(item);
    5049
Note: See TracChangeset for help on using the changeset viewer.