Example #1
0
 internal DeviceManager(
     IPortableDeviceManager portableDeviceManager,
     IDeviceFactory deviceFactory)
 {
     _portableDeviceManager = portableDeviceManager;
     _deviceFactory         = deviceFactory;
 }
        private static string GetDeviceStringProperty(
            IPortableDeviceManager deviceManager,
            string deviceId,
            Func <IPortableDeviceManager, string, ushort[], uint, uint> propertyGetter)
        {
            uint propertyValueCount = 0;

            try
            {
                // First, pass NULL to get the total number of characters to allocate for the string value.
                propertyValueCount = propertyGetter(deviceManager, deviceId, null, 0);
            }
            catch (Exception exception)
            {
                Console.WriteLine("-- Exception reading property for device {0}", deviceId);
                Console.WriteLine(exception);
                Console.WriteLine();
            }

            if (propertyValueCount == 0)
            {
                return(null);
            }

            var propertyValue = new ushort[propertyValueCount];

            propertyGetter(deviceManager, deviceId, propertyValue, propertyValueCount);

            return(ConvertToString(propertyValue));
        }
Example #3
0
 internal DeviceManager(
     IPortableDeviceManager portableDeviceManager,
     IDeviceFactory deviceFactory)
 {
     _portableDeviceManager = portableDeviceManager;
     _deviceFactory = deviceFactory;
 }
Example #4
0
 internal DeviceFactory(
     IPortableDeviceManager portableDeviceManager)
 {
     _portableDeviceManager = portableDeviceManager;
     _portableDeviceFactory = new PortableDeviceFactory();
     _portableDeviceHelper = new PortableDeviceHelper();
     _deviceStreamFactory = new DeviceStreamFactory();
 }
Example #5
0
 internal DeviceFactory(
     IPortableDeviceManager portableDeviceManager)
 {
     _portableDeviceManager = portableDeviceManager;
     _portableDeviceFactory = new PortableDeviceFactory();
     _portableDeviceHelper  = new PortableDeviceHelper();
     _deviceStreamFactory   = new DeviceStreamFactory();
 }
Example #6
0
 private static PortableDevice CreateDevice(IPortableDeviceManager deviceManager, string deviceId)
 {
     return(new PortableDevice
     {
         Id = deviceId,
         FriendlyName = GetFriendlyName(deviceManager, deviceId),
         Description = GetDescription(deviceManager, deviceId)
     });
 }
 /// <summary>
 /// turns a manufacturers id into a friendly name
 /// </summary>
 /// <param name="portableDeviceManager">device manager</param>
 /// <param name="deviceId">the id</param>
 /// <returns>name</returns>
 public string GetDeviceFriendlyName(IPortableDeviceManager portableDeviceManager, string deviceId)
 {
     return(GetDeviceStringProperty(
                portableDeviceManager,
                deviceId,
                (dm, id, value, count) =>
     {
         dm.GetDeviceFriendlyName(id, value, ref count);
         return count;
     }));
 }
 /// <summary>
 /// turns a manufacturers id into a friendly name
 /// </summary>
 /// <param name="portableDeviceManager">device manager</param>
 /// <param name="deviceId">the id</param>
 /// <returns>name</returns>
 public string GetDeviceFriendlyName(IPortableDeviceManager portableDeviceManager, string deviceId)
 {
     return GetDeviceStringProperty(
         portableDeviceManager,
         deviceId,
         (dm, id, value, count) =>
         {
             dm.GetDeviceFriendlyName(id, value, ref count);
             return count;
         });
 }
Example #9
0
 private static string GetDescription(
     IPortableDeviceManager deviceManager,
     string deviceId)
 {
     return(GetDeviceStringProperty(
                deviceManager,
                deviceId,
                (dm, id, value, count) =>
     {
         dm.GetDeviceDescription(id, value, ref count);
         return count;
     }));
 }
Example #10
0
 internal Device(
     IPortableDeviceManager portableDeviceManager,
     IPortableDeviceFactory portableDeviceFactory,
     IPortableDeviceHelper portableDeviceHelper,
     IDeviceStreamFactory deviceStreamFactory,
     string id)
 {
     _portableDeviceManager = portableDeviceManager;
     _portableDeviceFactory = portableDeviceFactory;
     _portableDeviceHelper  = portableDeviceHelper;
     _deviceStreamFactory   = deviceStreamFactory;
     Id = id;
     OpenDevice(id);
 }
Example #11
0
 internal Device(
     IPortableDeviceManager portableDeviceManager,
     IPortableDeviceFactory portableDeviceFactory, 
     IPortableDeviceHelper portableDeviceHelper,
     IDeviceStreamFactory deviceStreamFactory,
     string id)
 {
     _portableDeviceManager = portableDeviceManager;
     _portableDeviceFactory = portableDeviceFactory;
     _portableDeviceHelper = portableDeviceHelper;
     _deviceStreamFactory = deviceStreamFactory;
     Id = id;
     OpenDevice(id);
 }
Example #12
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);
        }
        private static string GetDeviceStringProperty(
            IPortableDeviceManager deviceManager,
            string deviceId,
            Func<IPortableDeviceManager, string, ushort[], uint, uint> propertyGetter)
        {
            uint propertyValueCount = 0;

            try
            {
                // First, pass NULL to get the total number of characters to allocate for the string value.
                propertyValueCount = propertyGetter(deviceManager, deviceId, null, 0);
            }
            catch (Exception exception)
            {
                Console.WriteLine("-- Exception reading property for device {0}", deviceId);
                Console.WriteLine(exception);
                Console.WriteLine();
            }

            if (propertyValueCount == 0)
            {
                return null;
            }

            var propertyValue = new ushort[propertyValueCount];

            propertyGetter(deviceManager, deviceId, propertyValue, propertyValueCount);

            return ConvertToString(propertyValue);
        }
 public PortableDeviceCollection()
 {
     this._deviceManager = Activator.CreateInstance(typeof(CLSID_PortableDeviceManager)) as IPortableDeviceManager;
 }
Example #15
0
 internal DeviceManager(
     IPortableDeviceManager portableDeviceManager)
     : this(portableDeviceManager, new DeviceFactory(portableDeviceManager))
 {
 }
Example #16
0
 internal DeviceManager(
     IPortableDeviceManager portableDeviceManager)
     : this(portableDeviceManager, new DeviceFactory(portableDeviceManager))
 {
 }