Beispiel #1
0
 public async Task SetSubscriptionPosition(Guid subscriptionId, long?position)
 {
     using (var scope = _serviceProvider.CreateScope())
     {
         using (var context = scope.ServiceProvider.GetRequiredService <SqlStreamStoreContext>())
         {
             var subscriptionPosition = new PeristentSubscriptionPosition
             {
                 SubscriptionId = subscriptionId,
                 Position       = position
             };
             context.Attach(subscriptionPosition);
             context.Entry(subscriptionPosition).Property(p => p.Position).IsModified = true;
             await context.SaveChangesAsync();
         }
     }
 }
Beispiel #2
0
        public async Task <long?> GetSubscriptionPosition(Guid subscriptionId, bool createIfNotExists)
        {
            using (var scope = _serviceProvider.CreateScope())
            {
                using var context = scope.ServiceProvider.GetRequiredService <SqlStreamStoreContext>();
                {
                    var subscriptionPosition = await context.SubscriptionPositions.FindAsync(subscriptionId);

                    if (createIfNotExists && subscriptionPosition == default)
                    {
                        subscriptionPosition = new PeristentSubscriptionPosition
                        {
                            SubscriptionId = subscriptionId
                        };
                        await context.SubscriptionPositions.AddAsync(subscriptionPosition);

                        await context.SaveChangesAsync();
                    }

                    //context.Entry(subscriptionPosition).State = EntityState.Detached;
                    return(subscriptionPosition?.Position);
                }
            }
        }