Beispiel #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="invocation"></param>
        /// <param name="arguments"></param>
        /// <returns></returns>
        public object Intercept(IInvocation invocation, params object[] arguments)
        {
            Object result = null;

            #region Logging
            if (_logger.IsDebugEnabled)
            {
                _logger.Debug("Dao Proxy call to " + invocation.Method.Name);
            }
            #endregion

            bool hasNoDaoSessionAttributeDefined = invocation.Method.IsDefined(
                typeof(DAOMethodAttribute), true);

            if (_passthroughMethods.Contains(invocation.Method.Name) ||
                hasNoDaoSessionAttributeDefined)
            {
                try
                {
                    result = invocation.Method.Invoke(_daoImplementation.DaoInstance, arguments);
                }
                catch (Exception e)
                {
                    throw UnWrapException(e, invocation.Method.Name);
                }
            }
            else
            {
                DaoManager daoManager = _daoImplementation.DaoManager;
                if (daoManager.IsDaoSessionStarted())
                {
                    try
                    {
                        result = invocation.Method.Invoke(_daoImplementation.DaoInstance, arguments);
                    }
                    catch (Exception e)
                    {
                        throw UnWrapException(e, invocation.Method.Name);
                    }
                }
                else
                {
                    #region Logging
                    if (_logger.IsDebugEnabled)
                    {
                        _logger.Debug("Dao Proxy, Open a connection ");
                    }
                    #endregion
                    // Open a connection
                    try
                    {
                        daoManager.OpenConnection();
                        result = invocation.Method.Invoke(_daoImplementation.DaoInstance, arguments);
                    }
                    catch (Exception e)
                    {
                        System.Diagnostics.Trace.WriteLine(invocation.Method.Name + ":" + e.Message);
                        throw UnWrapException(e, invocation.Method.Name);
                    }
                    finally
                    {
                        try
                        {
                            //if (daoManager.IsDaoSessionStarted() &&
                            //    daoManager.LocalDaoSession.Connection !=null)
                            daoManager.CloseConnection();
                        }
                        catch { }
                    }
                }
            }

            #region Logging
            if (_logger.IsDebugEnabled)
            {
                _logger.Debug("End of proxyfied call to " + invocation.Method.Name);
            }
            #endregion

            return(result);
        }
Beispiel #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="invocation"></param>
        /// <param name="arguments"></param>
        /// <returns></returns>
        public object Intercept(IInvocation invocation, params object[] arguments)
        {
            Object result = null;

            #region Logging
            if (_logger.IsDebugEnabled)
            {
                _logger.Debug("Dao Proxy call to " + invocation.Method.Name);
            }
            #endregion

            if (_passthroughMethods.Contains(invocation.Method.Name))
            {
                try
                {
                    result = invocation.Method.Invoke(_daoImplementation.DaoInstance, arguments);
                }
                catch (Exception e)
                {
                    throw UnWrapException(e, invocation.Method.Name);
                }
            }
            else
            {
                DaoManager daoManager = _daoImplementation.DaoManager;
                if (daoManager.IsDaoSessionStarted())
                {
                    try
                    {
                        result = invocation.Method.Invoke(_daoImplementation.DaoInstance, arguments);
                    }
                    catch (Exception e)
                    {
                        throw UnWrapException(e, invocation.Method.Name);
                    }
                }
                else
                {
                    #region Logging
                    if (_logger.IsDebugEnabled)
                    {
                        _logger.Debug("Dao Proxy, Open a connection ");
                    }
                    #endregion
                    // Open a connection
                    try
                    {
                        daoManager.OpenConnection();
                        result = invocation.Method.Invoke(_daoImplementation.DaoInstance, arguments);
                    }
                    catch (Exception e)
                    {
                        throw UnWrapException(e, invocation.Method.Name);
                    }
                    finally
                    {
                        daoManager.CloseConnection();
                    }
                }
            }

            #region Logging
            if (_logger.IsDebugEnabled)
            {
                _logger.Debug("End of proxyfied call to " + invocation.Method.Name);
            }
            #endregion

            return(result);
        }