/*--------------------------------------------------------------------------
         *                       DeletingItem_async
         *--------------------------------------------------------------------------*/
        public static async Task <bool> DeletingItem_async(Table table, int year, string title,
                                                           Expression condition = null)
        {
            Document deletedItem = null;

            operationSucceeded = false;
            operationFailed    = false;

            // Create Primitives for the HASH and RANGE portions of the primary key
            Primitive hash  = new Primitive(year.ToString(), true);
            Primitive range = new Primitive(title, false);
            DeleteItemOperationConfig deleteConfig = new DeleteItemOperationConfig( );

            deleteConfig.ConditionalExpression = condition;
            deleteConfig.ReturnValues          = ReturnValues.AllOldAttributes;

            Console.WriteLine("  -- Trying to delete the {0} movie \"{1}\"...", year, title);
            try
            {
                Task <Document> delItem = table.DeleteItemAsync(hash, range, deleteConfig);
                deletedItem = await delItem;
            }
            catch (Exception ex)
            {
                Console.WriteLine("     FAILED to delete the movie item, for this reason:\n       {0}\n", ex.Message);
                operationFailed = true;
                return(false);
            }
            Console.WriteLine("     -- SUCCEEDED in deleting the movie record that looks like this:\n" +
                              deletedItem.ToJsonPretty( ));
            operationSucceeded = true;
            return(true);
        }
示例#2
0
        public async Task <Document> DeleteItemAsync(DynamoDbTablesEnum dynamoDbTable,
                                                     Primitive primaryKey,
                                                     DeleteItemOperationConfig config)
        {
            Table table = this.LoadTable(dynamoDbTable);

            return(await table.DeleteItemAsync(primaryKey, config));
        }
        public async Task Delete(string id)
        {
            DeleteItemOperationConfig config = new DeleteItemOperationConfig
            {
                // Return the deleted item.
                ReturnValues = ReturnValues.AllOldAttributes
            };

            await this.table.DeleteItemAsync(id, config);
        }
示例#4
0
        public async Task Delete(string code)
        {
            List <StockEntity>        stockList = new List <StockEntity>();
            DeleteItemOperationConfig config    = new DeleteItemOperationConfig
            {
                // Return the deleted item.
                ReturnValues = ReturnValues.AllOldAttributes
            };

            await this.table.DeleteItemAsync(code, config);
        }
        private async Task <bool> DeleteItem(string id)
        {
            DeleteItemOperationConfig config = new DeleteItemOperationConfig {
                // Return the deleted item.
                ReturnValues = ReturnValues.AllOldAttributes
            };
            await _table.DeleteItemAsync(id, config);

            LambdaLogger.Log($"*** INFO: Deleted item {id}");
            return(true);
        }
示例#6
0
        public async void CleanupDbUnitTester(int id)
        {
            Table chatTable = Table.LoadTable(client, tableName);

            DeleteItemOperationConfig config = new DeleteItemOperationConfig
            {
                // Return the deleted item.
                ReturnValues = ReturnValues.AllOldAttributes
            };
            Document document = chatTable.DeleteItem(id, config);
        }
示例#7
0
        private static void DeleteRecommendation(Document document)
        {
            DeleteItemOperationConfig config = new DeleteItemOperationConfig
            {
                ReturnValues = ReturnValues.AllOldAttributes
            };

            //Console.WriteLine($"Turning off {document[ItemIdentifier]} from {document[AisleIdIdentifier]}");
            var task = _recommendationsTable.DeleteItemAsync(document);

            task.Wait();
        }
