views:

68

answers:

0
public class RollBack : OnMethodBoundaryAspect // or another AOP for meth interception
{
    public override void OnEntry(MethodExecutionEventArgs eventArgs)
    {
        try
        {
            ServiceConfig cfg = new ServiceConfig();
            cfg.Transaction = TransactionOption.RequiresNew;
            cfg.TrackingAppName = "Application Unit Tests";
            cfg.TransactionDescription = "Application Unit Tests Transaction";
            cfg.TransactionTimeout = 0x2710;
            ServiceDomain.Enter(cfg);
        }
        catch (Exception exception)
        {
            Console.WriteLine("Could not enter into a new transaction:\n" + exception);
        }
    }

    public override void OnExit(MethodExecutionEventArgs eventArgs)
    {
        try
        {
            if (ContextUtil.IsInTransaction)
            {
                ContextUtil.SetAbort();
            }
            ServiceDomain.Leave();
        }
        catch (Exception exception)
        {
            Console.WriteLine("Could not leave an existing transaction:\n" + exception);
        }
    }
}