Exemplo n.º 1
0
		private TransactionConfig CreateTransactionConfig(ComponentModel model)
		{
			TransactionConfig config = new TransactionConfig();
			GatherTransactionAttributes(config, model.Implementation);
			GatherTransactionConfiguration(config, model);
			return config;
		}
Exemplo n.º 2
0
        private void OnModelCreated(ComponentModel model)
        {
            if (IsTransactional(model))
            {
                TransactionConfig config = CreateTransactionConfig(model);

                _transactionConfigHolder.Register(model.Implementation, config);

                model.Interceptors.Add(
                    new InterceptorReference(typeof(TransactionInterceptor)));
            }
        }
Exemplo n.º 3
0
        private void GatherTransactionAttributes(TransactionConfig config, Type implementation)
        {
            MethodInfo[] methods = implementation.GetMethods(
                BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);

            foreach (MethodInfo method in methods)
            {
                if (method.IsDefined(typeof(RequiresTransactionAttribute), true))
                {
                    config.AddMethod(method);
                }
            }
        }
Exemplo n.º 4
0
        public object Intercept(IMethodInvocation invocation, params object[] args)
        {
            if (_transactionManager.CurrentTransaction != null)
            {
                // No support for nested transactions
                // is necessary
                return(invocation.Proceed(args));
            }

            TransactionConfig config =
                _transactionConfHolder.GetConfig(
                    invocation.Method.DeclaringType);

            if (config != null && config.IsMethodTransactional(invocation.Method))
            {
                ITransaction transaction =
                    _transactionManager.CreateTransaction();

                object value = null;

                try
                {
                    value = invocation.Proceed(args);

                    transaction.Commit();
                }
                catch (Exception ex)
                {
                    transaction.Rollback();

                    throw ex;
                }
                finally
                {
                    _transactionManager.Release(transaction);
                }

                return(value);
            }
            else
            {
                return(invocation.Proceed(args));
            }
        }
Exemplo n.º 5
0
        private void GatherTransactionConfiguration(TransactionConfig config, ComponentModel model)
        {
            if (model.Configuration == null)
            {
                return;
            }

            IConfiguration transactionNode = model.Configuration.Children["transaction"];

            if (transactionNode == null)
            {
                return;
            }

            foreach (IConfiguration methodNode in transactionNode.Children)
            {
                config.AddMethodName(methodNode.Value);
            }
        }
Exemplo n.º 6
0
		private void GatherTransactionConfiguration(TransactionConfig config, ComponentModel model)
		{
			if (model.Configuration == null) return;
			
			IConfiguration transactionNode = model.Configuration.Children["transaction"];

			if (transactionNode == null) return;

			foreach(IConfiguration methodNode in transactionNode.Children)
			{
				config.AddMethodName( methodNode.Value );
			}
		}
Exemplo n.º 7
0
		private void GatherTransactionAttributes(TransactionConfig config, Type implementation)
		{
			MethodInfo[] methods = implementation.GetMethods( 
				BindingFlags.Instance|BindingFlags.Public|BindingFlags.NonPublic );

			foreach(MethodInfo method in methods)
			{
				if (method.IsDefined( typeof(RequiresTransactionAttribute), true ))
				{
					config.AddMethod( method );
				}
			}
		}
		public void Register(Type implementation, TransactionConfig config)
		{
			_impl2Config[implementation] = config;
		}
Exemplo n.º 9
0
 public void Register(Type implementation, TransactionConfig config)
 {
     _impl2Config[implementation] = config;
 }