示例#1
0
 private void btnSilence_Click(object sender, EventArgs e)
 {
     _serviceClient.Silence();
 }
示例#2
0
文件: Status.cs 项目: magseet/AttiLA
        private void EnterState(State state)
        {
            UserInteractionEventArgs userInteractionArgs;
            bool trackingStarted;

            lock (lockStatus)
            {
                switch (_process.CurrentState)
                {
                case State.Idle:
                    // retrieve service status
                    ServiceStatus serviceStatus = null;
                    for (var attempts = Properties.Settings.Default.ClientRetries + 1;
                         attempts > 0; attempts--)
                    {
                        try
                        {
                            serviceStatus = ServiceStatus;
                            if (serviceStatus != null)
                            {
                                break;
                            }
                        }
                        catch { }
                    }

                    if (serviceStatus != null && serviceStatus.ContextId != null)
                    {
                        CurrentContextId = serviceStatus.ContextId;
                        // notify that AttiLA had a context
                        userInteractionArgs = new UserInteractionEventArgs
                        {
                            Code = UserInteractionCode.PreviousContextFound,
                            PreviousContextFoundValue = serviceStatus.ContextId
                        };
                        ThreadPool.QueueUserWorkItem(new WaitCallback(
                                                         (object o) => UserInteraction(this, userInteractionArgs)));
                    }

                    break;

                case State.WaitForSelection:
                    //Eventually stop notifications
                    _serviceClient.Silence();
                    break;

                case State.WaitForCorrectPrediction:

                    _timer.Enabled  = true;
                    _timer.Interval = Properties.Settings.Default.ClientTimeout;

                    // tracking start
                    trackingStarted = false;
                    for (var attempts = Properties.Settings.Default.ClientRetries + 1;
                         attempts > 0; attempts--)
                    {
                        try
                        {
                            trackingStarted = _serviceClient.TrackingStart(CurrentContextId);
                            if (trackingStarted)
                            {
                                break;
                            }
                        }
                        catch { }
                    }
                    if (!trackingStarted)
                    {
                        throw new StatusException(Properties.Resources.MsgTrackingStartFailure)
                              {
                                  Code = StatusExceptionCode.ServiceFailure
                              };
                    }
                    break;

                case State.WaitForWrongPrediction:
                    _serviceClient.TrackingStop();

                    userInteractionArgs = new UserInteractionEventArgs
                    {
                        Code = UserInteractionCode.CurrentContextFound
                    };
                    ThreadPool.QueueUserWorkItem(new WaitCallback(
                                                     (object o) => UserInteraction(this, userInteractionArgs)));

                    break;

                case State.WaitForConfirmation:
                    // Do nothing
                    break;

                case State.Tracking:
                    _timer.Enabled  = true;
                    _timer.Interval = Properties.Settings.Default.ClientTimeout;

                    // tracking start
                    trackingStarted = false;
                    for (var attempts = Properties.Settings.Default.ClientRetries + 1;
                         attempts > 0; attempts--)
                    {
                        try
                        {
                            trackingStarted = _serviceClient.TrackingStart(CurrentContextId);
                            if (trackingStarted)
                            {
                                break;
                            }
                        }
                        catch { }
                    }
                    if (!trackingStarted)
                    {
                        throw new StatusException(Properties.Resources.MsgTrackingStartFailure)
                              {
                                  Code = StatusExceptionCode.ServiceFailure
                              };
                    }
                    break;

                default:
                    break;
                }
            }
        }