- Timestamp:
- 10/01/19 14:36:32 (5 years ago)
- Location:
- branches/3026_IntegrationIntoSymSpace/HeuristicLab.Manufacture/Converters
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3026_IntegrationIntoSymSpace/HeuristicLab.Manufacture/Converters/BaseConverter.cs
r17281 r17283 10 10 public abstract class BaseConverter : IJsonItemConverter 11 11 { 12 public ComponentExtract(IItem value) {13 Componentdata = ExtractData(value);12 public JsonItem Extract(IItem value) { 13 JsonItem data = ExtractData(value); 14 14 data.Name = String.IsNullOrEmpty(data.Name) ? value.ItemName : data.Name; 15 15 return data; 16 16 } 17 17 18 public void Inject(IItem item, Componentdata) {18 public void Inject(IItem item, JsonItem data) { 19 19 if(data.Reference != null) { 20 Component.Merge(data, data.Reference);20 JsonItem.Merge(data, data.Reference); 21 21 } 22 22 InjectData(item, data); 23 23 } 24 24 25 public abstract void InjectData(IItem item, Componentdata);26 public abstract ComponentExtractData(IItem value);25 public abstract void InjectData(IItem item, JsonItem data); 26 public abstract JsonItem ExtractData(IItem value); 27 27 28 28 #region Helper -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.Manufacture/Converters/ConstrainedValueParameterConverter.cs
r17281 r17283 8 8 namespace HeuristicLab.Manufacture { 9 9 public class ConstrainedValueParameterConverter : ParameterBaseConverter { 10 public override void InjectData(IParameter parameter, Componentdata) {10 public override void InjectData(IParameter parameter, JsonItem data) { 11 11 foreach (var x in parameter.Cast<dynamic>().ValidValues) 12 12 if (x.GetType().Name == CastValue<string>(data.Default)) … … 17 17 } 18 18 19 public override ComponentExtractData(IParameter value) =>20 new Component() {19 public override JsonItem ExtractData(IParameter value) => 20 new JsonItem() { 21 21 Name = value.Name, 22 22 Default = value.ActualValue?.GetType().Name, … … 33 33 } 34 34 // 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>(); 37 37 var values = value.Cast<dynamic>().ValidValues; 38 38 foreach(var x in values) { 39 39 if (x is IParameterizedItem) { 40 Componenttmp = JsonItemConverter.Extract(x);40 JsonItem tmp = JsonItemConverter.Extract(x); 41 41 tmp.PrependPath(value.Name); 42 42 list.Add(tmp); -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.Manufacture/Converters/DummyConverter.cs
r17281 r17283 8 8 namespace HeuristicLab.Manufacture { 9 9 public class DummyConverter : BaseConverter { 10 public override void InjectData(IItem item, Componentdata) {10 public override void InjectData(IItem item, JsonItem data) { 11 11 // do nothing because the instance already exists and 12 12 // there are no values to inject 13 13 } 14 14 15 public override ComponentExtractData(IItem value) =>16 new Component() { Default = value.GetType().Name };15 public override JsonItem ExtractData(IItem value) => 16 new JsonItem() { Default = value.GetType().Name }; 17 17 } 18 18 } -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.Manufacture/Converters/EnumTypeConverter.cs
r17281 r17283 9 9 namespace HeuristicLab.Manufacture { 10 10 public class EnumTypeConverter : BaseConverter { 11 public override void InjectData(IItem item, Componentdata) =>11 public override void InjectData(IItem item, JsonItem data) => 12 12 item.Cast<dynamic>().Value = Enum.Parse( 13 13 item.GetType().GenericTypeArguments.First(), 14 14 CastValue<string>(data.Default)); 15 15 16 public override ComponentExtractData(IItem value) {17 Component data = new Component();16 public override JsonItem ExtractData(IItem value) { 17 JsonItem data = new JsonItem(); 18 18 object val = ((dynamic)value).Value; 19 19 Type enumType = val.GetType(); -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.Manufacture/Converters/LookupParameterConverter.cs
r17281 r17283 8 8 namespace HeuristicLab.Manufacture { 9 9 public class LookupParameterConverter : ParameterBaseConverter { 10 public override ComponentExtractData(IParameter value) {11 return new Component() { Name = value.Name };10 public override JsonItem ExtractData(IParameter value) { 11 return new JsonItem() { Name = value.Name }; 12 12 } 13 13 14 public override void InjectData(IParameter parameter, Componentdata) {14 public override void InjectData(IParameter parameter, JsonItem data) { 15 15 16 16 } -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.Manufacture/Converters/MultiCheckedOperatorConverter.cs
r17281 r17283 8 8 namespace HeuristicLab.Manufacture { 9 9 public class MultiCheckedOperatorConverter : ParameterizedItemConverter { 10 public override ComponentExtractData(IItem value) {11 Componentdata = base.ExtractData(value);10 public override JsonItem ExtractData(IItem value) { 11 JsonItem data = base.ExtractData(value); 12 12 13 13 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>(); 20 15 dynamic val = value.Cast<dynamic>(); 21 16 foreach (var op in val.Operators) { 22 data.Operators.Add(new Component() {17 data.Operators.Add(new JsonItem() { 23 18 Name = op.Name, 24 19 Default = val.Operators.ItemChecked(op), … … 30 25 } 31 26 32 public override void InjectData(IItem item, Componentdata) {27 public override void InjectData(IItem item, JsonItem data) { 33 28 base.InjectData(item, data); 34 29 … … 39 34 } 40 35 41 private bool GetOperatorState(string name, Componentdata) {36 private bool GetOperatorState(string name, JsonItem data) { 42 37 foreach(var op in data.Operators) { 43 38 if (op.Name == name) return op.Default.Cast<bool>(); -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.Manufacture/Converters/ParameterBaseConverter.cs
r17281 r17283 8 8 namespace HeuristicLab.Manufacture { 9 9 public abstract class ParameterBaseConverter : BaseConverter { 10 public override ComponentExtractData(IItem value) {10 public override JsonItem ExtractData(IItem value) { 11 11 IParameter param = value.Cast<IParameter>(); 12 Componentcomp = ExtractData(param);12 JsonItem comp = ExtractData(param); 13 13 //comp.Path = value.Cast<IParameter>().ActualValue?.ItemName; 14 14 /*comp.Path = value.Cast<IParameter>().Name + "." + comp.Path; … … 20 20 return comp; 21 21 } 22 public abstract ComponentExtractData(IParameter value);22 public abstract JsonItem ExtractData(IParameter value); 23 23 24 public override void InjectData(IItem item, Componentdata) => InjectData(item.Cast<IParameter>(), data);24 public override void InjectData(IItem item, JsonItem data) => InjectData(item.Cast<IParameter>(), data); 25 25 26 public abstract void InjectData(IParameter parameter, Componentdata);26 public abstract void InjectData(IParameter parameter, JsonItem data); 27 27 } 28 28 } -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.Manufacture/Converters/ParameterizedItemConverter.cs
r17281 r17283 2 2 using System.Collections.Generic; 3 3 using System.Linq; 4 using System.Text; 4 using System.Text;JsonItem obj 5 5 using System.Threading.Tasks; 6 6 using HeuristicLab.Core; … … 9 9 { 10 10 public class ParameterizedItemConverter : BaseConverter { 11 public override void InjectData(IItem item, Componentdata) {11 public override void InjectData(IItem item, JsonItem data) { 12 12 IParameterizedItem pItem = item.Cast<IParameterizedItem>(); 13 13 … … 19 19 } 20 20 21 public override ComponentExtractData(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; 26 26 27 27 foreach (var param in value.Cast<IParameterizedItem>().Parameters) { 28 Componentdata = JsonItemConverter.Extract(param);28 JsonItem data = JsonItemConverter.Extract(param); 29 29 data.Name = param.Name; 30 30 data.Path = param.Name; 31 data.PrependPath( obj.Path);31 data.PrependPath(item.Path); 32 32 data.UpdatePaths(); 33 33 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); 37 37 } 38 return obj;38 return item; 39 39 } 40 40 } -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.Manufacture/Converters/StringValueConverter.cs
r17281 r17283 9 9 namespace HeuristicLab.Manufacture { 10 10 public class StringValueConverter : BaseConverter { 11 public override void InjectData(IItem item, Componentdata) =>11 public override void InjectData(IItem item, JsonItem data) => 12 12 item.Cast<StringValue>().Value = CastValue<string>(data.Default); 13 13 14 public override ComponentExtractData(IItem value) =>15 new Component() {14 public override JsonItem ExtractData(IItem value) => 15 new JsonItem() { 16 16 Default = value.Cast<StringValue>().Value 17 17 }; -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.Manufacture/Converters/ValueParameterConverter.cs
r17281 r17283 9 9 public class ValueParameterConverter : ParameterBaseConverter { 10 10 11 public override void InjectData(IParameter parameter, Componentdata) =>11 public override void InjectData(IParameter parameter, JsonItem data) => 12 12 JsonItemConverter.Inject(parameter.ActualValue, data); 13 13 14 public override ComponentExtractData(IParameter value) {15 Componentdata = null;14 public override JsonItem ExtractData(IParameter value) { 15 JsonItem data = null; 16 16 if (value.ActualValue == null) 17 data = new Component();17 data = new JsonItem(); 18 18 else 19 19 data = JsonItemConverter.Extract(value.ActualValue); -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.Manufacture/Converters/ValueTypeArrayConverter.cs
r17281 r17283 13 13 where T : struct 14 14 { 15 public override void InjectData(IItem item, Componentdata) =>15 public override void InjectData(IItem item, JsonItem data) => 16 16 CopyArrayData(item.Cast<ArrayType>(), CastValue<T[]>(data.Default)); 17 17 18 public override ComponentExtractData(IItem value) =>19 new Component() {18 public override JsonItem ExtractData(IItem value) => 19 new JsonItem() { 20 20 Default = value.Cast<ArrayType>().CloneAsArray() 21 21 }; -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.Manufacture/Converters/ValueTypeMatrixConverter.cs
r17281 r17283 13 13 where T : struct 14 14 { 15 public override void InjectData(IItem item, Componentdata) =>15 public override void InjectData(IItem item, JsonItem data) => 16 16 CopyMatrixData(item.Cast<MatrixType>(), CastValue<T[,]>(data.Default)); 17 17 18 public override ComponentExtractData(IItem value) =>19 new Component() {18 public override JsonItem ExtractData(IItem value) => 19 new JsonItem() { 20 20 Default = value.Cast<MatrixType>().CloneAsMatrix() 21 21 }; -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.Manufacture/Converters/ValueTypeValueConverter.cs
r17281 r17283 12 12 where T : struct { 13 13 14 public override void InjectData(IItem item, Componentdata) =>14 public override void InjectData(IItem item, JsonItem data) => 15 15 item.Cast<ValueType>().Value = CastValue<T>(data.Default); 16 16 17 public override ComponentExtractData(IItem value) =>18 new Component() {17 public override JsonItem ExtractData(IItem value) => 18 new JsonItem() { 19 19 Default = value.Cast<ValueType>().Value, 20 20 Range = new object[] { GetMinValue(), GetMaxValue() }
Note: See TracChangeset
for help on using the changeset viewer.