Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/26/19 13:27:23 (5 years 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
File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.