Exemple #1
0
        public override async Task <DialogTurnResult> BeginDialogAsync(DialogContext dc, object options = null, CancellationToken cancellationToken = default)
        {
            string connectionString = ConnectionString.GetValue(dc.State);
            string databaseName     = Database.GetValue(dc.State);
            string containerName    = Container.GetValue(dc.State);
            string partitionKey     = PartitionKey.GetValue(dc.State);
            string document         = DocumentId.GetValue(dc.State);

            var results = await CosmosDelete(connectionString, databaseName, containerName, document, partitionKey, cancellationToken);

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

            await dc.Context.TraceActivityAsync(nameof(CosmosDbDelete), label : "Cosmos DB Delete result",
                                                value : new
            {
                Container    = containerName,
                Database     = databaseName,
                PartitionKey = partitionKey,
                DocumentId   = document,
                Results      = results
            });

            return(await dc.EndDialogAsync(result : results, cancellationToken : cancellationToken));
        }
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          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 #3
0
        public void CompositeTokenValue2()
        {
            /* 
             id1 | id2 | token_id1__id2
            -----+-----+----------------------
               1 |   2 |  4093852821103061060
             */

            var key = new PartitionKey();
            key.Set(new[] { CqlType.Int, CqlType.Text }, new object[] { 1, "2" });

            var calculatedToken = new MurmurToken();
            calculatedToken.Parse(key.GetValue());

            var tokenFromCassandra = new MurmurToken();
            tokenFromCassandra.Parse("4093852821103061060");

            Assert.AreEqual(tokenFromCassandra, calculatedToken);
        }
Exemple #4
0
        public void CompositeTokenValueFromClass()
        {
            /* 
             id1 | id2 | token_id1__id2
            -----+-----+----------------------
              10 |  20 | -9026262514124674157
             */

            var key = new PartitionKey();
            key.Set(new CompositeKeyType { Id1 = 10, Id2 = "20", Val="test"});

            var calculatedToken = new MurmurToken();
            calculatedToken.Parse(key.GetValue());

            var tokenFromCassandra = new MurmurToken();
            tokenFromCassandra.Parse("-9026262514124674157");

            Assert.AreEqual(tokenFromCassandra, calculatedToken);
        }
Exemple #5
0
        public void CompositeTokenValue1()
        {
            /* 
             id1 | id2 | token_id1__id2
            -----+-----+----------------------
              10 |  20 | -9026262514124674157
             */

            var key = new PartitionKey();
            key.Set(new[] {CqlType.Int, CqlType.Text}, new object[] {10, "20"});

            var calculatedToken = new MurmurToken();
            calculatedToken.Parse(key.GetValue());

            var tokenFromCassandra = new MurmurToken();
            tokenFromCassandra.Parse("-9026262514124674157");

            Assert.AreEqual(tokenFromCassandra, calculatedToken);
        }
        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));
            }

            CloudTable table        = GetCloudTable(dc);
            var        partitionKey = PartitionKey.GetValue(dc);
            var        rowKey       = RowKey.GetValue(dc);

            TableResult results = await table.ExecuteAsync(TableOperation.Retrieve(partitionKey, rowKey)).ConfigureAwait(false);

            var result = EntityToJObject((DynamicTableEntity)results.Result);

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

            return(await dc.EndDialogAsync(result : result, cancellationToken : cancellationToken).ConfigureAwait(false));
        }
Exemple #7
0
        public void SingleTokenValueFromArray()
        {
            /* 
             id1 | token_id1
            -----+----------------------
               1 | -4069959284402364209
             */

            var key = new PartitionKey();
            key.Set(new[] { CqlType.Int }, new object[] { 1 });

            var calculatedToken = new MurmurToken();
            calculatedToken.Parse(key.GetValue());

            var tokenFromCassandra = new MurmurToken();
            tokenFromCassandra.Parse("-4069959284402364209");

            Assert.AreEqual(tokenFromCassandra, calculatedToken);
        }