示例#1
0
        public int DemoAdvice(MethodJointPoint jp)
        {
            Console.WriteLine("Demo advice for {0} from {1}", jp.Args[0], jp.Method);
            jp.Args[0] = "Sheep!!"; // Subsituting the argument of the method

            return((int)jp.Execute() + 100);
        }
示例#2
0
文件: Driver.cs 项目: erhan0/aop
 public object LogQueriesAndUpdates(MethodJointPoint jp)
 {
     Console.WriteLine("Entering method {0} on object {1} with args {2}", jp.Method, jp.This, jp.Args);
     try
     {
         object result = jp.Execute();
         Console.WriteLine("Exits normally with return-value {0}", result);
         return(result);
     }
     catch (Exception e)
     {
         Console.WriteLine("Exits with exception: {0}", e);
         throw;
     }
 }
示例#3
0
        public object LogAroundMethod(MethodJointPoint jp)
        {
            Console.WriteLine("Entering {0} on {1}. Args:{2}", jp.Method, jp.This, string.Join(",", jp.Args));
            try
            {
                var result = jp.Execute();

                Console.WriteLine("Exitting {0}. Result: {1}", jp.Method, jp.Method.ReturnType == typeof(void)? "{void}": result);
                return result;
            }
            catch (Exception e)
            {
                Console.WriteLine("Exitting {0} with exception: '{1}'", jp.Method, e);
                throw;
            }
        }
 public object MyAdvice(MethodJointPoint jp)
 {
     Trace.TraceInformation("Entering {0} on {1}. Args:{2}", jp.Method, jp.This, string.Join(",", jp.Args));
     try
     {
         object result = (int)jp.Execute() * 2;
         if (jp.Method.ReturnType == typeof(void)) result = "{void}";
         Trace.TraceInformation("Exitting {0}. Result: {1}", jp.Method, result);
         return result;
     }
     catch (Exception e)
     {
         Trace.TraceInformation("Exitting {0} with exception: '{1}'", jp.Method, e);
         throw;
     }
 }
示例#5
0
        public object LogAroundMethod(MethodJointPoint jp)
        {
            try
            {
                ShardingCore.Process(jp.Method, jp.Args);

                var result = jp.Execute();

                if (jp.Method.ReturnType == typeof(void))
                {
                    result = "{void}";
                }

                return(result);
            }
            catch (Exception e)
            {
                throw;
            }
        }
示例#6
0
        public object LogAroundMethod(MethodJointPoint jp)
        {
            Trace.TraceInformation("Entering {0} on {1}. Args:{2}", jp.Method, jp.This, string.Join(",", jp.Args));
            try
            {
                var result = jp.Execute();

                if (jp.Method.ReturnType == typeof(void))
                {
                    result = "{void}";
                }

                Trace.TraceInformation("Exitting {0}. Result: {1}", jp.Method, result);
                return(result);
            }
            catch (Exception e)
            {
                Trace.TraceInformation("Exitting {0} with exception: '{1}'", jp.Method, e);
                throw;
            }
        }
示例#7
0
        public object WaitCursorAdvice(MethodJointPoint jp)
        {
            SheepAspectLab.Form1.WriteLog(string.Format("{1} >> ON ENTER : {0}", jp.Method.Name, "WaitCursorAdvice"));
            System.Windows.Forms.Form frm = (Form)jp.This;
            try
            {
                frm.Cursor = Cursors.WaitCursor;

                object result = jp.Execute();
                return(result);
            }
            catch (Exception ex)
            {
                SheepAspectLab.Form1.WriteLog(string.Format("{1} >> ON EXCEPTION : {0}", ex.Message, "WaitCursorAdvice"));
                throw;
            }
            finally
            {
                frm.Cursor = Cursors.Default;
                SheepAspectLab.Form1.WriteLog(string.Format("{1} >> ON LEAVE : {0}", jp.Method.Name, "WaitCursorAdvice"));
            }
        }
示例#8
0
 public object CatchAndLogAdvice(MethodJointPoint jp)
 {
     ///
     /// 寫 Log 機制在此為急用所以亂作,正式的應用應導入正式的 Log 模組,如:NLog 等。
     ///
     SheepAspectLab.Form1.WriteLog(string.Format("{1} >> ON ENTER : {0}", jp.Method.Name, "LogAdvice"));
     try
     {
         object result = jp.Execute();
         return(result);
     }
     catch (Exception ex)
     {
         SheepAspectLab.Form1.WriteLog(string.Format("{1} >> ON EXCEPTION : {0}", ex.Message, "LogAdvice"));
         MessageBox.Show(ex.Message, "Exception!", MessageBoxButtons.OK, MessageBoxIcon.Stop);
         return(null);
         //throw;
     }
     finally
     {
         SheepAspectLab.Form1.WriteLog(string.Format("{1} >> ON LEAVE : {0}", jp.Method.Name, "LogAdvice"));
     }
 }
        public object TransactionAroundMethod(MethodJointPoint jp)
        {
            Trace.TraceInformation("Entering {0} on {1}. Args:{2}", jp.Method, jp.This, string.Join(",", jp.Args));
            try
            {
                // 开启事务
                dbTransaction = DbFactory.GetInstance().Database.BeginTransaction();

                var result = jp.Execute();

                if (jp.Method.ReturnType == typeof(void))
                {
                    result = "{void}";
                }

                // 提交事务
                dbTransaction.Commit();

                Trace.TraceInformation("Exitting {0}. Result: {1}", jp.Method, result);
                return(result);
            }
            catch (Exception e)
            {
                // 回滚事务
                dbTransaction.Rollback();
                Trace.TraceInformation("Exitting {0} with exception: '{1}'", jp.Method, e);
                throw;
            }
            finally
            {
                if (dbTransaction != null)
                {
                    dbTransaction.Dispose();
                }
            }
        }
示例#10
0
 public object MockAdvice(MethodJointPoint jp)
 {
     return(advice(jp));
 }