aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.BL/ObservablesContextExtension.cs
diff options
context:
space:
mode:
authorRoy Ben Shabat <Roy.mail.net@gmail.com>2019-12-11 20:57:30 +0200
committerRoy Ben Shabat <Roy.mail.net@gmail.com>2019-12-11 20:57:30 +0200
commit621230afe9d9040536b43241e63117c9bb34beaa (patch)
treec9f3a3793372a1be6a7e73cdf633e2dae40c21c9 /Software/Visual_Studio/Tango.BL/ObservablesContextExtension.cs
parent3f069bb4a5303b2c732ba1263229f62526acc693 (diff)
downloadTango-621230afe9d9040536b43241e63117c9bb34beaa.tar.gz
Tango-621230afe9d9040536b43241e63117c9bb34beaa.zip
Implemented Jobs, JobRuns & Machine Events Synchronization.
Added synchronizations to Updates view on Machine Designer. Removed request response events logging from machine studio. Fixed issue with exception throwing from machine service. Implemented "New jobs synchronized" notification item to PPC. Added synchronization to PPC settings. Added Synchronization view to technician module. Implemented PPC Schema synchronizer utility. Added custom query support to EntityCollectionBuilder. Added synchronization status to TangoUpdate. Removed FK from Jobs and Job runs.
Diffstat (limited to 'Software/Visual_Studio/Tango.BL/ObservablesContextExtension.cs')
-rw-r--r--Software/Visual_Studio/Tango.BL/ObservablesContextExtension.cs31
1 files changed, 27 insertions, 4 deletions
diff --git a/Software/Visual_Studio/Tango.BL/ObservablesContextExtension.cs b/Software/Visual_Studio/Tango.BL/ObservablesContextExtension.cs
index b7559cdc3..263574f68 100644
--- a/Software/Visual_Studio/Tango.BL/ObservablesContextExtension.cs
+++ b/Software/Visual_Studio/Tango.BL/ObservablesContextExtension.cs
@@ -3,6 +3,7 @@ using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Data.Entity;
+using System.Data.Entity.Core.Objects;
using System.Data.Entity.Infrastructure;
using System.Data.SQLite;
using System.IO;
@@ -35,7 +36,7 @@ namespace Tango.BL
/// </summary>
public ObservablesContext()
{
-
+
}
/// <summary>
@@ -103,6 +104,15 @@ namespace Tango.BL
}
/// <summary>
+ /// Gets the inner object context.
+ /// </summary>
+ /// <returns></returns>
+ private ObjectContext GetObjectContext()
+ {
+ return ((IObjectContextAdapter)this).ObjectContext;
+ }
+
+ /// <summary>
/// Saves all changes made in this context to the underlying database.
/// </summary>
/// <returns>
@@ -110,6 +120,14 @@ namespace Tango.BL
/// </returns>
public override int SaveChanges()
{
+ foreach (var entity in ChangeTracker.Entries().Where(x => x.State == EntityState.Added || x.State == EntityState.Modified).ToList())
+ {
+ if (entity is IObservableEntity && entity != null)
+ {
+ (entity as IObservableEntity).OnBeforeSave();
+ }
+ }
+
var result = base.SaveChanges();
RaisePendingNotifications();
return result;
@@ -129,6 +147,14 @@ namespace Tango.BL
/// </remarks>
public override Task<int> SaveChangesAsync(CancellationToken cancellationToken)
{
+ foreach (var entity in ChangeTracker.Entries().Where(x => x.State == EntityState.Added || x.State == EntityState.Modified).ToList().Select(x => x.Entity).ToList())
+ {
+ if (entity is IObservableEntity && entity != null)
+ {
+ (entity as IObservableEntity).OnBeforeSave();
+ }
+ }
+
var result = base.SaveChangesAsync(cancellationToken);
RaisePendingNotifications();
return result;
@@ -168,9 +194,6 @@ namespace Tango.BL
{
IObservableEntity modified = entityEntry.Entity as IObservableEntity;
- //Good chance to update "LAST_UPDATED" field!
- modified.LastUpdated = DateTime.UtcNow;
-
foreach (var toNotify in ObservableEntitiesContainer.RegisteredEntities.ToList().Where(x => x.Guid == modified.Guid).ToList())
{
_pending_notifications.Add(new ObservableModifiedEventArgs(this, modified, toNotify));