aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.Integration/Observables/ObservableEntity.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Software/Visual_Studio/Tango.Integration/Observables/ObservableEntity.cs')
-rw-r--r--Software/Visual_Studio/Tango.Integration/Observables/ObservableEntity.cs33
1 files changed, 31 insertions, 2 deletions
diff --git a/Software/Visual_Studio/Tango.Integration/Observables/ObservableEntity.cs b/Software/Visual_Studio/Tango.Integration/Observables/ObservableEntity.cs
index 92dd88f34..d5b218453 100644
--- a/Software/Visual_Studio/Tango.Integration/Observables/ObservableEntity.cs
+++ b/Software/Visual_Studio/Tango.Integration/Observables/ObservableEntity.cs
@@ -18,6 +18,9 @@ using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
using System.Runtime.CompilerServices;
using System.Data.Entity.Core.Objects;
+using Tango.Serialization;
+using System.Xml.Serialization;
+using Newtonsoft.Json;
namespace Tango.Integration.Observables
{
@@ -65,6 +68,7 @@ namespace Tango.Integration.Observables
/// Gets or sets the entity last updated data and time.
/// </summary>
[Column("LAST_UPDATED")]
+ [JsonIgnore]
public DateTime LastUpdated
{
get { return _lastUpdated; }
@@ -76,6 +80,8 @@ namespace Tango.Integration.Observables
/// Gets a bind-able observable collection of the component properties.
/// </summary>
[NotMapped]
+ [XmlIgnore]
+ [JsonIgnore]
public ReadOnlyObservableCollection<ParameterItem> Parameters
{
get { return _parameters; }
@@ -108,7 +114,7 @@ namespace Tango.Integration.Observables
/// </summary>
public virtual void Save()
{
- GetDbContextFromEntity(this).SaveChanges();
+ ObservablesEntitiesAdapter.Instance.SaveChanges();
OnSaved();
}
@@ -213,7 +219,7 @@ namespace Tango.Integration.Observables
return null;
}
-
+
protected virtual void OnSaved()
{
Saved?.Invoke(this, new EventArgs());
@@ -243,6 +249,29 @@ namespace Tango.Integration.Observables
return context;
}
+ public virtual T Clone()
+ {
+ return (this as T).CloneEntity() as T;
+ }
+
+ public void Save(DbContext context)
+ {
+ context.SaveChanges();
+ OnSaved();
+ }
+
+ public Task SaveAsync(DbContext context)
+ {
+ return Task.Factory.StartNew(() => Save(context));
+ }
+
+ public bool CompareUsingJson(T entity)
+ {
+ String me = JsonConvert.SerializeObject(this);
+ String other = JsonConvert.SerializeObject(entity);
+ return me == other;
+ }
+
#region Operator Overloading
//public static bool operator ==(ObservableEntity<T> observable1, ObservableEntity<T> observable2)