Esempio n. 1
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="listener">A listener that wishes to be notified about device events.</param>
        public DeviceDetector(IDeviceEventListener listener)
        {
            _deviceEventListener = listener;

            // Setup UPnP device detection.
            UPnPConfiguration.LOGGER = new Tve3Logger();
            _upnpControlPointData    = new CPData();
            _upnpAgent = new UPnPNetworkTracker(_upnpControlPointData);
            _upnpAgent.RootDeviceAdded   += OnUpnpRootDeviceAdded;
            _upnpAgent.RootDeviceRemoved += OnUpnpRootDeviceRemoved;
            _upnpControlPoint             = new UPnPControlPoint(_upnpAgent);

            // Setup other (BDA, PBDA, WDM) device detection.
            try
            {
                InitBdaDetectionGraph();
            }
            catch (Exception ex)
            {
                Log.Log.Error("Failed to initialise the BDA device detection graph!\r\n{0}", ex);
                throw;
            }
            _systemDeviceChangeEventWatcher = new ManagementEventWatcher();
            // EventType 2 and 3 are device arrival and removal. See:
            // http://msdn.microsoft.com/en-us/library/windows/desktop/aa394124%28v=vs.85%29.aspx
            _systemDeviceChangeEventWatcher.Query         = new WqlEventQuery("SELECT * FROM Win32_DeviceChangeEvent WHERE EventType = 2 OR EventType = 3");
            _systemDeviceChangeEventWatcher.EventArrived += OnSystemDeviceConnectedOrDisconnected;
        }
Esempio n. 2
0
    /// <summary>
    /// Constructor.
    /// </summary>
    /// <param name="listener">A listener that wishes to be notified about device events.</param>
    public DeviceDetector(IDeviceEventListener listener)
    {
      _deviceEventListener = listener;

      // Setup UPnP device detection.
      UPnPConfiguration.LOGGER = new Tve3Logger();
      _upnpControlPointData = new CPData();
      _upnpAgent = new UPnPNetworkTracker(_upnpControlPointData);
      _upnpAgent.RootDeviceAdded += OnUpnpRootDeviceAdded;
      _upnpAgent.RootDeviceRemoved += OnUpnpRootDeviceRemoved;
      _upnpControlPoint = new UPnPControlPoint(_upnpAgent);

      // Setup other (BDA, PBDA, WDM) device detection.
      try
      {
        InitBdaDetectionGraph();
      }
      catch (Exception ex)
      {
        Log.Log.Error("Failed to initialise the BDA device detection graph!\r\n{0}", ex);
        throw;
      }
      _systemDeviceChangeEventWatcher = new ManagementEventWatcher();
      // EventType 2 and 3 are device arrival and removal. See:
      // http://msdn.microsoft.com/en-us/library/windows/desktop/aa394124%28v=vs.85%29.aspx
      _systemDeviceChangeEventWatcher.Query = new WqlEventQuery("SELECT * FROM Win32_DeviceChangeEvent WHERE EventType = 2 OR EventType = 3");
      _systemDeviceChangeEventWatcher.EventArrived += OnSystemDeviceConnectedOrDisconnected;
    }
Esempio n. 3
0
 public void Register(IDeviceEventListener listener)
 {
     _listeners.Add(listener);
 }
Esempio n. 4
0
 public void UnRegister(IDeviceEventListener listener)
 {
     _listeners.Remove(listener);
 }