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);
 }
예제 #2
0
        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);
        }
예제 #3
0
 private static void CheckProcessingRequirements(IncomingMessage message, object existingReceiver)
 {
     if (ExpectedNoneButFoundOne(message, existingReceiver) ||
         ExpectedOneButFoundNone(message, existingReceiver))
     {
         throw new MessageProcessingRequirementsViolationException(message);
     }
 }
예제 #4
0
 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;
 }
예제 #5
0
 public MessageReceivedEvent(DateTime receiveTime, IncomingMessage message)
 {
     ReceiveTime = receiveTime;
      Message = message;
 }
예제 #6
0
 private static bool ExpectedNoneButFoundOne(IncomingMessage message, object existingReceiver)
 {
     return existingReceiver != null && message.ProcessingRequirements == MessageProcessingRequirements.RequiresNew;
 }
 public MessageProcessingRequirementsViolationException(IncomingMessage message)
     : base(GetText(message))
 {
 }
예제 #8
0
 public bool WasAlreadyProcessed(IncomingMessage messageToBeProcessed)
 {
     return _receivedMessages.Any(x => x.Message.MessageId == messageToBeProcessed.MessageId);
 }
예제 #9
0
 public void OnEndMessageProcessing()
 {
     _messageBeingProcessed = null;
 }
예제 #10
0
 public void OnBeginMessageProcessing(IncomingMessage messageBeingProcessed)
 {
     _messageBeingProcessed = messageBeingProcessed;
 }
예제 #11
0
 public MessageReceivedEvent(DateTime receiveTime, IncomingMessage message)
 {
     ReceiveTime = receiveTime;
     Message     = message;
 }
예제 #12
0
 private static bool ExpectedNoneButFoundOne(IncomingMessage message, object existingReceiver)
 {
     return(existingReceiver != null && message.ProcessingRequirements == MessageProcessingRequirements.RequiresNew);
 }
예제 #13
0
        private static IMessageProcessor CreateProcessor(IncomingMessage message)
        {
            Type processorType = typeof(MessageProcessor <>).MakeGenericType(message.Payload.GetType());

            return((IMessageProcessor)Activator.CreateInstance(processorType));
        }
예제 #14
0
 public MessageProcessingRequirementsViolationException(IncomingMessage message)
     : base(GetText(message))
 {
 }