Esempio n. 1
0
		protected void Dispose(bool disposing)
		{
			if (this.disposed)
			{
				return;
			}
			
			GC.SuppressFinalize(this);

			try
			{
				this.commandsContext?.Dispose();
				this.DataAccessTransaction?.RemoveTransactionContext(this);
				this.dataAccessObjectDataContext = null;
			}
			finally
			{
				this.disposed = true;
			}
		}
Esempio n. 2
0
		private void OnVersionContextFinished(object sender, EventArgs eventArgs)
		{
			if (this.disposed)
			{
				throw new ObjectDisposedException(nameof(TransactionContext));
			}

			if (this.DataAccessTransaction == null)
			{
				this.dataAccessObjectDataContext = null;
				this.commandsContext?.Dispose();
				this.dataAccessModel.AsyncLocalAmbientTransactionContext = null;
				this.Dispose();
			}
		}
Esempio n. 3
0
		public DataAccessObjectDataContext GetCurrentDataContext()
		{
			if (this.disposed)
			{
				throw new ObjectDisposedException(nameof(TransactionContext));
			}

			return this.dataAccessObjectDataContext ?? (this.dataAccessObjectDataContext = new DataAccessObjectDataContext(this.dataAccessModel, this.dataAccessModel.GetCurrentSqlDatabaseContext()));
		}
Esempio n. 4
0
		protected void Dispose(bool disposing)
		{
			if (this.disposed)
			{
				return;
			}

			List<Exception> exceptions = null;

			foreach (var commandsContext in this.commandsContextsBySqlDatabaseContexts.Values)
			{
				try
				{
					commandsContext.Dispose();
				}
				catch (Exception e)
				{
					if (exceptions == null)
					{
						exceptions = new List<Exception>();
					}

					exceptions.Add(e);
				}
			}

			try
			{
				this.DataAccessTransaction?.RemoveTransactionContext(this);
				this.dataAccessModel.AsyncLocalTransactionContext = null;
				this.dataAccessObjectDataContext = null;
			}
			finally
			{
				this.disposed = true;

				if (exceptions?.Count > 0)
				{
					throw new AggregateException(exceptions);
				}
			}

			if (this.DataAccessTransaction != null)
			{
				if (!DataAccessTransaction.HasSystemTransaction)
				{
					DataAccessTransaction.Current?.Dispose();
				}
			}
		}
Esempio n. 5
0
		public virtual DatabaseTransactionContextAcquisition AcquirePersistenceTransactionContext(SqlDatabaseContext sqlDatabaseContext)
		{
			if (this.disposed)
			{
				throw new ObjectDisposedException(nameof(TransactionContext));
			}

			SqlTransactionalCommandsContext commandsContext;

			if (!this.commandsContextsBySqlDatabaseContexts.TryGetValue(sqlDatabaseContext, out commandsContext))
			{
				commandsContext = sqlDatabaseContext.CreateSqlTransactionalCommandsContext(this.DataAccessTransaction);
				
				this.commandsContextsBySqlDatabaseContexts[sqlDatabaseContext] = commandsContext;
			}

			var startIndex = this.GetExecutionVersion();

			var retval = new DatabaseTransactionContextAcquisition(this, sqlDatabaseContext, commandsContext);

			if (this.DataAccessTransaction == null)
			{
				retval.Disposed += (s, e) =>
				{
					if (this.GetExecutionVersion() <= startIndex)
					{
						this.dataAccessObjectDataContext = null;

						foreach (var cc in this.commandsContextsBySqlDatabaseContexts.Values)
						{
							cc.Dispose();
						}

						this.commandsContextsBySqlDatabaseContexts.Clear();
					}
				};
			}

			return retval;
		}
Esempio n. 6
0
		internal void VersionContextFinished(TransactionContextExecutionVersionContext executionVersionContext)
		{
			if (this.disposed)
			{
				throw new ObjectDisposedException(nameof(TransactionContext));
			}

			if (this.DataAccessTransaction == null)
			{
				this.dataAccessObjectDataContext = null;

				foreach (var cc in this.commandsContextsBySqlDatabaseContexts.Values)
				{
					cc.Dispose();
				}

				this.commandsContextsBySqlDatabaseContexts.Clear();
				this.dataAccessModel.AsyncLocalTransactionContext = null;
				this.Dispose();
			}
		}