示例#8
0
        public static void DeleteBook(this DynamoDBContext context, int sampleBookId)
        {
            Console.WriteLine("\n*** Executing DeleteBook() ***");
            // Optional configuration.
            var config = new DeleteItemOperationConfig
            {
                // Return the deleted item.
                ReturnValues = ReturnValues.AllOldAttributes
            };

            context.Delete <Book>(sampleBookId, config);
            Console.WriteLine("DeleteBook: Printing deleted just deleted...");
        }
        private static void DeleteBook(Table productCatalog)
        {
            Console.WriteLine("\n*** Executing DeleteBook() ***");
            // Optional configuration.
            DeleteItemOperationConfig config = new DeleteItemOperationConfig
            {
                // Return the deleted item.
                ReturnValues = ReturnValues.AllOldAttributes
            };
            Document document = productCatalog.DeleteItem(sampleBookId, config);

            Console.WriteLine("DeleteBook: Printing deleted just deleted...");
            PrintDocument(document);
        }
        public static async void DeleteBook(AmazonDynamoDBClient client, Table productCatalog)
        {
            Console.WriteLine("\n*** Executing DeleteBook() ***");
            // Optional configuration.
            DeleteItemOperationConfig config = new DeleteItemOperationConfig
            {
                // Return the deleted item.
                ReturnValues = ReturnValues.AllOldAttributes
            };
            Document document = await productCatalog.DeleteItemAsync(SampleBookId, config);

            Console.WriteLine("DeleteBook: Printing deleted just deleted...");

            PrintDocument(client, document);
        }
示例#11
0
        static void Main(string[] args)
        {
            // Get a Table object for the table that you created in Step 1
            Table table = GetTableObject("Movies");

            if (table == null)
            {
                return;
            }

            // Create the condition
            DeleteItemOperationConfig opConfig = new DeleteItemOperationConfig();

            opConfig.ConditionalExpression = new Expression();
            opConfig.ConditionalExpression.ExpressionAttributeValues[":val"] = 5.0;
            opConfig.ConditionalExpression.ExpressionStatement = "info.rating <= :val";

            // Delete this item
            try
            {
                table.DeleteItem(2015, "The Big New Movie", opConfig);
            }
            catch (Exception ex)
            {
                Console.WriteLine("\n Error: Could not delete the movie item with year={0}, title=\"{1}\"\n   Reason: {2}.",
                                  2015, "The Big New Movie", ex.Message);
            }

            // Try to retrieve it, to see if it has been deleted
            Document document = table.GetItem(2015, "The Big New Movie");

            if (document == null)
            {
                Console.WriteLine("\n The movie item with year={0}, title=\"{1}\" has been deleted.",
                                  2015, "The Big New Movie");
            }
            else
            {
                Console.WriteLine("\nRead back the item: \n" + document.ToJsonPretty());
            }

            // Keep the console open if in Debug mode...
            Console.Write("\n\n ...Press any key to continue");
            Console.ReadKey();
            Console.WriteLine();
        }
示例#12
0
        public async Task <bool> DeleteItemAsync(string id, CancellationToken token)
        {
            if (!Table.TryLoadTable(_client, TableName, out var table))
            {
                return(false);
            }

            var primitive = new Primitive(id, false);

            var config = new DeleteItemOperationConfig
            {
                ReturnValues = ReturnValues.AllOldAttributes
            };

            var response = await table.DeleteItemAsync(primitive, config, token);

            return(response != null);
        }
        /// <summary>
        /// Deletes the book with the supplied Id value from the DynamoDB table
        /// ProductCatalog.
        /// </summary>
        /// <param name="productCatalog">A DynamoDB table object.</param>
        /// <param name="sampleBookId">An integer value representing the book's ID.</param>
        public static async Task DeleteBook(
            Table productCatalog,
            int sampleBookId)
        {
            Console.WriteLine("\n*** Executing DeleteBook() ***");

            // Optional configuration.
            var config = new DeleteItemOperationConfig
            {
                // Returns the deleted item.
                ReturnValues = ReturnValues.AllOldAttributes,
            };
            Document document = await productCatalog.DeleteItemAsync(sampleBookId, config);

            Console.WriteLine("DeleteBook: Printing deleted just deleted...");

            PrintDocument(document);
        }
