Ejemplo n.º 1
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);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Resets the subscription stream position.
        /// </summary>
        /// <param name="subscriptionId">The subscription identifier.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <exception cref="NotFoundException">Subscription Group with Id {subscriptionConfiguration} not found</exception>
        public async Task ResetSubscriptionStreamPosition(Guid subscriptionId,
                                                          CancellationToken cancellationToken)
        {
            Guard.ThrowIfInvalidGuid(subscriptionId, typeof(ArgumentNullException), "A subscription group Id must be provided");

            using (SubscriptionServiceConfigurationContext context = this.ContextResolver())
            {
                Database.Models.SubscriptionConfiguration subscriptionConfiguration = await context.SubscriptionConfigurations.Where(g => g.SubscriptionId == subscriptionId)
                                                                                      .SingleOrDefaultAsync(cancellationToken);

                if (subscriptionConfiguration == null)
                {
                    throw new NotFoundException($"Subscription Group with Id {subscriptionConfiguration} not found");
                }

                // Reset the Stream Position
                subscriptionConfiguration.StreamPosition = null;

                await context.SaveChangesAsync(cancellationToken);
            }
        }