public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext)
        {
            TransactionOptions option = new TransactionOptions();

            option.IsolationLevel = Level;

            using (TransactionScope ts = new TransactionScope(TransactionScopeOption.Required, option))
            {
                try
                {
                    if (Output)
                    {
                        Logger.Write("Begin Tran " + input.MethodBase.Name, "General", 1);
                    }

                    var result = getNext()(input, getNext);
                    ts.Complete();

                    return(result);
                }
                catch (Exception ex)
                {
                    if (!(ex is ConfigurationErrorsException) && !(ex is ExtraDebugInfoException))
                    {
                        string msg = RuntimeInfoCollector.GenerateInputLogMsg(input);
                        ExtraDebugInfoException extraEx = new ExtraDebugInfoException(
                            "[extraInfo:" + msg + ",OriginInfo:" + ex.Message + "]", ex);
                        throw extraEx;
                    }
                    else
                    {
                        throw ex;
                    }
                }
                finally
                {
                    if (Output)
                    {
                        Logger.Write("Submit Tran " + input.MethodBase.Name, "General", 1);
                    }
                }
            }
        }
Example #2
0
        public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext)
        {
            Type t = input.MethodBase.GetType();

            try
            {
                Monitor.Enter(t);
                if (this.Output)
                {
                    Logger.Write("Get Lock " + input.MethodBase.Name, "General", 1);
                }
                IMethodReturn result = getNext()(input, getNext);

                return(result);
            }
            catch (Exception ex)
            {
                if (!(ex is ConfigurationErrorsException) && !(ex is ExtraDebugInfoException))
                {
                    string msg = RuntimeInfoCollector.GenerateInputLogMsg(input);
                    ExtraDebugInfoException extraEx = new ExtraDebugInfoException(
                        "[extraInfo:" + msg + ",OriginInfo:" + ex.Message + "]", ex);
                    throw extraEx;
                }
                else
                {
                    throw ex;
                }
            }
            finally
            {
                if (this.Output)
                {
                    Logger.Write("Free Lock " + input.MethodBase.Name, "General", 1);
                }
                Monitor.Exit(t);
            }
        }
Example #3
0
        public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext)
        {
            string   msg     = string.Empty;
            DateTime beforDT = System.DateTime.Now;

            try
            {
                Logger.Write(Header, "General", 1);
                msg = RuntimeInfoCollector.GenerateInputLogMsg(input);
                Logger.Write(msg, "General", 1);

                IMethodReturn result = getNext()(input, getNext);

                Logger.Write(RuntimeInfoCollector.GenerateOutputLogMsg(result), "General", 1);

                return(result);
            }
            catch (Exception ex)
            {
                if (!(ex is ConfigurationErrorsException) && !(ex is ExtraDebugInfoException))
                {
                    ExtraDebugInfoException extraEx = new ExtraDebugInfoException(
                        "[extraInfo:" + msg + ",OriginInfo:" + ex.Message + "]", ex);
                    throw extraEx;
                }
                else
                {
                    throw ex;
                }
            }
            finally
            {
                DateTime afterDT = System.DateTime.Now;
                TimeSpan ts      = afterDT.Subtract(beforDT);
                Logger.Write(string.Format("总共花费{0}ms.", ts.TotalMilliseconds), "General", 1);
                Logger.Write(Footer, "General", 1);
            }
        }