private List<MethodInfo> GetAllMethodsInType(IMethodInvocationContext context, IEnumerable<AspectAttributeBase> attributes, ExecutionOrder order) { string key = string.Format("{0}:{1}:{2}", context.ProxyType.Name, context.Method.Name, order); Type attributeExecutionOrderType; switch (order) { default: case ExecutionOrder.Before: attributeExecutionOrderType = typeof(WorksBeforeAttribute); break; case ExecutionOrder.After: attributeExecutionOrderType = typeof(WorksAfterAttribute); break; case ExecutionOrder.Exception: attributeExecutionOrderType = typeof(WorksOnExceptionAttribute); break; } List<MethodInfo> methods = new List<MethodInfo>(); foreach (var attribute in attributes) { foreach (var m in attribute.GetType().GetMethods().Where(m => m.GetCustomAttributes(attributeExecutionOrderType, true).Length > 0).ToList()) { methods.Add(m); } } return methods; }
// When the REMOTE side receives a quote request over chat (maybe from // LOCAL side subscribing to T42.RFQ.QuoteInquiryStream), // REMOTE side calls T42.RFQ.SendQuoteResponse to send a // response back. // Server calls Bridge to send response over chat private void SendQuoteResponseMethodHandler( IServerMethod method, IMethodInvocationContext invocationContext, IInstance caller, IServerMethodResultBuilder resultBuilder, Action <IServerMethodResult> asyncResponseCallback, object cookie) { var args = invocationContext.Arguments.ToDictionary(cv => cv.Name, cv => cv); var quantity = args.ContainsKey("quantity") ? (double?)args.SafeGetDouble("quantity") : null; bridge_.SendQuoteInquiryResponse( new RfqQuoteInquiryResponse( RfqResponseType.Quote, args.TryGetString("responseMessage"), args["requestId"].Value.AsString, args["requestParty"].Value.AsString, args["counterParty"].Value.AsString, args.TryGetString("productName"), null, quantity, args.SafeGetDouble("price"))); asyncResponseCallback(resultBuilder.Build()); }
public void BeforeMethodExecuted(IMethodInvocationContext context) { ICacheManager manager = DIContainer.DefaultContainer.Resolve<ICacheManager>(); string key = GetCacheKey(context); context.ReturnValue = manager.GetOrAdd<object>(key, () => context.Proceed(), TimeSpan.FromMinutes(CacheDuration)); context.Cancel = true; context.IsMethodExecuted = true; }
public void OnMethodExecuting(IMethodInvocationContext context) { ILog log = DIContainer.DefaultContainer.Resolve<ILog>(); log.DebugFormat("Method: {0} is executing...", context.Method.Name); context.ReturnValue = context.Proceed(); context.Cancel = true; log.DebugFormat("Method: {0} done executing.", context.Method.Name); }
private string GetCacheKey(IMethodInvocationContext context) { StringBuilder builder = new StringBuilder(); for (int i = 0; i < context.Args.Length; i++) { builder.AppendFormat("{0};", context.Args[i].ToString()); } return string.Format("{0}:{1}:{2}", context.ProxyType, context.Method.Name, builder.ToString()); }
private bool IterateAttributesAndReturnTrueIfCancel(IMethodInvocationContext context, IEnumerable<AspectAttributeBase> attributes, ExecutionOrder order, Exception ex = null) { List<MethodInfo> methods = GetAllMethodsInType(context, attributes, order); context.Exception = ex; bool cancelExecution = false; foreach (MethodInfo method in methods) { method.Invoke(Activator.CreateInstance(method.ReflectedType), new object[] { context }); cancelExecution = context.Cancel; } return cancelExecution; }
public void HandleError(IMethodInvocationContext context) { ILog log = DIContainer.DefaultContainer.Resolve<ILog>(); ITemplateEngine engine = DIContainer.DefaultContainer.Resolve<ITemplateEngine>(); object c = new { message = context.Exception.Message, time = DateTime.Now, methodName = context.Method.Name, type = context.ProxyType.FullName }; string text = engine.EvaluateTemplate(ErrorTextFormat, c); log.Error(text); }
public override void Process(IMethodInvocationContext context) { PropertyInfo pi = context.Args[0].GetType().GetProperty(PropertyName); object value = pi.GetValue(context.Args[0], null); int dataLength = value.ToString().Length; if (dataLength < MinLength) { context.Cancel = true; } else if (dataLength > MaxLength) { context.Cancel = true; } }
private bool IterateAttributesAndReturnTrueIfCancel(IMethodInvocationContext context, IEnumerable<AspectAttributeBase> attributes, ExecutionOrder order, Exception ex = null) { var methods = GetAllMethodsInType(context, attributes, order); context.Exception = ex; bool cancelExecution = false; foreach (var method in methods) { Delegate @delegate = DelegateUtils.GetMethod(method, context.Proxy); @delegate.DynamicInvoke(new object[] {context}); // method.Invoke(Activator.CreateInstance(method.ReflectedType), new object[] { context }); cancelExecution = context.Cancel; } return cancelExecution; }
private static IServerMethodResult OnHelloWorldInvoked( IServerMethod method, IMethodInvocationContext invocationContext, IInstance caller, IServerMethodResultBuilder resultBuilder, object cookie) { Log($"{caller.ApplicationName} said hello with these arguments: {{{invocationContext.Arguments.AsString()}}}"); // let's simulate a problem on the implementation side if (++invocationIndex_ % 3 == 0) { throw new Exception("Oops! Something happened!"); } // return empty (void) result. return(resultBuilder.Build()); }
// When the REMOTE side receives a comment from LOCAL side over chat // (maybe by LOCAL side calling T42.RFQ.SendCommentToCounterParty) // Server sends comment using Bridge, and // on the REMOTE side Server pushes comment to T42.RFQ.RequestPartyCommentStream // When the REMOTE side replies back by calling T42.RFQ.SendCommentToRequestParty // Server calls Bridge to send comment back over the chat and // on the LOCAL side pushes comment to T42.RFQ.CounterPartyCommentStream private void SendCommentToRequestPartyMethodHandler( IServerMethod method, IMethodInvocationContext invocationContext, IInstance caller, IServerMethodResultBuilder resultBuilder, Action <IServerMethodResult> asyncResponseCallback, object cookie) { var args = invocationContext.Arguments.ToDictionary(cv => cv.Name, cv => cv); bridge_.SendCommentToRequestParty( new RfqComment( args.TryGetString("requestId"), args["requestParty"].Value.AsString, args["counterParty"].Value.AsString, args.TryGetString("productName"), args["comment"].Value.AsString)); asyncResponseCallback(resultBuilder.Build()); }
public void AfterAspect(IMethodInvocationContext context) { _aspectExecutionStack.Push("AfterAspect2"); }
public void AfterMethodExecuted(IMethodInvocationContext context) { Debug.Write("Worked After"); }
/// <summary> /// Executes the aspect. /// </summary> /// <param name="context"></param> public abstract void Process(IMethodInvocationContext context);
public void OnException(IMethodInvocationContext context) { ILog log = CrowCore.LogService; //Crow.Library.InjectionContainer.DIContainer.DefaultContainer.Resolve<ILog>(); log.Error(context.Exception.Message); }
public void ExecuteAsync(IMethodInvocationContext context) { Task.Factory.StartNew(() => context.Proceed()); context.Cancel = true; }
public void BeforeAspect(IMethodInvocationContext context) { _aspectExecutionStack.Push("BeforeAspect2"); }
public void BeforeMethodExecuted(IMethodInvocationContext context) { Debug.Write("Worked Before"); }
public void OnExecuted(IMethodInvocationContext context) { Debug.Write("Exception throwed."); }