Exemplo n.º 1
0
 public bool Equals(ProjectionRequested other)
 {
     if (null != other)
     {
         if (other.DomainName.Equals(DomainName))
         {
             if (other.EntityTypeName.Equals(EntityTypeName))
             {
                 if (other.InstanceKey.Equals(InstanceKey))
                 {
                     if (other.AsOfDate.HasValue)
                     {
                         if (other.AsOfDate.Equals(AsOfDate))
                         {
                             // Everything matched including the as-of date
                             return(true);
                         }
                     }
                     else
                     {
                         if (!AsOfDate.HasValue)
                         {
                             // Everything matched and the as-of date is empty
                             return(true);
                         }
                     }
                 }
             }
         }
     }
     return(false);
 }
 /// <summary>
 /// Turn a projection requested event to the <see cref="Notification.QueueNotificationDispatcher"/> type of message
 /// </summary>
 /// <param name="evtPayload">
 /// The event for a projection being requested
 /// </param>
 /// <returns></returns>
 public static string ToQueueMessage(ProjectionRequested evtPayload)
 {
     if (evtPayload != null)
     {
         string asOf = "null";
         if (evtPayload.AsOfDate.HasValue)
         {
             asOf = evtPayload.AsOfDate.Value.ToString("O");
         }
         return($"|{evtPayload.ProjectionDomainName}|{evtPayload.ProjectionEntityTypeName}|{evtPayload.ProjectionInstanceKey}|{evtPayload.ProjectionTypeName}|{asOf}|{evtPayload.CorrelationIdentifier}");
     }
     return("");
 }
        /// <summary>
        /// Turn a queue notification message back into a projection requested event
        /// </summary>
        /// <param name="queuedMessage">
        /// The message sent by the <see cref="Notification.QueueNotificationDispatcher"/> for the command or query
        /// </param>
        /// <returns>
        /// If the string can be turned into a projection request then it is - otherwise null
        /// </returns>
        /// <remarks>
        /// Message is pipe separated
        /// E|Projection Requested|{command/query id}|{command/query sequence number}|null||{ProjectionDomainName}|{ProjectionEntityTypeName}|{ProjectionInstanceKey}|{ProjectionTypeName}|{AsOfDate}|{CorrelationIdentifier}
        /// </remarks>
        public static ProjectionRequested FromQueuedMessage(string queuedMessage)
        {
            if (!string.IsNullOrWhiteSpace(queuedMessage))
            {
                string[] messageParts = queuedMessage.Split('|');
                if (messageParts.Count() > 5)
                {
                    // Message has parts that can be converted to a projection request
                    ProjectionRequested request = new ProjectionRequested();
                    if (messageParts.Count() >= 6)
                    {
                        request.ProjectionDomainName = messageParts[5];
                    }
                    if (messageParts.Count() >= 7)
                    {
                        request.ProjectionEntityTypeName = messageParts[6];
                    }
                    if (messageParts.Count() >= 8)
                    {
                        request.ProjectionInstanceKey = messageParts[7];
                    }
                    if (messageParts.Count() >= 9)
                    {
                        request.ProjectionTypeName = messageParts[8];
                    }
                    if (messageParts.Count() >= 10)
                    {
                        //AsOfDate
                        if (!string.IsNullOrWhiteSpace(messageParts[9]))
                        {
                            DateTime asOf;
                            if (DateTime.TryParse(messageParts[9], out asOf))
                            {
                                request.AsOfDate = asOf;
                            }
                        }
                    }
                    if (messageParts.Count() >= 11)
                    {
                        request.CorrelationIdentifier = messageParts[10];
                    }

                    return(request);
                }
            }
            return(null);
        }