Exemple #1
0
        /// <summary>
        ///     Updates the expectation state according to the variables' value
        /// </summary>
        /// <param name="priority">The priority for which this check is performed</param>
        private void CheckExpectationsState(acceptor.RulePriority priority)
        {
            // Update the state of the expectation according to system's state
            foreach (Expect expect in ActiveExpectations())
            {
                Expectation expectation = expect.Expectation;

                // Determine if the deadline is reached
                if (expect.TimeOut < EventTimeLine.CurrentTime)
                {
                    switch (expect.Expectation.getKind())
                    {
                    case acceptor.ExpectationKind.aInstantaneous:
                    case acceptor.ExpectationKind.defaultExpectationKind:
                        // Instantaneous expectation who raised its deadling
                        EventTimeLine.AddModelEvent(new FailedExpectation(expect, CurrentPriority, null), true);
                        break;

                    case acceptor.ExpectationKind.aContinuous:
                        // Continuous expectation who raised its deadline
                        EventTimeLine.AddModelEvent(new ExpectationReached(expect, CurrentPriority, null), true);
                        break;
                    }
                }
                else
                {
                    ExplanationPart explanation = new ExplanationPart(expectation,
                                                                      "Expectation " + expectation.Expression);
                    try
                    {
                        if (expectation.getCyclePhase() == acceptor.RulePriority.defaultRulePriority ||
                            expectation.getCyclePhase() == priority)
                        {
                            switch (expectation.getKind())
                            {
                            case acceptor.ExpectationKind.aInstantaneous:
                            case acceptor.ExpectationKind.defaultExpectationKind:
                                if (getBoolValue(expectation, expectation.Expression, explanation))
                                {
                                    // An instantaneous expectation who reached its satisfactory condition
                                    EventTimeLine.AddModelEvent(
                                        new ExpectationReached(expect, priority, explanation), true);
                                }
                                else
                                {
                                    expectation.Explain = explanation;
                                }
                                break;

                            case acceptor.ExpectationKind.aContinuous:
                                if (expectation.getCondition() != null)
                                {
                                    if (!getBoolValue(expectation, expectation.ConditionTree, explanation))
                                    {
                                        // An continuous expectation who reached its satisfactory condition
                                        EventTimeLine.AddModelEvent(
                                            new ExpectationReached(expect, priority, explanation), true);
                                    }
                                    else
                                    {
                                        if (!getBoolValue(expectation, expectation.Expression, explanation))
                                        {
                                            // A continuous expectation who reached a case where it is not satisfied
                                            EventTimeLine.AddModelEvent(
                                                new FailedExpectation(expect, priority, explanation), true);
                                        }
                                        else
                                        {
                                            expectation.Explain = explanation;
                                        }
                                    }
                                }
                                else
                                {
                                    if (!getBoolValue(expectation, expectation.Expression, explanation))
                                    {
                                        // A continuous expectation who reached a case where it is not satisfied
                                        EventTimeLine.AddModelEvent(
                                            new FailedExpectation(expect, priority, explanation), true);
                                    }
                                    else
                                    {
                                        expectation.Explain = explanation;
                                    }
                                }
                                break;
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        expectation.AddErrorAndExplain(e.Message, explanation);
                    }
                }
            }
        }