aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.BL/ObservablesContextExtension.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Software/Visual_Studio/Tango.BL/ObservablesContextExtension.cs')
-rw-r--r--Software/Visual_Studio/Tango.BL/ObservablesContextExtension.cs53
1 files changed, 4 insertions, 49 deletions
diff --git a/Software/Visual_Studio/Tango.BL/ObservablesContextExtension.cs b/Software/Visual_Studio/Tango.BL/ObservablesContextExtension.cs
index 3d330b797..b7559cdc3 100644
--- a/Software/Visual_Studio/Tango.BL/ObservablesContextExtension.cs
+++ b/Software/Visual_Studio/Tango.BL/ObservablesContextExtension.cs
@@ -3,9 +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.SqlClient;
using System.Data.SQLite;
using System.IO;
using System.Linq;
@@ -26,7 +24,6 @@ namespace Tango.BL
private ObservablesContextAdapter _adapter;
private static DataSource _override_datasource;
private DataSource _dataSource;
- private static List<ObservablesContext> _open_contexts;
/// <summary>
/// Gets a value indicating whether this instance is disposed.
@@ -34,19 +31,11 @@ namespace Tango.BL
public bool IsDisposed { get; private set; }
/// <summary>
- /// Initializes the <see cref="ObservablesContext"/> class.
- /// </summary>
- static ObservablesContext()
- {
- _open_contexts = new List<ObservablesContext>();
- }
-
- /// <summary>
/// Initializes a new instance of the <see cref="ObservablesContext"/> class.
/// </summary>
public ObservablesContext()
{
- _open_contexts.Add(this);
+
}
/// <summary>
@@ -56,7 +45,6 @@ namespace Tango.BL
/// <param name="isFile">if set to <c>true</c> will try to connect to an .mdf file.</param>
public ObservablesContext(DataSource dataSource) : base(dataSource.ToConnection(), true)
{
- _open_contexts.Add(this);
_dataSource = dataSource;
Database.SetInitializer<ObservablesContext>(null);
Configuration.LazyLoadingEnabled = false;
@@ -115,15 +103,6 @@ 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>
@@ -131,14 +110,6 @@ 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;
@@ -158,14 +129,6 @@ 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;
@@ -205,6 +168,9 @@ 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));
@@ -297,7 +263,6 @@ namespace Tango.BL
/// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
protected override void Dispose(bool disposing)
{
- _open_contexts.Remove(this);
base.Dispose(disposing);
IsDisposed = true;
}
@@ -308,16 +273,6 @@ namespace Tango.BL
{
_override_datasource.AccessToken = accessToken;
_override_datasource.AccessTokenExpiration = expiration;
-
- foreach (var context in _open_contexts.Where(x => x._dataSource.Type == DataSourceType.AccessToken))
- {
- context._dataSource = _override_datasource;
- var connection = context.Database.Connection as SqlConnection;
- if (connection != null)
- {
- connection.AccessToken = context._dataSource.AccessToken;
- }
- }
}
}
}