Example #1
0
        static void m_sessionComManager_DeviceStateChanged(object sender, _DeviceStateEventArgs e)
        {
            Console.WriteLine("Session Manager event: device state changed: " + e.State);

            // if our "Active device" was unplugged, detach from it and attach to new one
            if (e.State == DeviceState.DeviceState_Removed && m_activeDevice != null && string.Compare(e.DevicePath, m_activeDevice.DevicePath, true) == 0)
            {
                DetachDevice();
                AttachDevice();
            }
            else if (e.State == DeviceState.DeviceState_Added && m_activeDevice == null)
            {
                // if device is plugged, and we don't have "Active device", just attach to it
                AttachDevice();
            }
        }
Example #2
0
        static void m_sessionComManager_DeviceStateChanged(object sender, _DeviceStateEventArgs e)
        {
            Console.WriteLine("Session Manager event: device state changed: " + e.State);

            // if our "Active device" was unplugged, detach from it and attach to new one
            if (e.State == DeviceState.DeviceState_Removed && m_activeDevice != null && string.Compare(e.DevicePath, m_activeDevice.DevicePath, true) == 0)
            {
                DetachDevice();
                AttachDevice();
            }
            else if (e.State == DeviceState.DeviceState_Added && m_activeDevice == null)
            {
                // if device is plugged, and we don't have "Active device", just attach to it
                AttachDevice();
            }
        }
        private void OnDeviceStateChanged(object sender, _DeviceStateEventArgs e)
        {
            _traceContext.Status("OnDeviceStateChanged " + e.ToString());
            Debug.WriteLine("OnDeviceStateChanged " + e.ToString());
            switch (e.State)
            {
                case DeviceState.DeviceState_Added:
                    // register event handlers
                    if (m_device != null)
                    {
                        UnRegisterEvents();
                    }

                    m_device = m_comSession.ActiveDevice;
                    RegisterEvents();
                    _notificationService.Notify(String.Format("{0} headset connected", m_device.ProductName), "Headset", NotificationType.Info, TimeSpan.FromSeconds(2));
                    break;
                case DeviceState.DeviceState_Removed:
                    // unregister event handlers
                    if (m_device != null)
                    {
                        UnRegisterEvents();
                    }
                    m_device = null;
                    _notificationService.Notify("Plantronics Headset Removed", "Headset", NotificationType.Info, TimeSpan.FromSeconds(2));
                    break;
            }
        }