Exemple #1
0
        public override async Task <DialogTurnResult> BeginDialogAsync(DialogContext dc, object options = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (this.Disabled != null && this.Disabled.GetValue(dc.State) == true)
            {
                return(await dc.EndDialogAsync(cancellationToken : cancellationToken).ConfigureAwait(false));
            }

            var          connectionString  = ConnectionString.GetValue(dc.State);
            var          databaseName      = Database.GetValue(dc.State);
            var          containerName     = Container.GetValue(dc.State);
            var          item              = Item.GetValue(dc.State);
            var          partitionKeyValue = PartitionKey.GetValue(dc.State);
            PartitionKey?partitionKey      = (!String.IsNullOrEmpty(partitionKeyValue)) ? new PartitionKey(partitionKeyValue) : (PartitionKey?)null;
            var          client            = CosmosClientCache.GetClient(connectionString);
            var          database          = client.GetDatabase(databaseName);
            var          container         = database.GetContainer(containerName);

            var result = await container.CreateItemAsync(item, partitionKey : partitionKey, cancellationToken : cancellationToken).ConfigureAwait(false);

            if (this.ResultProperty != null)
            {
                dc.State.SetValue(this.ResultProperty.GetValue(dc.State), result.Resource);
            }

            return(await dc.EndDialogAsync(result : result, cancellationToken : cancellationToken).ConfigureAwait(false));
        }
Exemple #2
0
        public override async Task <DialogTurnResult> BeginDialogAsync(DialogContext dc, object options = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (this.Disabled != null && this.Disabled.GetValue(dc.State) == true)
            {
                return(await dc.EndDialogAsync(cancellationToken : cancellationToken).ConfigureAwait(false));
            }

            var connectionString = ConnectionString.GetValue(dc.State);
            var databaseName     = Database.GetValue(dc.State);
            var containerName    = Container.GetValue(dc.State);
            var query            = Query.GetValue(dc.State);
            var client           = CosmosClientCache.GetClient(connectionString);
            var database         = client.GetDatabase(databaseName);
            var container        = database.GetContainer(containerName);
            FeedIterator <object> queryResultSetIterator = container.GetItemQueryIterator <object>(new QueryDefinition(query));

            List <object> items = new List <object>();

            while (queryResultSetIterator.HasMoreResults)
            {
                FeedResponse <object> currentResultSet = await queryResultSetIterator.ReadNextAsync();

                items.AddRange(currentResultSet.Resource);
            }

            if (this.ResultProperty != null)
            {
                dc.State.SetValue(this.ResultProperty.GetValue(dc.State), items);
            }

            return(await dc.EndDialogAsync(result : items, cancellationToken : cancellationToken).ConfigureAwait(false));
        }
        public override async Task <DialogTurnResult> BeginDialogAsync(DialogContext dc, object options = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (this.Disabled != null && this.Disabled.GetValue(dc.State) == true)
            {
                return(await dc.EndDialogAsync(cancellationToken : cancellationToken).ConfigureAwait(false));
            }

            var connectionString = ConnectionString.GetValue(dc.State);
            var databaseName     = Database.GetValue(dc.State);
            var client           = CosmosClientCache.GetClient(connectionString);
            var result           = await client.CreateDatabaseIfNotExistsAsync(databaseName);

            return(await dc.EndDialogAsync(result : result.Resource, cancellationToken : cancellationToken).ConfigureAwait(false));
        }
Exemple #4
0
        public override async Task <DialogTurnResult> BeginDialogAsync(DialogContext dc, object options = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (this.Disabled != null && this.Disabled.GetValue(dc.State) == true)
            {
                return(await dc.EndDialogAsync(cancellationToken : cancellationToken).ConfigureAwait(false));
            }

            var connectionString = ConnectionString.GetValue(dc.State);
            var databaseName     = Database.GetValue(dc.State);
            var containerName    = Container.GetValue(dc.State);
            var itemId           = ItemId?.GetValue(dc.State);
            var partitionKey     = PartitionKey.GetValue(dc.State);
            var client           = CosmosClientCache.GetClient(connectionString);
            var database         = client.GetDatabase(databaseName);
            var container        = database.GetContainer(containerName);

            var result = await container.DeleteItemAsync <object>(itemId, new PartitionKey(partitionKey), cancellationToken : cancellationToken).ConfigureAwait(false);

            return(await dc.EndDialogAsync(result : result.Resource, cancellationToken : cancellationToken).ConfigureAwait(false));
        }