コード例 #1
0
        private IEnumerable <Tuple <T, StreamSequenceToken> > SerializeExternalEvents <T>(EventSequenceTokenV2 sequenceToken)
        {
            var serializedEvents = _events
                                   .Select((@event, iteration) =>
            {
                try
                {
                    T message;
                    var messageType = typeof(T);

                    if (messageType.IsPrimitive || messageType == typeof(string) || messageType == typeof(decimal))
                    {
                        message = (T)Convert.ChangeType(@event, typeof(T));
                    }
                    else
                    {
                        message = JsonConvert
                                  .DeserializeObject <T>((string)@event);                               // todo: support for multiple serializer
                    }
                    return(Tuple.Create <T, StreamSequenceToken>(message, sequenceToken.CreateSequenceTokenForEvent(iteration)));
                }
                catch (Exception)
                {
                    return(null);
                }
            })
                                   .Where(@event => @event != null);

            return(serializedEvents);
        }
コード例 #2
0
        private Tuple <T, StreamSequenceToken> DeserializeExternalEvent <T>(
            EventSequenceTokenV2 sequenceToken,
            object @event,
            int iteration
            )
        {
            T   message;
            var messageType = typeof(T);

            if (messageType == typeof(byte[]))
            {
                message = (T)@event;
            }
            else if (messageType.IsPrimitive || messageType == typeof(string) || messageType == typeof(decimal))
            {
                message = (T)Convert.ChangeType(@event, typeof(T));
            }
            else
            {
                message = _deserializer.Deserialize <T>(_queueProps, (byte[])@event);
            }

            return(Tuple.Create <T, StreamSequenceToken>(message, sequenceToken.CreateSequenceTokenForEvent(iteration)));
        }
コード例 #3
0
 public IEnumerable <Tuple <T, StreamSequenceToken> > GetEvents <T>()
 {
     return(events.OfType <T>().Select((e, i) => Tuple.Create <T, StreamSequenceToken>(e, sequenceToken.CreateSequenceTokenForEvent(i))));
 }