private void DoEscapeTest(string data, bool useBatch, bool includeKey) { DynamicTableEntity ent = new DynamicTableEntity(includeKey ? "temp" + data : "temp", Guid.NewGuid().ToString()); ent.Properties.Add("foo", new EntityProperty(data)); // Insert if (useBatch) { TableBatchOperation batch = new TableBatchOperation(); batch.Insert(ent); currentTable.ExecuteBatch(batch); } else { currentTable.Execute(TableOperation.Insert(ent)); } // Retrieve TableResult res = null; if (useBatch) { TableBatchOperation batch = new TableBatchOperation(); batch.Retrieve(ent.PartitionKey, ent.RowKey); res = (currentTable.ExecuteBatch(batch))[0]; } else { res = currentTable.Execute(TableOperation.Retrieve(ent.PartitionKey, ent.RowKey)); } // Check equality DynamicTableEntity retrievedEntity = res.Result as DynamicTableEntity; Assert.IsNotNull(retrievedEntity); Assert.AreEqual(ent.PartitionKey, retrievedEntity.PartitionKey); Assert.AreEqual(ent.RowKey, retrievedEntity.RowKey); Assert.AreEqual(ent.ETag, retrievedEntity.ETag); Assert.AreEqual(ent.Properties.Count, retrievedEntity.Properties.Count); Assert.AreEqual(ent.Properties["foo"], retrievedEntity.Properties["foo"]); // Query using data filter TableQuery query = new TableQuery(); query.Where(string.Format( "(PartitionKey eq \'{0}\') and (RowKey eq \'{1}\') and (foo eq \'{2}\')", ent.PartitionKey, ent.RowKey, data.Replace("\'", "\'\'"))); retrievedEntity = currentTable.ExecuteQuery(query).Single(); Assert.IsNotNull(retrievedEntity); Assert.AreEqual(ent.PartitionKey, retrievedEntity.PartitionKey); Assert.AreEqual(ent.RowKey, retrievedEntity.RowKey); Assert.AreEqual(ent.ETag, retrievedEntity.ETag); Assert.AreEqual(ent.Properties.Count, retrievedEntity.Properties.Count); Assert.AreEqual(ent.Properties["foo"], retrievedEntity.Properties["foo"]); // Merge ent.Properties.Add("foo2", new EntityProperty("bar2")); if (useBatch) { TableBatchOperation batch = new TableBatchOperation(); batch.Merge(ent); currentTable.ExecuteBatch(batch); } else { currentTable.Execute(TableOperation.Merge(ent)); } // Retrieve if (useBatch) { TableBatchOperation batch = new TableBatchOperation(); batch.Retrieve(ent.PartitionKey, ent.RowKey); res = (currentTable.ExecuteBatch(batch))[0]; } else { res = currentTable.Execute(TableOperation.Retrieve(ent.PartitionKey, ent.RowKey)); } retrievedEntity = res.Result as DynamicTableEntity; Assert.AreEqual(ent.PartitionKey, retrievedEntity.PartitionKey); Assert.AreEqual(ent.RowKey, retrievedEntity.RowKey); Assert.AreEqual(ent.ETag, retrievedEntity.ETag); Assert.AreEqual(ent.Properties.Count, retrievedEntity.Properties.Count); Assert.AreEqual(ent.Properties["foo"], retrievedEntity.Properties["foo"]); // Replace ent.Properties.Remove("foo2"); ent.Properties.Add("foo3", new EntityProperty("bar3")); if (useBatch) { TableBatchOperation batch = new TableBatchOperation(); batch.Replace(ent); currentTable.ExecuteBatch(batch); } else { currentTable.Execute(TableOperation.Replace(ent)); } // Retrieve if (useBatch) { TableBatchOperation batch = new TableBatchOperation(); batch.Retrieve(ent.PartitionKey, ent.RowKey); res = (currentTable.ExecuteBatch(batch))[0]; } else { res = currentTable.Execute(TableOperation.Retrieve(ent.PartitionKey, ent.RowKey)); } retrievedEntity = res.Result as DynamicTableEntity; Assert.AreEqual(ent.PartitionKey, retrievedEntity.PartitionKey); Assert.AreEqual(ent.RowKey, retrievedEntity.RowKey); Assert.AreEqual(ent.ETag, retrievedEntity.ETag); Assert.AreEqual(ent.Properties.Count, retrievedEntity.Properties.Count); Assert.AreEqual(ent.Properties["foo"], retrievedEntity.Properties["foo"]); }
public async Task TableRegionalQueryOnSupportedTypesAsync() { string currentPrimaryLanguage = ApplicationLanguages.PrimaryLanguageOverride; ApplicationLanguages.PrimaryLanguageOverride = "tr"; CloudTableClient client = GenerateCloudTableClient(); CloudTable table = client.GetTableReference(GenerateRandomTableName()); await table.CreateAsync(); try { // Setup TableBatchOperation batch = new TableBatchOperation(); string pk = Guid.NewGuid().ToString(); DynamicTableEntity middleRef = null; for (int m = 0; m < 100; m++) { ComplexEntity complexEntity = new ComplexEntity(); complexEntity.String = string.Format("{0:0000}", m); complexEntity.Binary = new byte[] { 0x01, 0x02, (byte)m }; complexEntity.BinaryPrimitive = new byte[] { 0x01, 0x02, (byte)m }; complexEntity.Bool = m % 2 == 0 ? true : false; complexEntity.BoolPrimitive = m % 2 == 0 ? true : false; complexEntity.Double = m + ((double)m / 100); complexEntity.DoublePrimitive = m + ((double)m / 100); complexEntity.Int32 = m; complexEntity.IntegerPrimitive = m; complexEntity.Int64 = (long)int.MaxValue + m; complexEntity.LongPrimitive = (long)int.MaxValue + m; complexEntity.Guid = Guid.NewGuid(); DynamicTableEntity dynEnt = new DynamicTableEntity(pk, string.Format("{0:0000}", m)); dynEnt.Properties = complexEntity.WriteEntity(null); batch.Insert(dynEnt); if (m == 50) { middleRef = dynEnt; } // Add delay to make times unique await Task.Delay(100); } await table.ExecuteBatchAsync(batch); // 1. Filter on String ExecuteQueryAndAssertResults(table, TableQuery.GenerateFilterCondition("String", QueryComparisons.GreaterThanOrEqual, "0050"), 50); // 2. Filter on Guid ExecuteQueryAndAssertResults(table, TableQuery.GenerateFilterConditionForGuid("Guid", QueryComparisons.Equal, middleRef.Properties["Guid"].GuidValue.Value), 1); // 3. Filter on Long ExecuteQueryAndAssertResults(table, TableQuery.GenerateFilterConditionForLong("Int64", QueryComparisons.GreaterThanOrEqual, middleRef.Properties["LongPrimitive"].Int64Value.Value), 50); ExecuteQueryAndAssertResults(table, TableQuery.GenerateFilterConditionForLong("LongPrimitive", QueryComparisons.GreaterThanOrEqual, middleRef.Properties["LongPrimitive"].Int64Value.Value), 50); // 4. Filter on Double ExecuteQueryAndAssertResults(table, TableQuery.GenerateFilterConditionForDouble("Double", QueryComparisons.GreaterThanOrEqual, middleRef.Properties["Double"].DoubleValue.Value), 50); ExecuteQueryAndAssertResults(table, TableQuery.GenerateFilterConditionForDouble("DoublePrimitive", QueryComparisons.GreaterThanOrEqual, middleRef.Properties["DoublePrimitive"].DoubleValue.Value), 50); // 5. Filter on Integer ExecuteQueryAndAssertResults(table, TableQuery.GenerateFilterConditionForInt("Int32", QueryComparisons.GreaterThanOrEqual, middleRef.Properties["Int32"].Int32Value.Value), 50); ExecuteQueryAndAssertResults(table, TableQuery.GenerateFilterConditionForInt("IntegerPrimitive", QueryComparisons.GreaterThanOrEqual, middleRef.Properties["IntegerPrimitive"].Int32Value.Value), 50); // 6. Filter on Date ExecuteQueryAndAssertResults(table, TableQuery.GenerateFilterConditionForDate("DateTimeOffset", QueryComparisons.GreaterThanOrEqual, middleRef.Properties["DateTimeOffset"].DateTimeOffsetValue.Value), 50); // 7. Filter on Boolean ExecuteQueryAndAssertResults(table, TableQuery.GenerateFilterConditionForBool("Bool", QueryComparisons.Equal, middleRef.Properties["Bool"].BooleanValue.Value), 50); ExecuteQueryAndAssertResults(table, TableQuery.GenerateFilterConditionForBool("BoolPrimitive", QueryComparisons.Equal, middleRef.Properties["BoolPrimitive"].BooleanValue.Value), 50); // 8. Filter on Binary ExecuteQueryAndAssertResults(table, TableQuery.GenerateFilterConditionForBinary("Binary", QueryComparisons.Equal, middleRef.Properties["Binary"].BinaryValue), 1); ExecuteQueryAndAssertResults(table, TableQuery.GenerateFilterConditionForBinary("BinaryPrimitive", QueryComparisons.Equal, middleRef.Properties["BinaryPrimitive"].BinaryValue), 1); // 9. Filter on Binary GTE ExecuteQueryAndAssertResults(table, TableQuery.GenerateFilterConditionForBinary("Binary", QueryComparisons.GreaterThanOrEqual, middleRef.Properties["Binary"].BinaryValue), 50); ExecuteQueryAndAssertResults(table, TableQuery.GenerateFilterConditionForBinary("BinaryPrimitive", QueryComparisons.GreaterThanOrEqual, middleRef.Properties["BinaryPrimitive"].BinaryValue), 50); // 10. Complex Filter on Binary GTE ExecuteQueryAndAssertResults(table, TableQuery.CombineFilters( TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, middleRef.PartitionKey), TableOperators.And, TableQuery.GenerateFilterConditionForBinary("Binary", QueryComparisons.GreaterThanOrEqual, middleRef.Properties["Binary"].BinaryValue)), 50); ExecuteQueryAndAssertResults(table, TableQuery.GenerateFilterConditionForBinary("BinaryPrimitive", QueryComparisons.GreaterThanOrEqual, middleRef.Properties["BinaryPrimitive"].BinaryValue), 50); } finally { ApplicationLanguages.PrimaryLanguageOverride = currentPrimaryLanguage; table.DeleteIfExistsAsync().AsTask().Wait(); } }
/// <summary> /// Executes a batch operation on a table as an atomic operation. /// </summary> /// <param name="batch">The <see cref="TableBatchOperation"/> object representing the operations to execute on the table.</param> /// <returns>An enumerable collection of <see cref="TableResult"/> objects that contains the results, in order, of each operation in the <see cref="TableBatchOperation"/> on the table.</returns> public IAsyncOperation <IList <TableResult> > ExecuteBatchAsync(TableBatchOperation batch) { return(this.ExecuteBatchAsync(batch, null /* RequestOptions */, null /* OperationContext */)); }
/// <summary> /// Executes a batch operation on a table as an atomic operation, using the specified <see cref="TableRequestOptions"/> and <see cref="OperationContext"/>. /// </summary> /// <param name="batch">The <see cref="TableBatchOperation"/> object representing the operations to execute on the table.</param> /// <param name="requestOptions">A <see cref="TableRequestOptions"/> object that specifies execution options, such as retry policy and timeout settings, for the operation.</param> /// <param name="operationContext">An <see cref="OperationContext"/> object for tracking the current operation.</param> /// <returns>An enumerable collection of <see cref="TableResult"/> objects that contains the results, in order, of each operation in the <see cref="TableBatchOperation"/> on the table.</returns> public IAsyncOperation <IList <TableResult> > ExecuteBatchAsync(TableBatchOperation batch, TableRequestOptions requestOptions, OperationContext operationContext) { CommonUtility.AssertNotNull("batch", batch); return(batch.ExecuteAsync(this.ServiceClient, this.Name, requestOptions, operationContext)); }
private async Task DoEscapeTestAsync(string data, bool useBatch, bool includeKey) { DynamicTableEntity ent = new DynamicTableEntity(includeKey ? "temp" + data : "temp", Guid.NewGuid().ToString()); ent.Properties.Add("foo", new EntityProperty(data)); // Insert if (useBatch) { TableBatchOperation batch = new TableBatchOperation(); batch.Insert(ent); await currentTable.ExecuteBatchAsync(batch); } else { await currentTable.ExecuteAsync(TableOperation.Insert(ent)); } // Retrieve TableResult res = null; if (useBatch) { TableBatchOperation batch = new TableBatchOperation(); batch.Retrieve(ent.PartitionKey, ent.RowKey); res = (await currentTable.ExecuteBatchAsync(batch))[0]; } else { res = await currentTable.ExecuteAsync(TableOperation.Retrieve(ent.PartitionKey, ent.RowKey)); } // Check equality DynamicTableEntity retrievedEntity = res.Result as DynamicTableEntity; Assert.AreEqual(ent.PartitionKey, retrievedEntity.PartitionKey); Assert.AreEqual(ent.RowKey, retrievedEntity.RowKey); Assert.AreEqual(ent.ETag, retrievedEntity.ETag); Assert.AreEqual(ent.Properties.Count, retrievedEntity.Properties.Count); Assert.AreEqual(ent.Properties["foo"], retrievedEntity.Properties["foo"]); // Merge ent.Properties.Add("foo2", new EntityProperty("bar2")); if (useBatch) { TableBatchOperation batch = new TableBatchOperation(); batch.Merge(ent); await currentTable.ExecuteBatchAsync(batch); } else { await currentTable.ExecuteAsync(TableOperation.Merge(ent)); } // Retrieve if (useBatch) { TableBatchOperation batch = new TableBatchOperation(); batch.Retrieve(ent.PartitionKey, ent.RowKey); res = (await currentTable.ExecuteBatchAsync(batch))[0]; } else { res = await currentTable.ExecuteAsync(TableOperation.Retrieve(ent.PartitionKey, ent.RowKey)); } retrievedEntity = res.Result as DynamicTableEntity; Assert.AreEqual(ent.PartitionKey, retrievedEntity.PartitionKey); Assert.AreEqual(ent.RowKey, retrievedEntity.RowKey); Assert.AreEqual(ent.ETag, retrievedEntity.ETag); Assert.AreEqual(ent.Properties.Count, retrievedEntity.Properties.Count); Assert.AreEqual(ent.Properties["foo"], retrievedEntity.Properties["foo"]); // Replace ent.Properties.Remove("foo2"); ent.Properties.Add("foo3", new EntityProperty("bar3")); if (useBatch) { TableBatchOperation batch = new TableBatchOperation(); batch.Replace(ent); await currentTable.ExecuteBatchAsync(batch); } else { await currentTable.ExecuteAsync(TableOperation.Replace(ent)); } // Retrieve if (useBatch) { TableBatchOperation batch = new TableBatchOperation(); batch.Retrieve(ent.PartitionKey, ent.RowKey); res = (await currentTable.ExecuteBatchAsync(batch))[0]; } else { res = await currentTable.ExecuteAsync(TableOperation.Retrieve(ent.PartitionKey, ent.RowKey)); } retrievedEntity = res.Result as DynamicTableEntity; Assert.AreEqual(ent.PartitionKey, retrievedEntity.PartitionKey); Assert.AreEqual(ent.RowKey, retrievedEntity.RowKey); Assert.AreEqual(ent.ETag, retrievedEntity.ETag); Assert.AreEqual(ent.Properties.Count, retrievedEntity.Properties.Count); Assert.AreEqual(ent.Properties["foo"], retrievedEntity.Properties["foo"]); }
private async Task DoTableGenericQueryOnSupportedTypesAsync(TablePayloadFormat format) { CloudTableClient client = GenerateCloudTableClient(); client.DefaultRequestOptions.PayloadFormat = format; CloudTable table = client.GetTableReference(GenerateRandomTableName()); await table.CreateAsync(); try { // Setup TableBatchOperation batch = new TableBatchOperation(); string pk = Guid.NewGuid().ToString(); ComplexEntity middleRef = null; for (int m = 0; m < 100; m++) { ComplexEntity complexEntity = new ComplexEntity(pk, string.Format("{0:0000}", m)); complexEntity.String = string.Format("{0:0000}", m); complexEntity.Binary = new byte[] { 0x01, 0x02, (byte)m }; complexEntity.BinaryPrimitive = new byte[] { 0x01, 0x02, (byte)m }; complexEntity.Bool = m % 2 == 0 ? true : false; complexEntity.BoolPrimitive = m % 2 == 0 ? true : false; complexEntity.Double = m + ((double)m / 100); complexEntity.DoublePrimitive = m + ((double)m / 100); complexEntity.Int32 = m; complexEntity.IntegerPrimitive = m; complexEntity.Int64 = (long)int.MaxValue + m; complexEntity.LongPrimitive = (long)int.MaxValue + m; complexEntity.Guid = Guid.NewGuid(); batch.Insert(complexEntity); if (m == 50) { middleRef = complexEntity; } // Add delay to make times unique await Task.Delay(100); } await table.ExecuteBatchAsync(batch); // 1. Filter on String ExecuteQueryAndAssertResults(table, TableQuery.GenerateFilterCondition("String", QueryComparisons.GreaterThanOrEqual, "0050"), 50); // 2. Filter on Guid ExecuteQueryAndAssertResults(table, TableQuery.GenerateFilterConditionForGuid("Guid", QueryComparisons.Equal, middleRef.Guid), 1); // 3. Filter on Long ExecuteQueryAndAssertResults(table, TableQuery.GenerateFilterConditionForLong("Int64", QueryComparisons.GreaterThanOrEqual, middleRef.LongPrimitive), 50); ExecuteQueryAndAssertResults(table, TableQuery.GenerateFilterConditionForLong("LongPrimitive", QueryComparisons.GreaterThanOrEqual, middleRef.LongPrimitive), 50); // 4. Filter on Double ExecuteQueryAndAssertResults(table, TableQuery.GenerateFilterConditionForDouble("Double", QueryComparisons.GreaterThanOrEqual, middleRef.Double), 50); ExecuteQueryAndAssertResults(table, TableQuery.GenerateFilterConditionForDouble("DoublePrimitive", QueryComparisons.GreaterThanOrEqual, middleRef.DoublePrimitive), 50); // 5. Filter on Integer ExecuteQueryAndAssertResults(table, TableQuery.GenerateFilterConditionForInt("Int32", QueryComparisons.GreaterThanOrEqual, middleRef.Int32), 50); ExecuteQueryAndAssertResults(table, TableQuery.GenerateFilterConditionForInt("IntegerPrimitive", QueryComparisons.GreaterThanOrEqual, middleRef.IntegerPrimitive), 50); // 6. Filter on Date ExecuteQueryAndAssertResults(table, TableQuery.GenerateFilterConditionForDate("DateTimeOffset", QueryComparisons.GreaterThanOrEqual, middleRef.DateTimeOffset), 50); // 7. Filter on Boolean ExecuteQueryAndAssertResults(table, TableQuery.GenerateFilterConditionForBool("Bool", QueryComparisons.Equal, middleRef.Bool), 50); ExecuteQueryAndAssertResults(table, TableQuery.GenerateFilterConditionForBool("BoolPrimitive", QueryComparisons.Equal, middleRef.BoolPrimitive), 50); // 8. Filter on Binary ExecuteQueryAndAssertResults(table, TableQuery.GenerateFilterConditionForBinary("Binary", QueryComparisons.Equal, middleRef.Binary), 1); ExecuteQueryAndAssertResults(table, TableQuery.GenerateFilterConditionForBinary("BinaryPrimitive", QueryComparisons.Equal, middleRef.BinaryPrimitive), 1); // 9. Filter on Binary GTE ExecuteQueryAndAssertResults(table, TableQuery.GenerateFilterConditionForBinary("Binary", QueryComparisons.GreaterThanOrEqual, middleRef.Binary), 50); ExecuteQueryAndAssertResults(table, TableQuery.GenerateFilterConditionForBinary("BinaryPrimitive", QueryComparisons.GreaterThanOrEqual, middleRef.BinaryPrimitive), 50); // 10. Complex Filter on Binary GTE ExecuteQueryAndAssertResults(table, TableQuery.CombineFilters( TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, middleRef.PartitionKey), TableOperators.And, TableQuery.GenerateFilterConditionForBinary("Binary", QueryComparisons.GreaterThanOrEqual, middleRef.Binary)), 50); ExecuteQueryAndAssertResults(table, TableQuery.GenerateFilterConditionForBinary("BinaryPrimitive", QueryComparisons.GreaterThanOrEqual, middleRef.BinaryPrimitive), 50); } finally { table.DeleteIfExistsAsync().Wait(); } }
public static async Task MyClassInitialize(TestContext testContext) { CloudTableClient tableClient = GenerateCloudTableClient(); currentTable = tableClient.GetTableReference(GenerateRandomTableName()); await currentTable.CreateIfNotExistsAsync(); // Bulk Query Entities for (int i = 0; i < 15; i++) { TableBatchOperation batch = new TableBatchOperation(); for (int j = 0; j < 100; j++) { var ent = GenerateRandomEntity("tables_batch_" + i.ToString()); ent.RowKey = string.Format("{0:0000}", j); batch.Insert(ent); } await currentTable.ExecuteBatchAsync(batch); } complexEntityTable = tableClient.GetTableReference(GenerateRandomTableName()); await complexEntityTable.CreateAsync(); // Setup TableBatchOperation complexBatch = new TableBatchOperation(); string pk = Guid.NewGuid().ToString(); for (int m = 0; m < 100; m++) { ComplexEntity complexEntity = new ComplexEntity(pk, string.Format("{0:0000}", m)); complexEntity.String = string.Format("{0:0000}", m); complexEntity.Binary = new byte[] { 0x01, 0x02, (byte)m }; complexEntity.BinaryPrimitive = new byte[] { 0x01, 0x02, (byte)m }; complexEntity.Bool = m % 2 == 0 ? true : false; complexEntity.BoolPrimitive = m % 2 == 0 ? true : false; complexEntity.Double = m + ((double)m / 100); complexEntity.DoublePrimitive = m + ((double)m / 100); complexEntity.Int32 = m; complexEntity.Int32N = m; complexEntity.IntegerPrimitive = m; complexEntity.IntegerPrimitiveN = m; complexEntity.Int64 = (long)int.MaxValue + m; complexEntity.LongPrimitive = (long)int.MaxValue + m; complexEntity.LongPrimitiveN = (long)int.MaxValue + m; complexEntity.Guid = Guid.NewGuid(); complexBatch.Insert(complexEntity); if (m == 50) { middleRef = complexEntity; } // Add delay to make times unique Thread.Sleep(100); } await complexEntityTable.ExecuteBatchAsync(complexBatch); }
public virtual Task <IList <TableResult> > ExecuteBatchAsync(TableBatchOperation batch, TableRequestOptions requestOptions, OperationContext operationContext, CancellationToken cancellationToken) { throw new System.NotImplementedException(); }
public virtual Task <IList <TableResult> > ExecuteBatchAsync(TableBatchOperation batch) { throw new System.NotImplementedException(); }