private void InterceptAsync(IInvocation invocation, TransactionalAttribute attribute)
        {
            _logger.LogInformation($"BeginTransaction with IsolationLevel: {attribute.IsolationLevel}");

            _dbContext.BeginTransaction(attribute.IsolationLevel);

            try
            {
                invocation.Proceed();
            }
            catch (Exception)
            {
                _dbContext.RollbackTransaction();
                throw;
            }

            if (invocation.Method.ReturnType == typeof(Task))
            {
                invocation.ReturnValue = InterceptAsync((Task)invocation.ReturnValue, _dbContext);
            }
            else //Task<TResult>
            {
                invocation.ReturnValue = typeof(TransactionInterceptor)
                                         .GetMethod(nameof(InterceptWithResultAsync),
                                                    BindingFlags.NonPublic | BindingFlags.Static)
                                         ?.MakeGenericMethod(invocation.Method.ReturnType.GenericTypeArguments[0])
                                         .Invoke(null, new[] { invocation.ReturnValue, _dbContext });
            }
        }
        private void InterceptAsync(IInvocation invocation, TransactionalAttribute attribute)
        {
            var transaction = _provider.BeginTransaction(attribute.IsolationLevel);

            try
            {
                invocation.Proceed();
            }
            catch (Exception)
            {
                transaction.Rollback();
                throw;
            }

            if (invocation.Method.ReturnType == typeof(Task))
            {
                invocation.ReturnValue = InterceptAsync((Task)invocation.ReturnValue, transaction);
            }
            else //Task<TResult>
            {
                invocation.ReturnValue = typeof(TransactionInterceptor)
                                         .GetMethod(nameof(InterceptWitResultAsync),
                                                    BindingFlags.NonPublic | BindingFlags.Static)
                                         ?.MakeGenericMethod(invocation.Method.ReturnType.GenericTypeArguments[0])
                                         .Invoke(null, new[] { invocation.ReturnValue, transaction });
            }
        }
Ejemplo n.º 3
0
        public DataPortalMethodInfo()
        {
#if !(ANDROID || IOS) && !NETFX_CORE
            TransactionalAttribute = new TransactionalAttribute(TransactionalTypes.Manual);
#else
            TransactionalType = TransactionalTypes.Manual;
#endif
        }
Ejemplo n.º 4
0
        public DataPortalMethodInfo()
        {
#if !SILVERLIGHT && !NETFX_CORE
            TransactionalAttribute = new TransactionalAttribute(TransactionalTypes.Manual);
#else
            TransactionalType = TransactionalTypes.Manual;
#endif
        }
Ejemplo n.º 5
0
 public DataPortalMethodInfo()
 {
     #if !(ANDROID || IOS) && !NETFX_CORE
       TransactionalAttribute = new TransactionalAttribute(TransactionalTypes.Manual);
     #else
       TransactionalType = TransactionalTypes.Manual;
     #endif
 }
Ejemplo n.º 6
0
    public DataPortalMethodInfo()
    {
#if !SILVERLIGHT && !NETFX_CORE
      TransactionalAttribute = new TransactionalAttribute(TransactionalTypes.Manual);
#else
      TransactionalType = TransactionalTypes.Manual;
#endif

    }
 private void Intercept(IInvocation invocation, TransactionalAttribute attribute)
 {
     if (invocation.Method.IsAsync())
     {
         InterceptAsync(invocation, attribute);
     }
     else
     {
         InterceptSync(invocation, attribute);
     }
 }
Ejemplo n.º 8
0
 private static TransactionalAttribute GetTransactionalAttribute(System.Reflection.MethodInfo method)
 {
   TransactionalAttribute result;
   if (IsTransactionalMethod(method))
   {
     result =
       (TransactionalAttribute)Attribute.GetCustomAttribute(
       method, typeof(TransactionalAttribute));
   }
   else
     result = new TransactionalAttribute(TransactionalTypes.Manual);
   return result;
 }
Ejemplo n.º 9
0
        private static TransactionalAttribute GetTransactionalAttribute(System.Reflection.MethodInfo method)
        {
            TransactionalAttribute result;

            if (IsTransactionalMethod(method))
            {
                result =
                    (TransactionalAttribute)Attribute.GetCustomAttribute(
                        method, typeof(TransactionalAttribute));
            }
            else
            {
                result = new TransactionalAttribute(TransactionalTypes.Manual);
            }
            return(result);
        }
        private static TransactionalTypes GetTransactionalType(MethodInfo method)
        {
            TransactionalTypes result;

            if (IsTransactionalMethod(method))
            {
                TransactionalAttribute attrib =
                    (TransactionalAttribute)Attribute.GetCustomAttribute(
                        method, typeof(TransactionalAttribute));
                result = attrib.TransactionType;
            }
            else
            {
                result = TransactionalTypes.Manual;
            }
            return(result);
        }
