コード例 #1
0
        private async Task CommitEventsAsync(EventStoreBase store)
        {
            var events = new[]
            {
                new ThingyPingEvent(PingId.New),
            };

            for (int i = 0; i < NumberOfEvents; i++)
            {
                await RetryAsync(async() =>
                {
                    var allEvents = await store.LoadEventsAsync <ThingyAggregate, ThingyId>(ThingyId,
                                                                                            CancellationToken.None).ConfigureAwait(false);

                    var version = allEvents.Count;
                    var serializedEvents
                        = from aggregateEvent in events
                          let metadata = new Metadata
                        {
                            AggregateSequenceNumber = ++version,
                            AggregateName           = "ThingyAggregate",
                            Timestamp = DateTimeOffset.Now
                        }
                    let uncommittedEvent = new UncommittedEvent(aggregateEvent, metadata)
                                           select uncommittedEvent;

                    var readOnlyEvents = new ReadOnlyCollection <UncommittedEvent>(serializedEvents.ToList());

                    await store.StoreAsync <ThingyAggregate, ThingyId>(ThingyId, readOnlyEvents,
                                                                       SourceId.New, CancellationToken.None)
                    .ConfigureAwait(false);
                }).ConfigureAwait(false);
            }
        }
コード例 #2
0
 /// <summary>Creates service definition that can be registered with a server</summary>
 /// <param name="serviceImpl">An object implementing the server-side handling logic.</param>
 public static grpc::ServerServiceDefinition BindService(EventStoreBase serviceImpl)
 {
     return(grpc::ServerServiceDefinition.CreateBuilder()
            .AddMethod(__Method_AppendToStream, serviceImpl.AppendToStream)
            .AddMethod(__Method_SubscribeToStreamFrom, serviceImpl.SubscribeToStreamFrom)
            .AddMethod(__Method_CreatePersistentSubscription, serviceImpl.CreatePersistentSubscription)
            .AddMethod(__Method_UpdatePersistentSubscription, serviceImpl.UpdatePersistentSubscription)
            .AddMethod(__Method_DeletePersistentSubscription, serviceImpl.DeletePersistentSubscription)
            .AddMethod(__Method_ConnectToPersistentSubscription, serviceImpl.ConnectToPersistentSubscription).Build());
 }
コード例 #3
0
        private EventStoreBase CreateStore()
        {
            var aggregateFactory  = Mock.Of <IAggregateFactory>();
            var resolver          = Mock.Of <IResolver>();
            var metadataProviders = Enumerable.Empty <IMetadataProvider>();
            var snapshotStore     = Mock.Of <ISnapshotStore>();
            var log               = new NullLog();
            var factory           = new DomainEventFactory();
            var persistence       = new InMemoryEventPersistence(log);
            var upgradeManager    = new EventUpgradeManager(log, resolver);
            var definitionService = new EventDefinitionService(log);

            definitionService.Load(typeof(ThingyPingEvent));
            var serializer = new EventJsonSerializer(new JsonSerializer(), definitionService, factory);

            var store = new EventStoreBase(log, aggregateFactory,
                                           serializer, upgradeManager, metadataProviders,
                                           persistence, snapshotStore);

            return(store);
        }
コード例 #4
0
        private EventStoreBase CreateStore()
        {
            var aggregateFactory  = Mock <IAggregateFactory>();
            var serviceProvider   = Mock <IServiceProvider>();
            var metadataProviders = Enumerable.Empty <IMetadataProvider>();
            var snapshotStore     = Mock <ISnapshotStore>();
            var factory           = new DomainEventFactory();
            var persistence       = new InMemoryEventPersistence(Logger <InMemoryEventPersistence>());
            var upgradeManager    = new EventUpgradeManager(Logger <EventUpgradeManager>(), serviceProvider);
            var definitionService = new EventDefinitionService(Logger <EventDefinitionService>(), Mock <ILoadedVersionedTypes>());

            definitionService.Load(typeof(ThingyPingEvent));
            var serializer = new EventJsonSerializer(new JsonSerializer(), definitionService, factory);

            var store = new EventStoreBase(
                Logger <EventStoreBase>(),
                aggregateFactory,
                serializer, upgradeManager, metadataProviders,
                persistence, snapshotStore);

            return(store);
        }