private void EnumerateDevices()
        {
            if ((_deviceNameCache != null) && (_deviceIdCache != null))
            {
                return;
            }

            uint deviceCount = 0;

            _portableDeviceManager.GetDevices(null, ref deviceCount);

            var deviceIds = new string[deviceCount];

            _portableDeviceManager.GetDevices(deviceIds, ref deviceCount);

            var devices = deviceIds.Select(CreateDevice).ToList();

            _deviceNameCache = devices.ToDictionary(device => device.Name);
            _deviceIdCache   = devices.ToDictionary(device => device.Id);
        }
Exemple #2
0
        private static List <PortableDevice> EnumerateAllDevices(IPortableDeviceManager deviceManager)
        {
            uint deviceCount = 0;

            deviceManager.RefreshDeviceList();
            deviceManager.GetDevices(null, ref deviceCount);

            var devices = new List <PortableDevice>();

            if (deviceCount == 0)
            {
                return(devices);
            }

            var deviceIds = new string[deviceCount];

            deviceManager.GetDevices(deviceIds, ref deviceCount);

            devices.AddRange(deviceIds.Select(id => CreateDevice(deviceManager, id)));

            return(devices);
        }