Ejemplo n.º 11
0
        //[Transactional]
        public static void TakeOrder127()
        {
            Type   arg_22_0 = typeof(Program);
            string arg_22_1 = "TakeOrder";

            Type[]                 types            = new Type[0];
            MemberInfo             method           = arg_22_0.GetMethod(arg_22_1, types);
            MethodAspectArgs       methodAspectArgs = new MethodAspectArgs();
            MAList                 mAList           = new MAList();
            TransactionalAttribute item             = method.GetCustomAttributes(typeof(TransactionalAttribute), false)[0] as TransactionalAttribute;

            mAList.Add(item);
            foreach (MethodAspect current in mAList)
            {
                current.OnStart(methodAspectArgs);
            }
            try
            {
                Program._TakeOrder_33();
                foreach (MethodAspect current in mAList)
                {
                    current.OnSuccess(methodAspectArgs);
                }
            }
            catch (Exception ex)
            {
                methodAspectArgs.Exception = ex;
                foreach (MethodAspect current in mAList)
                {
                    current.OnException(methodAspectArgs);
                }
                switch ((int)mAList[0].ExceptionStrategy)
                {
                case 1:
                    throw ex;

                case 2:
                    throw;
                }
            }
            foreach (MethodAspect current in mAList)
            {
                current.OnEnd(methodAspectArgs);
            }
        }
Ejemplo n.º 12
0
        private IDataPortalServer GetServicedComponentPortal(TransactionalAttribute transactionalAttribute)
        {
            switch (transactionalAttribute.TransactionIsolationLevel)
            {
            case TransactionIsolationLevel.Serializable:
                return(new ServicedDataPortalSerializable());

            case TransactionIsolationLevel.RepeatableRead:
                return(new ServicedDataPortalRepeatableRead());

            case TransactionIsolationLevel.ReadCommitted:
                return(new ServicedDataPortalReadCommitted());

            case TransactionIsolationLevel.ReadUncommitted:
                return(new ServicedDataPortalReadUncommitted());

            default:
                throw new ArgumentOutOfRangeException("transactionalAttribute");
            }
        }
Ejemplo n.º 13
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TransactionalDataPortal" /> class.
 /// </summary>
 /// <param name="transactionalAttribute">
 /// The transactional attribute that defines transaction options to be used with transactions.
 /// </param>
 public TransactionalDataPortal(TransactionalAttribute transactionalAttribute)
 {
     _transactionalAttribute = transactionalAttribute;
 }
Ejemplo n.º 14
0
 private IDataPortalServer GetServicedComponentPortal(TransactionalAttribute transactionalAttribute)
 {
   switch (transactionalAttribute.TransactionIsolationLevel)
   {
     case TransactionIsolationLevel.Serializable:
       return new ServicedDataPortalSerializable();
     case TransactionIsolationLevel.RepeatableRead:
       return new ServicedDataPortalRepeatableRead();
     case TransactionIsolationLevel.ReadCommitted:
       return new ServicedDataPortalReadCommitted();
     case TransactionIsolationLevel.ReadUncommitted:
       return new ServicedDataPortalReadUncommitted();
     default:
       throw new ArgumentOutOfRangeException("transactionalAttribute");
   }
 }
Ejemplo n.º 15
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TransactionalDataPortal" /> class.
 /// </summary>
 /// <param name="transactionalAttribute">
 /// The transactional attribute that defines transaction options to be used with transactions.
 /// </param>
 public TransactionalDataPortal(TransactionalAttribute transactionalAttribute)
 {
   _transactionalAttribute = transactionalAttribute;
 }
Ejemplo n.º 16
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TransactionalDataPortal" /> class.
 /// </summary>
 /// <param name="dataPortalBroker">The broker that is used to perform the data access operation</param>
 /// <param name="transactionalAttribute">
 /// The transactional attribute that defines transaction options to be used with transactions.
 /// </param>
 public TransactionalDataPortal(DataPortalBroker dataPortalBroker, TransactionalAttribute transactionalAttribute)
 {
     _portal = dataPortalBroker;
     _transactionalAttribute = transactionalAttribute;
 }