Example #1
0
        protected override bool ObservedDataMeetControlCriterion(Dictionary <Type, List <IDatum> > typeData)
        {
            bool satisfied = false;

            // if there is no ongoing control statement, then check all available statements.
            if (_ongoingControlStatement == null)
            {
                foreach (AsplStatement statement in Statements)
                {
                    if (statement.Criterion.SatisfiedBy(typeData))
                    {
                        _statementToBeginControl = statement;
                        satisfied = true;
                        break;
                    }
                }
            }
            // otherwise, recheck the criterion of the ongoing control statement. we'll continue
            // with control as long as the ongoing criterion continues to be satisfied. we will
            // not switch to a new control statement until the current one becomes unsatisfied.
            else
            {
                satisfied = _ongoingControlStatement.Criterion.SatisfiedBy(typeData);
            }

            return(satisfied);
        }
Example #2
0
        protected override async Task OnStateChangedAsync(SensingAgentState previousState, SensingAgentState currentState, CancellationToken cancellationToken)
        {
            await base.OnStateChangedAsync(previousState, currentState, cancellationToken);

            List <ProtocolSetting> newSettings = new List <ProtocolSetting>();

            // first gather up settings to apply as a result of exiting the previous state

            if (previousState == SensingAgentState.ActiveObservation)
            {
                newSettings.AddRange(EndActiveObservationSettings);
            }

            // next gather up settings to apply as a result of entering the current state

            if (currentState == SensingAgentState.ActiveObservation)
            {
                newSettings.AddRange(BeginActiveObservationSettings);
            }
            else if (currentState == SensingAgentState.OpportunisticControl || currentState == SensingAgentState.ActiveControl)
            {
                // hang on to the begin-control statement. we need ensure that the
                // same statement used to begin control is also used to end it.
                _ongoingControlStatement = _statementToBeginControl;

                // reset the begin-control statement. we won't set it again until
                // control has ended and we've reset the ongoing control statement.
                _statementToBeginControl = null;

                // add the begin-control settings
                newSettings.AddRange(_ongoingControlStatement.BeginControlSettings);

                // update state description to include the ongoing-control statement
                StateDescription += ":  " + _ongoingControlStatement.Id;
            }
            else if (currentState == SensingAgentState.EndingControl)
            {
                newSettings.AddRange(_ongoingControlStatement.EndControlSettings);
                _ongoingControlStatement = null;
            }

            if (newSettings.Count > 0)
            {
                SensusServiceHelper.Logger.Log("Applying " + newSettings.Count + " protocol setting(s) for transition from " + previousState + " to " + currentState + ".", LoggingLevel.Normal, GetType());
                await(Protocol as Protocol).ApplySettingsAsync(newSettings, cancellationToken);
            }
        }