Esempio n. 1
0
        private async void ConnectToDevice_Click(Object sender, RoutedEventArgs eventArgs)
        {
            var             selection = ConnectDevices.SelectedItems;
            DeviceListEntry entry     = null;

            if (selection.Count > 0)
            {
                var obj = selection[0];
                entry = (DeviceListEntry)obj;

                if (entry != null)
                {
                    // Create an EventHandlerForDevice to watch for the device we are connecting to
                    EventHandlerForDevice.CreateNewEventHandlerForDevice();

                    // Get notified when the device was successfully connected to or about to be closed
                    EventHandlerForDevice.Current.OnDeviceConnected = this.OnDeviceConnected;
                    EventHandlerForDevice.Current.OnDeviceClose     = this.OnDeviceClosing;

                    // It is important that the FromIdAsync call is made on the UI thread because the consent prompt can only be displayed
                    // on the UI thread. Since this method is invoked by the UI, we are already in the UI thread.
                    Boolean openSuccess = await EventHandlerForDevice.Current.OpenDeviceAsync(entry.DeviceInformation, entry.DeviceSelector);

                    // Disable connect button if we connected to the device
                    UpdateConnectDisconnectButtonsAndList(!openSuccess);
                }
            }
        }
        private async void OnDeviceClosing(EventHandlerForDevice sender, DeviceInformation deviceInformation)
        {
            UnregisterFromInputReportEvent();

            await rootPage.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, new DispatchedHandler(() =>
            {
                UpdateRegisterEventButtons();
            }));
        }
Esempio n. 3
0
        /// <summary>
        /// If all the devices have been enumerated, select the device in the list we connected to. Otherwise let the EnumerationComplete event
        /// from the device watcher handle the device selection
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="deviceInformation"></param>
        private void OnDeviceConnected(EventHandlerForDevice sender, DeviceInformation deviceInformation)
        {
            // Find and select our connected device
            if (isAllDevicesEnumerated)
            {
                SelectDeviceInList(EventHandlerForDevice.Current.DeviceInformation.Id);

                ButtonDisconnectFromDevice.Content = ButtonNameDisconnectFromDevice;
            }

            rootPage.NotifyUser("Currently connected to: " + EventHandlerForDevice.Current.DeviceInformation.Id, NotifyType.StatusMessage);
        }
Esempio n. 4
0
 /// <summary>
 /// The device was closed. If we will autoreconnect to the device, reflect that in the UI
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="deviceInformation"></param>
 private async void OnDeviceClosing(EventHandlerForDevice sender, DeviceInformation deviceInformation)
 {
     await rootPage.Dispatcher.RunAsync(
         CoreDispatcherPriority.Normal,
         new DispatchedHandler(() =>
     {
         // We were connected to the device that was unplugged, so change the "Disconnect from device" button
         // to "Do not reconnect to device"
         if (ButtonDisconnectFromDevice.IsEnabled && EventHandlerForDevice.Current.IsEnabledAutoReconnect)
         {
             ButtonDisconnectFromDevice.Content = ButtonNameDisableReconnectToDevice;
         }
     }));
 }
        /// <summary>
        /// The device was closed. If we will autoreconnect to the device, reflect that in the UI
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="deviceInformation"></param>
        private async void OnDeviceClosing(EventHandlerForDevice sender, DeviceInformation deviceInformation)
        {
            await rootPage.Dispatcher.RunAsync(
                CoreDispatcherPriority.Normal,
                new DispatchedHandler(() =>
            {
                // We were connected to the device that was unplugged, so change the "Disconnect from device" button
                // to "Do not reconnect to device"
                if (ButtonDisconnectFromDevice.IsEnabled && EventHandlerForDevice.Current.IsEnabledAutoReconnect)
                {
                    ButtonDisconnectFromDevice.Content = ButtonNameDisableReconnectToDevice;

                    UpdateConnectDisconnectButtonsAndList(false);
                }
                else
                {
                    // We don't plan on automatically reconnecting to a device, so enable the connect button
                    UpdateConnectDisconnectButtonsAndList(true);
                }
            }));
        }
        /// <summary>
        /// If all the devices have been enumerated, select the device in the list we connected to. Otherwise let the EnumerationComplete event
        /// from the device watcher handle the device selection
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="onDeviceConnectedEventArgs"></param>
        private void OnDeviceConnected(EventHandlerForDevice sender, OnDeviceConnectedEventArgs onDeviceConnectedEventArgs)
        {
            // Find and select our connected device
            if (isAllDevicesEnumerated)
            {
                ButtonDisconnectFromDevice.Content = ButtonNameDisconnectFromDevice;

                if (onDeviceConnectedEventArgs.IsDeviceSuccessfullyConnected)
                {
                    SelectDeviceInList(EventHandlerForDevice.Current.DeviceInformation.Id);

                    UpdateConnectDisconnectButtonsAndList(false);

                    rootPage.NotifyUser("Currently connected to: " + EventHandlerForDevice.Current.DeviceInformation.Id, NotifyType.StatusMessage);
                }
                else
                {
                    // Prevent auto reconnect from occuring
                    EventHandlerForDevice.Current.IsEnabledAutoReconnect = false;

                    UpdateConnectDisconnectButtonsAndList(true);
                }
            }
        }
 /// <summary>
 /// Creates a new instance of EventHandlerForDevice, enables auto reconnect, and uses it as the Current instance.
 /// </summary>
 public static void CreateNewEventHandlerForDevice()
 {
     eventHandlerForDevice = new EventHandlerForDevice();
 }
