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); } }
public void NeedWeddingLicence(JoinPointContext jpc) { Person from = ((Person)jpc.Sender); if (!from.HasWeddingLicence()) { GetWeddingLicence(from); } }
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)); } }
public static void clearCache(JoinPointContext context) { if (context.ReturnType == null || context.ReturnType == typeof(void)) { return; } Cache cache = Cache.instance(context.CurrentTarget); cache.clearCache(); }
private void Execute() { if (FilterContext.IsInnerCall(this, 5)) { } JoinPointContext jpc = new JoinPointContext(); jpc.ReturnType = typeof(void); jpc.CurrentSelector = "test"; }
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); }
public void after2(JoinPointContext context) { report("after2 " + context.StartSelector); if (context.StartSelector.Equals("func4")) { String ret = (String)context.ReturnValue; ret = ret + " #After2#"; context.ReturnValue = ret; } }
public override void Execute(JoinPointContext context) { foreach (ArgumentInfo ai in context.GetArguments.Values) { if (ai.Type == typeof(string)) { ai.AddResourceOp("expectEncrypted"); ai.AddResourceOp("verify"); } } }
public override void Execute(JoinPointContext context) { long stoptime = DateTime.Now.Ticks; long starttime = (long)context.GetProperty("starttime"); TimeSpan timeSpan = new TimeSpan(stoptime - starttime); Console.WriteLine("Timed method {0} (declaring type {1})", context.MethodInformation.Name, context.MethodInformation.DeclaringType.FullName); }
public static bool ShouldTraceCondition(JoinPointContext context) { string classname = context.StartTarget.GetType().FullName; if (ClassTraceLevel.ContainsKey(classname)) { return(ClassTraceLevel[classname] < 3); } return(false); }
public override void Execute(JoinPointContext context) { foreach (ArgumentInfo ai in context.GetArguments.Values) { if (ai.Type == typeof(string)) { string val = (string)ai.Value; ai.AddResourceOp("encrypt"); val = Convert.ToBase64String(Encoding.UTF8.GetBytes(val)); ai.Value = val; } } }
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); }
public override void Execute(JoinPointContext context) { long starttime = 0; long freq = 0; if (QueryPerformanceFrequency(out freq) == false) { starttime = DateTime.Now.Ticks; } else { QueryPerformanceCounter(out starttime); } context.AddProperty("frequency", freq); context.AddProperty("starttime", starttime); }
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); }
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); } }
public override void Execute(JoinPointContext context) { }
public override void Execute(JoinPointContext context) { clearCache(context); }
public void printFM3(JoinPointContext jpc) { Console.WriteLine("Second(FM3)"); }
public void printFM4(JoinPointContext jpc) { Console.WriteLine("Third(FM4)"); }
public void printFM1(JoinPointContext jpc) { Console.WriteLine("First(FM1)"); }
public void printFM2(JoinPointContext jpc) { Console.WriteLine("Fourth(FM2)"); }
public override void Execute(JoinPointContext context) { if (context == null) { TraceBuffer.WriteLine("TracingIN: Context not set!"); return; } String sender = "unknown"; if (context.Sender != null) { sender = context.Sender.GetType().FullName; } String target = "unknown"; if (context.StartTarget != null) { target = context.StartTarget.GetType().FullName; } TraceBuffer.WriteLine("TracingIN: Sender={0}, Target={1}, Selector={2} ", sender, target, context.StartSelector); if (context.ArgumentCount > 0) { for (short i = 0; i < context.ArgumentCount; i++) { ArgumentInfo argumentInfo = context.GetArgumentInfo(i); if (argumentInfo == null) { TraceBuffer.WriteLine(" argument {0} -> no argument info available", i); continue; } string argdirection = "-"; if ((argumentInfo.Attributes & ArgumentAttributes.In) == ArgumentAttributes.In) { argdirection = "input"; } if ((argumentInfo.Attributes & ArgumentAttributes.Out) == ArgumentAttributes.Out) { argdirection = "output"; } if ((argumentInfo.Attributes & ArgumentAttributes.Optional) == ArgumentAttributes.Optional) { argdirection = "optional"; } if (argumentInfo.Value == null) { TraceBuffer.WriteLine(" argument {0} ({2}) -> {1} = null", i, context.GetArgumentType(i).Name, argdirection); continue; } String argvalue; try { argvalue = argumentInfo.Value.ToString(); } catch (Exception) { argvalue = "<exception>"; } TraceBuffer.WriteLine(" argument {0} ({3}) -> {1} = {2}", i, context.GetArgumentType(i).Name, argvalue, argdirection); } } }
public override void Execute(JoinPointContext context) { if (context == null) { TraceBuffer.WriteLine("OUT Tracing: Context not set!"); return; } // Sender, Target, Methodname String sender = "unknown"; if (context.Sender != null) { sender = context.Sender.GetType().FullName; } String target = "unknown"; if (context.StartTarget != null) { target = context.StartTarget.GetType().FullName; } TraceBuffer.WriteLine("OUT Tracing: Sender={0}, Target={1}, MethodName={2} ", sender, target, context.StartSelector); // Out arguments if (context.ArgumentCount > 0) { for (short i = 0; i < context.ArgumentCount; i++) { ArgumentInfo argumentInfo = context.GetArgumentInfo(i); if (argumentInfo != null && argumentInfo.IsOut()) { if (argumentInfo.Value == null) { TraceBuffer.WriteLine(" argument {0} (out) -> {1} = null", i, context.GetArgumentType(i).Name); continue; } String argvalue; try { argvalue = argumentInfo.Value.ToString(); } catch (Exception) { argvalue = "<exception>"; } TraceBuffer.WriteLine(" argument {0} (out) -> {1} = {2}", i, context.GetArgumentType(i).Name, argvalue); } } } // Returnvalue if (context.HasReturnValue) { if (context.ReturnType == null) { TraceBuffer.WriteLine(" return type = null"); } else if (context.ReturnValue == null) { TraceBuffer.WriteLine(" return type = {0}, return value = null", context.ReturnType.FullName); } else if (context.StartSelector == "ToString") { TraceBuffer.WriteLine(" return type = {0}, return value = <unable to determine>", context.ReturnType.FullName); } else { String returnValue; try { returnValue = context.ReturnValue.ToString(); } catch (Exception) { returnValue = "<exception>"; } TraceBuffer.WriteLine(" return type = {0}, return value = {1}", context.ReturnType.FullName, returnValue); } } }
public override void Execute(JoinPointContext context) { if (context == null) { TraceBuffer.WriteLine("TracingIN: Context not set!"); return; } String sender = "unknown"; if (context.Sender != null) { sender = context.Sender.GetType().FullName; } Type target = null; if (context.StartTarget != null) { target = context.StartTarget.GetType(); } TraceBuffer.WriteLine("TracingIN: Sender={0}, Target={1}, Selector={2} ", sender, target.FullName, context.StartSelector); System.Reflection.MethodInfo mi = target.GetMethod(context.StartSelector, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly | BindingFlags.Instance); if (mi != null && context.ArgumentCount > 0) { System.Reflection.ParameterInfo[] pi = mi.GetParameters(); for (int j = 0; j < pi.Length; j++) { if (!(pi[j].IsOut || pi[j].IsRetval)) { ArgumentInfo argumentInfo = context.GetArgumentInfo((short)(j + 1)); string argdirection = "input"; if (pi[j].IsOut) { argdirection = "output"; } if (pi[j].IsOptional) { argdirection = "optional"; } if (argumentInfo.Value == null) { TraceBuffer.WriteLine(" argument {0} ({2}) -> {1} = null", j + 1, pi[j].ParameterType.FullName, argdirection); continue; } String argvalue; try { argvalue = argumentInfo.Value.ToString(); } catch (Exception) { argvalue = "<exception>"; } TraceBuffer.WriteLine(" argument {0} ({3}) -> {1} = {2}", j + 1, pi[j].ParameterType.FullName, argvalue, argdirection); } } } //if (context.ArgumentCount > 0) //{ // for (short i=1; i <= context.ArgumentCount; i++) // { // ArgumentInfo argumentInfo = context.GetArgumentInfo(i); // string argdirection = "-"; // if ((argumentInfo.Attributes & ArgumentAttributes.In) == ArgumentAttributes.In) // argdirection = "input"; // if ((argumentInfo.Attributes & ArgumentAttributes.Out) == ArgumentAttributes.Out) // argdirection = "output"; // if ((argumentInfo.Attributes & ArgumentAttributes.Optional) == ArgumentAttributes.Optional) // argdirection = "optional"; // if (argumentInfo.Value == null) // { // TraceFile.WriteLine(" argument {0} ({2}) -> {1} = null", i, context.GetArgumentType(i), argdirection); // continue; // } // String argvalue; // try // { // argvalue = argumentInfo.Value.ToString(); // } // catch (Exception) // { // argvalue = "<exception>"; // } // TraceFile.WriteLine(" argument {0} ({3})-> {1} = {2}", i, context.GetArgumentType(i).FullName, argvalue, argdirection); // } //} //System.Reflection.MethodInfo[] mi = t.GetMethods(BindingFlags.Public // | BindingFlags.NonPublic | BindingFlags.DeclaredOnly | BindingFlags.Instance); //for (int i = 0; i < mi.Length; i++) //{ // //Console.WriteLine("\tSearching for method: "+rm.getSelector()+" == "+mi[i].get_Name()); // if (mi[i].Name == (string)context.GetProperty("selector")) // { // if (((object[])context.GetProperty("args")).Length == 0) // { // Object[] obj = new Object[0]; // Console.WriteLine("TracingIN: " + t.Name + "." + (string)context.GetProperty("selector")); // break; // } // int k = 0; // ArrayList list = new ArrayList(); // System.Reflection.ParameterInfo[] pi = mi[i].GetParameters(); // for (int j = 0; j < pi.Length; j++) // { // if (!(pi[j].IsOut || !pi[j].IsRetval)) // { // list.Add(context.GetProperty("Arg[" + k + "]")); // } // k++; // } // Console.WriteLine("TracingIN[" + list.ToArray().Length + "]: " + list.ToString()); // break; // } //} }
public void Play(JoinPointContext jpc) { PlayBand(); }
/// <summary> /// Implements the behavior of the FilterAction. You must override this method and supply your own filteraction implementation. /// </summary> /// <param name="context">Join Point Context information.</param> /// <remarks>If the developer has set the CreateJoinPointContext to <see langword="false"/> /// in the <see cref="T:Composestar.StarLight.Filters.FilterTypes.FilterActionAttribute"/>, then the weaver injects <see langword="null"/> instead of a /// <see cref="Composestar.StarLight.ContextInfo.JoinPointContext"/>.</remarks> public abstract void Execute(JoinPointContext context);
public override void Execute(JoinPointContext context) { long starttime = DateTime.Now.Ticks; context.AddProperty("starttime", starttime); }
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); }
public override void Execute(JoinPointContext context) { storeCachedValue(context); }
public override void Execute(JoinPointContext context) { if (context == null) { TraceBuffer.WriteLine("OUT Tracing: Context not set!"); return; } // Sender, Target, Methodname String sender = "unknown"; if (context.Sender != null) { sender = context.Sender.GetType().FullName; } Type target = null; if (context.StartTarget != null) { target = context.StartTarget.GetType(); } TraceBuffer.WriteLine("OUT Tracing: Sender={0}, Target={1}, MethodName={2} ", sender, target, context.StartSelector); System.Reflection.MethodInfo mi = target.GetMethod(context.StartSelector, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly | BindingFlags.Instance); if (mi != null && context.ArgumentCount > 0) { System.Reflection.ParameterInfo[] pi = mi.GetParameters(); for (int j = 0; j < pi.Length; j++) { if (pi[j].IsOut) { ArgumentInfo argumentInfo = context.GetArgumentInfo((short)(j + 1)); if (argumentInfo.Value == null) { TraceBuffer.WriteLine(" argument {0} (out) -> {1} = null", j + 1, pi[j].ParameterType.FullName); continue; } String argvalue; try { argvalue = argumentInfo.Value.ToString(); } catch (Exception) { argvalue = "<exception>"; } TraceBuffer.WriteLine(" argument {0} (out) -> {1} = {2}", j + 1, pi[j].ParameterType.FullName, argvalue); } } } // Returnvalue if (context.HasReturnValue) { if (context.ReturnType == null) { TraceBuffer.WriteLine(" return type = null"); } else if (context.ReturnValue == null) { TraceBuffer.WriteLine(" return type = {0}, return value = null", context.ReturnType.FullName); } else if (context.StartSelector != "ToString") { TraceBuffer.WriteLine(" return type = {0}, return value = ", context.ReturnType.FullName); } else { String returnValue; try { returnValue = context.ReturnValue.ToString(); } catch (Exception) { returnValue = "<exception>"; } TraceBuffer.WriteLine(" return type = {0}, return value = (1)", context.ReturnType.FullName, returnValue); } } //Type t = context.GetProperty("target").GetType(); ////Console.WriteLine("Tracing IN method: "+t.get_Name() + "." + rm.getSelector()); //System.Reflection.MethodInfo[] mi = t.GetMethods(BindingFlags.Public // | BindingFlags.NonPublic | BindingFlags.DeclaredOnly | BindingFlags.Instance); //for (int i = 0; i < mi.Length; i++) //{ // //Console.WriteLine("\tSearching for method: "+rm.getSelector()+" == "+mi[i].get_Name()); // if (mi[i].Name == (string)context.GetProperty("selector")) // { // if (((object[])context.GetProperty("args")).Length == 0) // { // Object[] obj = new Object[0]; // Console.WriteLine("TracingOUT: " + t.Name + "." + (string)context.GetProperty("selector")); // break; // } // int k = 0; // ArrayList list = new ArrayList(); // System.Reflection.ParameterInfo[] pi = mi[i].GetParameters(); // for (int j = 0; j < pi.Length; j++) // { // if (pi[j].IsOut) // { // list.Add(context.GetProperty("Arg[" + k + "]")); // } // k++; // } // Console.WriteLine("TracingOUT[" + context.GetProperty("returnvalue") + "][" + list.ToArray().Length + "]: " + list.ToString()); // break; // } //} }