Exemple #1
0
        /// <summary>
        /// Copy method.
        /// </summary>
        internal static Message With(
            this IMessage message,
            string text = null,
            MessageSeverity?severity = null,
            DateTimeOffset?timestamp = null,
            string eventName         = null,
            object state             = null,
            IReadOnlyList <KeyValuePair <string, object> > properties         = null,
            IEnumerable <KeyValuePair <string, object> > propertiesEnumerable = null,
            PropertyListAddMode propertyListAddMode = PropertyListAddMode.Set)
        {
            var propertiesToAdd = properties ?? (IReadOnlyList <KeyValuePair <string, object> >)propertiesEnumerable?.ToList() ?? Array.Empty <KeyValuePair <string, object> >();
            IReadOnlyList <KeyValuePair <string, object> > propList;

            if (propertyListAddMode == PropertyListAddMode.Set)
            {
                propList = propertiesToAdd;
            }
            else if (propertyListAddMode == PropertyListAddMode.Merge)
            {
                propList = message.Properties.AddWithReplace(propertiesToAdd);
            }
            else if (propertyListAddMode == PropertyListAddMode.AddIfNotExists)
            {
                propList = message.Properties.AddIfNotExists(propertiesToAdd);
            }
            else
            {
                propList = Array.Empty <KeyValuePair <string, object> >();
            }

            return(new Message(
                       timestamp: timestamp ?? message.Timestamp,
                       severity: severity ?? message.Severity,
                       text: text ?? message.Text,
                       eventName: eventName ?? message.EventName,
                       state: state ?? message.State,
                       properties: propList));
        }
Exemple #2
0
 /// <summary>
 /// Creates new copy of <see cref="Message"/> with required <see cref="IMessage.Properties"/>.
 /// </summary>
 /// <param name="message">Source message.</param>
 /// <param name="properties">New state.</param>
 /// <param name="propertyListAddMode">Property list add mode.</param>
 /// <returns>New instance of <see cref="Message"/> with changed <see cref="IMessage.Properties"/>.</returns>
 public static Message WithProperties(
     this IMessage message,
     IEnumerable <KeyValuePair <string, object> > properties,
     PropertyListAddMode propertyListAddMode = PropertyListAddMode.Set)
 => message.With(propertiesEnumerable: properties, propertyListAddMode: propertyListAddMode);