Пример #1
0
 public Task Append(Message message, MessageJournalCategory category,
                    CancellationToken cancellationToken = new CancellationToken())
 {
     return(_categories.Contains(category)
         ? _inner.Append(message, category, cancellationToken)
         : Task.FromResult(0));
 }
Пример #2
0
 /// <summary>
 /// Initializes a new <see cref="MessageJournalEntry"/>
 /// </summary>
 /// <param name="category">The category of journaled message (e.g. sent, received, published)</param>
 /// <param name="position">The position of the message in the journal</param>
 /// <param name="timestamp">The timestamp associated with the journal entry</param>
 /// <param name="data">The message</param>
 public MessageJournalEntry(MessageJournalCategory category, MessageJournalPosition position, DateTime timestamp, Message data)
 {
     Category  = category;
     Position  = position ?? throw new ArgumentNullException(nameof(position));
     Timestamp = timestamp;
     Data      = data ?? throw new ArgumentNullException(nameof(data));
 }
        /// <summary>
        /// Determines the timestamp for the journaled message based on the journal category and
        /// correlating dates in the message headers.
        /// </summary>
        /// <param name="message">The message</param>
        /// <param name="category">The journal category</param>
        /// <returns>Returns the timestamp for the journaled message based on the journal category and
        /// correlating dates in the message headers.</returns>
        /// <remarks>
        /// Falls back to the current UTC date/time if the expected headers are not set
        /// </remarks>
        public static DateTime GetJournalTimestamp(this Message message, MessageJournalCategory category)
        {
            var headers   = message.Headers;
            var timestamp = DateTime.UtcNow;

            if (Equals(category, MessageJournalCategory.Sent) && headers.Sent != default(DateTime))
            {
                timestamp = headers.Sent;
            }
            else if (Equals(category, MessageJournalCategory.Received) && headers.Received != default(DateTime))
            {
                timestamp = headers.Received;
            }
            else if (Equals(category, MessageJournalCategory.Published) && headers.Published != default(DateTime))
            {
                timestamp = headers.Published;
            }
            return(timestamp);
        }
 /// <inheritdoc />
 public Task Append(Message message, MessageJournalCategory category,
                    CancellationToken cancellationToken = new CancellationToken())
 {
     return(_inner.Append(message.WithSanitizedHeaders(), category, cancellationToken));
 }