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. CustomerEntity customer = new CustomerEntity("Harp", "Walter") { Email = "*****@*****.**", PhoneNumber = "425-555-0101" }; // Demonstrate how to insert the entity Console.WriteLine("Insert an Entity."); customer = await SamplesUtils.InsertOrMergeEntityAsync(table, customer); // Demonstrate how to Update the entity by changing the phone number Console.WriteLine("Update an existing Entity using the InsertOrMerge Upsert Operation."); customer.PhoneNumber = "425-555-0105"; await SamplesUtils.InsertOrMergeEntityAsync(table, customer); Console.WriteLine(); // Demonstrate how to Read the updated entity using a point query Console.WriteLine("Reading the updated Entity."); customer = await SamplesUtils.RetrieveEntityUsingPointQueryAsync(table, "Harp", "Walter"); Console.WriteLine(); // Demonstrate how to Delete an entity //Console.WriteLine("Delete the entity. "); //await SamplesUtils.DeleteEntityAsync(table, customer); //Console.WriteLine(); }
/// <summary> /// Tests a table SAS to determine which operations it allows. /// </summary> /// <param name="sasUri">A string containing a URI with a SAS appended.</param> /// <param name="customer">The customer entity.</param> /// <returns>A Task object</returns> private static async Task TestTableSAS(string sasUri, CustomerEntity customer) { // Try performing table operations with the SAS provided. // Note that the storage account credentials are not required here; the SAS provides the necessary // authentication information on the URI. // Return a reference to the table using the SAS URI. CloudTable table = new CloudTable(new Uri(sasUri)); // Upsert (add/update) operations: insert an entity. // This operation requires both add and update permissions on the SAS. try { // Insert the new entity. customer = await SamplesUtils.InsertOrMergeEntityAsync(table, customer); Console.WriteLine("Add operation succeeded for SAS {0}", sasUri); Console.WriteLine(); } catch (StorageException e) { if (e.RequestInformation.HttpStatusCode == 403) { Console.WriteLine("Add operation failed for SAS {0}", sasUri); Console.WriteLine("Additional error information: " + e.Message); Console.WriteLine(); } else { Console.WriteLine(e.Message); Console.ReadLine(); throw; } } // Read operation: query an entity. // This operation requires read permissions on the SAS. CustomerEntity customerRead = null; try { TableOperation retrieveOperation = TableOperation.Retrieve <CustomerEntity>(customer.PartitionKey, customer.RowKey); TableResult result = await table.ExecuteAsync(retrieveOperation); customerRead = result.Result as CustomerEntity; if (customerRead != null) { Console.WriteLine("\t{0}\t{1}\t{2}\t{3}", customerRead.PartitionKey, customerRead.RowKey, customerRead.Email, customerRead.PhoneNumber); } Console.WriteLine("Read operation succeeded for SAS {0}", sasUri); Console.WriteLine(); } catch (StorageException e) { if (e.RequestInformation.HttpStatusCode == 403) { Console.WriteLine("Read operation failed for SAS {0}", sasUri); Console.WriteLine("Additional error information: " + e.Message); Console.WriteLine(); } else { Console.WriteLine(e.Message); Console.ReadLine(); throw; } } // Delete operation: delete an entity. try { if (customerRead != null) { await SamplesUtils.DeleteEntityAsync(table, customerRead); } Console.WriteLine("Delete operation succeeded for SAS {0}", sasUri); Console.WriteLine(); } catch (StorageException e) { if (e.RequestInformation.HttpStatusCode == 403) { Console.WriteLine("Delete operation failed for SAS {0}", sasUri); Console.WriteLine("Additional error information: " + e.Message); Console.WriteLine(); } else { Console.WriteLine(e.Message); Console.ReadLine(); throw; } } Console.WriteLine(); }
private static async Task BasicDataOperationsAsync(CloudTable table) { Console.WriteLine("Enter the count of entries you will make"); int count = Convert.ToInt32(Console.ReadLine()); for (int i = 0; i < count; i++) { Console.WriteLine("Enter details of user " + (i + 1)); Console.WriteLine(); Console.WriteLine("Enter your first name"); string str1 = Console.ReadLine(); Console.WriteLine("Enter your last name"); string str2 = Console.ReadLine(); Console.WriteLine("Enter your email Address"); string str3 = Console.ReadLine(); Console.WriteLine("Enter your Phone number"); string str4 = Console.ReadLine(); // Create an instance of a customer entity. See the Model\CustomerEntity.cs for a description of the entity. CustomerEntity customer = new CustomerEntity(str1, str2) { Email = str3, PhoneNumber = str4 }; // Demonstrate how to insert the entity Console.WriteLine("Insert an Entity."); await SamplesUtils.InsertOrMergeEntityAsync(table, customer); } // Demonstrate how to Update the entity by changing the phone number //Console.WriteLine("Update an existing Entity using the InsertOrMerge Upsert Operation."); //customer.PhoneNumber = "9810738851"; //await SamplesUtils.InsertOrMergeEntityAsync(table, customer); //Console.WriteLine(); // Demonstrate how to Read the updated entity using a point query Console.WriteLine("Retrieving data from cloud"); Console.WriteLine("Enter The first name"); string strFname = Console.ReadLine(); Console.WriteLine("Enter your last name"); string strLname = Console.ReadLine(); //Console.WriteLine("Reading the updated Entity."); await SamplesUtils.RetrieveEntityUsingPointQueryAsync(table, strFname, strLname); Console.WriteLine(); // Demonstrate how to Delete an entity //Console.WriteLine("Delete the entity. "); //await SamplesUtils.DeleteEntityAsync(table, customer); //Console.WriteLine(); //TableQuery<CustomerEntity> query = new TableQuery<CustomerEntity>() // .Where( // TableQuery.CombineFilters( // TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, "Aman"), // TableOperators.And, // TableQuery.GenerateFilterCondition("Email", QueryComparisons.Equal, "*****@*****.**") // )); //await table.ExecuteQuerySegmentedAsync<CustomerEntity>(query, null); //Console.WriteLine("AmanPrint"); }