示例#14
0
        public void Delete <T>(string[] ids, bool failIfMissing = false)
        {
            string tableName = GetTableName(typeof(T));
            Table  table     = Table.LoadTable(client, tableName);

            DeleteItemOperationConfig config = new DeleteItemOperationConfig();

            if (failIfMissing)
            {
                config.ConditionalExpression = new Expression();
                foreach (string hash in table.HashKeys)
                {
                    config.ConditionalExpression.ExpressionAttributeNames.Add("#" + hash, hash);
                    string statement = "(attribute_exists(#" + hash + "))";

                    if (String.IsNullOrWhiteSpace(config.ConditionalExpression.ExpressionStatement))
                    {
                        config.ConditionalExpression.ExpressionStatement = statement;
                    }
                    else
                    {
                        config.ConditionalExpression.ExpressionStatement = " and " + statement;
                    }
                }
            }

            Task <Document> task;

            if (ids.Length <= 1)
            {
                task = table.DeleteItemAsync(ids[0], config);
            }
            else
            {
                task = table.DeleteItemAsync(ids[0], ids[1], config);
            }

            task.Wait(defaultTimeout);
        }
示例#15
0
        private void TestExpressionsOnDelete(Table hashTable)
        {
            Document doc1 = new Document();

            doc1["Id"]    = 13;
            doc1["Price"] = 6;
            hashTable.PutItem(doc1);

            Expression expression = new Expression();

            expression.ExpressionStatement = "Price > :price";
            expression.ExpressionAttributeValues[":price"] = 7;

            DeleteItemOperationConfig config = new DeleteItemOperationConfig();

            config.ConditionalExpression = expression;

            Assert.IsFalse(hashTable.TryDeleteItem(doc1, config));

            expression.ExpressionAttributeValues[":price"] = 4;
            Assert.IsTrue(hashTable.TryDeleteItem(doc1, config));
        }
示例#16
0
        private async Task TestExpressionsOnDelete(Table hashTable)
        {
            Document doc1 = new Document();

            doc1["Id"]    = 13;
            doc1["Price"] = 6;
            await hashTable.PutItemAsync(doc1);

            Expression expression = new Expression();

            expression.ExpressionStatement = "Price > :price";
            expression.ExpressionAttributeValues[":price"] = 7;

            DeleteItemOperationConfig config = new DeleteItemOperationConfig();

            config.ConditionalExpression = expression;

            await Assert.ThrowsAsync <ConditionalCheckFailedException>(() => hashTable.DeleteItemAsync(doc1, config));

            expression.ExpressionAttributeValues[":price"] = 4;
            await hashTable.DeleteItemAsync(doc1, config);
        }
示例#17
0
        private async Task TestExpressionsOnDelete(Table hashTable)
        {
            Document doc1 = new Document();

            doc1["Id"]    = 13;
            doc1["Price"] = 6;
            await hashTable.PutItemAsync(doc1);

            Expression expression = new Expression();

            expression.ExpressionStatement = "Price > :price";
            expression.ExpressionAttributeValues[":price"] = 7;

            DeleteItemOperationConfig config = new DeleteItemOperationConfig();

            config.ConditionalExpression = expression;

            //Assert.IsFalse(hashTable.TryDeleteItem(doc1, config));
            await AssertExtensions.ExpectExceptionAsync(hashTable.DeleteItemAsync(doc1, config));

            expression.ExpressionAttributeValues[":price"] = 4;
            //Assert.IsTrue(hashTable.TryDeleteItem(doc1, config));
            await hashTable.DeleteItemAsync(doc1, config);
        }
示例#18
0
    private void DeleteBook()
    {
        this.displayMessage += ("\n*** Executing DeleteBook() ***");
        // Optional configuration.
        DeleteItemOperationConfig config = new DeleteItemOperationConfig
        {
            // Return the deleted item.
            ReturnValues = ReturnValues.AllOldAttributes
        };

        productCatalog.DeleteItemAsync(sampleBookId, config,
                                       (AmazonDynamoResult <Document> result) =>
        {
            if (result.Exception != null)
            {
                this.displayMessage += ("\nDeleteBook ; " + result.Exception.Message);
                Debug.LogException(result.Exception);
                return;
            }
            Document document    = result.Response;
            this.displayMessage += ("\nDeleteBook: Printing deleted just deleted...");
            PrintDocument(document);
        }, null);
    }