Changeset 17407
- Timestamp:
- 01/27/20 12:18:06 (5 years ago)
- Location:
- branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface
- Files:
-
- 1 deleted
- 16 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/AlgorithmConverter.cs
r17406 r17407 13 13 public override Type ConvertableType => typeof(IAlgorithm); 14 14 15 public override void Inject Data(IItem item, IJsonItem data, IJsonItemConverter root) {16 base.Inject Data(item, data, root);15 public override void Inject(IItem item, IJsonItem data, IJsonItemConverter root) { 16 base.Inject(item, data, root); 17 17 IAlgorithm algorithm = item as IAlgorithm; 18 18 IJsonItem problemData = data.Children.Where(x => x.Name == algorithm.Problem.Name).First(); … … 20 20 21 21 } 22 23 public override void Populate(IItem value, IJsonItem item, IJsonItemConverter root) {24 base.Populate(value, item, root);22 23 public override IJsonItem Extract(IItem value, IJsonItemConverter root) { 24 IJsonItem item = base.Extract(value, root); 25 25 IAlgorithm algorithm = value as IAlgorithm; 26 foreach (var res in algorithm.Results) {27 item.AddChilds(new ResultItem() { 28 Name = res.Name, 29 Value = true, 30 Range = new object[] { true, false } 26 foreach (var res in algorithm.Results) { 27 item.AddChilds(new ResultItem() { 28 Name = res.Name, 29 Value = true, 30 Range = new object[] { true, false } 31 31 }); 32 32 } 33 33 item.AddChilds(root.Extract(algorithm.Problem, root)); 34 return item; 34 35 } 35 36 } -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/BaseConverter.cs
r17406 r17407 14 14 public abstract Type ConvertableType { get; } 15 15 16 public void Inject(IItem item, IJsonItem data, IJsonItemConverter root) { 17 18 InjectData(item, data, root); 19 } 20 21 public IJsonItem Extract(IItem value, IJsonItemConverter root) { 22 IJsonItem data = new JsonItem() { Name = value.ItemName }; 23 Populate(value, data, root); 24 return data; 25 } 26 27 public abstract void InjectData(IItem item, IJsonItem data, IJsonItemConverter root); 28 public abstract void Populate(IItem value, IJsonItem item, IJsonItemConverter root); // TODO: populate? 16 public abstract void Inject(IItem item, IJsonItem data, IJsonItemConverter root); 17 public abstract IJsonItem Extract(IItem value, IJsonItemConverter root); 29 18 30 19 #region Helper -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/ConstrainedValueParameterConverter.cs
r17406 r17407 8 8 9 9 namespace HeuristicLab.JsonInterface { 10 public class ConstrainedValueParameterConverter : ParameterBaseConverter {10 public class ConstrainedValueParameterConverter : BaseConverter { 11 11 public override int Priority => 3; 12 12 public override Type ConvertableType => typeof(IConstrainedValueParameter<>); 13 13 14 public override void InjectData(IParameter parameter, IJsonItem data, IJsonItemConverter root) { 15 foreach(var x in GetValidValues(parameter)) 14 public override void Inject(IItem item, IJsonItem data, IJsonItemConverter root) { 15 IParameter parameter = item as IParameter; 16 foreach (var x in GetValidValues(parameter)) 16 17 if(x.ToString() == CastValue<string>(data.Value)) 17 18 parameter.ActualValue = x; … … 24 25 } 25 26 } 27 28 public override IJsonItem Extract(IItem value, IJsonItemConverter root) { 29 IParameter parameter = value as IParameter; 26 30 27 public override void Populate(IParameter value, IJsonItem item, IJsonItemConverter root) { 28 item.AddChilds(GetParameterizedChilds(value)); 29 item.Name = value.Name; 30 item.Value = value.ActualValue?.ToString(); 31 item.Range = GetValidValues(value).Select(x => x.ToString()); 32 } 31 IJsonItem item = new JsonItem() { 32 Name = parameter.Name, 33 Value = parameter.ActualValue?.ToString(), 34 Range = GetValidValues(parameter).Select(x => x.ToString()) 35 }; 36 item.AddChilds(GetParameterizedChilds(parameter)); 37 38 return item; 39 } 33 40 34 41 #region Helper -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/EnumTypeConverter.cs
r17406 r17407 12 12 public override Type ConvertableType => typeof(EnumValue<>); 13 13 14 public override void Inject Data(IItem item, IJsonItem data, IJsonItemConverter root) =>14 public override void Inject(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 19 public override void Populate(IItem value, IJsonItem item, IJsonItemConverter root) {18 19 public override IJsonItem Extract(IItem value, IJsonItemConverter root) { 20 20 object val = ((dynamic)value).Value; 21 21 Type enumType = val.GetType(); 22 item.Value = Enum.GetName(enumType, val); 23 item.Range = Enum.GetNames(enumType); 22 return new JsonItem() { 23 Name = value.ItemName, 24 Value = Enum.GetName(enumType, val), 25 Range = Enum.GetNames(enumType) 26 }; 24 27 } 25 28 } -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/LookupParameterConverter.cs
r17406 r17407 7 7 8 8 namespace HeuristicLab.JsonInterface { 9 public class LookupParameterConverter : ParameterBaseConverter {9 public class LookupParameterConverter : BaseConverter { 10 10 public override int Priority => 3; 11 11 public override Type ConvertableType => typeof(ILookupParameter); 12 13 public override void Inject(IItem item, IJsonItem data, IJsonItemConverter root) => 14 ((ILookupParameter)item).ActualName = data.ActualName as string; 12 15 13 public override void Populate(IParameter value, IJsonItem item, IJsonItemConverter root) { 14 item.Name = value.Name; 15 item.ActualName = ((ILookupParameter)value).ActualName; 16 } 16 public override IJsonItem Extract(IItem value, IJsonItemConverter root) { 17 IParameter parameter = value as IParameter; 17 18 18 public override void InjectData(IParameter parameter, IJsonItem data, IJsonItemConverter root) => 19 ((ILookupParameter)parameter).ActualName = data.ActualName as string; 19 IJsonItem item = new JsonItem() { 20 Name = parameter.Name, 21 ActualName = ((ILookupParameter)parameter).ActualName 22 }; 23 return item; 24 } 20 25 } 21 26 } -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/MultiCheckedOperatorConverter.cs
r17406 r17407 11 11 public override int Priority => 3; 12 12 public override Type ConvertableType => typeof(ICheckedMultiOperator<>); 13 14 public override void Inject(IItem item, IJsonItem data, IJsonItemConverter root) { 15 base.Inject(item, data, root); 13 16 14 public override void Populate(IItem value, IJsonItem item, IJsonItemConverter root) { 15 base.Populate(value, item, root); 17 dynamic val = item as dynamic; 18 foreach (var op in val.Operators) 19 val.Operators.SetItemCheckedState(op, GetOperatorState(op.Name, data)); 20 } 16 21 22 public override IJsonItem Extract(IItem value, IJsonItemConverter root) { 23 IJsonItem item = base.Extract(value, root); 17 24 dynamic val = value as dynamic; 18 25 foreach (var op in val.Operators) { … … 23 30 }); 24 31 } 32 return item; 25 33 } 26 34 27 public override void InjectData(IItem item, IJsonItem data, IJsonItemConverter root) {28 base.InjectData(item, data, root);29 35 30 dynamic val = item as dynamic; 31 foreach (var op in val.Operators) 32 val.Operators.SetItemCheckedState(op, GetOperatorState(op.Name, data)); 33 } 34 36 #region Helper 35 37 private bool GetOperatorState(string name, IJsonItem data) { 36 38 foreach(var op in data.Children) { … … 39 41 return false; 40 42 } 43 #endregion 41 44 } 42 45 } -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/ParameterizedItemConverter.cs
r17406 r17407 11 11 public override Type ConvertableType => typeof(IParameterizedItem); 12 12 13 public override void Inject Data(IItem item, IJsonItem data, IJsonItemConverter root) {13 public override void Inject(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, IJsonItem item, IJsonItemConverter root) { 23 public override IJsonItem Extract(IItem value, IJsonItemConverter root) { 24 IJsonItem item = new JsonItem() { Name = value.ItemName }; 25 24 26 var parameterizedItem = value as IParameterizedItem; 25 26 27 foreach (var param in parameterizedItem.Parameters) { 27 28 if (!param.Hidden) { 28 29 IJsonItem tmp = root.Extract(param, root); 29 if (!(tmp is UnsupportedJsonItem))30 if (!(tmp is UnsupportedJsonItem)) 30 31 item.AddChilds(tmp); 31 32 } 32 33 33 } 34 35 return item; 34 36 } 35 37 } -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/RegressionProblemDataConverter.cs
r17406 r17407 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, IJsonItem item, IJsonItemConverter root) { 16 public override void Inject(IItem item, IJsonItem data, IJsonItemConverter root) { 17 // TODO: inject data 18 throw new NotImplementedException(); 19 } 20 21 public override IJsonItem Extract(IItem value, IJsonItemConverter root) { 22 IJsonItem item = new JsonItem() { Name = value.ItemName }; 23 17 24 dynamic val = (dynamic)value; 18 25 object dataset = (object)val.Dataset; … … 38 45 Range = variables.Select(x => x.Value) 39 46 }); 40 } 41 42 public override void InjectData(IItem item, IJsonItem data, IJsonItemConverter root) { 43 // TODO: inject data 44 throw new NotImplementedException(); 47 return item; 45 48 } 46 49 } -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/StringValueConverter.cs
r17406 r17407 12 12 public override Type ConvertableType => typeof(StringValue); 13 13 14 public override void Inject Data(IItem item, IJsonItem data, IJsonItemConverter root) =>14 public override void Inject(IItem item, IJsonItem data, IJsonItemConverter root) => 15 15 ((StringValue)item).Value = CastValue<string>(data.Value); 16 16 17 public override void Populate(IItem value, IJsonItem item, IJsonItemConverter root) => 18 item.Value = ((StringValue)value).Value; 17 public override IJsonItem Extract(IItem value, IJsonItemConverter root) => 18 new JsonItem() { 19 Name = value.ItemName, 20 Value = ((StringValue)value).Value 21 }; 19 22 } 20 23 } -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/ValueLookupParameterConverter.cs
r17406 r17407 7 7 8 8 namespace HeuristicLab.JsonInterface { 9 public class ValueLookupParameterConverter : ParameterBaseConverter {9 public class ValueLookupParameterConverter : BaseConverter { 10 10 public override int Priority => 4; 11 11 public override Type ConvertableType => typeof(IValueLookupParameter); 12 12 13 public override void Populate(IParameter value, IJsonItem item, IJsonItemConverter root) { 13 public override void Inject(IItem item, IJsonItem data, IJsonItemConverter root) { 14 IValueLookupParameter param = item as IValueLookupParameter; 15 param.ActualName = CastValue<string>(data.ActualName); 16 if (param.Value != null) 17 root.Inject(param.Value, data, root); 18 } 19 20 public override IJsonItem Extract(IItem value, IJsonItemConverter root) { 14 21 IValueLookupParameter param = value as IValueLookupParameter; 15 16 item.Name = value.Name; 17 item.ActualName = param.ActualName; 22 23 IJsonItem item = new JsonItem() { 24 Name = param.Name, 25 ActualName = param.ActualName 26 }; 18 27 19 28 object actualValue = null; 20 29 IEnumerable<object> actualRange = null; 21 if (param.Value != null) {30 if (param.Value != null) { 22 31 IJsonItem tmp = root.Extract(param.Value, root); 23 32 tmp.Parent = item; … … 29 38 item.Value = actualValue; 30 39 item.Range = actualRange; 31 } 32 33 public override void InjectData(IParameter parameter, IJsonItem data, IJsonItemConverter root) { 34 IValueLookupParameter param = parameter as IValueLookupParameter; 35 param.ActualName = CastValue<string>(data.ActualName); 36 if (param.Value != null) 37 root.Inject(param.Value, data, root); 40 return item; 38 41 } 39 42 } -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/ValueParameterConverter.cs
r17406 r17407 7 7 8 8 namespace HeuristicLab.JsonInterface { 9 public class ValueParameterConverter : ParameterBaseConverter {9 public class ValueParameterConverter : BaseConverter { 10 10 public override int Priority => 2; 11 11 public override Type ConvertableType => typeof(IValueParameter); 12 12 13 public override void InjectData(IParameter parameter, IJsonItem data, IJsonItemConverter root) { 13 public override void Inject(IItem value, IJsonItem data, IJsonItemConverter root) { 14 IParameter parameter = value as IParameter; 15 14 16 if (parameter.ActualValue == null && data.Value != null) 15 17 parameter.ActualValue = Instantiate(parameter.DataType); … … 17 19 } 18 20 19 public override void Populate(IParameter value, IJsonItem item, IJsonItemConverter root) { 20 item.Name = value.Name; 21 if (value.ActualValue != null) { 22 IJsonItem tmp = root.Extract(value.ActualValue, root); 23 if(!(tmp is UnsupportedJsonItem)) { 21 public override IJsonItem Extract(IItem value, IJsonItemConverter root) { 22 IParameter parameter = value as IParameter; 23 24 IJsonItem item = new JsonItem() { 25 Name = parameter.Name 26 }; 27 28 if (parameter.ActualValue != null) { 29 IJsonItem tmp = root.Extract(parameter.ActualValue, root); 30 if (!(tmp is UnsupportedJsonItem)) { 24 31 if (tmp.Name == "[OverridableParamName]") { 25 tmp.Name = value.Name;32 tmp.Name = parameter.Name; 26 33 JsonItem.Merge(item as JsonItem, tmp as JsonItem); 27 34 } else … … 29 36 } 30 37 } 38 return item; 31 39 } 32 40 } -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/ValueRangeConverter.cs
r17406 r17407 27 27 private const BindingFlags Flags = BindingFlags.NonPublic | BindingFlags.Instance; 28 28 29 public override void Populate(IItem value, IJsonItem item, IJsonItemConverter root) { 30 var field = value.GetType().GetField("values", Flags); 31 Tuple<T,T> tuple = (Tuple<T,T>)field.GetValue(value); 32 item.Name = "[OverridableParamName]"; 33 item.Value = new object[] { tuple.Item1.Value, tuple.Item2.Value }; 34 item.Range = new object[] { GetMinValue(tuple.Item1.Value.GetType()), GetMaxValue(tuple.Item2.Value.GetType()) }; 35 } 36 37 public override void InjectData(IItem item, IJsonItem data, IJsonItemConverter root) { 29 public override void Inject(IItem item, IJsonItem data, IJsonItemConverter root) { 38 30 object[] arr = (object[])data.Value; 39 31 Tuple<T,T> tuple = new Tuple<T,T>(Instantiate<T>(arr[0]), Instantiate<T>(arr[1])); … … 41 33 field.SetValue(tuple, item); 42 34 } 35 36 public override IJsonItem Extract(IItem value, IJsonItemConverter root) { 37 var field = value.GetType().GetField("values", Flags); 38 Tuple<T, T> tuple = (Tuple<T, T>)field.GetValue(value); 39 return new JsonItem() { 40 Name = "[OverridableParamName]", 41 Value = new object[] { tuple.Item1.Value, tuple.Item2.Value }, 42 Range = new object[] { GetMinValue(typeof(TType)), GetMaxValue(typeof(TType)) } 43 }; 44 } 45 43 46 } 44 47 } -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/ValueTypeArrayConverter.cs
r17406 r17407 34 34 where T : struct 35 35 { 36 public override void Inject Data(IItem item, IJsonItem data, IJsonItemConverter root) =>36 public override void Inject(IItem item, IJsonItem data, IJsonItemConverter root) => 37 37 CopyArrayData(((ArrayType)item), CastValue<T[]>(data.Value)); 38 38 39 public override void Populate(IItem value, IJsonItem item, IJsonItemConverter root) { 40 item.Name = "[OverridableParamName]"; 41 item.Value = ((ArrayType)value).CloneAsArray(); 42 } 39 public override IJsonItem Extract(IItem value, IJsonItemConverter root) => 40 new JsonItem() { 41 Name = "[OverridableParamName]", 42 Value = ((ArrayType)value).CloneAsArray() 43 }; 43 44 44 45 #region Helper -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/ValueTypeMatrixConverter.cs
r17406 r17407 33 33 where T : struct 34 34 { 35 public override void Inject Data(IItem item, IJsonItem data, IJsonItemConverter root) =>35 public override void Inject(IItem item, IJsonItem data, IJsonItemConverter root) => 36 36 CopyMatrixData(item as MatrixType, data.Value); 37 37 38 public override void Populate(IItem value, IJsonItem item, IJsonItemConverter root) { 39 item.Name = "[OverridableParamName]"; 40 item.Value = ((MatrixType)value).CloneAsMatrix(); 41 } 38 public override IJsonItem Extract(IItem value, IJsonItemConverter root) => 39 new JsonItem() { 40 Name = "[OverridableParamName]", 41 Value = ((MatrixType)value).CloneAsMatrix() 42 43 }; 42 44 43 45 #region Helper -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/ValueTypeValueConverter.cs
r17406 r17407 38 38 where T : struct { 39 39 40 public override void Inject Data(IItem item, IJsonItem data, IJsonItemConverter root) =>40 public override void Inject(IItem item, IJsonItem data, IJsonItemConverter root) => 41 41 ((ValueType)item).Value = CastValue<T>(data.Value); 42 42 43 public override void Populate(IItem value, IJsonItem item, IJsonItemConverter root) { 44 item.Name = "[OverridableParamName]"; 45 item.Value = ((ValueType)value).Value; 46 item.Range = new object[] { GetMinValue(typeof(T)), GetMaxValue(typeof(T)) }; 47 } 43 public override IJsonItem Extract(IItem value, IJsonItemConverter root) => 44 new JsonItem() { 45 Name = "[OverridableParamName]", 46 Value = ((ValueType)value).Value, 47 Range = new object[] { GetMinValue(typeof(T)), GetMaxValue(typeof(T)) } 48 }; 48 49 } 49 50 } -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/HeuristicLab.JsonInterface.csproj
r17406 r17407 74 74 <Compile Include="JsonTemplateInstantiator.cs" /> 75 75 <Compile Include="Converters\ConstrainedValueParameterConverter.cs" /> 76 <Compile Include="Converters\ParameterBaseConverter.cs" />77 76 <Compile Include="Converters\ParameterizedItemConverter.cs" /> 78 77 <Compile Include="Converters\ValueParameterConverter.cs" />
Note: See TracChangeset
for help on using the changeset viewer.