Esempio n. 8
0
 /// <summary>
 /// Creates a new instance of EventHandlerForDevice, enables auto reconnect, and uses it as the Current instance.
 /// </summary>
 public static void CreateNewEventHandlerForDevice()
 {
     eventHandlerForDevice = new EventHandlerForDevice();
 }
        private async void OnDeviceClosing(EventHandlerForDevice sender, DeviceInformation deviceInformation)
        {
            UnregisterFromInputReportEvent();

            await rootPage.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, new DispatchedHandler(() =>
                {
                    UpdateRegisterEventButtons();
                }));
        }
        /// <summary>
        /// The device was closed. If we will autoreconnect to the device, reflect that in the UI
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="deviceInformation"></param>
        private async void OnDeviceClosing(EventHandlerForDevice sender, DeviceInformation deviceInformation)
        {
            await rootPage.Dispatcher.RunAsync(
                CoreDispatcherPriority.Normal,
                new DispatchedHandler(() =>
                {
                    // We were connected to the device that was unplugged, so change the "Disconnect from device" button
                    // to "Do not reconnect to device"
                    if (ButtonDisconnectFromDevice.IsEnabled && EventHandlerForDevice.Current.IsEnabledAutoReconnect)
                    {
                        ButtonDisconnectFromDevice.Content = ButtonNameDisableReconnectToDevice;

                        UpdateConnectDisconnectButtonsAndList(false);
                    }
                    else
                    {
                        // We don't plan on automatically reconnecting to a device, so enable the connect button
                        UpdateConnectDisconnectButtonsAndList(true);
                    }
                }));
        }
        /// <summary>
        /// If all the devices have been enumerated, select the device in the list we connected to. Otherwise let the EnumerationComplete event
        /// from the device watcher handle the device selection
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="onDeviceConnectedEventArgs"></param>
        private void OnDeviceConnected(EventHandlerForDevice sender, OnDeviceConnectedEventArgs onDeviceConnectedEventArgs)
        {
            // Find and select our connected device
            if (isAllDevicesEnumerated)
            {
                ButtonDisconnectFromDevice.Content = ButtonNameDisconnectFromDevice;

                if (onDeviceConnectedEventArgs.IsDeviceSuccessfullyConnected)
                {
                    SelectDeviceInList(EventHandlerForDevice.Current.DeviceInformation.Id);

                    UpdateConnectDisconnectButtonsAndList(false);

                    rootPage.NotifyUser("Currently connected to: " + EventHandlerForDevice.Current.DeviceInformation.Id, NotifyType.StatusMessage);
                }
                else
                {
                    // Prevent auto reconnect from occuring
                    EventHandlerForDevice.Current.IsEnabledAutoReconnect = false;

                    UpdateConnectDisconnectButtonsAndList(true);
                }
            }
        }
 /// <summary>
 /// The device was closed. If we will autoreconnect to the device, reflect that in the UI
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="deviceInformation"></param>
 private async void OnDeviceClosing(EventHandlerForDevice sender, DeviceInformation deviceInformation)
 {
     await rootPage.Dispatcher.RunAsync(
         CoreDispatcherPriority.Normal,
         new DispatchedHandler(() =>
         {
             // We were connected to the device that was unplugged, so change the "Disconnect from device" button
             // to "Do not reconnect to device"
             if (ButtonDisconnectFromDevice.IsEnabled && EventHandlerForDevice.Current.IsEnabledAutoReconnect)
             {
                 ButtonDisconnectFromDevice.Content = ButtonNameDisableReconnectToDevice;
             }
         }));
 }
        /// <summary>
        /// If all the devices have been enumerated, select the device in the list we connected to. Otherwise let the EnumerationComplete event
        /// from the device watcher handle the device selection
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="deviceInformation"></param>
        private void OnDeviceConnected(EventHandlerForDevice sender, DeviceInformation deviceInformation)
        {
            // Find and select our connected device
            if (isAllDevicesEnumerated)
            {
                SelectDeviceInList(EventHandlerForDevice.Current.DeviceInformation.Id);

                ButtonDisconnectFromDevice.Content = ButtonNameDisconnectFromDevice;
            }

            rootPage.NotifyUser("Currently connected to: " + EventHandlerForDevice.Current.DeviceInformation.Id, NotifyType.StatusMessage);
        }