public IVersionedEvent Deserialize(EventData @event)
 {
     using (var reader = new StringReader(@event.Payload))
     {
         return((IVersionedEvent)_serializer.Deserialize(reader));
     }
 }
예제 #2
0
        public List <STest> NewtonsoftJsonDeserializerFromStream()
        {
            List <STest> data = null;

            for (var i = 0; i < N; i++)
            {
                _jsonSerializerStream.Position = 0;
                data = _jsonSerializer.Deserialize <List <STest> >(_jsonSerializerStream);
            }
            return(data);
        }
예제 #3
0
        public async Task When_call_SaveChanges_Should_store_the_snapshot()
        {
            // Arrange

            var snapshotStrategy = CreateSnapshotStrategy();

            var eventStore = new StubEventStore();
            var session    = _sessionFactory(eventStore, _eventPublisherMock.Object, snapshotStrategy);

            var stubAggregate = StubSnapshotAggregate.Create("Snap");

            stubAggregate.AddEntity("Child 1");
            stubAggregate.AddEntity("Child 2");

            await session.AddAsync(stubAggregate).ConfigureAwait(false);


            // Act

            await session.SaveChangesAsync().ConfigureAwait(false);

            // Assert

            eventStore.SaveSnapshotMethodCalled.Should().BeTrue();

            var commitedSnapshot = StubEventStore.Snapshots.First(e => e.AggregateId == stubAggregate.Id);

            commitedSnapshot.Should().NotBeNull();

            var metadata = (IMetadata)_textSerializer.Deserialize <EventSource.Metadata>(commitedSnapshot.SerializedMetadata);

            var snapshotClrType = metadata.GetValue(MetadataKeys.SnapshotClrType);

            Type.GetType(snapshotClrType).Name.Should().Be(typeof(StubSnapshotAggregateSnapshot).Name);

            var snapshot = _textSerializer.Deserialize <StubSnapshotAggregateSnapshot>(commitedSnapshot.SerializedData);

            snapshot.Name.Should().Be(stubAggregate.Name);
            snapshot.SimpleEntities.Count.Should().Be(stubAggregate.Entities.Count);
        }
예제 #4
0
        public override void Run()
        {
            Trace.WriteLine("Starting processing of messages");

            // Initiates the message pump and callback is invoked for each message that is received, calling close on the client will stop the pump.
            Client.OnMessage(receivedMessage =>
            {
                try
                {
                    // Process the message
                    Trace.WriteLine("Processing Service Bus message: " + receivedMessage.SequenceNumber.ToString());

                    ITextSerializer serializer = new JsonTextSerializer();
                    using (var stream = receivedMessage.GetBody <Stream>())
                        using (var reader = new StreamReader(stream))
                        {
                            var payload = serializer.Deserialize(reader);

                            var commandType         = payload.GetType();
                            ICommandHandler handler = null;

                            if (handlers.TryGetValue(commandType, out handler))
                            {
                                // Invoke message handler to handle the message
                                ((dynamic)handler).Handle((dynamic)payload);


                                // Finish recieving the message and dequeue
                                receivedMessage.Complete();
                            }
                            else
                            {
                                receivedMessage.DeadLetter();
                            }
                        }
                }
                catch
                {
                    // Handle any message processing specific exceptions here
                    receivedMessage.DeadLetter();
                }
            });

            CompletedEvent.WaitOne();
        }