public static void Execute(Action<Context> action, Context context = null) { context = context ?? new Context(); s_contexts.Value.Push(context); try { action(context); } finally { s_contexts.Value.Pop(); } }
public void Intercept(IInvocation invocation) { assertIsValid(invocation.Method); // TODO: fix dependency on IoC var address = m_address ?? m_target.Configuration.Attributes[WindsorEx.ADDRESS]; var key = m_target.Configuration.Attributes[WindsorEx.REMOTE_KEY]; Console.WriteLine("invoking {0} on {1}", invocation, address); var ctx = new Context {RecipientKey = key, RecipientPath = address}; var invocationPayload = new InvocationMessage(ctx, invocation); replaceCallbacksWithTokens(invocationPayload); var payload = m_serializer.Serialize(invocationPayload); var transportMessage = new TransportMessage(payload, address); m_transport.OnNext(transportMessage); }
public void ScheduleTimeoutAction(string token, Delegate callback) { var ctx = MessagelessContext.CurrentContext; if (ctx == null) return; if (ctx.TimeOut == default(TimeSpan)) return; var subscription = Observable .Timer(ctx.TimeOut) .Select(_ => { var context = new Context { RecipientKey = token, TimeOut = ctx.TimeOut, CallbackTimedOut = true }; var callbackMessage = new CallbackMessage(context, callback.GetType(), null); var payload = m_serializer.Serialize(callbackMessage); var transportMessage = new TransportMessage(payload, m_transport.LocalPath); return transportMessage; }) .Finally(() => DismissTimeoutAction(token)) .Subscribe(m_transport); m_timeoutTimers[token] = subscription; }
private Delegate tokenToCallbackProxy(string token, Type callbackType, string senderPath) { var context = new Context{RecipientPath = senderPath, RecipientKey = token}; var callbackInterceptor = new CallbackInterceptor(context, callbackType, m_transport, m_serializer, m_kernel, m_timeoutManager); var callbackMethodInfo = callbackType.GetMethod("Invoke"); var parameterTypes = callbackMethodInfo.GetParameters() .Select(p => p.ParameterType) .ToArray(); var method = callbackInterceptor.GetType().GetMethods() .Where(mi => mi.Name == "Intercept") .Single(mi =>mi.GetParameters().Count() == parameterTypes.Length); if (method.IsGenericMethodDefinition) method = method.MakeGenericMethod(parameterTypes); var callbackProxy = Delegate.CreateDelegate(callbackType, callbackInterceptor, method, throwOnBindFailure: true); return callbackProxy; }
public InvocationMessage(Context context, MethodInfo method, object[] arguments) { Context = context; Method = method; Arguments = arguments; }
public InvocationMessage(Context context, IInvocation invocation) : this(context, invocation.Method, invocation.Arguments) { }
public CallbackMessage(Context context, Type delegateType, object[] arguments) { Context = context; DelegateType = delegateType; Arguments = arguments ?? new object[Method.GetParameters().Length]; }