示例#1
0
        public static JournaledEvent Create(IDictionary <string, object> properties)
        {
            Require.NotNull(properties, "properties");

            var payload = new MemoryStream();

            ((Stream)properties[JournaledEventPropertyNames.EventPayload]).CopyTo(payload);

            var headers = new Dictionary <string, string>();

            if (properties.ContainsKey(JournaledEventPropertyNames.EventHeaders))
            {
                var propertyValue = properties[JournaledEventPropertyNames.EventHeaders];

                // for backward compatibility reading from string
                if (propertyValue is string)
                {
                    var stringValue = (string)properties[JournaledEventPropertyNames.EventHeaders];
                    if (stringValue.IsNotNullOrEmpty())
                    {
                        headers = JournaledEventHeadersSerializer.Deserialize((string)properties[JournaledEventPropertyNames.EventHeaders]);
                    }
                }
                else
                {
                    headers = JournaledEventHeadersSerializer.Deserialize((Stream)properties[JournaledEventPropertyNames.EventHeaders]);
                }
            }

            Option <DateTimeOffset> commitTime = Option.None();
            object commitTimeValue;

            if (properties.TryGetValue(KnownProperties.Timestamp, out commitTimeValue))
            {
                commitTime = Option.Some((DateTimeOffset)commitTimeValue);
            }

            Option <StreamVersion> offset = Option.None();
            object offsetValue;

            if (properties.TryGetValue(KnownProperties.RowKey, out offsetValue))
            {
                offset = Option.Some(StreamVersion.Parse((string)offsetValue));
            }

            return(new JournaledEvent(
                       (Guid)properties[JournaledEventPropertyNames.EventId],
                       (string)properties[JournaledEventPropertyNames.EventType],
                       commitTime,
                       offset,
                       headers,
                       payload));
        }
示例#2
0
        public Dictionary <string, object> ToDictionary()
        {
            var result = new Dictionary <string, object>(JournaledEventPropertyNames.All.Length)
            {
                [JournaledEventPropertyNames.EventId]      = m_eventId,
                [JournaledEventPropertyNames.EventType]    = m_eventTypeName,
                [JournaledEventPropertyNames.EventPayload] = GetEventPayload(),
                [JournaledEventPropertyNames.EventHeaders] = JournaledEventHeadersSerializer.Serialize(m_eventHeaders)
            };

            return(result);
        }