void _phoneController_StateChanged(object sender, UnderControl.Shared.PhoneControllerStateEventArgs e)
        {
            IsPhoneDeviceReady = e.State == PhoneControllerState.Ready;

            // depending on the current phone controller state, we perform different actions:
            // * try to re-initialize if the controller has closed
            // * send the initial configuration and activate/deactivate data acquisition when the controller is ready
            // * update our status display in every case
            switch (e.State)
            {
                case PhoneControllerState.Initialized:
                    Status = "Waiting for a client connection...";
                    break;
                case PhoneControllerState.Ready:
                    Status = "Phone is connected!";

                    // send config
                    InitializeConfiguration();

                    // send all required commands
                    InitializeAccelerometer();
                    InitializeTouch();
                    InitializeTapGestures();
                    InitializeTextInput();
                    break;
                case PhoneControllerState.Closing:
                    Status = "Connection to phone is closing.";
                    break;
                case PhoneControllerState.Closed:
                    Status = "Connection to phone closed.";

                    // try to re-initialize
                    Initialize();
                    break;
                case PhoneControllerState.Error:
                    Status = "Error";
                    break;
            }
        }
 void _phoneController_DataMessageReceived(object sender, UnderControl.Shared.Data.DataMessageEventArgs e)
 {
     // let all input messages be processed by the input emulator
     try
     {
         _inputEmulator.Process(e.DataMessage);
     }
     catch (Exception ex)
     {
         // that kind of input injection has some potential for failures,
         // for example when the secure desktop (UAC) is active we cannot
         // inject input that way and will receive an error.
         AddError(string.Format("Error while processing input data of type {0}: {1}", e.DataMessage.DataType, ex.Message));
     }
 }
        void _phoneController_Error(object sender, UnderControl.Shared.ErrorEventArgs e)
        {
            IsPhoneDeviceReady = _phoneController.State == PhoneControllerState.Ready;

            //add a message for the user...
            AddError(e.Error.Message);

            try
            {
                // ...then shut down. this eventually leads to a transition to the "Closed"
                // state, which in turn triggers a re-initialization of the controller
                // (in the PhoneController_StateChanged method).
                _phoneController.Shutdown();
            }
            catch (Exception ex)
            {
                AddError("Error while shutting down controller: " + ex.Message);
            }
        }
        void DataSource_DataTypesChanged(object sender, UnderControl.Shared.Data.DataTypesChangedEventArgs e)
        {
            _logger.Trace("Received DataTypesChanged event from controller client");

            AdjustDataTypesVisibility(e.NewDataTypes);
            InitializeDataSource(e.NewDataTypes);
        }
        void controllerClient_StateChanged(object sender, UnderControl.Shared.PhoneControllerStateEventArgs e)
        {
            if (_waitForInitializedState && e.State != PhoneControllerState.Initialized)
            {
                return;
            }
            _waitForInitializedState = false;

            //let's see what we should do
            switch (e.State)
            {
                case PhoneControllerState.Closed:
                    NavigateBackToMainPage();
                    break;
                case PhoneControllerState.Ready:
                    // stop timer if applicable
                    if (_timer != null)
                    {
                        _timer.Stop();
                        _timer = null;
                    }
                    IsWaitingForConnection = false;

                    //initial setup
                    AdjustInputMarginThickness();
                    var activeDataTypes = ApplicationContext.Current.ControllerClient.DataSource.GetActiveDataTypes();
                    AdjustDataTypesVisibility(activeDataTypes);
                    InitializeDataSource(activeDataTypes);
                    break;
            }
        }
        void controllerClient_Error(object sender, UnderControl.Shared.ErrorEventArgs e)
        {
            if (_timer != null)
            {
                _timer.Stop();
                _timer = null;
            }
            IsWaitingForConnection = false;

            //show to the user
            MessageBox.Show("An unexpected error occurrred:" + e.Error.Message);

            NavigateBackToMainPage();
        }
Example #7
0
        void controller_StateChanged(object sender, UnderControl.Shared.PhoneControllerStateEventArgs e)
        {
            _logger.Trace("Received StateChanged event of controller client");

            if (e.State == PhoneControllerState.Ready)
            {
                _logger.Trace("Navigating to page InputPage");

                HidePrompt();

                ApplicationContext.Current.NavigationService.Navigate(new Uri("/InputPage.xaml", UriKind.Relative));
            }
        }
Example #8
0
        void controller_Error(object sender, UnderControl.Shared.ErrorEventArgs e)
        {
            HidePrompt();

            try
            {
                // shut down the controller
                ApplicationContext.Current.ControllerClient.Shutdown();
            }
            catch (PhoneControllerException)
            {
                // ignore if this error happens
            }

            // give the message prompt (if applicable)
            //a chance to hide itself before we show a message box
            Deployment.Current.Dispatcher.BeginInvoke(() =>
                {
                    var technicalDetails = e.Error.ErrorCode ?? e.Error.Message;
                    var message =
                        string.Format(
                            "An error occurred while communicating to the server. Please try again later.{0}Technical details: '{1}'",
                            Environment.NewLine,
                            technicalDetails);
                    MessageBox.Show(message);
                });
        }