private static string GetText(IncomingMessage message) { return string.Format(message.ProcessingRequirements == MessageProcessingRequirements.RequiresExisting ? "Expected to find existing aggregate with ID {0}" : "Expected to find no aggregates with ID {0}", message.ReceiverId); }
private static IMessagingAggregateRoot GetReceiver(IUnitOfWorkContext work, IncomingMessage message) { var existingReceiver = (IMessagingAggregateRoot)work.GetById(message.ReceiverType, message.ReceiverId, null); CheckProcessingRequirements(message, existingReceiver); return existingReceiver ?? CreateNewAggregateInstance(message.ReceiverType, message.ReceiverId); }
private static void CheckProcessingRequirements(IncomingMessage message, object existingReceiver) { if (ExpectedNoneButFoundOne(message, existingReceiver) || ExpectedOneButFoundNone(message, existingReceiver)) { throw new MessageProcessingRequirementsViolationException(message); } }
public object GetRelatedMessage(IncomingMessage messageBeingProcessed) { if (messageBeingProcessed.RelatedMessageId.HasValue) { var relatedEvent = _sentMessages.FirstOrDefault(x => x.Message.MessageId == messageBeingProcessed.RelatedMessageId.Value); return relatedEvent != null ? relatedEvent.Message.Payload : null; } return null; }
public MessageReceivedEvent(DateTime receiveTime, IncomingMessage message) { ReceiveTime = receiveTime; Message = message; }
private static bool ExpectedNoneButFoundOne(IncomingMessage message, object existingReceiver) { return existingReceiver != null && message.ProcessingRequirements == MessageProcessingRequirements.RequiresNew; }
public MessageProcessingRequirementsViolationException(IncomingMessage message) : base(GetText(message)) { }
public bool WasAlreadyProcessed(IncomingMessage messageToBeProcessed) { return _receivedMessages.Any(x => x.Message.MessageId == messageToBeProcessed.MessageId); }
public void OnEndMessageProcessing() { _messageBeingProcessed = null; }
public void OnBeginMessageProcessing(IncomingMessage messageBeingProcessed) { _messageBeingProcessed = messageBeingProcessed; }
private static bool ExpectedNoneButFoundOne(IncomingMessage message, object existingReceiver) { return(existingReceiver != null && message.ProcessingRequirements == MessageProcessingRequirements.RequiresNew); }
private static IMessageProcessor CreateProcessor(IncomingMessage message) { Type processorType = typeof(MessageProcessor <>).MakeGenericType(message.Payload.GetType()); return((IMessageProcessor)Activator.CreateInstance(processorType)); }