- Timestamp:
- 03/17/20 12:33:35 (5 years ago)
- Location:
- branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Models
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Models/ArrayJsonItem.cs
r17473 r17477 9 9 public abstract class ArrayJsonItem<T> : ValueJsonItem<T[]>, IArrayJsonItem { 10 10 public virtual bool Resizable { get; set; } 11 public override void Set FromJObject(JObject jObject) {12 base.Set FromJObject(jObject);11 public override void SetJObject(JObject jObject) { 12 base.SetJObject(jObject); 13 13 Resizable = (jObject[nameof(IArrayJsonItem.Resizable)]?.ToObject<bool>()).GetValueOrDefault(); 14 14 } -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Models/DateTimeJsonItem.cs
r17473 r17477 4 4 using System.Text; 5 5 using System.Threading.Tasks; 6 using Newtonsoft.Json.Linq; 6 7 7 8 namespace HeuristicLab.JsonInterface { 8 9 public class DateTimeJsonItem : IntervalRestrictedValueJsonItem<DateTime> { 9 10 protected override bool Validate() => Minimum.CompareTo(Value) >= 0 && Maximum.CompareTo(Value) <= 0; 11 12 public override JObject GenerateJObject() { 13 var obj = base.GenerateJObject(); 14 15 if (Minimum.CompareTo(DateTime.MinValue) == 0) 16 obj.Property("Minimum").Remove(); 17 18 if (Maximum.CompareTo(DateTime.MaxValue) == 0) 19 obj.Property("Maximum").Remove(); 20 21 return obj; 22 } 23 24 public override void SetJObject(JObject jObject) { 25 Minimum = DateTime.MinValue; 26 Maximum = DateTime.MaxValue; 27 base.SetJObject(jObject); 28 } 10 29 } 11 30 } -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Models/DoubleJsonItems.cs
r17473 r17477 4 4 using System.Text; 5 5 using System.Threading.Tasks; 6 using Newtonsoft.Json.Linq; 6 7 7 8 namespace HeuristicLab.JsonInterface { 8 public class DoubleJsonItem : IntervalRestrictedValueJsonItem<double> { }9 public class DoubleArrayJsonItem : IntervalRestrictedArrayJsonItem<double> { }10 public class DoubleRangeJsonItem : RangedJsonItem<double> { }9 public class DoubleJsonItem : IntervalRestrictedValueJsonItem<double> { 10 public override JObject GenerateJObject() { 11 var obj = base.GenerateJObject(); 11 12 13 if (Minimum.CompareTo(double.MinValue) == 0) 14 obj.Property("Minimum").Remove(); 15 16 if (Maximum.CompareTo(double.MaxValue) == 0) 17 obj.Property("Maximum").Remove(); 18 19 return obj; 20 } 21 22 public override void SetJObject(JObject jObject) { 23 Minimum = double.MinValue; 24 Maximum = double.MaxValue; 25 base.SetJObject(jObject); 26 } 27 } 28 public class DoubleArrayJsonItem : IntervalRestrictedArrayJsonItem<double> { 29 public override JObject GenerateJObject() { 30 var obj = base.GenerateJObject(); 31 32 if (Minimum.CompareTo(double.MinValue) == 0) 33 obj.Property("Minimum").Remove(); 34 35 if (Maximum.CompareTo(double.MaxValue) == 0) 36 obj.Property("Maximum").Remove(); 37 38 return obj; 39 } 40 41 public override void SetJObject(JObject jObject) { 42 Minimum = double.MinValue; 43 Maximum = double.MaxValue; 44 base.SetJObject(jObject); 45 } 46 } 47 public class DoubleRangeJsonItem : RangedJsonItem<double> { 48 public override JObject GenerateJObject() { 49 var obj = base.GenerateJObject(); 50 51 if (Minimum.CompareTo(double.MinValue) == 0) 52 obj.Property("Minimum").Remove(); 53 54 if (Maximum.CompareTo(double.MaxValue) == 0) 55 obj.Property("Maximum").Remove(); 56 57 return obj; 58 } 59 60 public override void SetJObject(JObject jObject) { 61 Minimum = double.MinValue; 62 Maximum = double.MaxValue; 63 base.SetJObject(jObject); 64 } 65 } 12 66 public class DoubleMatrixJsonItem : IntervalRestrictedMatrixJsonItem<double> { 13 /* 14 protected override bool IsInRange() { 15 for (int c = 0; c < Value.Length; ++c) { 16 for (int r = 0; r < Value[c].Length; ++r) { 17 if (Value[c][r] < Range.First() && Range.Last() < Value[c][r]) 18 return false; 19 } 20 } 21 return true; 67 public override JObject GenerateJObject() { 68 var obj = base.GenerateJObject(); 69 70 if (Minimum.CompareTo(double.MinValue) == 0) 71 obj.Property("Minimum").Remove(); 72 73 if (Maximum.CompareTo(double.MaxValue) == 0) 74 obj.Property("Maximum").Remove(); 75 76 return obj; 22 77 } 23 */ 78 79 public override void SetJObject(JObject jObject) { 80 Minimum = double.MinValue; 81 Maximum = double.MaxValue; 82 base.SetJObject(jObject); 83 } 24 84 } 25 85 } -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Models/IntJsonItems.cs
r17473 r17477 4 4 using System.Text; 5 5 using System.Threading.Tasks; 6 using Newtonsoft.Json.Linq; 6 7 7 8 namespace HeuristicLab.JsonInterface { 8 public class IntJsonItem : IntervalRestrictedValueJsonItem<int> { } 9 public class IntArrayJsonItem : IntervalRestrictedArrayJsonItem<int> { } 10 public class IntRangeJsonItem : RangedJsonItem<int> { } 9 public class IntJsonItem : IntervalRestrictedValueJsonItem<int> { 10 public override JObject GenerateJObject() { 11 var obj = base.GenerateJObject(); 12 13 if (Minimum.CompareTo(int.MinValue) == 0) 14 obj.Property("Minimum").Remove(); 15 16 if (Maximum.CompareTo(int.MaxValue) == 0) 17 obj.Property("Maximum").Remove(); 18 19 return obj; 20 } 21 22 public override void SetJObject(JObject jObject) { 23 Minimum = int.MinValue; 24 Maximum = int.MaxValue; 25 base.SetJObject(jObject); 26 } 27 } 28 public class IntArrayJsonItem : IntervalRestrictedArrayJsonItem<int> { 29 public override JObject GenerateJObject() { 30 var obj = base.GenerateJObject(); 31 32 if (Minimum.CompareTo(int.MinValue) == 0) 33 obj.Property("Minimum").Remove(); 34 35 if (Maximum.CompareTo(int.MaxValue) == 0) 36 obj.Property("Maximum").Remove(); 37 38 return obj; 39 } 40 41 public override void SetJObject(JObject jObject) { 42 Minimum = int.MinValue; 43 Maximum = int.MaxValue; 44 base.SetJObject(jObject); 45 } 46 } 47 public class IntRangeJsonItem : RangedJsonItem<int> { 48 public override JObject GenerateJObject() { 49 var obj = base.GenerateJObject(); 50 51 if (Minimum.CompareTo(int.MinValue) == 0) 52 obj.Property("Minimum").Remove(); 53 54 if (Maximum.CompareTo(int.MaxValue) == 0) 55 obj.Property("Maximum").Remove(); 56 57 return obj; 58 } 59 60 public override void SetJObject(JObject jObject) { 61 Minimum = int.MinValue; 62 Maximum = int.MaxValue; 63 base.SetJObject(jObject); 64 } 65 } 11 66 public class IntMatrixJsonItem : IntervalRestrictedMatrixJsonItem<int> { 12 /* 13 protected override bool IsInRange() { 14 for (int c = 0; c < Value.Length; ++c) { 15 for (int r = 0; r < Value[c].Length; ++r) { 16 if (Value[c][r] < Range.First() && Range.Last() < Value[c][r]) 17 return false; 18 } 19 } 20 return true; 67 public override JObject GenerateJObject() { 68 var obj = base.GenerateJObject(); 69 70 if (Minimum.CompareTo(int.MinValue) == 0) 71 obj.Property("Minimum").Remove(); 72 73 if (Maximum.CompareTo(int.MaxValue) == 0) 74 obj.Property("Maximum").Remove(); 75 76 return obj; 21 77 } 22 */ 78 79 public override void SetJObject(JObject jObject) { 80 Minimum = int.MinValue; 81 Maximum = int.MaxValue; 82 base.SetJObject(jObject); 83 } 23 84 } 24 85 } -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Models/IntervalRestrictedArrayJsonItem.cs
r17473 r17477 20 20 } 21 21 22 public override void SetFromJObject(JObject jObject) { 23 base.SetFromJObject(jObject); 24 Minimum = jObject[nameof(IIntervalRestrictedJsonItem<T>.Minimum)].ToObject<T>(); 25 Maximum = jObject[nameof(IIntervalRestrictedJsonItem<T>.Maximum)].ToObject<T>(); 22 public override void SetJObject(JObject jObject) { 23 base.SetJObject(jObject); 24 25 var minProp = jObject[nameof(IIntervalRestrictedJsonItem<T>.Minimum)]; 26 if (minProp != null) Minimum = minProp.ToObject<T>(); 27 28 29 var maxProp = jObject[nameof(IIntervalRestrictedJsonItem<T>.Maximum)]; 30 if (maxProp != null) Maximum = maxProp.ToObject<T>(); 26 31 } 27 32 } -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Models/IntervalRestrictedMatrixJsonItem.cs
r17473 r17477 20 20 return true; 21 21 } 22 public override void SetFromJObject(JObject jObject) { 23 base.SetFromJObject(jObject); 24 Minimum = jObject[nameof(IIntervalRestrictedJsonItem<T>.Minimum)].ToObject<T>(); 25 Maximum = jObject[nameof(IIntervalRestrictedJsonItem<T>.Maximum)].ToObject<T>(); 22 public override void SetJObject(JObject jObject) { 23 base.SetJObject(jObject); 24 25 var minProp = jObject[nameof(IIntervalRestrictedJsonItem<T>.Minimum)]; 26 if (minProp != null) Minimum = minProp.ToObject<T>(); 27 28 29 var maxProp = jObject[nameof(IIntervalRestrictedJsonItem<T>.Maximum)]; 30 if (maxProp != null) Maximum = maxProp.ToObject<T>(); 26 31 } 27 32 } -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Models/IntervalRestrictedValueJsonItem.cs
r17473 r17477 14 14 protected override bool Validate() => Minimum.CompareTo(Value) <= 0 && Maximum.CompareTo(Value) >= 0; 15 15 16 public override void SetFromJObject(JObject jObject) { 17 base.SetFromJObject(jObject); 18 Minimum = jObject[nameof(IIntervalRestrictedJsonItem<T>.Minimum)].ToObject<T>(); 19 Maximum = jObject[nameof(IIntervalRestrictedJsonItem<T>.Maximum)].ToObject<T>(); 16 public override void SetJObject(JObject jObject) { 17 base.SetJObject(jObject); 18 19 var minProp = jObject[nameof(IIntervalRestrictedJsonItem<T>.Minimum)]; 20 if (minProp != null) Minimum = minProp.ToObject<T>(); 21 22 23 var maxProp = jObject[nameof(IIntervalRestrictedJsonItem<T>.Maximum)]; 24 if (maxProp != null) Maximum = maxProp.ToObject<T>(); 20 25 } 21 26 } -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Models/JsonItem.cs
r17473 r17477 62 62 } 63 63 } 64 65 //public virtual object Value { get; set; } 66 67 //public virtual IEnumerable<object> Range { get; set; } 68 64 69 65 // TODO jsonIgnore dataType? 70 66 … … 105 101 public void LoosenPath() => fixedPath = ""; 106 102 107 public virtual void SetFromJObject(JObject jObject) { 108 //Value = jObject[nameof(IJsonItem.Value)]?.ToObject<object>(); 109 //Range = jObject[nameof(IJsonItem.Range)]?.ToObject<object[]>(); 110 } 103 public virtual JObject GenerateJObject() => 104 JObject.FromObject(this, new JsonSerializer() { 105 TypeNameHandling = TypeNameHandling.None, 106 NullValueHandling = NullValueHandling.Ignore, 107 ReferenceLoopHandling = ReferenceLoopHandling.Ignore 108 }); 109 110 public virtual void SetJObject(JObject jObject) { } 111 111 #endregion 112 112 113 #region Helper 114 /* 115 * TODO protected abstract bool Validate(); 116 */ 113 #region Abstract Methods 117 114 protected abstract bool Validate(); 118 /* 119 protected virtual bool IsInRange() { 120 bool b1 = true, b2 = true; 121 if (Value is IEnumerable && !(Value is string)) { 122 foreach (var x in (IEnumerable)Value) { 123 b1 = b1 ? IsInRangeList(x) : b1; 124 b2 = b2 ? IsInNumericRange(x) : b2; 115 #endregion 116 117 #region IEnumerable Support 118 public virtual IEnumerator<IJsonItem> GetEnumerator() { 119 yield return this; 120 121 if (Children != null) { 122 foreach (var x in Children) { 123 foreach (var c in x) { 124 yield return c; 125 } 125 126 } 126 } 127 else { 128 b1 = IsInRangeList(Value); 129 b2 = IsInNumericRange(Value); 130 } 131 return b1 || b2; 127 } 132 128 } 133 129 134 protected bool IsInRangeList(object value) { 135 foreach (var x in Range) 136 if (x.Equals(value)) return true; 137 return false; 138 } 139 140 protected bool IsInNumericRange(object value) => 141 IsInNumericRange<ulong>(value) 142 || IsInNumericRange<uint>(value) 143 || IsInNumericRange<ushort>(value) 144 || IsInNumericRange<long>(value) 145 || IsInNumericRange<int>(value) 146 || IsInNumericRange<short>(value) 147 || IsInNumericRange<byte>(value) 148 || IsInNumericRange<float>(value) 149 || IsInNumericRange<double>(value) 150 || (value is float && float.IsNaN((float)value)) 151 || (value is double && double.IsNaN((double)value)); 152 153 protected bool IsInNumericRange<T>(object value) where T : IComparable { 154 object min = Range.First(), max = Range.Last(); 155 return 156 value != null && min != null && max != null && value is T && min is T && max is T && 157 (((T)min).CompareTo(value) == -1 || ((T)min).CompareTo(value) == 0) && 158 (((T)max).CompareTo(value) == 1 || ((T)max).CompareTo(value) == 0); 159 } 160 */ 130 IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); 161 131 #endregion 162 132 } -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Models/LookupJsonItem.cs
r17473 r17477 10 10 public virtual string ActualName { get; set; } 11 11 12 public override void Set FromJObject(JObject jObject) {13 base.Set FromJObject(jObject);12 public override void SetJObject(JObject jObject) { 13 base.SetJObject(jObject); 14 14 ActualName = jObject[nameof(ILookupJsonItem.ActualName)]?.ToString(); 15 15 } -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Models/MatrixJsonItem.cs
r17473 r17477 23 23 } 24 24 25 public override void Set FromJObject(JObject jObject) {26 base.Set FromJObject(jObject);25 public override void SetJObject(JObject jObject) { 26 base.SetJObject(jObject); 27 27 RowsResizable = (jObject[nameof(IMatrixJsonItem.RowsResizable)]?.ToObject<bool>()).GetValueOrDefault(); 28 28 ColumnsResizable = (jObject[nameof(IMatrixJsonItem.ColumnsResizable)]?.ToObject<bool>()).GetValueOrDefault(); -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Models/ValueJsonItem.cs
r17473 r17477 10 10 public object Value { get; set; } 11 11 12 //public IEnumerable<object> Range { get; set; } 13 14 public override void SetFromJObject(JObject jObject) { 12 public override void SetJObject(JObject jObject) { 15 13 Value = jObject[nameof(IValueJsonItem.Value)]?.ToObject<object>(); 16 //Range = jObject[nameof(IValueJsonItem.Range)]?.ToObject<object[]>();17 14 } 18 15 … … 24 21 set => base.Value = value; 25 22 } 26 27 /*28 public new IEnumerable<T> Range {29 get => base.Range?.Cast<T>();30 set => base.Range = value.Cast<object>();31 }32 */33 23 34 24 private T ConvertObject(object obj) { … … 42 32 } 43 33 44 public override void Set FromJObject(JObject jObject) {34 public override void SetJObject(JObject jObject) { 45 35 if(jObject[nameof(IValueJsonItem<T>.Value)] != null) 46 36 Value = jObject[nameof(IValueJsonItem<T>.Value)].ToObject<T>(); 47 //Range = jObject[nameof(IValueJsonItem<T>.Range)]?.ToObject<T[]>();48 37 } 49 38 } -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Models/ValueLookupJsonItem.cs
r17473 r17477 5 5 using System.Threading.Tasks; 6 6 using Newtonsoft.Json; 7 using Newtonsoft.Json.Linq; 7 8 8 9 namespace HeuristicLab.JsonInterface { 9 10 public class ValueLookupJsonItem : LookupJsonItem, IValueLookupJsonItem { 10 [JsonIgnore]11 public IJsonItem JsonItemReference { get; set; }11 12 public IJsonItem ActualValue { get; set; } 12 13 13 14 protected override bool Validate() { 14 if ( JsonItemReference == null) return true;15 if (ActualValue == null) return true; 15 16 IList<IJsonItem> faultyItems = new List<IJsonItem>(); 16 return JsonItemReference.GetValidator().Validate(ref faultyItems); 17 return ActualValue.GetValidator().Validate(ref faultyItems); 18 } 19 20 public override JObject GenerateJObject() { 21 var obj = base.GenerateJObject(); 22 if(ActualValue != null) { 23 var actualValue = ActualValue.GenerateJObject(); 24 obj.Add(nameof(IValueLookupJsonItem.ActualValue), actualValue); 25 } 26 return obj; 27 } 28 29 public override IEnumerator<IJsonItem> GetEnumerator() { 30 using (var it = base.GetEnumerator()) { 31 while(it.MoveNext()) { 32 yield return it.Current; 33 } 34 } 35 if(ActualValue != null) { 36 using (var it = ActualValue.GetEnumerator()) { 37 while (it.MoveNext()) { 38 yield return it.Current; 39 } 40 } 41 } 17 42 } 18 43 }
Note: See TracChangeset
for help on using the changeset viewer.