public bool RemoveRule(MatchingRule ruleToRemove)
{
if (ruleToRemove == null)
{
throw new ArgumentNullException(nameof(ruleToRemove));
}
if (string.IsNullOrWhiteSpace(this.rulesStorageKey))
{
throw new InvalidOperationException(
"Unable to remove a matching rule at this time, the service has not yet loaded a matching rule set.");
}
var existingGroup = MatchingRulesGroupedByBucket.FirstOrDefault(g => g.Bucket == ruleToRemove.Bucket);
if (existingGroup == null)
{
return false;
}
var success1 = existingGroup.Rules.Remove(ruleToRemove);
var success2 = this.matchingRules.Remove(ruleToRemove);
var removedRule = ruleToRemove;
this.logger.LogInfo(_ => "Matching Rule is being Removed: " + removedRule);
if (!success1)
{
this.logger.LogWarning(
_ => "Matching Rule was not removed successfully from the Grouped list: " + removedRule);
}
if (!success2)
{
this.logger.LogWarning(
_ => "Matching Rule was not removed successfully from the flat list: " + removedRule);
}
return true;
}