示例#1
0
文件: Status.cs 项目: magseet/AttiLA
        public void ReportPrediction(string contextId)
        {
            lock (lockStatus)
            {
                if (_process.CurrentState == State.WaitForCorrectPrediction ||
                    _process.CurrentState == State.Tracking)
                {
                    if (contextId == null || contextId != _currentContextId)
                    {
                        // error notification
                        var errorArgs = new StatusErrorNotificationEventArgs(
                            StatusErrorNotificationCode.UnexpectedPrediction
                            );
                        ThreadPool.QueueUserWorkItem(new WaitCallback(
                                                         (object o) => StatusErrorNotification(this, errorArgs)));
                    }
                    else
                    {
                        // expected prediction (correct)
                        var nextState = _process.MoveNext(Command.CorrectPrediction);
                        //expected state: WaitForWrongPrediction
                        _timer.Stop();
                        EnterState(nextState);
                    }
                }
                else if (_process.CurrentState == State.WaitForWrongPrediction)
                {
                    if (contextId == null || contextId != _currentContextId)
                    {
                        // expected prediction (wrong)
                        var nextState = _process.MoveNext(Command.WrongPrediction);
                        //expected state: WaitForConfirmation
                        EnterState(nextState);

                        var userInteractionArgs = new UserInteractionEventArgs
                        {
                            Code = UserInteractionCode.BetterContextFound,
                            BetterContextFoundValue = contextId
                        };
                        ThreadPool.QueueUserWorkItem(new WaitCallback(
                                                         (object o) => UserInteraction(this, userInteractionArgs)));
                    }
                }
                else if (_process.CurrentState == State.WaitForConfirmation)
                {
                    // expected prediction
                    var nextState = _process.MoveNext(Command.CorrectPrediction);
                    //expected state: WaitForWrongPrediction
                    EnterState(nextState);
                }
            }
        }
示例#2
0
        void _status_StatusErrorNotification(object sender, StatusErrorNotificationEventArgs e)
        {
            StatusErrorNotificationEventArgs args = (StatusErrorNotificationEventArgs)e;

            switch (args.Code)
            {
            case StatusErrorNotificationCode.TrackingSessionFailed:
                break;

            case StatusErrorNotificationCode.UnexpectedPrediction:
                break;
            }
        }
示例#3
0
        void _status_StatusErrorNotification(object sender, StatusErrorNotificationEventArgs e)
        {
            var args = e as StatusErrorNotificationEventArgs;

            Debug.WriteLine("[BleDA] StatusErrorNotification: " + args.Code.ToString());
            switch (args.Code)
            {
            case StatusErrorNotificationCode.UnexpectedPrediction:
                break;

            case StatusErrorNotificationCode.TrackingSessionFailed:
                _status.NotifyIcon.ShowBalloonTip(Properties.Resources.PopupWarning, Properties.Resources.MsgAlignmentFailed, BalloonIcon.Warning);
                break;

            default:
                break;
            }
        }
示例#4
0
文件: Status.cs 项目: magseet/AttiLA
        /// <summary>
        /// Timer event handler.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void _timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            _timer.Stop();

            State nextState = State.Unknown, leavingState = _process.CurrentState;
            UserInteractionEventArgs         userInteractionArgs;
            StatusErrorNotificationEventArgs errorArgs;

            lock (lockStatus)
            {
                switch (leavingState)
                {
                case State.WaitForCorrectPrediction:
                    // error notification
                    errorArgs = new StatusErrorNotificationEventArgs(
                        StatusErrorNotificationCode.TrackingSessionFailed
                        );
                    ThreadPool.QueueUserWorkItem(new WaitCallback(
                                                     (object o) => StatusErrorNotification(this, errorArgs)));

                    nextState = _process.MoveNext(Command.None);
                    //expected state: WaitForSelection
                    break;

                case State.Tracking:
                    userInteractionArgs = new UserInteractionEventArgs
                    {
                        Code = UserInteractionCode.TrackingSessionSucceded
                    };
                    ThreadPool.QueueUserWorkItem(new WaitCallback(
                                                     (object o) => UserInteraction(this, userInteractionArgs)));

                    nextState = _process.MoveNext(Command.None);
                    //expected state: WaitForWrongPrediction
                    break;

                default:
                    break;
                }

                EnterState(nextState);
            }
        }
示例#5
0
文件: Status.cs 项目: magseet/AttiLA
        /// <summary>
        /// Inform about User context selection
        /// </summary>
        /// <param name="contextId"></param>
        /// <exception cref="SettingsException"></exception>
        /// <returns></returns>
        public bool ContextSelected(string contextId)
        {
            if (contextId == null)
            {
                throw new ArgumentNullException("contextId");
            }

            if (!EntityService <Context> .IsValidObjectID(contextId))
            {
                throw new ArgumentOutOfRangeException("contextId");
            }
            lock (lockStatus)
            {
                State nextState;
                if (contextId != CurrentContextId)
                {
                    // notify that the selection is different than the previous one
                    var userInteractionArgs = new UserInteractionEventArgs
                    {
                        Code = UserInteractionCode.NewContextSelected
                    };
                    ThreadPool.QueueUserWorkItem(new WaitCallback(
                                                     (object o) => UserInteraction(this, userInteractionArgs)));

                    CurrentContextId = contextId;
                    // new context selected
                    _timer.Stop();
                    nextState = _process.MoveNext(Command.Selection);
                    //expected state: WaitForCorrectPrediction

                    try
                    {
                        EnterState(nextState);
                    }
                    catch (StatusException se)
                    {
                        // error notification
                        var errorArgs = new StatusErrorNotificationEventArgs(
                            StatusErrorNotificationCode.TrackingSessionFailed,
                            se
                            );
                        ThreadPool.QueueUserWorkItem(new WaitCallback(
                                                         (object o) => StatusErrorNotification(this, errorArgs)));
                    }
                }
                else if (_process.CurrentState == State.WaitForConfirmation)
                {
                    // confirmation
                    nextState = _process.MoveNext(Command.Confirmation);
                    //expected state: Tracking

                    try
                    {
                        EnterState(nextState);
                    }
                    catch (StatusException se)
                    {
                        // error notification
                        var errorArgs = new StatusErrorNotificationEventArgs(
                            StatusErrorNotificationCode.TrackingSessionFailed,
                            se
                            );
                        ThreadPool.QueueUserWorkItem(new WaitCallback(
                                                         (object o) => StatusErrorNotification(this, errorArgs)));
                    }
                }
                else
                {
                    // if the service is in Idle, need to be put in notification
                    AwakeService();
                }
            }
            return(true);
        }