aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.BL/ObservableEntity.cs
diff options
context:
space:
mode:
authorRoy Ben-Shabat <Roy@Twine-s.com>2019-01-06 16:42:20 +0200
committerRoy Ben-Shabat <Roy@Twine-s.com>2019-01-06 16:42:20 +0200
commit6da42fd28ffbb680d85bb9e695520713ff51022a (patch)
tree4569c171a0d3a482374fe44d506d35549a677765 /Software/Visual_Studio/Tango.BL/ObservableEntity.cs
parenta7137c1f053ba48c3ce22bee483fe7f716cc90cb (diff)
downloadTango-6da42fd28ffbb680d85bb9e695520713ff51022a.tar.gz
Tango-6da42fd28ffbb680d85bb9e695520713ff51022a.zip
Some work on entity serialization.
Diffstat (limited to 'Software/Visual_Studio/Tango.BL/ObservableEntity.cs')
-rw-r--r--Software/Visual_Studio/Tango.BL/ObservableEntity.cs96
1 files changed, 47 insertions, 49 deletions
diff --git a/Software/Visual_Studio/Tango.BL/ObservableEntity.cs b/Software/Visual_Studio/Tango.BL/ObservableEntity.cs
index e98e48422..bee94552e 100644
--- a/Software/Visual_Studio/Tango.BL/ObservableEntity.cs
+++ b/Software/Visual_Studio/Tango.BL/ObservableEntity.cs
@@ -26,6 +26,7 @@ using System.ComponentModel;
using Tango.Core.Json;
using Newtonsoft.Json.Converters;
using Tango.BL.Serialization;
+using Newtonsoft.Json.Linq;
namespace Tango.BL
{
@@ -436,6 +437,12 @@ Maybe you have deleted an entity that was no yet inserted into database?", LogCa
{
ContractResolver = new SerializableEntityContractResolver(serializationStrategy, flags),
};
+
+ if (flags.HasFlag(EntitySerializationFlags.PreserveReferencesHandling))
+ {
+ settings.PreserveReferencesHandling = PreserveReferencesHandling.All;
+ }
+
settings.Converters.Add(new StringEnumConverter { CamelCaseText = false });
return JsonConvert.DeserializeObject<T>(json, settings);
}
@@ -446,19 +453,56 @@ Maybe you have deleted an entity that was no yet inserted into database?", LogCa
{
ContractResolver = new SerializableEntityContractResolver(serializationStrategy, flags),
};
+
+ if (flags.HasFlag(EntitySerializationFlags.PreserveReferencesHandling))
+ {
+ settings.PreserveReferencesHandling = PreserveReferencesHandling.All;
+ }
+
settings.Converters.Add(new StringEnumConverter { CamelCaseText = false });
- String json = JsonConvert.SerializeObject(this, Formatting.Indented, settings);
+ String json = JsonConvert.SerializeObject(this, flags.HasFlag(EntitySerializationFlags.Indented) ? Formatting.Indented : Formatting.None, settings);
return json;
}
public static T FromJson(String json)
{
- return FromJson(json, new EntitySerializationStrategy(), EntitySerializationFlags.IgnoreReferenceTypes);
+ return FromJson(json, new EntitySerializationStrategy(), EntitySerializationFlags.IgnoreReferenceTypes | EntitySerializationFlags.Indented);
}
public String ToJson()
{
- return ToJson(new EntitySerializationStrategy(), EntitySerializationFlags.IgnoreReferenceTypes);
+ return ToJson(new EntitySerializationStrategy(), EntitySerializationFlags.IgnoreReferenceTypes | EntitySerializationFlags.Indented);
+ }
+
+ public void PopulateFromJson(string json)
+ {
+ //JsonCobnve
+
+ //JObject from = JObject.Parse(json);
+ //JObject entity = new JObject(this);
+ //from.Merge()
+
+ //Person p = new Person()
+ //{
+ // Age = 30,
+ // Name = "Roy",
+ //};
+
+ //Person p2 = new Person();
+ //p2.Adderess = new Address()
+ //{
+ // City = "Gan Yavne",
+ // Street = "Yohanan"
+ //};
+
+ //String j1 = JsonConvert.SerializeObject(p);
+ //String j2 = JsonConvert.SerializeObject(p2);
+
+ //JsonConvert.PopulateObject(j2, p, new JsonSerializerSettings()
+ //{
+ // NullValueHandling = NullValueHandling.Ignore,
+
+ //});
}
#endregion
@@ -632,51 +676,5 @@ Maybe you have deleted an entity that was no yet inserted into database?", LogCa
}
#endregion
-
- #region Operator Overloading
-
- //public static bool operator ==(ObservableEntity<T> observable1, ObservableEntity<T> observable2)
- //{
- // if (object.ReferenceEquals(observable1, null) || object.ReferenceEquals(observable2, null))
- // {
- // return object.ReferenceEquals(observable1, observable2);
- // }
-
- // return observable1.Guid.ToLower() == observable2.Guid.ToLower();
- //}
-
- //public static bool operator !=(ObservableEntity<T> observable1, ObservableEntity<T> observable2)
- //{
- // if (object.ReferenceEquals(observable1, null) || object.ReferenceEquals(observable2, null))
- // {
- // return !object.ReferenceEquals(observable1, observable2);
- // }
-
- // return observable1.Guid.ToLower() != observable2.Guid.ToLower();
- //}
-
- //public override bool Equals(object obj)
- //{
- // if (object.ReferenceEquals(this, null) || object.ReferenceEquals(obj, null))
- // {
- // return object.ReferenceEquals(this, obj);
- // }
-
- // if (obj is ObservableEntity<T>)
- // {
- // return Guid.ToLower() == (obj as ObservableEntity<T>).Guid.ToLower();
- // }
- // else
- // {
- // return false;
- // }
- //}
-
- //public override int GetHashCode()
- //{
- // return base.GetHashCode();
- //}
-
- #endregion
}
}