예제 #1
0
 void EnsureDbCreated()
 {
     using (var dbContext = new CommandServiceDataContext(dbContextOptions))
     {
         dbContext.Database.EnsureCreated();
     }
 }
예제 #2
0
        async Task <Event> CreateEvent <T>(string productId, string eventType, T arg)
        {
            using (var dataContext = new CommandServiceDataContext(dbContextOptions))
            {
                var @event = new Event
                {
                    Seq  = Interlocked.Increment(ref seq),
                    Data = MakeEventData(productId, eventType, arg),
                };
                await dataContext.Events.AddAsync(@event);

                await dataContext.SaveChangesAsync();

                return(@event);
            }
        }
예제 #3
0
        void OnReplayEvents(ReplayEvents replayEvents)
        {
            using (var dataContext = new CommandServiceDataContext(dbContextOptions))
            {
                var query = dataContext.Events
                            .Where(evt => evt.Seq >= replayEvents.From)
                            .AsQueryable();
                if (replayEvents.To.HasValue)
                {
                    query = query.Where(evt => evt.Seq <= replayEvents.To);
                }

                var events = query
                             .OrderBy(evt => evt.Seq)
                             .ToArray();

                foreach (var @event in events)
                {
                    var message = ConstructMessage <IMessage <object> >(@event);
                    messageQueue.Publish(message);
                }
            }
        }