|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Technewlogic.ObjectLounge.Framework.Transactions;
using Technewlogic.ObjectLounge.Framework.Proxy;
using Technewlogic.ObjectLounge.Framework.BaseConcerns;
using System.Reflection;
namespace Technewlogic.ObjectLounge.Framework.Transactions
{
/// <summary>
/// Die ITransactionMapper Implementierung für den ShadowStorage-Concern.
/// </summary>
public class ShadowStorageTransactionMapper
{
internal ShadowStorageTransactionMapper(
TransactionManager transactionManager)
{
_transactionManager = transactionManager;
_transactionalStorage = new TransactionalStorage<IShadowStorageBehavior>(
new ShadowStorageBehavior(),
_transactionManager);
_transactionManager.RollingBack
+= new EventHandler<TransactionEventArgs>(_transactionManager_RollingBack);
_transactionManager.Committing
+= new EventHandler<TransactionEventArgs>(_transactionManager_Committing);
}
private readonly TransactionManager _transactionManager;
private readonly TransactionalStorage<IShadowStorageBehavior> _transactionalStorage;
internal void RegisterRollbackAction(string propertyName, Action<object> restoreValueMethod)
{
_transactionalStorage.Value
.RegisterRollbackAction(propertyName, restoreValueMethod);
}
private void _transactionManager_RollingBack(object sender, TransactionEventArgs e)
{
if (_transactionalStorage.HasCurrentTransactionValue)
_transactionalStorage.Value.RestorePropertyValues();
}
private void _transactionManager_Committing(object sender, TransactionEventArgs e)
{
if (_transactionalStorage.HasCurrentTransactionValue)
_transactionalStorage.ClearOwnerScope();
}
/// <param name="value">Der Gespeicherte Propertywert (wenn True zurückgegeben wird).</param>
/// <returns>
/// True, wenn das angeforderte Property von einer anderen (nicht der aktuellen)
/// noch laufenden Transaktion geschrieben wurde.
/// </returns>
internal bool TryGetCommittedValue<T>(string propertyName, out T value)
{
if (_transactionalStorage.HasDifferentTransactionValue)
{
if (_transactionalStorage.Value.BackupProperties.ContainsKey(propertyName))
{
value = (T)_transactionalStorage.Value.BackupProperties[propertyName];
return true;
}
}
value = default(T);
return false;
}
internal void OnPropertyChanging(string propertyName, object newValue, object oldVvalue)
{
// Wird jetzt im TransactionManager global gemacht
//if (_transactionalStorage.HasDifferentTransactionValue)
// Error.EntityInTransaction(this, _transactionalStorage.OwnerTransaction); // TODO: this ist nicht ganz korrekt, eigentlich müsste es die entity sein
}
internal void OnPropertyChanged(string propertyName, object newValue, object oldVvalue)
{
// Prüfung auf Korrektheit ist oben schon geschehen
if (!_transactionalStorage.HasCurrentTransactionValue)
{
_transactionalStorage.SetOwnerScope();
// IMP: An Transaction-Events anhängen für commit / rollback und den Concern löschen (evtl. im Storage machen)
}
_transactionalStorage.Value.HandlePropertySet(propertyName, oldVvalue);
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.