예제 #1
0
        /// <summary>
        /// It creates a data subscription in a database. The subscription will expose all documents that match the specified subscription options.
        /// </summary>
        /// <returns>Created subscription name.</returns>
        public async Task <string> CreateAsync(SubscriptionCreationOptions options, string database = null, CancellationToken token = default)
        {
            if (options == null)
            {
                throw new InvalidOperationException("Cannot create a subscription if options is null");
            }

            if (options.Query == null)
            {
                throw new InvalidOperationException("Cannot create a subscription if the script is null");
            }

            database = _store.GetDatabase(database);

            var requestExecutor = _store.GetRequestExecutor(database);

            using (requestExecutor.ContextPool.AllocateOperationContext(out JsonOperationContext context))
            {
                var command = new CreateSubscriptionCommand(_store.Conventions, options);
                await requestExecutor.ExecuteAsync(command, context, sessionInfo : null, token : token).ConfigureAwait(false);

                return(command.Result.Name);
            }
        }
 private void GenerateSubscription(CreateSubscriptionCommand command)
 {
     subscription = new Subscription(DateTime.Now.AddMonths(1));
 }
예제 #3
0
        public async Task <ActionResult <Guid> > Post(CreateSubscriptionCommand command)
        {
            Guid subscriptionId = await _mediator.Send(command);

            return(subscriptionId);
        }