public async Task ParseBatchCloudAction <T>(AzureTableDictionary <T> dictionary) { var SW = Stopwatch.StartNew(); if (!dictionary.Items.Any()) { return; } var IndexesAdded = 0; var IndexesDeleted = 0; var ItemsToSave = new List <T>(); var ItemsToSoftDelete = new List <T>(); var ItemsToHardDelete = new List <T>(); foreach (var item in dictionary.Items) { if ((item as AzureTableEntity)._IsSoftDeleted) { ItemsToSoftDelete.Add(item); } else if ((item as AzureTableEntity)._HardDeleteWithBatch) { ItemsToHardDelete.Add(item); } else { ItemsToSave.Add(item); } } if (ItemsToSoftDelete.Count > 0 || ItemsToHardDelete.Count > 0) { NewInsertsOnlyOperation = false; } if (ItemsToSoftDelete.Any()) { IndexesDeleted = IndexesDeleted + await BatchCloudActionSoftDeleteItems(dictionary, ItemsToSoftDelete); } if (ItemsToHardDelete.Any()) { IndexesDeleted = IndexesDeleted + await BatchCloudActionHardDeleteItems(dictionary, ItemsToHardDelete); } if (ItemsToSave.Any()) { IndexesAdded = IndexesAdded + await BatchCloudActionAddItems(dictionary, ItemsToSave); } Debug.WriteLine(string.Format( "=== Items: {3} Added, {4} SoftDeleted, {5} HardDeleted --- Indexes: {6} Added, {7} Deleted \n" + "=== End Batch Cloud Action Operations for {0} @ {1} Elapsed {2} \n" , typeof(T), DateTime.UtcNow, SW.Elapsed, ItemsToSave.Count, ItemsToSoftDelete.Count, ItemsToHardDelete.Count, IndexesAdded, IndexesDeleted)); //dictionary.Items = ItemsToSave; }
private async Task <int> DeleteOldRows <T>(AzureTableDictionary <T> dictionary, List <T> items) { Debug.WriteLine($"== Start DeleteOldRows => Old Row Batch Delete Operation on {items.First().GetType().Name} {items.Count} ========="); var OperationSW = Stopwatch.StartNew(); int DeletedOldRowsCount = 0; foreach (var item in items) { DeletedOldRowsCount += await DeleteOldRows(dictionary, item); } Debug.WriteLine($"== End DeleteOldRows => Old Row Batch Delete Operation on {items.First().GetType().Name} {items.Count} {OperationSW.Elapsed.ToString()} ========="); return(DeletedOldRowsCount); }
private async Task <int> BatchCloudActionHardDeleteItems <T>(AzureTableDictionary <T> dictionary, List <T> list) { if (!list.Any()) { return(0); } //foreach (var item in list) // await Utils.DeleteBlobs(item, PrimaryStorageAccount()); await BatchCloudTableOperation(list.First().GetType().Name, PrimaryStorageAccount(), Utils.SetRowAndPartitionKeys(list), true); return(await UpdateIndexesForListItems(list, true)); }
private async Task <int> DeleteOldRows <T>(AzureTableDictionary <T> dictionary, T item) { var OperationSW = Stopwatch.StartNew(); var rowKeyValue = Utils.GetRowKeyValue(item); var rowkeyFilter = Utils.FilterString("RowKey", QueryComparisons.Equal, rowKeyValue); var timestampFilter = Utils.FilterString("Timestamp", QueryComparisons.LessThan, DateTime.UtcNow.AddMinutes(-2)); var oldRowKeysFilter = Utils.CombineFilterStrings(new List <string>() { rowkeyFilter, timestampFilter }); var oldRows = await dictionary.QueryAllAsync(oldRowKeysFilter) ?? new List <T>(); await BatchCloudTableOperation(typeof(T).Name, PrimaryStorageAccount(), oldRows, true); Debug.WriteLine($"== Old Row Delete Operation on {item.GetType().Name} {(item as AzureTableEntity).RowKey} found = {oldRows.Count} {OperationSW.Elapsed.ToString()} ========="); return(oldRows.Count); }
private async Task <int> BatchCloudActionAddItems <T>(AzureTableDictionary <T> dictionary, List <T> list) { if (!list.Any()) { return(0); } foreach (var item in list) { CheckRequiredFields(item); (item as AzureTableEntity).Timestamp = DateTime.UtcNow; } var results = await BatchCloudTableOperation(typeof(T).Name, PrimaryStorageAccount(), Utils.SetRowAndPartitionKeys(list), false); if (!NewInsertsOnlyOperation) { DeleteOldRows(dictionary, results); } return(await UpdateIndexesForListItems(results, false)); }