Пример #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);
                }
            }
        }