/// <summary>
/// Performs a set of previous changes, performs the specified operation, and records new changes that
/// occur as a result of the previous changes and the specified operation.
/// </summary>
/// <param name="operation"></param>
/// <param name="transaction"></param>
/// <returns></returns>
public ModelTransaction Perform(Action operation, ModelTransaction transaction)
{
// Create an event scope to track changes that occur as a result of applying previous changes
ModelEventScope eventScope = new ModelEventScope();
try
{
// Perform previous changes
Perform();
// Return the new changes that occurred while applying the previous changes
return(Chain(transaction).Record(() =>
{
// Allow model subscribers to be notified of the previous changes
eventScope.Exit();
// Clear the reference to the event scope to ensure it is not disposed twice
eventScope = null;
// Perform the specified operation
if (operation != null)
{
operation();
}
}));
}
catch (Exception actionException)
{
try
{
if (eventScope != null)
{
eventScope.Exit();
}
}
catch (Exception disposalException)
{
throw new ModelEventScope.ScopeException(disposalException, actionException);
}
throw;
}
}