Changeset 17371


Ignore:
Timestamp:
11/26/19 13:27:23 (3 weeks ago)
Author:
dpiringe
Message:

#3026:

  • added new Converters:
    • CheckedItemListConverter
    • ItemCollectionConverter
    • PrimitiveConverter: not implemented yet
    • ConfigurableConverter: maybe this converter can replace all others
  • added program for testing -> HeuristicLab.ConfigStarter
  • added the option to register converter with an attic guid
Location:
branches/3026_IntegrationIntoSymSpace
Files:
11 added
4 edited

Legend:

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

    r17353 r17371  
    8686
    8787    protected object GetDefaultValue(Type t) => t.IsValueType ? Activator.CreateInstance(t) : null;
     88
     89   
     90
    8891    #endregion
    8992  }
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/HeuristicLab.JsonInterface.csproj

    r17353 r17371  
    6363    <Compile Include="Attributes\ConvertableAttribute.cs" />
    6464    <Compile Include="Constants.cs" />
     65    <Compile Include="Converters\CheckedItemListConverter.cs" />
     66    <Compile Include="Converters\ConfigurableConverter.cs" />
     67    <Compile Include="Converters\ItemCollectionConverter.cs" />
    6568    <Compile Include="Converters\ParameterConverter.cs" />
     69    <Compile Include="Converters\PrimitiveConverter.cs" />
    6670    <Compile Include="Converters\StorableConverter.cs" />
    6771    <Compile Include="Converters\ValueLookupParameterConverter.cs" />
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/JsonItem.cs

    r17354 r17371  
    133133    public static JsonItem BuildJsonItem(JObject obj, IDictionary<string, string> typeList) {
    134134      object val = obj[nameof(Value)]?.ToObject<object>();
    135       if (val is JContainer)
    136         val = ((JContainer)val).ToObject<object[]>();
     135      if (val is JContainer) {
     136        //try {
     137          val = ((JContainer)val).ToObject<object[]>();
     138        /*} catch (Exception) { }
     139        try {
     140          val = ((JContainer)val).ToObject<object[,]>();
     141        } catch (Exception) { }*/
     142      }
     143       
    137144
    138145      return new JsonItem() {
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/JsonItemConverter.cs

    r17353 r17371  
    66using HeuristicLab.Core;
    77using HeuristicLab.Data;
     8using HeuristicLab.PluginInfrastructure;
     9using HEAL.Attic;
     10using System.Collections;
    811
    912namespace HeuristicLab.JsonInterface {
     
    3033      if (!Converters.ContainsKey(type))
    3134        Converters.Add(type, new ConverterPriorityContainer() { Converter = converter, Priority = priority });
     35    }
     36
     37
     38    public static void Register(string atticGuid, IJsonItemConverter converter, int priority) =>
     39      Register(new Guid(atticGuid), converter, priority);
     40
     41    public static void Register(Guid atticGuid, IJsonItemConverter converter, int priority) {
     42      if (Mapper.StaticCache.TryGetType(atticGuid, out Type type)) {
     43        Register(type, converter, priority);
     44      }
    3245    }
    3346
     
    6881        return best.Converter;
    6982      }
     83
     84      Type t = Mapper.StaticCache.GetType(new Guid("25137f88-66b9-48d7-a2bd-60190082e044"));
     85
     86     
     87
    7088      return new DummyConverter();
    7189    }
     
    113131      Register(typeof(IConstrainedValueParameter<>), new ConstrainedValueParameterConverter(), 3);
    114132      Register(typeof(ICheckedMultiOperator<>), new MultiCheckedOperatorConverter(), 3);
     133
     134      //ApplicationManager.Manager
     135      // "25137f88-66b9-48d7-a2bd-60190082e044"
     136      //new Guid("25137f88-66b9-48d7-a2bd-60190082e044")
     137      // ISymbol
     138
     139      Register("25137f88-66b9-48d7-a2bd-60190082e044",
     140        new ConfigurableConverter()
     141        .Primitive("InitialFrequency", ElementType.Property, new object[] { 0.0, 1.0 })
     142        .Primitive("Enabled", ElementType.Property, true)
     143        .Primitive("MinimumArity", ElementType.Property, 0)
     144        .Primitive("MaximumArity", ElementType.Property, 10),
     145        5);
     146
     147      // Dataset
     148      Register("49F4D145-50D7-4497-8D8A-D190CD556CC8",
     149        new ConfigurableConverter() //TODO: set guid to enable inheritance?
     150        /*.PrimitiveEnumerable("VariableNames", ElementType.Property)
     151        .PrimitiveEnumerable("DoubleVariables", ElementType.Property)
     152        .PrimitiveEnumerable("StringVariables", ElementType.Property)
     153        .PrimitiveEnumerable("DateTimeVariables", ElementType.Property)*/
     154        .PrimitiveEnumerable("storableData", ElementType.Field, new double[,] { }),
     155        5);
     156
     157      // ICheckedItemList<>
     158      Register("ba4a82ca-92eb-47a1-95a7-f41f6ef470f4",
     159        new ConfigurableConverter()
     160        .This((o,t) => {
     161          dynamic itemList = o as dynamic;
     162          IList<JsonItem> jsonItems = new List<JsonItem>();
     163          int count = 0;
     164          foreach(var obj in itemList) {
     165            IItem item = obj as IItem;
     166            JsonItem checkedStatus = new JsonItem() {
     167              Name = "Checked",
     168              Value = itemList.ItemChecked(obj),
     169              Range = new object[] { false, true }
     170            };
     171            JsonItem value = Extract(item);
     172
     173            jsonItems.Add(new JsonItem() {
     174              Name = item.ItemName + count++,
     175              Parameters = new JsonItem[] {
     176                checkedStatus, value
     177              },
     178              Type = item.GetType().AssemblyQualifiedName
     179            });
     180          }
     181          return jsonItems;
     182        }),
     183        5);
    115184    }
    116185  }
Note: See TracChangeset for help on using the changeset viewer.