示例#1
0
        public static async Task <ArcheoEntity> InsertOrMergeEntityAsync(CloudTable table, ArcheoEntity entitiy)
        {
            if (entitiy == null)
            {
                throw new ArgumentNullException("ArcheoEntity");
            }

            try
            {
                Microsoft.Azure.Cosmos.Table.TableOperation insertOrMergeOperation = TableOperation.InsertOrMerge(entitiy);
                TableResult result = await table.ExecuteAsync(insertOrMergeOperation);

                ArcheoEntity insertedCustomer = result.Result as ArcheoEntity;

                if (result.RequestCharge.HasValue)
                {
                    Console.WriteLine("Request Charge of InsertOrMerge Operation: " + result.RequestCharge);
                }
                return(insertedCustomer);
            }
            catch (StorageException e)
            {
                Console.WriteLine(e.Message);
                Console.ReadLine();
                throw;
            }
        }
示例#2
0
        public static async Task <ArcheoEntity> RetrieveEntityUsingPointQueryAsync(CloudTable table, string partitionKey, string rowKey)
        {
            try
            {
                TableOperation retrieveOperation = TableOperation.Retrieve <ArcheoEntity>(partitionKey, rowKey);
                TableResult    result            = await table.ExecuteAsync(retrieveOperation);

                ArcheoEntity archeoObj = result.Result as ArcheoEntity;
                if (archeoObj != null)
                {
                    Console.WriteLine("\t{0}\t{1}\t{2}\t{3}", archeoObj.PartitionKey, archeoObj.RowKey, archeoObj.Description, archeoObj.Code);
                }

                if (result.RequestCharge.HasValue)
                {
                    Console.WriteLine("Request Charge of Retrieve Operation: " + result.RequestCharge);
                }

                return(archeoObj);
            }
            catch (StorageException e)
            {
                Console.WriteLine(e.Message);
                Console.ReadLine();
                throw;
            }
        }
示例#3
0
        private static async Task BasicDataOperationsAsync(CloudTable table)
        {
            // Create an instance of a customer entity. See the Model\CustomerEntity.cs for a description of the entity.
            ArcheoEntity archeoObj = new ArcheoEntity("Harp", "Walter")
            {
                Particularities = "*****@*****.**",
                Description     = "425-555-0101"
            };

            // Demonstrate how to insert the entity
            Console.WriteLine("Insert an Entity.");
            archeoObj = await ArcheoTableUtils.InsertOrMergeEntityAsync(table, archeoObj);

            // Demonstrate how to Update the entity by changing the phone number
            Console.WriteLine("Update an existing Entity using the InsertOrMerge Upsert Operation.");
            archeoObj.Description = "425-555-0105";
            await ArcheoTableUtils.InsertOrMergeEntityAsync(table, archeoObj);

            Console.WriteLine();

            // Demonstrate how to Read the updated entity using a point query
            Console.WriteLine("Reading the updated Entity.");
            archeoObj = await ArcheoTableUtils.RetrieveEntityUsingPointQueryAsync(table, "Harp", "Walter");

            Console.WriteLine();

            // Demonstrate how to Delete an entity
            //Console.WriteLine("Delete the entity. ");
            //await SamplesUtils.DeleteEntityAsync(table, customer);
            //Console.WriteLine();
        }
示例#4
0
        public static async Task DeleteEntityAsync(CloudTable table, ArcheoEntity deleteEntity)
        {
            try
            {
                if (deleteEntity == null)
                {
                    throw new ArgumentNullException("deleteEntity");
                }

                TableOperation deleteOperation = TableOperation.Delete(deleteEntity);
                TableResult    result          = await table.ExecuteAsync(deleteOperation);

                if (result.RequestCharge.HasValue)
                {
                    Console.WriteLine("Request Charge of Delete Operation: " + result.RequestCharge);
                }
            }
            catch (StorageException e)
            {
                Console.WriteLine(e.Message);
                Console.ReadLine();
                throw;
            }
        }