public static void DeleteRegexeMatchs(DataConfig providerConfig, POCO.System system, string fileUri) { List <Filter> filters = new List <Filter>(); Filter pk = new Filter("PartitionKey", system.PartitionKey, "eq"); filters.Add(pk); string rowkey = fileUri; Filter rk = new Filter("RowKey", rowkey, "ge"); filters.Add(rk); rk = new Filter("RowKey", Utils.GetLessThanFilter(rowkey), "lt"); filters.Add(rk); switch (providerConfig.ProviderType) { case "azure.tableservice": // Get a list of entities to delete List <POCO.CaptureRegexMatch> captureMatches = GetRegexMatches(providerConfig, system, fileUri); //TODO better way for bulk delete foreach (POCO.CaptureRegexMatch l in captureMatches) { AzureRegexMatch az = new AzureRegexMatch(l); az.ETag = "*"; CloudTable table = Utils.GetCloudTable(providerConfig, AzureTableNames.RecordAssociationRegexMatch); TableOperation operation = TableOperation.Delete(az); Task <TableResult> tDelete = table.ExecuteAsync(operation); tDelete.Wait(); // Check for "success with no status" code if (tDelete.Result.HttpStatusCode != 204) { // TODO bool isNotDeleted = true; } } break; case "internal.mongodb": FilterDefinition <BsonDocument> filter = Utils.GenerateMongoFilter <BsonDocument>(filters); // Delete the rows IMongoCollection <BsonDocument> collection = Utils.GetMongoCollection <BsonDocument>(providerConfig, Record.MongoTableNames.RecordKeyPhrases); DeleteResult result = collection.DeleteMany(filter); return; default: throw new ApplicationException("Data provider not recognised: " + providerConfig.ProviderType); } return; }
public static bool AddRegexMatchs(DataConfig providerConfig, List <CaptureRegexMatch> matches) { bool isSaved = false; switch (providerConfig.ProviderType) { case "azure.tableservice": List <TableOperation> ops = new List <TableOperation>(); CloudTable table = Utils.GetCloudTable(providerConfig, AzureTableNames.RecordAssociationRegexMatch); foreach (POCO.CaptureRegexMatch match in matches) { AzureRegexMatch az = new AzureRegexMatch(match); TableOperation operation = TableOperation.InsertOrReplace(az); Task tUpdate = table.ExecuteAsync(operation); tUpdate.Wait(); } break; case "internal.mongodb": IMongoCollection <MongoRegexMatchUpsert> collection = Utils.GetMongoCollection <MongoRegexMatchUpsert>(providerConfig, MongoTableNames.RecordAssociationRegexMatch); foreach (POCO.CaptureRegexMatch match in matches) { MongoRegexMatchUpsert mongoObject = Utils.ConvertType <MongoRegexMatchUpsert>(match); // Create the update filter List <DataFactory.Filter> filters = new List <DataFactory.Filter>(); DataFactory.Filter pkFilter = new DataFactory.Filter("PartitionKey", Utils.CleanTableKey(mongoObject.PartitionKey), "eq"); DataFactory.Filter rkFilter = new DataFactory.Filter("RowKey", Utils.CleanTableKey(mongoObject.RowKey), "eq"); filters.Add(pkFilter); filters.Add(rkFilter); FilterDefinition <MongoRegexMatchUpsert> filter = Utils.GenerateMongoFilter <MongoRegexMatchUpsert>(filters); // Create the upsert options MongoDB.Driver.ReplaceOptions options = new ReplaceOptions(); options.IsUpsert = true; // Upsert collection.ReplaceOne(filter, mongoObject, options); } break; default: throw new ApplicationException("Data provider not recognised: " + providerConfig.ProviderType); } isSaved = true; return(isSaved); }