public void BadlyFormedExpression(string malformedExpression)
        {
            string altMalformedExpression = malformedExpression.Replace('(', Syntax.AltOpeningBracket).Replace(')', Syntax.AltClosingBracket);

            Assert.Throws(typeof(ApplicationException), () =>
            {
                _ = TriggerExpression.Parse(null, altMalformedExpression);
            });
        }
Ejemplo n.º 2
0
        public void Execute(List <TriggerItem> triggerItems)
        {
            var         filteredTriggerItems = new List <TriggerItem>();
            TriggerItem defaultTriggerItem   = null;

            if (!triggerItems.Any())
            {
                return;
            }

            if (TriggerExpression == null)
            {
                defaultTriggerItem = triggerItems.First();
                WatchdogEventSource.Current.RuleFired(this.ToString(defaultTriggerItem), defaultTriggerItem.ToString(), false);
                return;
            }

            if (RuleFilter != null)
            {
                foreach (var triggerItem in triggerItems)
                {
                    var result = (RuleFilter.Execute(triggerItem) == "1" ? true : false);
                    if (result)
                    {
                        filteredTriggerItems.Add(triggerItem);
                    }
                }

                if (!filteredTriggerItems.Any())
                {
                    defaultTriggerItem = triggerItems.First();
                    _firstTriggered    = null;
                    _triggeringItem    = null;
                    WatchdogEventSource.Current.RuleFired(this.ToString(defaultTriggerItem), defaultTriggerItem.ToString(), false);
                    return;
                }
            }

            if (AggregateData)
            {
                filteredTriggerItems = CreateAggregatedData(filteredTriggerItems);
            }

            foreach (var filteredTriggerItem in filteredTriggerItems)
            {
                if (TriggerExpression.Execute(filteredTriggerItem) != 0)
                {
                    if (_firstTriggered == null)
                    {
                        _firstTriggered = DateTime.UtcNow;
                    }
                    _triggeringItem = filteredTriggerItem;
                    WatchdogEventSource.Current.RuleFired(this.ToString(filteredTriggerItem), filteredTriggerItem.ToString(), true);
                    return;
                }
            }

            defaultTriggerItem = triggerItems.First();
            _firstTriggered    = null;
            _triggeringItem    = null;
            WatchdogEventSource.Current.RuleFired(this.ToString(defaultTriggerItem), defaultTriggerItem.ToString(), false);
        }
Ejemplo n.º 3
0
 public string ToString(TriggerItem triggerItem)
 {
     return($"RuleFilter={RuleFilter.ToString(triggerItem)}; Expression={TriggerExpression.ToString(triggerItem)}; TriggerPeriod={TriggerPeriod.ToString()}; " +
            $"GracePeriod={ActionGracePeriod.ToString()}; Action={TriggerAction.GetType().FullName}");
 }