示例#1
0
        public void after(JoinPointContext context)
        {
            report("after " + context.StartSelector);

            if (context.StartSelector.Equals("func4"))
            {
                String ret = (String)context.ReturnValue;
                ret = ret + " #After#";
                context.ReturnValue = ret;
            }
            else if (context.StartSelector.Equals("func9"))
            {
                int arg = (int)context.GetArgumentValue(0);
                Console.WriteLine("AFTER: Value of x after func9: " + arg + ". Add one to value.");
                arg = arg + 1;
                context.SetArgumentValue(0, arg);
            }
            else if (context.StartSelector.Equals("func10"))
            {
                int arg = (int)context.GetArgumentValue(0);
                Console.WriteLine("AFTER: Value of x after func10: " + arg + ". Add one to value.");
                arg = arg + 1;
                context.SetArgumentValue(0, arg);
            }
        }
示例#2
0
        public void archiveMessage(JoinPointContext jpc)
        {
            string sender   = (string)jpc.GetArgumentValue(0);
            string receiver = (string)jpc.GetArgumentValue(1);
            string message  = (string)jpc.GetArgumentValue(2);

            Console.WriteLine("\nArchiving message");
            Console.WriteLine("Sender:   {0}", sender);
            Console.WriteLine("Receiver: {0}", receiver);
            Console.WriteLine("Message:  {0}", message);
        }
示例#3
0
		public void PayIncomeTax(JoinPointContext jpc)
		{
			int ammount = (int) jpc.GetArgumentValue(0);
			if(ammount > 2000)
			{
				Console.WriteLine("Because the income is more then 2000, he needs to pay income tax");
				jpc.SetArgumentValue(0,ammount - CalculateTax(ammount));
			}
		}
示例#4
0
        public void before(JoinPointContext context)
        {
            report("before " + context.StartSelector);

            if (context.StartSelector.Equals("func4"))
            {
                int arg = (int)context.GetArgumentValue(0);
                arg = arg + 1;
                context.AddArgument(0, arg.GetType(), arg);
            }
            else if (context.StartSelector.Equals("func9"))
            {
                object arg = context.GetArgumentValue(0);
                Console.WriteLine("\targ=" + (arg == null ? "null" : "'" + arg + "'"));
            }
            else if (context.StartSelector.Equals("func10"))
            {
                int arg = (int)context.GetArgumentValue(0);
                Console.WriteLine("BEFORE: Value of x before func10: " + arg + ". Add one to value.");
                arg = arg + 1;
                context.SetArgumentValue(0, arg);
            }
        }
示例#5
0
        public static void storeCachedValue(JoinPointContext context)
        {
            if (!context.HasReturnValue)
            {
                return;
            }
            Cache  cache = Cache.instance(context.CurrentTarget);
            Object args  = null;

            if (context.ArgumentCount > 0)
            {
                args = context.GetArgumentValue(0);
            }
            cache.setCache(context.MethodInformation, args, context.ReturnValue);
        }
示例#6
0
        public static bool getCachedValue(JoinPointContext context)
        {
            if (context.ReturnType == null || context.ReturnType == typeof(void))
            {
                return(false);
            }
            Cache  cache = Cache.instance(context.CurrentTarget);
            Object args  = null;

            if (context.ArgumentCount > 0)
            {
                args = context.GetArgumentValue(0);
            }
            Object val;

            if (cache.getCache(context.MethodInformation, args, out val))
            {
                context.ReturnValue = val;
                return(true);
            }
            return(false);
        }
示例#7
0
        public override void Execute(JoinPointContext context)
        {
            long   stoptime    = 0;
            double executetime = 0;

            // Get the frequency from the JoinPointContext, this frequency was stored in the StartTimerAction
            long freq = (long)context.GetProperty("frequency");

            if (freq == 0)
            {
                stoptime = DateTime.Now.Ticks;
            }
            else
            {
                QueryPerformanceCounter(out stoptime);
            }

            if (context == null)
            {
                TraceFile.WriteLine("StopTimer: Context not set!");
                return;
            }

            // Get the starttime from the JoinPointContext, this starttime was stored int he StartTimerAction
            long starttime = (long)context.GetProperty("starttime");

            if (freq == 0)
            {
                TimeSpan executeTimeSpan = new TimeSpan(stoptime - starttime);
                executetime = (double)executeTimeSpan.Milliseconds;
            }
            else
            {
                executetime = ((double)(stoptime - starttime) / (double)freq) / 1000;
            }

            String sender = "unknown";

            if (context.Sender != null)
            {
                sender = context.Sender.GetType().FullName;
            }

            String target = "unknown";

            if (context.StartTarget != null)
            {
                target = context.StartTarget.GetType().FullName;
            }

            String args = "";

            if (context.ArgumentCount > 0)
            {
                for (short i = 0; i < context.ArgumentCount; i++)
                {
                    if (context.GetArgumentValue(i) != null)
                    {
                        if (args != "")
                        {
                            args = args + ",";
                        }
                        args = args + context.GetArgumentValue(i).GetType().FullName;
                    }
                }
            }

            TraceFile.WriteLine("The execution of message: {0}.{1}({2}) took {3:0.0000} msec.", target, context.StartSelector, args, executetime);
        }