private void ProcessRuleUpdate(CacheChangeData update) { try { // update the rules if (update != null) { UpdateRules(update); } long updatesDispatchedLocal = Interlocked.Decrement(ref _dispatchedEventCount); if (updatesDispatchedLocal > 0) { // more updates following - just exit return; } // process the rules ProcessAllRules(); } catch (Exception ex) { ReportUncaughtError("ProcessRuleUpdate", null, ex, null); throw; } }
private void UpdateRules(CacheChangeData update) { if (update.NewItem == null) { throw new ArgumentException("update.NewItem is null: " + update); } string ruleName = null; try { ruleName = update.NewItem.Name; switch (update.Change) { case CacheChange.CacheCleared: _ruleStore.Clear(); break; case CacheChange.ItemExpired: case CacheChange.ItemRemoved: { var oldExternalRule = (AlertRule)update.OldItem.Data; // stop old rule StopOldRule(oldExternalRule, null); Logger.LogDebug("Rule {0}: Removed.", oldExternalRule.PrivateKey); } break; case CacheChange.ItemCreated: { var newExternalRule = (AlertRule)update.NewItem.Data; var newInternalRule = new InternalRule(newExternalRule); StartNewRule(newExternalRule, newInternalRule); Logger.LogDebug("Rule {0}: Created.", newExternalRule.PrivateKey); } break; case CacheChange.ItemUpdated: { var oldExternalRule = (AlertRule)update.OldItem.Data; var newExternalRule = (AlertRule)update.NewItem.Data; var newInternalRule = new InternalRule(newExternalRule); StopOldRule(oldExternalRule, newInternalRule); StartNewRule(newExternalRule, newInternalRule); Logger.LogDebug("Rule {0}: Updated.", newExternalRule.PrivateKey); } break; } } catch (Exception ex) { ReportUncaughtError("UpdateRules", ruleName, ex, null); } }
private void ProcessRuleUpdate(CacheChangeData update) { // update the rules if (update != null) { switch (update.Change) { case CacheChange.CacheCleared: _ruleStore.Clear(); break; case CacheChange.ItemExpired: case CacheChange.ItemRemoved: { FileImportRule oldImportRule = (FileImportRule)update.OldItem.Data; _ruleStore.Remove(oldImportRule.PrivateKey.ToLower()); Logger.LogDebug("Rule {0}: Removed.", oldImportRule.RuleName); } break; case CacheChange.ItemCreated: { var newImportRule = (FileImportRule)update.NewItem.Data; _ruleStore[newImportRule.PrivateKey.ToLower()] = new InternalRule(newImportRule); Logger.LogDebug("Rule {0}: Created.", newImportRule.RuleName); } break; case CacheChange.ItemUpdated: { //var oldImportRule = (FileImportRule)update.OldItem.Data; var newImportRule = (FileImportRule)update.NewItem.Data; //InternalRule oldRule = _RuleStore.GetValue(newImportRulePrivateKey.ToLower(), null); var newRule = new InternalRule(newImportRule); _ruleStore[newImportRule.PrivateKey.ToLower()] = newRule; Logger.LogDebug("Rule {0}: Updated.", newImportRule.RuleName); } break; } } long requestsDispatched = Interlocked.Decrement(ref _updateRequestsDispatched); if (requestsDispatched > 0) { // more requests following - just exit return; } // process the rules DateTimeOffset currentTime = DateTimeOffset.Now; foreach (InternalRule rule in _ruleStore.Values) { try { if (rule.LastMonitored + rule.MonitorPeriod < currentTime) { // update LastMonitored first to prevent infinite looping // when there are repeated expression evaluation exceptions rule.LastMonitored = currentTime; ProcessRule(IntClient.Target, rule, currentTime); } } catch (Exception ruleExcp) { Logger.LogError("Rule {0}: EXCEPTION! {1}'", rule.RuleName, ruleExcp); } } }