public Variant GetValue(MessageDataItem dataItem) { if (Message) { return new Variant() { StringValue = dataItem.Message, Type = VariantType.String } } ; if (Value != null) { return(Value.Value); } if (Attribute != null) { Variant result = dataItem.GetAttributeAsVariant(Attribute.Name); if (result.Type != Attribute.Type) { throw new InvalidCastException("Attribute type mismatch."); } return(result); } throw new InvalidOperationException("Value Expression is not defined."); } }
public bool Evaluate(MessageDataItem dataItem) { if (And != null) { return(And.All(x => x?.Evaluate(dataItem) == true)); } if (Or != null) { return(Or.Any(x => x?.Evaluate(dataItem) == true)); } if (Not != null) { return(!Not.Evaluate(dataItem)); } if (Exists != null) { if (Exists.Attribute != null) { if (dataItem.AttributeExists(Exists.Attribute.Name ?? "")) { if (dataItem.GetAttributeAsVariant(Exists.Attribute.Name).Type == Exists.Attribute.Type) { return(true); } } } } if (SimpleExpression != null) { return(SimpleExpression.Evaluate(dataItem)); } if (InExpression != null) { return(InExpression.Evaluate(dataItem)); } if (RegExExpression != null) { return(RegExExpression.Evaluate(dataItem)); } if (ModuleExpressionModule != null) { return(ModuleExpressionModule.IsMatch(dataItem)); } return(false); }
} // null if message body public void SetField(GroupCollection groups, MessageDataItem inputMessage, ref string outMessage, Dictionary <string, Variant> outAttributes) { if (!string.IsNullOrEmpty(Input?.Group)) { string dynamicOutputAttribute; if (string.IsNullOrEmpty(Input.GroupToOutputAttribute)) { dynamicOutputAttribute = OutputAttribute; } else { dynamicOutputAttribute = groups[Input.GroupToOutputAttribute].Value; } switch (Input.Type) { case VariantType.Boolean: if (bool.TryParse(groups[Input.Group]?.Value, out bool newBoolValue)) { if (string.IsNullOrEmpty(dynamicOutputAttribute)) { outMessage = newBoolValue.ToString(); } else { outAttributes[dynamicOutputAttribute] = new Variant { BooleanValue = newBoolValue, Type = VariantType.Boolean } }; } return; case VariantType.DateTime: if (string.IsNullOrEmpty(Input.Format)) { if (DateTime.TryParse(groups[Input.Group]?.Value, out DateTime newDateTimeValue)) { if (string.IsNullOrEmpty(dynamicOutputAttribute)) { outMessage = newDateTimeValue.ToString(); } else { outAttributes[dynamicOutputAttribute] = new Variant { DateTimeValue = newDateTimeValue, Type = VariantType.DateTime } } } ; } else { if (DateTime.TryParseExact(groups[Input.Group]?.Value, Input.Format, null, DateTimeStyles.AssumeLocal, out DateTime newDateTimeValue)) { if (string.IsNullOrEmpty(dynamicOutputAttribute)) { outMessage = newDateTimeValue.ToString(); } else { outAttributes[dynamicOutputAttribute] = new Variant { DateTimeValue = newDateTimeValue, Type = VariantType.DateTime } } } ; } return; case VariantType.Float: if (float.TryParse(groups[Input.Group].Value, out float newFloatValue)) { if (string.IsNullOrEmpty(dynamicOutputAttribute)) { outMessage = (newFloatValue.ToString()); } else { outAttributes[dynamicOutputAttribute] = new Variant { FloatValue = newFloatValue, Type = VariantType.Float } } } ; return; case VariantType.Int: if (int.TryParse(groups[Input.Group].Value, out int newIntValue)) { if (string.IsNullOrEmpty(dynamicOutputAttribute)) { outMessage = (newIntValue.ToString()); } else { outAttributes[dynamicOutputAttribute] = new Variant { IntValue = newIntValue, Type = VariantType.Int } } } ; return; case VariantType.String: if (string.IsNullOrEmpty(dynamicOutputAttribute)) { outMessage = groups[Input.Group]?.Value ?? ""; } else { outAttributes[dynamicOutputAttribute] = new Variant { StringValue = groups[Input.Group]?.Value, Type = VariantType.String } }; return; } } if (Input?.Message == true) { if (string.IsNullOrEmpty(OutputAttribute)) { outMessage = inputMessage.Message; } else { outAttributes[OutputAttribute] = new Variant { StringValue = inputMessage.Message, Type = VariantType.String } }; return; } if (!string.IsNullOrEmpty(Input?.Attribute)) { if (string.IsNullOrEmpty(OutputAttribute)) { if (inputMessage.AttributeExists(Input.Attribute)) { outMessage = inputMessage.GetAttributeAsVariant(Input.Attribute).ToString(); } } else { if (inputMessage.AttributeExists(Input.Attribute)) { outAttributes[OutputAttribute] = inputMessage.GetAttributeAsVariant(Input.Attribute); } } return; } if (Input?.Value != null) { switch (Input.Type) { case VariantType.Boolean: if (bool.TryParse(Input.Value, out bool newBoolValue)) { if (string.IsNullOrEmpty(OutputAttribute)) { outMessage = newBoolValue.ToString(); } else { outAttributes[OutputAttribute] = new Variant { BooleanValue = newBoolValue, Type = VariantType.Boolean } }; } return; case VariantType.DateTime: if (string.IsNullOrEmpty(Input.Format)) { if (DateTime.TryParse(Input.Value, out DateTime newDateTimeValue)) { if (string.IsNullOrEmpty(OutputAttribute)) { outMessage = newDateTimeValue.ToString(); } else { outAttributes[OutputAttribute] = new Variant { DateTimeValue = newDateTimeValue, Type = VariantType.DateTime } } } ; } else { if (DateTime.TryParseExact(Input.Value, Input.Format, null, DateTimeStyles.AssumeLocal, out DateTime newDateTimeValue)) { if (string.IsNullOrEmpty(OutputAttribute)) { outMessage = newDateTimeValue.ToString(); } else { outAttributes[OutputAttribute] = new Variant { DateTimeValue = newDateTimeValue, Type = VariantType.DateTime } } } ; } return; case VariantType.Float: if (float.TryParse(Input.Value, out float newFloatValue)) { if (string.IsNullOrEmpty(OutputAttribute)) { outMessage = (newFloatValue.ToString()); } else { outAttributes[OutputAttribute] = new Variant { FloatValue = newFloatValue, Type = VariantType.Float } } } ; return; case VariantType.Int: if (int.TryParse(Input.Value, out int newIntValue)) { if (string.IsNullOrEmpty(OutputAttribute)) { outMessage = (newIntValue.ToString()); } else { outAttributes[OutputAttribute] = new Variant { IntValue = newIntValue, Type = VariantType.Int } } } ; return; case VariantType.String: if (string.IsNullOrEmpty(OutputAttribute)) { outMessage = Input.Value; } else { outAttributes[OutputAttribute] = new Variant { StringValue = Input.Value, Type = VariantType.String } }; return; } } } }