public SmallTalksDectectorData ToDetectorData(RulesData rules) { return(new SmallTalksDectectorData { SmallTalksIntents = rules.Rules.Select(r => ToIntent(r)).ToList() }); }
public void WriteToFile(RulesData.RulesData rulesData, string xmlFileName) { xmlFileName = xmlFileName ?? string.Empty; if (string.IsNullOrEmpty(xmlFileName)) return; var serializer = new XmlSerializer(typeof(RulesData.RulesData)); using (TextWriter writer = new StreamWriter(xmlFileName)) { serializer.Serialize(writer, rulesData); } }
/// <summary> /// Generate JSON based on rules to create alert conditions /// </summary> /// <param name="rule"></param> /// <param name="counter"></param> /// <returns></returns> public JObject GenerateRulesData(RulesData rule, int counter) { JObject dataStream = JObject.Parse(rule.dataStream); if (rule.triggerConditions != null) { foreach (var tc in rule.triggerConditions) { var parent = dataStream.SelectToken(tc.parentJsonPropertyPath); if (tc.propertyType.ToLower() == "datetime") { parent[tc.propertyName] = DateTime.UtcNow.AddSeconds(tc.utcAddSeconds).ToString(tc.datetimeStringFormat); } else if (tc.propertyType.ToLower() == "double" || tc.propertyType.ToLower() == "decimal") { if (!(tc.ruleNotTriggerTimeInMinutes.Contains(counter))) { if (tc.castAsString) { parent[tc.propertyName] = (!string.IsNullOrEmpty(tc.ruleTriggerValue)) ? tc.ruleTriggerValue : GetRandomDouble(tc.ruleTriggerMinRange, tc.ruleTriggerMaxRange).ToString(); } else { parent[tc.propertyName] = (!string.IsNullOrEmpty(tc.ruleTriggerValue)) ? double.Parse(tc.ruleTriggerValue) : GetRandomDouble(tc.ruleTriggerMinRange, tc.ruleTriggerMaxRange); } } else { if (tc.castAsString) { parent[tc.propertyName] = (!string.IsNullOrEmpty(tc.ruleNotTriggerValue)) ? tc.ruleNotTriggerValue : GetRandomDouble(tc.ruleNotTriggerMinRange, tc.ruleNotTriggerMaxRange).ToString(); } else { parent[tc.propertyName] = (!string.IsNullOrEmpty(tc.ruleNotTriggerValue)) ? double.Parse(tc.ruleNotTriggerValue) : GetRandomDouble(tc.ruleNotTriggerMinRange, tc.ruleNotTriggerMaxRange); } } } else if (tc.propertyType.ToLower() == "int" || tc.propertyType.ToLower() == "long") { if (!(tc.ruleNotTriggerTimeInMinutes.Contains(counter))) { if (tc.castAsString) { parent[tc.propertyName] = (!string.IsNullOrEmpty(tc.ruleTriggerValue)) ? tc.ruleTriggerValue : GetRandomInt((int)tc.ruleTriggerMinRange, (int)tc.ruleTriggerMaxRange).ToString(); } else { parent[tc.propertyName] = (!string.IsNullOrEmpty(tc.ruleTriggerValue)) ? int.Parse(tc.ruleTriggerValue) : GetRandomInt((int)tc.ruleTriggerMinRange, (int)tc.ruleTriggerMaxRange); } } else { if (tc.castAsString) { parent[tc.propertyName] = (!string.IsNullOrEmpty(tc.ruleNotTriggerValue)) ? tc.ruleNotTriggerValue : GetRandomInt((int)tc.ruleNotTriggerMinRange, (int)tc.ruleNotTriggerMaxRange).ToString(); } else { parent[tc.propertyName] = (!string.IsNullOrEmpty(tc.ruleNotTriggerValue)) ? int.Parse(tc.ruleNotTriggerValue) : GetRandomInt((int)tc.ruleNotTriggerMinRange, (int)tc.ruleNotTriggerMaxRange); } } } else if (tc.propertyType.ToLower() == "string") { if (!(tc.ruleNotTriggerTimeInMinutes.Contains(counter))) { parent[tc.propertyName] = tc.ruleTriggerValue; } else { parent[tc.propertyName] = tc.ruleNotTriggerValue; } } } } return(dataStream); }
protected void Init() { _rules = rules; dependencyContainer.Bind <Main>(this); context.Bind(); }
protected IConditionEvaluator GetEvaluator(RulesData.RuleCondition condition) { var evaluator = _implementedTypes.FirstOrDefault(ev => ev.IsResponsibleFor(condition)); return evaluator; }
public virtual bool Evaluate(RulesData.RuleCondition condition) { var evaluator = GetEvaluator(condition); var result = evaluator != null && evaluator.Evaluate(condition); return result; }
public virtual void LoadRulesFromRulesObject(RulesData.RulesData rulesData) { _rulesData = rulesData; }
public string WriteToString(RulesData.RulesData rulesData) { string result = XmlSerializationHelpers.ToXml(rulesData); return result; }
protected override bool EvaluateInternal(RulesData.RuleCondition ruleCondition) { bool testValue; Boolean.TryParse(ruleCondition.Value ?? string.Empty, out testValue); return testValue; }