Changeset 17281
- Timestamp:
- 10/01/19 13:45:03 (5 years ago)
- Location:
- branches/3026_IntegrationIntoSymSpace/HeuristicLab.Manufacture
- Files:
-
- 1 added
- 2 deleted
- 2 edited
- 13 copied
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
branches/3026_IntegrationIntoSymSpace/HeuristicLab.Manufacture/Converters/BaseConverter.cs
r17280 r17281 8 8 9 9 namespace HeuristicLab.Manufacture { 10 public abstract class Base Transformer : ITypeTransformer10 public abstract class BaseConverter : IJsonItemConverter 11 11 { 12 12 public Component Extract(IItem value) { -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.Manufacture/Converters/ConstrainedValueParameterConverter.cs
r17280 r17281 7 7 8 8 namespace HeuristicLab.Manufacture { 9 public class ConstrainedValueParameter Transformer : ParameterBaseTransformer {9 public class ConstrainedValueParameterConverter : ParameterBaseConverter { 10 10 public override void InjectData(IParameter parameter, Component data) { 11 11 foreach (var x in parameter.Cast<dynamic>().ValidValues) … … 14 14 15 15 if (parameter.ActualValue is IParameterizedItem && data.Reference != null) 16 Transformer.Inject(parameter.ActualValue, data.Reference);16 JsonItemConverter.Inject(parameter.ActualValue, data.Reference); 17 17 } 18 18 … … 38 38 foreach(var x in values) { 39 39 if (x is IParameterizedItem) { 40 Component tmp = Transformer.Extract(x);40 Component tmp = JsonItemConverter.Extract(x); 41 41 tmp.PrependPath(value.Name); 42 42 list.Add(tmp); -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.Manufacture/Converters/DummyConverter.cs
r17280 r17281 7 7 8 8 namespace HeuristicLab.Manufacture { 9 public class Dummy Transformer : BaseTransformer {9 public class DummyConverter : BaseConverter { 10 10 public override void InjectData(IItem item, Component data) { 11 11 // do nothing because the instance already exists and -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.Manufacture/Converters/EnumTypeConverter.cs
r17280 r17281 8 8 9 9 namespace HeuristicLab.Manufacture { 10 public class EnumType Transformer : BaseTransformer {10 public class EnumTypeConverter : BaseConverter { 11 11 public override void InjectData(IItem item, Component data) => 12 12 item.Cast<dynamic>().Value = Enum.Parse( -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.Manufacture/Converters/LookupParameterConverter.cs
r17280 r17281 7 7 8 8 namespace HeuristicLab.Manufacture { 9 public class LookupParameter Transformer : ParameterBaseTransformer {9 public class LookupParameterConverter : ParameterBaseConverter { 10 10 public override Component ExtractData(IParameter value) { 11 11 return new Component() { Name = value.Name }; -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.Manufacture/Converters/MultiCheckedOperatorConverter.cs
r17280 r17281 7 7 8 8 namespace HeuristicLab.Manufacture { 9 public class MultiCheckedOperator Transformer : ParameterizedItemTransformer {9 public class MultiCheckedOperatorConverter : ParameterizedItemConverter { 10 10 public override Component ExtractData(IItem value) { 11 11 Component data = base.ExtractData(value); -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.Manufacture/Converters/ParameterBaseConverter.cs
r17280 r17281 7 7 8 8 namespace HeuristicLab.Manufacture { 9 public abstract class ParameterBase Transformer : BaseTransformer {9 public abstract class ParameterBaseConverter : BaseConverter { 10 10 public override Component ExtractData(IItem value) { 11 11 IParameter param = value.Cast<IParameter>(); -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.Manufacture/Converters/ParameterizedItemConverter.cs
r17280 r17281 8 8 namespace HeuristicLab.Manufacture 9 9 { 10 public class ParameterizedItem Transformer : BaseTransformer {10 public class ParameterizedItemConverter : BaseConverter { 11 11 public override void InjectData(IItem item, Component data) { 12 12 IParameterizedItem pItem = item.Cast<IParameterizedItem>(); … … 15 15 foreach (var sp in data.Parameters) 16 16 if (pItem.Parameters.TryGetValue(sp.Name, out IParameter param)) 17 Transformer.Inject(param, sp);17 JsonItemConverter.Inject(param, sp); 18 18 } 19 19 } … … 26 26 27 27 foreach (var param in value.Cast<IParameterizedItem>().Parameters) { 28 Component data = Transformer.Extract(param);28 Component data = JsonItemConverter.Extract(param); 29 29 data.Name = param.Name; 30 30 data.Path = param.Name; -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.Manufacture/Converters/StringValueConverter.cs
r17280 r17281 8 8 9 9 namespace HeuristicLab.Manufacture { 10 public class StringValue Transformer : BaseTransformer {10 public class StringValueConverter : BaseConverter { 11 11 public override void InjectData(IItem item, Component data) => 12 12 item.Cast<StringValue>().Value = CastValue<string>(data.Default); -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.Manufacture/Converters/ValueParameterConverter.cs
r17280 r17281 7 7 8 8 namespace HeuristicLab.Manufacture { 9 public class ValueParameter Transformer : ParameterBaseTransformer {9 public class ValueParameterConverter : ParameterBaseConverter { 10 10 11 11 public override void InjectData(IParameter parameter, Component data) => 12 Transformer.Inject(parameter.ActualValue, data);12 JsonItemConverter.Inject(parameter.ActualValue, data); 13 13 14 14 public override Component ExtractData(IParameter value) { … … 17 17 data = new Component(); 18 18 else 19 data = Transformer.Extract(value.ActualValue);19 data = JsonItemConverter.Extract(value.ActualValue); 20 20 data.Name = value.Name; 21 21 return data; -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.Manufacture/Converters/ValueTypeArrayConverter.cs
r17280 r17281 9 9 10 10 namespace HeuristicLab.Manufacture { 11 public class ValueTypeArray Transformer<ArrayType, T> : BaseTransformer11 public class ValueTypeArrayConverter<ArrayType, T> : BaseConverter 12 12 where ArrayType : ValueTypeArray<T> 13 13 where T : struct -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.Manufacture/Converters/ValueTypeMatrixConverter.cs
r17280 r17281 9 9 10 10 namespace HeuristicLab.Manufacture { 11 public class ValueTypeMatrix Transformer<MatrixType, T> : BaseTransformer11 public class ValueTypeMatrixConverter<MatrixType, T> : BaseConverter 12 12 where MatrixType : ValueTypeMatrix<T> 13 13 where T : struct -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.Manufacture/Converters/ValueTypeValueConverter.cs
r17280 r17281 8 8 9 9 namespace HeuristicLab.Manufacture { 10 public class ValueTypeValue Transformer<ValueType, T> : BaseTransformer10 public class ValueTypeValueConverter<ValueType, T> : BaseConverter 11 11 where ValueType : ValueTypeValue<T> 12 12 where T : struct { -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.Manufacture/Interfaces/IJsonItemConverter.cs
r17280 r17281 8 8 9 9 namespace HeuristicLab.Manufacture { 10 public interface I TypeTransformer {10 public interface IJsonItemConverter { 11 11 /// <summary> 12 12 /// Extracts all infos out of an IItem to create a Component. -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.Manufacture/JCGenerator.cs
r17280 r17281 55 55 public string GenerateTemplate(IAlgorithm algorithm, IProblem problem, params string[] freeParameters) { 56 56 algorithm.Problem = problem; 57 Component algorithmData = Transformer.Extract(algorithm);58 Component problemData = Transformer.Extract(problem);57 Component algorithmData = JsonItemConverter.Extract(algorithm); 58 Component problemData = JsonItemConverter.Extract(problem); 59 59 PopulateJsonItems(algorithmData); 60 60 PopulateJsonItems(problemData); -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.Manufacture/JCInstantiator.cs
r17280 r17281 31 31 algorithm.Problem = problem; 32 32 33 Transformer.Inject(algorithm, algorithmData);34 Transformer.Inject(algorithm, problemData);33 JsonItemConverter.Inject(algorithm, algorithmData); 34 JsonItemConverter.Inject(algorithm, problemData); 35 35 36 36 return algorithm; -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.Manufacture/JsonItemConverter.cs
r17280 r17281 8 8 9 9 namespace HeuristicLab.Manufacture { 10 public static class Transformer {11 private static IDictionary<Type, I TypeTransformer> transformers = new Dictionary<Type, ITypeTransformer>();10 public static class JsonItemConverter { 11 private static IDictionary<Type, IJsonItemConverter> transformers = new Dictionary<Type, IJsonItemConverter>(); 12 12 13 public static void Register(Type type, I TypeTransformer transformer) { // TODO: explizit13 public static void Register(Type type, IJsonItemConverter transformer) { // TODO: explizit 14 14 if (!transformers.ContainsKey(type)) 15 15 transformers.Add(type, transformer); … … 17 17 18 18 19 public static void Register<T>(I TypeTransformer transformer) => Register(typeof(T), transformer);19 public static void Register<T>(IJsonItemConverter transformer) => Register(typeof(T), transformer); 20 20 21 public static IEnumerable<I TypeTransformer> Get(Type type) {22 IList<KeyValuePair<Type, I TypeTransformer>> possibleTransformers = new List<KeyValuePair<Type, ITypeTransformer>>();21 public static IEnumerable<IJsonItemConverter> Get(Type type) { 22 IList<KeyValuePair<Type, IJsonItemConverter>> possibleTransformers = new List<KeyValuePair<Type, IJsonItemConverter>>(); 23 23 24 24 … … 30 30 31 31 if(possibleTransformers.Count > 0) { 32 I TypeTransformer nearest = possibleTransformers.First().Value;32 IJsonItemConverter nearest = possibleTransformers.First().Value; 33 33 int nearestDistance = -1; 34 34 foreach (var x in possibleTransformers) { … … 39 39 } 40 40 } 41 return new I TypeTransformer[] { nearest };41 return new IJsonItemConverter[] { nearest }; 42 42 /* 43 43 return possibleTransformers.OrderBy(x => { … … 46 46 */ 47 47 } 48 return new I TypeTransformer[] { new DummyTransformer() };48 return new IJsonItemConverter[] { new DummyConverter() }; 49 49 } 50 50 51 51 internal static void Inject(IItem item, Component data) { 52 IEnumerable<I TypeTransformer> arr = Get(item.GetType());52 IEnumerable<IJsonItemConverter> arr = Get(item.GetType()); 53 53 foreach (var transformer in arr) 54 54 transformer.Inject(item, data); … … 56 56 57 57 internal static Component Extract(IItem item) { 58 IEnumerable<I TypeTransformer> arr = Get(item.GetType());58 IEnumerable<IJsonItemConverter> arr = Get(item.GetType()); 59 59 Component data = new Component(); 60 60 foreach (var transformer in arr) … … 64 64 65 65 66 static Transformer() {67 Register<IntValue>(new ValueTypeValue Transformer<IntValue, int>());68 Register<DoubleValue>(new ValueTypeValue Transformer<DoubleValue, double>());69 Register<PercentValue>(new ValueTypeValue Transformer<PercentValue, double>());70 Register<BoolValue>(new ValueTypeValue Transformer<BoolValue, bool>());71 Register<DateTimeValue>(new ValueTypeValue Transformer<DateTimeValue, DateTime>());72 Register<StringValue>(new StringValue Transformer());66 static JsonItemConverter() { 67 Register<IntValue>(new ValueTypeValueConverter<IntValue, int>()); 68 Register<DoubleValue>(new ValueTypeValueConverter<DoubleValue, double>()); 69 Register<PercentValue>(new ValueTypeValueConverter<PercentValue, double>()); 70 Register<BoolValue>(new ValueTypeValueConverter<BoolValue, bool>()); 71 Register<DateTimeValue>(new ValueTypeValueConverter<DateTimeValue, DateTime>()); 72 Register<StringValue>(new StringValueConverter()); 73 73 74 Register<IntArray>(new ValueTypeArray Transformer<IntArray, int>());75 Register<DoubleArray>(new ValueTypeArray Transformer<DoubleArray, double>());76 Register<PercentArray>(new ValueTypeArray Transformer<PercentArray, double>());77 Register<BoolArray>(new ValueTypeArray Transformer<BoolArray, bool>());74 Register<IntArray>(new ValueTypeArrayConverter<IntArray, int>()); 75 Register<DoubleArray>(new ValueTypeArrayConverter<DoubleArray, double>()); 76 Register<PercentArray>(new ValueTypeArrayConverter<PercentArray, double>()); 77 Register<BoolArray>(new ValueTypeArrayConverter<BoolArray, bool>()); 78 78 79 Register<IntMatrix>(new ValueTypeMatrix Transformer<IntMatrix, int>());80 Register<DoubleMatrix>(new ValueTypeMatrix Transformer<DoubleMatrix, double>());81 Register<PercentMatrix>(new ValueTypeMatrix Transformer<PercentMatrix, double>());82 Register<BoolMatrix>(new ValueTypeMatrix Transformer<BoolMatrix, bool>());79 Register<IntMatrix>(new ValueTypeMatrixConverter<IntMatrix, int>()); 80 Register<DoubleMatrix>(new ValueTypeMatrixConverter<DoubleMatrix, double>()); 81 Register<PercentMatrix>(new ValueTypeMatrixConverter<PercentMatrix, double>()); 82 Register<BoolMatrix>(new ValueTypeMatrixConverter<BoolMatrix, bool>()); 83 83 84 Register(typeof(IConstrainedValueParameter<>), new ConstrainedValueParameterTransformer()); 85 Register(typeof(ILookupParameter), new LookupParameterTransformer()); 86 Register(typeof(IValueParameter), new ValueParameterTransformer()); 87 Register(typeof(IParameterizedItem), new ParameterizedItemTransformer()); 88 Register(typeof(ICheckedMultiOperator<>), new MultiCheckedOperatorTransformer()); 84 Register(typeof(IConstrainedValueParameter<>), new ConstrainedValueParameterConverter()); 85 Register(typeof(ILookupParameter), new LookupParameterConverter()); 86 Register(typeof(IValueParameter), new ValueParameterConverter()); 87 Register(typeof(IParameterizedItem), new ParameterizedItemConverter()); 88 Register(typeof(ICheckedMultiOperator<>), new MultiCheckedOperatorConverter()); 89 Register(typeof(EnumValue<>), new EnumTypeConverter()) 89 90 } 90 91
Note: See TracChangeset
for help on using the changeset viewer.