public void OnMessageRecived_GetHandlersByMessage() { var outputGatewayEventHandlerArgs = new OutputGatewayEventHandlerArgs<IControlMessage, MessageHeader> {Message = new Mock<IControlMessage>().Object}; _inputGateway.Raise(x => x.OnMessage += null, outputGatewayEventHandlerArgs); _handlerRepository.Verify(x => x.GetHandlersByMessage(It.IsAny<Type>())); }
public void OnMessageRecived_GetHandlersByMessage() { var outputGatewayEventHandlerArgs = new OutputGatewayEventHandlerArgs <IControlMessage, MessageHeader> { Message = new Mock <IControlMessage>().Object }; _inputGateway.Raise(x => x.OnMessage += null, outputGatewayEventHandlerArgs); _handlerRepository.Verify(x => x.GetHandlersByMessage(It.IsAny <Type>())); }
public void OnMessageRecived_ResolveHandler_True() { var outputGatewayEventHandlerArgs = new OutputGatewayEventHandlerArgs<IControlMessage, MessageHeader> { Message = new Mock<IControlMessage>().Object }; _handlerRepository.Setup(x => x.GetHandlersByMessage(It.IsAny<Type>())).Returns( new List<Type>(new[] { new Mock<IControlMessage>().Object.GetType() })); var iocMock = new Mock<IIoc>(); ContextManager.Create(iocMock.Object); iocMock.Setup(x => x.Resolve(It.IsAny<Type>())).Returns(new object()); _inputGateway.Raise(x => x.OnMessage += null, outputGatewayEventHandlerArgs); iocMock.Verify(x => x.Resolve(It.IsAny<Type>())); }
private void MessageReceived(object sender, OutputGatewayEventHandlerArgs <TMessage, MessageHeader> args) { var listTask = new List <Task>(); Logger.Debug(string.Format("Ha llegado el Mensaje:{0}", args.SerializedMessage)); Logger.Debug(string.Format("Tipo del Mensaje:{0}", args.Header.BodyType)); //Buscar en los handlers para procesar el mensaje foreach (var type in _handlerRepository.GetHandlersByMessage(args.Message.GetType())) { var typeClosure = type; listTask.Add(Task.Factory.StartNew(() => { try { using (var messageContext = ContextManager.Instance.CreateNewContext()) { Logger.Debug(string.Format("Se abre el handler {0}: ", typeClosure.FullName)); InitializeContext(messageContext, args); using (var messageHandler = (IDisposable)messageContext.Resolve(typeClosure)) { InitializeMessageHandler(messageHandler); try { InvokeMethodHandle(messageHandler, args.Message); } catch (Exception exception) { Logger.Fatal("Error On Handler", exception); Logger.Fatal(string.Format("Message Error: {0}", args.SerializedMessage), exception); } } } } catch (Exception ex) { Logger.Error("Error Message Received", ex); Logger.Fatal(string.Format("Message Error: {0}", args.SerializedMessage), ex); } })); } Task.WaitAll(listTask.ToArray()); }
public void OnMessageRecived_ResolveHandler_True() { var outputGatewayEventHandlerArgs = new OutputGatewayEventHandlerArgs <IControlMessage, MessageHeader> { Message = new Mock <IControlMessage>().Object }; _handlerRepository.Setup(x => x.GetHandlersByMessage(It.IsAny <Type>())).Returns( new List <Type>(new[] { new Mock <IControlMessage>().Object.GetType() })); var iocMock = new Mock <IIoc>(); ContextManager.Create(iocMock.Object); iocMock.Setup(x => x.Resolve(It.IsAny <Type>())).Returns(new object()); _inputGateway.Raise(x => x.OnMessage += null, outputGatewayEventHandlerArgs); iocMock.Verify(x => x.Resolve(It.IsAny <Type>())); }
/// <summary> /// Messages the received. /// </summary> /// <param name="sender">The sender.</param> /// <param name="args">The args.</param> private void MessageReceived(object sender, OutputGatewayEventHandlerArgs <IControlMessage, MessageHeader> args) { var listTask = new List <Task>(); Logger.Debug("Control Message Received"); //Buscar en los handlers para procesar el mensaje foreach (Type type in _handlerRepository.GetHandlersByMessage(args.Message.GetType())) { Type typeClosure = type; listTask.Add(Task.Factory.StartNew(() => { try { using (IMessageContext messageContext = ContextManager.Instance.CreateNewContext()) { object messageHandler = messageContext.Resolve(typeClosure); SetPropertyToHandler(messageHandler, "Controller", this); SetPropertyToHandler(messageHandler, "Processor", Processor); InvokeMethodHandle(messageHandler, args.Message); } } catch (Exception ex) { var message = args.Message.ToJson(); Logger.Error(string.Format("Error Mensaje de Control: {0}", message), ex); InvokeOnErrorHandler(message, args.Header, args.SerializedMessage, typeClosure, ex); } })); } Task.WaitAll(listTask.ToArray()); }
/// <summary> /// Messages the received. /// </summary> /// <param name="sender">The sender.</param> /// <param name="args">The args.</param> private void MessageReceived(object sender, OutputGatewayEventHandlerArgs <byte[], RouterHeader> args) { InvokeOnMessageReceived(); try { if (!string.IsNullOrEmpty(args.Header.BodyType)) { if (args.Header.Type != MessageBusType.Reply) { _routerOutputHelper.Publish(args.Header.BodyType, args.Header.Priority, args.SerializedMessage); } else { _routerOutputHelper.Reply(args.Header.Identification, args.Header.Priority, args.SerializedMessage); } } else { Logger.Error(string.Format("El mensaje no tiene bodytype: {0}", Encoding.UTF8.GetString(args.SerializedMessage))); } } catch (Exception ex) { Logger.Error(string.Format("Error publish bus: {0}", Encoding.UTF8.GetString(args.SerializedMessage)), ex); var messageByte = new byte[args.Header.MessageLength]; args.Message.CopyTo(messageByte, 15); var message = _serializer.Deserialize <MessageBus>(messageByte); OnOnRouterError(message, ex); } InvokeOnMessageSent(args.Message != null ? new MonitorEventArgs { MessageCreatedAt = args.Header.CreatedAt } : new MonitorEventArgs()); }
/// <summary> /// Messages the received. /// </summary> /// <param name="sender">The sender.</param> /// <param name="args">The args.</param> private void MessageReceived(object sender, OutputGatewayEventHandlerArgs<byte[], RouterHeader> args) { InvokeOnMessageReceived(); try { if (!string.IsNullOrEmpty(args.Header.BodyType)) { if (args.Header.Type != MessageBusType.Reply) _routerOutputHelper.Publish(args.Header.BodyType, args.Header.Priority, args.SerializedMessage); else { _routerOutputHelper.Reply(args.Header.Identification, args.Header.Priority, args.SerializedMessage); } } else { Logger.Error(string.Format("El mensaje no tiene bodytype: {0}", Encoding.UTF8.GetString(args.SerializedMessage))); } } catch (Exception ex) { Logger.Error(string.Format("Error publish bus: {0}", Encoding.UTF8.GetString(args.SerializedMessage)), ex); var messageByte = new byte[args.Header.MessageLength]; args.Message.CopyTo(messageByte, 15); var message = _serializer.Deserialize<MessageBus>(messageByte); OnOnRouterError(message, ex); } InvokeOnMessageSent(args.Message != null ? new MonitorEventArgs {MessageCreatedAt = args.Header.CreatedAt} : new MonitorEventArgs()); }
/// <summary> /// Messages the received. /// </summary> /// <param name="sender">The sender.</param> /// <param name="args">The args.</param> private void MessageReceived(object sender, OutputGatewayEventHandlerArgs<IControlMessage, MessageHeader> args) { var listTask = new List<Task>(); Logger.Debug("Control Message Received"); //Buscar en los handlers para procesar el mensaje foreach (Type type in _handlerRepository.GetHandlersByMessage(args.Message.GetType())) { Type typeClosure = type; listTask.Add(Task.Factory.StartNew(() => { try { using (IMessageContext messageContext = ContextManager.Instance.CreateNewContext()) { object messageHandler = messageContext.Resolve(typeClosure); SetPropertyToHandler(messageHandler, "Controller", this); SetPropertyToHandler(messageHandler, "Processor", Processor); InvokeMethodHandle(messageHandler, args.Message); } } catch (Exception ex) { var message = args.Message.ToJson(); Logger.Error(string.Format("Error Mensaje de Control: {0}", message), ex); InvokeOnErrorHandler(message, args.Header, args.SerializedMessage, typeClosure, ex); } })); } Task.WaitAll(listTask.ToArray()); }
public void Setup() { _mockIdentification = new Mock<Identification>(); _mockInputGateway = new Mock<IInputGateway<IMessage, MessageHeader>>(); _mockHandlerRepository = new Mock<IHandlerRepository>(); _subject = new AgentFake(_mockIdentification.Object, _mockInputGateway.Object, _mockHandlerRepository.Object); _mockHandler = new Mock<IMessageHandler<IMessage>>(); var mockHeader = new Mock<MessageHeader>(); mockHeader.SetupAllProperties(); _outputGatewayEventHandlerArgs = new OutputGatewayEventHandlerArgs<IMessage, MessageHeader> { Message = new Mock<IMessage>().Object, Header = mockHeader.Object }; _iocMock = new Mock<IIoc>(); _mockOutputGateway = new Mock<IOutputGateway<IMessage>>(); }
/// <summary> /// Initializes the message context. /// </summary> /// <param name="messageContext">The message context.</param> /// <param name="args">The args.</param> private static void InitializeContext(IMessageContext messageContext, OutputGatewayEventHandlerArgs <TMessage, MessageHeader> args) { messageContext.MessageInfo.Body = args.Message; messageContext.MessageInfo.Header = args.Header; }