in Services/DataX.Flow/DataX.Flow.CodegenRules/Engine.cs [142:198]
private void AutoCodegenAlerts(string productId)
{
List<Rule> rules = new List<Rule>();
if (string.IsNullOrEmpty(productId))
{
rules = _allrules.Where(r => r.Isalert).ToList();
}
else
{
rules = _allrules.Where(r => r.ProductId == productId && r.Isalert).ToList();
}
if (rules == null || rules.Count() <= 0)
{
return;
}
// Check all the rules to determine what kinds of alerts user has set up
Dictionary<string, List<string>> keyValues = new Dictionary<string, List<string>>();
foreach (Rule rule in rules)
{
if (!keyValues.ContainsKey(rule.TargetTable))
{
keyValues.Add(rule.TargetTable, new List<string>() { rule.RuleType });
}
else if(!keyValues[rule.TargetTable].Contains(rule.RuleType))
{
keyValues[rule.TargetTable].Add(rule.RuleType);
}
}
foreach(string key in keyValues.Keys)
{
foreach (string ruleType in keyValues[key])
{
// Check if the code already contains the API call for processing alert. If not, then add it
if (ruleType == "SimpleRule")
{
Regex simpleRegex = new Regex(@"ProcessAlerts\s{0,}\(\s{0,}" + key + @"\s{0,}\)", RegexOptions.IgnoreCase);
MatchCollection m1 = simpleRegex.Matches(_code);
if (m1 == null || m1.Count <= 0)
{
_code += $"\nProcessAlerts({key});";
}
}
else
{
Regex aggRegex = new Regex(@"ProcessAggregateAlerts\s{0,}\(\s{0,}" + key + @"\s{0,}\)", RegexOptions.IgnoreCase);
MatchCollection m2 = aggRegex.Matches(_code);
if (m2 == null || m2.Count <= 0)
{
_code += $"\nProcessAggregateAlerts({key});";
}
}
}
}
}