예제 #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          itemId            = ItemId.GetValue(dc.State);
            var          partitionKeyValue = PartitionKey.GetValue(dc.State);
            PartitionKey partitionKey      = new PartitionKey(partitionKeyValue);
            var          client            = CosmosClientCache.GetClient(connectionString);
            var          database          = client.GetDatabase(databaseName);
            var          container         = database.GetContainer(containerName);

            var result = await container.ReadItemAsync <object>(id : itemId, 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.Resource, cancellationToken : cancellationToken).ConfigureAwait(false));
        }