Beispiel #1
0
        /// <summary>
        /// Gets the next catchup subscription configuration.
        /// </summary>
        /// <param name="eventStoreServerId">The event store server identifier.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns></returns>
        public async Task <CatchupSubscriptionConfiguration> GetNextCatchupSubscriptionConfiguration(Guid eventStoreServerId, CancellationToken cancellationToken)
        {
            CatchupSubscriptionConfiguration result = null;

            using (SubscriptionServiceConfigurationContext context = this.ContextResolver())
            {
                // Find the next subscription based on Create date (only 1 is returned to simplify processing)
                Database.Models.CatchupSubscriptionConfiguration nextCatchUpSubscription = await context
                                                                                           .CatchupSubscriptionConfigurations
                                                                                           .Where(c => c.EventStoreServerId == eventStoreServerId)
                                                                                           .OrderBy(c => c.CreateDateTime).FirstOrDefaultAsync(cancellationToken);

                // Check if we have found a subscription to process
                if (nextCatchUpSubscription != null)
                {
                    result = new CatchupSubscriptionConfiguration
                    {
                        Name               = nextCatchUpSubscription.Name,
                        SubscriptionId     = nextCatchUpSubscription.SubscriptionId,
                        EventStoreServerId = nextCatchUpSubscription.EventStoreServerId,
                        Position           = nextCatchUpSubscription.Position,
                        StreamName         = nextCatchUpSubscription.StreamName,
                        EndPointUri        = nextCatchUpSubscription.EndPointUri,
                        CreateDateTime     = nextCatchUpSubscription.CreateDateTime
                    };
                }
            }

            return(result);
        }
Beispiel #2
0
        /// <summary>
        /// Deletes the catch up subscription.
        /// </summary>
        /// <param name="catchUpSubscriptionId">The catch up subscription identifier.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <exception cref="NotFoundException">Catch Up Subscription Group with Id {catchUpSubscriptionId} not found</exception>
        public async Task DeleteCatchUpSubscription(Guid catchUpSubscriptionId,
                                                    CancellationToken cancellationToken)
        {
            Guard.ThrowIfInvalidGuid(catchUpSubscriptionId, typeof(ArgumentNullException), "A catchup subscription Id must be provided");

            using (SubscriptionServiceConfigurationContext context = this.ContextResolver())
            {
                Database.Models.CatchupSubscriptionConfiguration catchUpSubscriptionConfiguration = await context.CatchupSubscriptionConfigurations.Where(c => c.SubscriptionId == catchUpSubscriptionId)
                                                                                                    .SingleOrDefaultAsync(cancellationToken);

                if (catchUpSubscriptionConfiguration == null)
                {
                    throw new NotFoundException($"Catch Up Subscription Group with Id {catchUpSubscriptionId} not found");
                }

                context.CatchupSubscriptionConfigurations.Remove(catchUpSubscriptionConfiguration);

                await context.SaveChangesAsync(cancellationToken);
            }
        }
Beispiel #3
0
        public async Task <CatchupSubscriptionConfiguration> GetCatchupSubscriptionConfiguration(Guid subscriptionId,
                                                                                                 CancellationToken cancellationToken)
        {
            CatchupSubscriptionConfiguration result = new CatchupSubscriptionConfiguration();

            using (SubscriptionServiceConfigurationContext context = this.ContextResolver())
            {
                Database.Models.CatchupSubscriptionConfiguration catchupSubscriptionConfiguration =
                    await context.CatchupSubscriptionConfigurations.Where(s => s.SubscriptionId == subscriptionId).SingleOrDefaultAsync(cancellationToken);

                result = new CatchupSubscriptionConfiguration
                {
                    EventStoreServerId = catchupSubscriptionConfiguration.EventStoreServerId,
                    EndPointUri        = catchupSubscriptionConfiguration.EndPointUri,
                    Name           = catchupSubscriptionConfiguration.Name,
                    StreamName     = catchupSubscriptionConfiguration.StreamName,
                    Position       = catchupSubscriptionConfiguration.Position,
                    SubscriptionId = catchupSubscriptionConfiguration.SubscriptionId,
                    CreateDateTime = catchupSubscriptionConfiguration.CreateDateTime
                };
            }

            return(result);
        }