Exemple #1
0
        private static String ToStringEvaluateTrue(EvalAuditStateNode current, String patternExpression, MatchedEventMap matchEvent, EvalStateNode fromNode, bool isQuitted)
        {
            var writer = new StringWriter();

            WritePatternExpr(current, patternExpression, writer);
            writer.Write(" evaluate-true {");

            writer.Write(" from: ");
            TypeHelper.WriteInstance(writer, fromNode, false);

            writer.Write(" map: {");
            var delimiter = "";
            var data      = matchEvent.MatchingEvents;

            for (int i = 0; i < data.Length; i++)
            {
                var name  = matchEvent.Meta.TagsPerIndex[i];
                var value = matchEvent.GetMatchingEventAsObject(i);
                writer.Write(delimiter);
                writer.Write(name);
                writer.Write("=");
                if (value is EventBean)
                {
                    writer.Write(((EventBean)value).Underlying.ToString());
                }
                else if (value is EventBean[])
                {
                    writer.Write(EventBeanUtility.Summarize((EventBean[])value));
                }
                delimiter = ", ";
            }

            writer.Write("} quitted: ");
            writer.Write(isQuitted);

            writer.Write("}");
            return(writer.ToString());
        }
        public void EvaluateTrue(MatchedEventMap matchEvent, EvalStateNode fromNode, bool isQuitted)
        {
            Instrument.With(
                i => i.QPatternMatchUntilEvaluateTrue(_evalMatchUntilNode, matchEvent, fromNode == _stateUntil),
                i => i.APatternMatchUntilEvaluateTrue(_stateMatcher == null && _stateUntil == null),
                () =>
            {
                bool isMatcher = false;
                if (fromNode == _stateMatcher)
                {
                    // Add the additional tagged events to the list for later posting
                    isMatcher = true;
                    _numMatches++;
                    int[] tags = _evalMatchUntilNode.FactoryNode.TagsArrayed;
                    for (int i = 0; i < tags.Length; i++)
                    {
                        var theEvent = matchEvent.GetMatchingEventAsObject(tags[i]);
                        if (theEvent != null)
                        {
                            if (_matchedEventArrays[i] == null)
                            {
                                _matchedEventArrays[i] = new List <EventBean>();
                            }
                            if (theEvent is EventBean)
                            {
                                _matchedEventArrays[i].Add((EventBean)theEvent);
                            }
                            else
                            {
                                EventBean[] arrayEvents = (EventBean[])theEvent;
                                _matchedEventArrays[i].AddAll(arrayEvents);
                            }
                        }
                    }
                }

                if (isQuitted)
                {
                    if (isMatcher)
                    {
                        _stateMatcher = null;
                    }
                    else
                    {
                        _stateUntil = null;
                    }
                }

                // handle matcher evaluating true
                if (isMatcher)
                {
                    if ((IsTightlyBound) && (_numMatches == _lowerbounds))
                    {
                        QuitInternal();
                        MatchedEventMap consolidated = Consolidate(
                            matchEvent, _matchedEventArrays, _evalMatchUntilNode.FactoryNode.TagsArrayed);
                        ParentEvaluator.EvaluateTrue(consolidated, this, true);
                    }
                    else
                    {
                        // restart or keep started if not bounded, or not upper bounds, or upper bounds not reached
                        bool restart = (!IsBounded) ||
                                       (_upperbounds == null) ||
                                       (_upperbounds > _numMatches);
                        if (_stateMatcher == null)
                        {
                            if (restart)
                            {
                                EvalNode childMatcher = _evalMatchUntilNode.ChildNodeSub;
                                _stateMatcher         = childMatcher.NewState(this, null, 0L);
                                _stateMatcher.Start(_beginState);
                            }
                        }
                        else
                        {
                            if (!restart)
                            {
                                _stateMatcher.Quit();
                                _stateMatcher = null;
                            }
                        }
                    }
                }
                else
                // handle until-node
                {
                    QuitInternal();

                    // consolidate multiple matched events into a single event
                    MatchedEventMap consolidated = Consolidate(
                        matchEvent, _matchedEventArrays, _evalMatchUntilNode.FactoryNode.TagsArrayed);

                    if ((_lowerbounds != null) && (_numMatches < _lowerbounds))
                    {
                        ParentEvaluator.EvaluateFalse(this, true);
                    }
                    else
                    {
                        ParentEvaluator.EvaluateTrue(consolidated, this, true);
                    }
                }
            });
        }