private void AddToList(MatchingRule rule) { if (!(rule is SingleUseMatchingRule)) { Rules.Add(rule); RulesGroupedByBucket.Single(g => g.Bucket == rule.Bucket).Rules.Add(rule); EventHandler <MatchingRuleEventArgs> handler = RuleAdded; handler?.Invoke(this, new MatchingRuleEventArgs { Rule = rule }); } this.applicationDatabaseService.NotifyOfChange(ApplicationDataType.MatchingRules); }
private void OnRuleRemoved(object sender, EventArgs e) { var rule = (MatchingRule)sender; var flatList = (ObservableCollection <MatchingRule>) this.FlatListBox.ItemsSource; flatList.Remove(rule); var groupedList = (ObservableCollection <RulesGroupedByBucket>) this.GroupedByListBox.ItemsSource; RulesGroupedByBucket group = groupedList.FirstOrDefault(g => g.Bucket == rule.Bucket); if (group != null) { group.Rules.Remove(rule); } }
private void AddRule(MatchingRule ruleToAdd) { if (ruleToAdd == null) { throw new ArgumentNullException(nameof(ruleToAdd)); } if (string.IsNullOrWhiteSpace(this.rulesStorageKey)) { throw new InvalidOperationException("Unable to add a matching rule at this time, the service has not yet loaded a matching rule set."); } // Make sure no rule already exists with this id: if (MatchingRules.Any(r => r.RuleId == ruleToAdd.RuleId)) { throw new DuplicateNameException($"Unable to add new matching rule: Rule ID {ruleToAdd.RuleId} already exists in the collection."); } // Check to see if an existing group object for the desired bucket already exists. var existingGroup = MatchingRulesGroupedByBucket.FirstOrDefault(group => group.Bucket == ruleToAdd.Bucket); if (existingGroup == null) { // Create a new group object for this bucket. var addNewGroup = new RulesGroupedByBucket(ruleToAdd.Bucket, new[] { ruleToAdd }); this.matchingRulesGroupedByBucket.Add(addNewGroup); this.matchingRules.Add(ruleToAdd); } else { // Add to existing group object. if (existingGroup.Rules.Contains(ruleToAdd)) { this.logger.LogWarning(l => "Attempt to add new rule failed. Rule already exists in Grouped collection. " + ruleToAdd); return; } existingGroup.Rules.Add(ruleToAdd); if (MatchingRules.Contains(ruleToAdd)) { this.logger.LogWarning(l => "Attempt to add new rule failed. Rule already exists in main collection. " + ruleToAdd); return; } this.matchingRules.Add(ruleToAdd); } this.logger.LogInfo(_ => "Matching Rule Added: " + ruleToAdd); }
private void OnRuleAdded(object sender, MatchingRuleEventArgs e) { MatchingRule rule = e.Rule; var flatList = (ObservableCollection <MatchingRule>) this.FlatListBox.ItemsSource; if (flatList.All(r => r.RuleId != rule.RuleId)) { flatList.Add(rule); } var groupedList = (ObservableCollection <RulesGroupedByBucket>) this.GroupedByListBox.ItemsSource; RulesGroupedByBucket group = groupedList.SingleOrDefault(g => g.Bucket == rule.Bucket); if (group == null) { group = new RulesGroupedByBucket(rule.Bucket, new[] { rule }); groupedList.Add(group); } if (group.Rules.All(r => r.RuleId != rule.RuleId)) { group.Rules.Add(rule); } }
private void OnRuleAdded(object sender, MatchingRuleEventArgs e) { MatchingRule rule = e.Rule; var flatList = (ObservableCollection<MatchingRule>)this.FlatListBox.ItemsSource; if (flatList.All(r => r.RuleId != rule.RuleId)) { flatList.Add(rule); } var groupedList = (ObservableCollection<RulesGroupedByBucket>)this.GroupedByListBox.ItemsSource; RulesGroupedByBucket group = groupedList.SingleOrDefault(g => g.Bucket == rule.Bucket); if (group == null) { group = new RulesGroupedByBucket(rule.Bucket, new[] { rule }); groupedList.Add(group); } if (group.Rules.All(r => r.RuleId != rule.RuleId)) { group.Rules.Add(rule); } }
private void AddToList(MatchingRule rule) { RulesGroupedByBucket existingGroup = RulesGroupedByBucket.FirstOrDefault(group => group.Bucket == rule.Bucket); if (existingGroup == null) { var addNewGroup = new RulesGroupedByBucket(rule.Bucket, new[] { rule }); RulesGroupedByBucket.Add(addNewGroup); Rules.Add(rule); } else { existingGroup.Rules.Add(rule); Rules.Add(rule); } SaveRules(); this.logger.LogInfo(() => "Matching Rule Added: " + rule); EventHandler<MatchingRuleEventArgs> handler = RuleAdded; if (handler != null) { handler(this, new MatchingRuleEventArgs { Rule = rule }); } }
private void OnClosedNotificationReceived(object sender, EventArgs eventArgs) { Rules.Clear(); RulesGroupedByBucket.Clear(); SelectedRule = null; }