private void RaiseEvent(IPipelineEvent @event, bool ignoreAbort = false) { ObservedEvents.TryGetValue(@event.GetType(), out var observersForEvent); if (observersForEvent == null || observersForEvent.Count == 0) { return; } foreach (var observerPair in observersForEvent) { var observer = observerPair.PipelineObserver; if (_log.IsVerboseEnabled) { _log.Verbose(string.Format(_raisingPipelineEvent, @event.Name, StageName, observer.GetType().FullName)); } try { observerPair.MethodInfo.Invoke(observer, new object[] { @event }); } catch (Exception ex) { throw new PipelineException( string.Format(_raisingPipelineEvent, @event.Name, StageName, observer.GetType().FullName), ex); } if (Aborted && !ignoreAbort) { return; } } }
public RegisterEventAfter(IPipelineStage pipelineStage, List <IPipelineEvent> eventsToExecute, IPipelineEvent pipelineEvent) { _pipelineStage = pipelineStage; _eventsToExecute = eventsToExecute; _pipelineEvent = pipelineEvent; }
public bool IsSatisfiedBy(IPipelineEvent pipelineEvent) { Guard.AgainstNull(pipelineEvent, nameof(pipelineEvent)); return(_assessors.All(assessor => assessor.Invoke(pipelineEvent)) && _specifications.All(specification => specification.IsSatisfiedBy(pipelineEvent))); }
public DeserializationExceptionEventArgs(IPipelineEvent pipelineEvent, IQueue workQueue, IQueue errorQueue, Exception exception) : base(pipelineEvent) { WorkQueue = workQueue; ErrorQueue = errorQueue; Exception = exception; }
public IPipelineStage WithEvent(IPipelineEvent pipelineEvent) { Guard.AgainstNull(pipelineEvent, "pipelineEvent"); PipelineEvents.Add(pipelineEvent); return(this); }
public void Register(IPipelineEvent pipelineEventToRegister) { Guard.AgainstNull(pipelineEventToRegister, "pipelineEventToRegister"); var index = _eventsToExecute.IndexOf(_pipelineEvent); _eventsToExecute.Insert(index, pipelineEventToRegister); }
public MessageHandlerInvokeResult Invoke(IPipelineEvent pipelineEvent) { var messageType = pipelineEvent.Pipeline.State.GetTransportMessage().MessageType; _invokeCounts.TryGetValue(messageType, out int count); _invokeCounts[messageType] = count + 1; return(MessageHandlerInvokeResult.InvokedHandler(this)); }
public IPipelineStage Register(IPipelineEvent pipelineEventToRegister) { Guard.AgainstNull(pipelineEventToRegister, "pipelineEventToRegister"); var index = _eventsToExecute.IndexOf(_pipelineEvent); _eventsToExecute.Insert(index + 1, pipelineEventToRegister); return(_pipelineStage); }
public HandlerExceptionEventArgs(IPipelineEvent pipelineEvent, TransportMessage transportMessage, object message, IQueue workQueue, IQueue errorQueue, Exception exception) : base(pipelineEvent) { TransportMessage = transportMessage; Message = message; WorkQueue = workQueue; ErrorQueue = errorQueue; Exception = exception; }
public static void Register(this Pipeline pipeline, IPipelineEvent @event) { string eventName = @event.GetType().Name; if (pipeline.Events.ContainsKey(eventName)) { return; } pipeline.Events.Add(eventName, @event); }
public MessageHandlerInvokeResult Invoke(IPipelineEvent pipelineEvent) { var messageType = pipelineEvent.Pipeline.State.GetTransportMessage().MessageType; if (!_invokeCounts.ContainsKey(messageType)) { _invokeCounts.Add(messageType, 0); } _invokeCounts[messageType] = _invokeCounts[messageType] + 1; return(MessageHandlerInvokeResult.InvokedHandler(this)); }
public MessageHandlerInvokeResult Invoke(IPipelineEvent pipelineEvent) { Guard.AgainstNull(pipelineEvent, "pipelineEvent"); var state = pipelineEvent.Pipeline.State; var message = state.GetMessage(); var handler = GetHandler(message.GetType()); if (handler == null) { return(MessageHandlerInvokeResult.InvokeFailure()); } var transportMessage = state.GetTransportMessage(); var messageType = message.GetType(); ContextMethod contextMethod; lock (_lockInvoke) { if (!_cache.ContainsKey(messageType)) { var interfaceType = typeof(IMessageHandler <>).MakeGenericType(messageType); var method = handler.GetType().GetInterfaceMap(interfaceType).TargetMethods.SingleOrDefault(); if (method == null) { throw new ProcessMessageMethodMissingException(string.Format( EsbResources.ProcessMessageMethodMissingException, handler.GetType().FullName, messageType.FullName)); } _cache.Add(messageType, new ContextMethod { ContextType = typeof(HandlerContext <>).MakeGenericType(messageType), Method = handler.GetType().GetInterfaceMap(typeof(IMessageHandler <>).MakeGenericType(messageType)).TargetMethods.SingleOrDefault() }); } contextMethod = _cache[messageType]; } var handlerContext = Activator.CreateInstance(contextMethod.ContextType, _configuration, _transportMessageFactory, _pipelineFactory, _subscriptionManager, transportMessage, message, state.GetActiveState()); contextMethod.Method.Invoke(handler, new[] { handlerContext }); return(MessageHandlerInvokeResult.InvokedHandler(handler)); }
public MessageNotHandledEventArgs(IPipelineEvent pipelineEvent, IQueue workQueue, IQueue errorQueue, TransportMessage transportMessage, object message) : base(pipelineEvent) { Guard.AgainstNull(pipelineEvent, nameof(pipelineEvent)); Guard.AgainstNull(workQueue, nameof(workQueue)); Guard.AgainstNull(errorQueue, nameof(errorQueue)); Guard.AgainstNull(transportMessage, nameof(transportMessage)); Guard.AgainstNull(message, nameof(message)); WorkQueue = workQueue; ErrorQueue = errorQueue; TransportMessage = transportMessage; Message = message; }
public MessageHandlerInvokeResult Invoke(IPipelineEvent pipelineEvent) { var state = pipelineEvent.Pipeline.State; var transportMessage = state.GetTransportMessage(); var message = state.GetMessage(); if (!_configuration.ProcessActivator.IsProcessMessage(transportMessage, message)) { return _defaultMessageHandlerInvoker.Invoke(pipelineEvent); } var processInstance = _configuration.ProcessActivator.Create(transportMessage, message); EventStream stream; using (_databaseContextFactory.Create(_configuration.ProviderName, _configuration.ConnectionString)) { stream = _eventStore.Get(processInstance.CorrelationId); } stream.Apply(processInstance); var messageType = message.GetType(); var contextType = typeof (ProcessHandlerContext<>).MakeGenericType(messageType); var processType = processInstance.GetType(); var method = processType.GetMethod("ProcessMessage", new[] {contextType}); if (method == null) { throw new ProcessMessageMethodMissingException(string.Format( EsbResources.ProcessMessageMethodMissingException, processInstance.GetType().FullName, messageType.FullName)); } var handlerContext = Activator.CreateInstance(contextType, state.GetServiceBus(), transportMessage, message, state.GetActiveState(), _keyStore, stream); method.Invoke(processInstance, new[] {handlerContext}); using (_databaseContextFactory.Create(_configuration.ProviderName, _configuration.ConnectionString)) { _eventStore.SaveEventStream(stream); } return MessageHandlerInvokeResult.InvokedHandler(processInstance); }
public MessageHandlerInvokeResult Invoke(IPipelineEvent pipelineEvent) { Guard.AgainstNull(pipelineEvent, "pipelineEvent"); var state = pipelineEvent.Pipeline.State; var bus = state.GetServiceBus(); var message = state.GetMessage(); var handler = bus.Configuration.MessageHandlerFactory.GetHandler(message); if (handler == null) { return(MessageHandlerInvokeResult.InvokeFailure()); } try { var transportMessage = state.GetTransportMessage(); var messageType = message.GetType(); var contextType = typeof(HandlerContext <>).MakeGenericType(messageType); var method = handler.GetType().GetMethod("ProcessMessage", new[] { contextType }); if (method == null) { throw new ProcessMessageMethodMissingException(string.Format( EsbResources.ProcessMessageMethodMissingException, handler.GetType().FullName, messageType.FullName)); } var handlerContext = Activator.CreateInstance(contextType, bus, transportMessage, message, state.GetActiveState()); method.Invoke(handler, new[] { handlerContext }); } finally { bus.Configuration.MessageHandlerFactory.ReleaseHandler(handler); } return(MessageHandlerInvokeResult.InvokedHandler(handler)); }
public RegisterEventBefore(List <IPipelineEvent> eventsToExecute, IPipelineEvent pipelineEvent) { _eventsToExecute = eventsToExecute; _pipelineEvent = pipelineEvent; }
public MessageHandlerInvokeResult Invoke(IPipelineEvent pipelineEvent) { Guard.AgainstNull(pipelineEvent, nameof(pipelineEvent)); var state = pipelineEvent.Pipeline.State; var message = state.GetMessage(); var messageType = message.GetType(); var handler = GetHandler(messageType); if (handler == null) { return(MessageHandlerInvokeResult.InvokeFailure()); } var transportMessage = state.GetTransportMessage(); try { ContextMethod contextMethod; lock (LockInvoke) { if (!_cache.TryGetValue(messageType, out contextMethod)) { var interfaceType = typeof(IMessageHandler <>).MakeGenericType(messageType); var method = handler.GetType().GetInterfaceMap(interfaceType).TargetMethods.SingleOrDefault(); if (method == null) { throw new HandlerMessageMethodMissingException(string.Format( Resources.HandlerMessageMethodMissingException, handler.GetType().FullName, messageType.FullName)); } contextMethod = new ContextMethod { ContextType = typeof(HandlerContext <>).MakeGenericType(messageType), Method = handler.GetType() .GetInterfaceMap(typeof(IMessageHandler <>).MakeGenericType(messageType)) .TargetMethods.SingleOrDefault() }; _cache.Add(messageType, contextMethod); } } var handlerContext = Activator.CreateInstance(contextMethod.ContextType, _configuration, _transportMessageFactory, _pipelineFactory, _subscriptionManager, transportMessage, message, state.GetActiveState()); state.SetHandlerContext((IMessageSender)handlerContext); contextMethod.Method.Invoke(handler, new[] { handlerContext }); } finally { if (handler is IReusability reusability && !reusability.IsReusable) { ReleaseHandler(messageType); } } return(MessageHandlerInvokeResult.InvokedHandler(handler)); }
public bool IsSatisfiedBy(IPipelineEvent candidate) { return(candidate.Pipeline.State.GetTransportMessage().IsHandledHere()); }
public QueueEmptyEventArgs(IPipelineEvent pipelineEvent, IQueue queue) : base(pipelineEvent) { Queue = queue; }
public PipelineEventEventArgs(IPipelineEvent pipelineEvent) { PipelineEvent = pipelineEvent; }
public void Invoke(IPipelineEvent @event) { _invoker.Invoke(_pipelineObserver, @event); }