public StorageServicesAdapter(PortableDevice device)
 {
     this.device         = device;
     portableDeviceClass = device.PortableDeviceClass;
     storages            = new ObservableCollection <PortableDeviceFunctionalObject>(ExtractStorageServices());
     Storages            = new ReadOnlyObservableCollection <PortableDeviceFunctionalObject>(storages);
 }
 public StorageServicesAdapter(PortableDevice device)
 {
     this.device = device;
     portableDeviceClass = device.PortableDeviceClass;
     storages = new ObservableCollection<PortableDeviceFunctionalObject>(ExtractStorageServices());
     Storages = new ReadOnlyObservableCollection<PortableDeviceFunctionalObject>(storages);
 }
示例#3
0
        public unsafe byte[] DownloadFileToStream(PortableDeviceFile file)
        {
            IPortableDeviceContent iportableDeviceContent;

            PortableDeviceClass.Content(out iportableDeviceContent);
            IPortableDeviceResources iportableDeviceResources;

            iportableDeviceContent.Transfer(out iportableDeviceResources);
            uint            num = 0;
            _tagpropertykey tagpropertykey;

            tagpropertykey.fmtid = new Guid(3894311358U, 13552, 16831, 181, 63, 241, 160, 106, 232, 120, 66);
            tagpropertykey.pid   = 0;
            PortableDeviceApiLib.IStream istream;
            iportableDeviceResources.GetStream(file.Id, ref tagpropertykey, 0U, ref num, out istream);
            var stream = (System.Runtime.InteropServices.ComTypes.IStream)istream;

            using (var memoryStream = new MemoryStream())
            {
                var count    = 0;
                var cb       = 8192;
                var numArray = new byte[cb];
                do
                {
                    stream.Read(numArray, cb, new IntPtr(&count));
                    memoryStream.Write(numArray, 0, count);
                }while (count >= cb);
                Marshal.ReleaseComObject(stream);
                Marshal.ReleaseComObject(istream);
                return(memoryStream.ToArray());
            }
        }
示例#4
0
        /// <summary>
        /// This method loads the sub folders and files within the device.
        /// NOTE: It only loads the subfolder and file information.
        /// No actual binary is loaded as this could potentially be a very
        /// piece of data in memory.
        /// </summary>
        /// <param name="portableDeviceItem"></param>
        private void LoadDeviceData(PortableDeviceClass portableDeviceItem)
        {
            IPortableDeviceContent content;

            portableDeviceItem.Content(out content);
            LoadDeviceItems(content);
        }
示例#5
0
        public PortableDeviceClass GetDevice(string deviceId)
        {
            PortableDeviceClass deviceClass = new PortableDeviceClass();

            deviceClass.Open(deviceId, _hClientDeviceValues);
            return(deviceClass);
        }
示例#6
0
        /// <summary>
        /// インスタンスを初期化します。
        /// </summary>
        /// <param name="id">デバイスの識別子。</param>
        /// <exception cref="ArgumentException">id が null 参照、もしくは空文字です。</exception>
        internal WpdDevice( string id )
        {
            if( String.IsNullOrEmpty( id ) ) { throw new ArgumentException( "'id' is null or empty." ); }

            this.Id = id;
            this._device = new PortableDeviceClass();
        }
        /// <summary>
        ///     Extract command supported by device
        /// </summary>
        /// <param name="portableDeviceClass"></param>
        internal void ExtractCommands(PortableDeviceClass portableDeviceClass)
        {
            IPortableDeviceCapabilities capabilities;

            portableDeviceClass.Capabilities(out capabilities);

            IPortableDeviceKeyCollection values;

            capabilities.GetSupportedCommands(out values);

            var             key = new _tagpropertykey();
            _tagpropertykey tt;

            uint count = 1;

            values.GetCount(ref count);
            for (uint i = 0; i < count; i++)
            {
                values.GetAt(i, ref key);

                string currentName = null;
                foreach (FieldInfo fi in typeof(PortableDevicePKeys).GetFields())
                {
                    tt = (_tagpropertykey)fi.GetValue(null);
                    if (key.fmtid == tt.fmtid && key.pid == tt.pid)
                    {
                        currentName = fi.Name;
                    }
                }

                commands.Add(currentName ?? key.pid + " " + key.fmtid, key);
            }
        }
        /// <summary>
        ///     Connect to the portable device
        /// </summary>
        /// <param name="appName"></param>
        /// <param name="majorVersionNumber"></param>
        /// <param name="minorVersionNumber"></param>
        public void ConnectToDevice(string appName, float majorVersionNumber, float minorVersionNumber)
        {
            if (string.IsNullOrEmpty(appName))
            {
                throw new ArgumentNullException("appName");
            }

            //Creating propValues for connection
            var clientValues = (IPortableDeviceValues) new PortableDeviceValuesClass();

            //Set the application name
            _tagpropertykey prop = PortableDevicePKeys.WPD_CLIENT_NAME;

            clientValues.SetStringValue(ref prop, appName);
            //Set the App version
            prop = PortableDevicePKeys.WPD_CLIENT_MAJOR_VERSION;
            clientValues.SetFloatValue(ref prop, majorVersionNumber);
            //Set the app minor version
            prop = PortableDevicePKeys.WPD_CLIENT_MINOR_VERSION;
            clientValues.SetFloatValue(ref prop, minorVersionNumber);

            //Open connection
            PortableDeviceClass.Open(DeviceId, clientValues);

            //Extract device capabilities
            ExtractDeviceCapabilities();

            eventCallback = new PortableDeviceEventCallback(this);
            // According to documentation pParameters should be null (see http://msdn.microsoft.com/en-us/library/dd375684%28v=VS.85%29.aspx )
            PortableDeviceClass.Advise(0, eventCallback, null, out adviseCookie);

            IsConnected = true;
        }
示例#9
0
        /// <summary>
        /// Construct the device by obtainin the device properties and the sub data.
        ///
        /// NOTE:
        /// There is a difference with the device id and the id.
        /// The id indicates the object id within the windows portable device.
        /// The device id indicates the object id within the operating system.
        ///
        /// The initial id for all windows portable devices is hard coded to "DEVICE"
        /// </summary>
        /// <param name="deviceId"></param>
        public Device(string deviceId, bool withDeviceItems = true) : base("DEVICE")
        {
            DeviceId        = deviceId;
            ComDeviceObject = new PortableDeviceClass();
            Connect();
            IPortableDeviceValues deviceProperties = ExtractDeviceProperties(ComDeviceObject);

            ContentType     = new ContentTypeProperty(deviceProperties);
            DeviceType      = new TypeProperty(deviceProperties);
            FirmwareVersion = new FirmwareVersionProperty(deviceProperties);
            FriendlyName    = new FriendlyNameProperty(deviceProperties);
            Manufacturer    = new ManufacturerProperty(deviceProperties);
            Model           = new ModelProperty(deviceProperties);
            Name            = new NameProperty(deviceProperties);
            SerialNumber    = new SerialNumberProperty(deviceProperties);

            if (withDeviceItems == true)
            {
                LoadDeviceData(ComDeviceObject);

                do
                {
                    System.Threading.Thread.Sleep(100);
                } while (UtilityHelper.threadList.Count > 0);
            }
            Disconnect();
        }
示例#10
0
 public void CleanUp()
 {
     if (this.device != null)
     {
         this.device.Close();
         this.device = null;
     }
 }
示例#11
0
 /// <summary>
 ///     Default constructor
 /// </summary>
 /// <param name="deviceId"></param>
 internal PortableDevice(string deviceId)
 {
     if (string.IsNullOrEmpty(deviceId))
         throw new ArgumentNullException("deviceId");
     dispatcher = new object();
     PortableDeviceClass = new PortableDeviceClass();
     values = new Dictionary<string, object>();
     DeviceId = deviceId;
     PropertiesHelper = new PropertiesHelper(this);
 }
示例#12
0
        public void Disconnect()
        {
            if (!_isConnected)
            {
                return;
            }

            PortableDeviceClass.Close();
            _isConnected = false;
        }
        /// <summary>
        ///     Execute the specified command
        /// </summary>
        /// <param name="command"></param>
        public void ExecuteCommand(_tagpropertykey command)
        {
            var commandValues = (IPortableDeviceValues) new PortableDeviceValuesClass();
            IPortableDeviceValues results;

            commandValues.SetGuidValue(ref PortableDevicePKeys.WPD_PROPERTY_COMMON_COMMAND_CATEGORY, ref command.fmtid);
            commandValues.SetUnsignedIntegerValue(ref PortableDevicePKeys.WPD_PROPERTY_COMMON_COMMAND_ID, command.pid);

            // According to documentation, first parameter should be 0 (see http://msdn.microsoft.com/en-us/library/dd375691%28v=VS.85%29.aspx)
            PortableDeviceClass.SendCommand(0, commandValues, out results);
        }
        /// <summary>
        ///     Disconnect from device
        /// </summary>
        public void Disconnect()
        {
            if (!IsConnected)
            {
                return;
            }

            PortableDeviceClass.Unadvise(adviseCookie);
            eventCallback = null;
            IsConnected   = false;
        }
示例#15
0
        public PortableDeviceFolder GetContents()
        {
            var root = new PortableDeviceFolder("DEVICE", "DEVICE");

            IPortableDeviceContent content;

            PortableDeviceClass.Content(out content);

            EnumerateContents(ref content, root);

            return(root);
        }
示例#16
0
        public WpdDevice(string deviceId)
        {
            var clientInfo = new PortableDeviceTypesLib.PortableDeviceValuesClass();

            this.device = new PortableDeviceClass();
            this.device.Open(deviceId, (IPortableDeviceValues)clientInfo);
            this.DeviceID = deviceId;
            this.device.Content(out this.content);

            this.Properties = new WpdPropertyCollection(this.Content, this.ObjectID);
            this.Properties.Refresh();
        }
示例#17
0
        /// <summary>
        /// 获取设备信息
        /// </summary>
        /// <param name="deviceId"></param>
        /// <returns></returns>
        private static IPortableDeviceContent GetDeviceContent(string deviceId)
        {
            IPortableDeviceValues clientInfo     = (IPortableDeviceValues) new PortableDeviceTypesLib.PortableDeviceValuesClass();
            PortableDeviceClass   portableDevice = new PortableDeviceClass();

            portableDevice.Open(deviceId, clientInfo);

            IPortableDeviceContent content;

            portableDevice.Content(out content);
            return(content);
        }
 /// <summary>
 ///     Default constructor
 /// </summary>
 /// <param name="deviceId"></param>
 internal PortableDevice(string deviceId)
 {
     if (string.IsNullOrEmpty(deviceId))
     {
         throw new ArgumentNullException("deviceId");
     }
     dispatcher          = new object();
     PortableDeviceClass = new PortableDeviceClass();
     values           = new Dictionary <string, object>();
     DeviceId         = deviceId;
     PropertiesHelper = new PropertiesHelper(this);
 }
示例#19
0
        public void CreateFolder(string folderName, string parentObjectId)
        {
            IPortableDeviceContent content;

            PortableDeviceClass.Content(out content);

            string objectID = null;

            var values = GetRequiredPropertiesForFolderType(folderName, parentObjectId);

            content.CreateObjectWithPropertiesOnly(values, objectID);
        }
示例#20
0
        public void Connect()
        {
            if (_isConnected)
            {
                return;
            }

            var clientInfo = (IPortableDeviceValues) new PortableDeviceValuesClass();

            PortableDeviceClass.Open(DeviceId, clientInfo);
            _isConnected = true;
        }
        /// <summary>
        /// Initialize a new instance of the <see cref="FunctionalCategory"/> class
        /// </summary>
        /// <param name="portableDeviceClass"></param>
        /// <param name="guid"></param>
        /// <param name="name"></param>
        internal FunctionalCategory(PortableDeviceClass portableDeviceClass, Guid guid, string name)
        {
            if (guid == Guid.Empty)
                throw new ArgumentException("guid cann't be Guid.Empty");
            if (string.IsNullOrEmpty(name))
                throw new ArgumentNullException("name");
            this.contentTypes = new Dictionary<Guid, ContentType>();

            this.Guid = guid;
            this.Name = name;

            this.ExtractContentType(portableDeviceClass, guid);
        }
示例#22
0
        /// <summary>
        ///     Initialize a new instance of the <see cref="ContentType" /> class
        /// </summary>
        /// <param name="portableDeviceClass"></param>
        /// <param name="guid"></param>
        /// <param name="name"></param>
        internal ContentType(PortableDeviceClass portableDeviceClass, Guid guid, string name)
        {
            if (guid == Guid.Empty)
                throw new Exception("guid cann't be Guid.Empty");
            if (string.IsNullOrEmpty(name))
                throw new ArgumentNullException("name");

            formats = new Dictionary<Guid, string>();
            Guid = guid;
            Name = name;

            ExtractSupportedFormat(portableDeviceClass, guid);
        }
        /// <summary>
        ///     Extract device capabilities
        /// </summary>
        /// <param name="portableDeviceClass"></param>
        internal void ExtractDeviceCapabilities(PortableDeviceClass portableDeviceClass)
        {
            if (portableDeviceClass == null)
            {
                throw new ArgumentNullException("portableDeviceClass");
            }

            try
            {
                IPortableDeviceCapabilities capabilities;
                portableDeviceClass.Capabilities(out capabilities);

                if (capabilities == null)
                {
                    Trace.WriteLine("Cannot extract capabilities from device");
                    throw new PortableDeviceException("Cannot extract capabilities from device");
                }

                IPortableDevicePropVariantCollection functionalCategories;
                capabilities.GetFunctionalCategories(out functionalCategories);

                if (functionalCategories == null)
                {
                    throw new PortableDeviceException("Failed to extract functionnal categories");
                }

                uint countCategories = 1;
                functionalCategories.GetCount(ref countCategories);
                var values = new tag_inner_PROPVARIANT();

                string categoryName;
                Guid   currentGuid;
                for (uint i = 0; i < countCategories; i++)
                {
                    functionalCategories.GetAt(i, ref values);
                    var pValues = (IPortableDeviceValues) new PortableDeviceValuesClass();

                    pValues.SetValue(ref PortableDevicePKeys.WPD_COMMAND_CAPABILITIES_GET_SUPPORTED_FUNCTIONAL_CATEGORIES, ref values);
                    pValues.GetStringValue(ref PortableDevicePKeys.WPD_COMMAND_CAPABILITIES_GET_SUPPORTED_FUNCTIONAL_CATEGORIES, out categoryName);
                    currentGuid = new Guid(categoryName);
                    this.functionalCategories.Add(currentGuid, new FunctionalCategory(
                                                      portableDeviceClass,
                                                      currentGuid,
                                                      PortableDeviceHelpers.GetKeyNameFromGuid(currentGuid)));
                }
            }
            catch (Exception ex)
            {
                throw new PortableDeviceException("Error on extract device capabilities", ex);
            }
        }
示例#24
0
        public EntryObjectEnumerator(Device device)
        {
            Reset();

            _hEntryManager = new EntryManager(device);
            PortableDeviceClass deviceClass = new PortableDeviceClass();

            deviceClass.Open(device.Id, DeviceManager.ClientValues);
            deviceClass.Content(out _hDeviceContent);

            _lEntryObjects = new List <EntryObject>();

            FindChild(_sCurrentObjectId, _iCurrentLevel);
        }
        private void StartEnumerate(IObjectEnumerateHelper enumHelper)
        {
            lock (dispatcher)
            {
                enumerateHelper = enumHelper;
                IPortableDeviceContent pContent;
                PortableDeviceClass.Content(out pContent);

                Content = new PortableDeviceFunctionalObject("DEVICE");
                Enumerate(ref pContent, "DEVICE", Content, enumerateHelper);

                RaisePropertyChanged("Content");
            }
        }
示例#26
0
 public EntryManager(Device device)
 {
     _hDevice        = device;
     _hDeviceManager = new DeviceManager();
     try
     {
         _hDeviceClass = _hDeviceManager.GetDevice(device.Id);
     }
     catch
     {
         MessageBox.Show("Please connect a device before fetching songs.", "ZenseMe");
         return;
     }
 }
示例#27
0
        public string CreateFolder(string folderName, string parentObjectId)
        {
            IPortableDeviceContent content;

            PortableDeviceClass.Content(out content);

            var values = GetRequiredPropertiesForFolder(folderName, parentObjectId);

            string folderId = null;

            content.CreateObjectWithPropertiesOnly(values, ref folderId);

            return(folderId);
        }
示例#28
0
        private void ExtractContentType(PortableDeviceClass portableDeviceClass, Guid functionalCategory)
        {
            if (portableDeviceClass == null)
            {
                throw new ArgumentNullException("portableDeviceClass");
            }

            try
            {
                PortableDeviceApiLib.IPortableDeviceCapabilities capabilities;
                portableDeviceClass.Capabilities(out capabilities);

                if (capabilities == null)
                {
                    System.Diagnostics.Trace.WriteLine("Cannot extract capabilities from device");
                    throw new PortableDeviceException("Cannot extract capabilities from device");
                }


                PortableDeviceApiLib.IPortableDeviceValues pValues = (PortableDeviceApiLib.IPortableDeviceValues) new PortableDeviceTypesLib.PortableDeviceValuesClass();


                //Functional objects variables
                IPortableDevicePropVariantCollection contentTypes;
                uint countObjects            = 1;
                tag_inner_PROPVARIANT values = new tag_inner_PROPVARIANT();
                string contentTypeName;
                Guid   currentContentTypeGuid;
                capabilities.GetSupportedContentTypes(ref functionalCategory, out contentTypes);

                contentTypes.GetCount(ref countObjects);
                for (uint i = 0; i < countObjects; i++)
                {
                    contentTypes.GetAt(i, ref values);

                    pValues.SetValue(ref PortableDevicePKeys.WPD_COMMAND_CAPABILITIES_GET_SUPPORTED_CONTENT_TYPES, ref values);
                    pValues.GetStringValue(ref PortableDevicePKeys.WPD_COMMAND_CAPABILITIES_GET_SUPPORTED_CONTENT_TYPES, out contentTypeName);
                    currentContentTypeGuid = new Guid(contentTypeName);
                    this.contentTypes.Add(currentContentTypeGuid, new ContentType(
                                              portableDeviceClass,
                                              currentContentTypeGuid,
                                              PortableDeviceHelpers.GetKeyNameFromGuid(currentContentTypeGuid)));
                }
            }
            catch (Exception ex)
            {
                throw new PortableDeviceException("Error on extract functional object", ex);
            }
        }
示例#29
0
        private static IPortableDevice OpenDevice(string deviceId)
        {
            var deviceValues = (IPortableDeviceValues) new PortableDeviceTypesLib.PortableDeviceValuesClass();

            deviceValues.SetStringValue(ref PortableDevicePropertyKeys.WPD_CLIENT_NAME, "Test MTP Client");
            deviceValues.SetUnsignedIntegerValue(ref PortableDevicePropertyKeys.WPD_CLIENT_MAJOR_VERSION, 1);
            deviceValues.SetUnsignedIntegerValue(ref PortableDevicePropertyKeys.WPD_CLIENT_MINOR_VERSION, 0);
            deviceValues.SetUnsignedIntegerValue(ref PortableDevicePropertyKeys.WPD_CLIENT_REVISION, 1);

            var device = new PortableDeviceClass();

            device.Open(deviceId, deviceValues);

            return(device);
        }
示例#30
0
        /// <summary>
        /// create from unique ID, this will attach PodcastUtilities as a client to the specified device
        /// </summary>
        /// <param name="deviceId">ID</param>
        /// <returns>the device</returns>
        public IPortableDevice Create(string deviceId)
        {
            var deviceValues = (IPortableDeviceValues) new PortableDeviceTypesLib.PortableDeviceValuesClass();

            deviceValues.SetStringValue(ref PortableDevicePropertyKeys.WPD_CLIENT_NAME, "PodcastUtilities.PortableDevices");
            deviceValues.SetUnsignedIntegerValue(ref PortableDevicePropertyKeys.WPD_CLIENT_MAJOR_VERSION, 1);
            deviceValues.SetUnsignedIntegerValue(ref PortableDevicePropertyKeys.WPD_CLIENT_MINOR_VERSION, 0);
            deviceValues.SetUnsignedIntegerValue(ref PortableDevicePropertyKeys.WPD_CLIENT_REVISION, 1);

            var device = new PortableDeviceClass();

            device.Open(deviceId, deviceValues);

            return(device);
        }
示例#31
0
        /// <summary>
        /// This method gets the list of properties from the properties list that pertain only to the device.
        /// </summary>
        /// <param name="portableDeviceItem"></param>
        /// <returns></returns>
        private IPortableDeviceValues ExtractDeviceProperties(PortableDeviceClass portableDeviceItem)
        {
            IPortableDeviceContent    content;
            IPortableDeviceProperties properties;

            portableDeviceItem.Content(out content);
            content.Properties(out properties);

            // Retrieve the values for the properties

            IPortableDeviceValues propertyValues;

            properties.GetValues(Id, null, out propertyValues);

            return(propertyValues);
        }
示例#32
0
        public void TransferContentToDevice(string fileName, string parentObjectId)
        {
            IPortableDeviceContent content;

            PortableDeviceClass.Content(out content);


            var values =
                GetRequiredPropertiesForContentType(fileName, parentObjectId);


            PortableDeviceApiLib.IStream tempStream;
            uint optimalTransferSizeBytes = 0;

            content.CreateObjectWithPropertiesAndData(
                values,
                out tempStream,
                ref optimalTransferSizeBytes,
                null);

            var targetStream =
                (System.Runtime.InteropServices.ComTypes.IStream)tempStream;


            try
            {
                using (var sourceStream =
                           new FileStream(fileName, FileMode.Open, FileAccess.Read))
                {
                    var buffer = new byte[optimalTransferSizeBytes];
                    int bytesRead;
                    do
                    {
                        bytesRead = sourceStream.Read(
                            buffer, 0, (int)optimalTransferSizeBytes);
                        var pcbWritten = IntPtr.Zero;
                        targetStream.Write(
                            buffer, bytesRead, pcbWritten);
                    } while (bytesRead > 0);
                }
                targetStream.Commit(0);
            }
            finally
            {
                Marshal.ReleaseComObject(tempStream);
            }
        }
        private void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (!string.IsNullOrEmpty(adviseCookie))
                {
                    PortableDeviceClass.Unadvise(adviseCookie);
                }

                if (IsConnected)
                {
                    PortableDeviceClass.Close();
                }
            }

            PortableDeviceClass = null;
        }
示例#34
0
        /// <summary>
        ///     Initialize a new instance of the <see cref="FunctionalCategory" /> class
        /// </summary>
        /// <param name="portableDeviceClass"></param>
        /// <param name="guid"></param>
        /// <param name="name"></param>
        internal FunctionalCategory(PortableDeviceClass portableDeviceClass, Guid guid, string name)
        {
            if (guid == Guid.Empty)
            {
                throw new ArgumentException("guid cann't be Guid.Empty");
            }
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException("name");
            }
            contentTypes = new Dictionary <Guid, ContentType>();

            Guid = guid;
            Name = name;

            ExtractContentType(portableDeviceClass, guid);
        }
示例#35
0
        /// <summary>
        /// 连接设备
        /// </summary>
        /// <param name="DeviceId"></param>
        /// <param name="portableDevice"></param>
        /// <param name="deviceContent"></param>
        /// <returns></returns>
        private static IPortableDeviceValues Connect(string DeviceId, out PortableDevice portableDevice, out IPortableDeviceContent deviceContent)
        {
            IPortableDeviceValues clientInfo = (IPortableDeviceValues) new PortableDeviceTypesLib.PortableDeviceValuesClass();

            portableDevice = new PortableDeviceClass();
            portableDevice.Open(DeviceId, clientInfo);
            portableDevice.Content(out deviceContent);

            IPortableDeviceProperties deviceProperties;

            deviceContent.Properties(out deviceProperties);

            IPortableDeviceValues deviceValues;

            deviceProperties.GetValues("DEVICE", null, out deviceValues);
            return(deviceValues);
        }
示例#36
0
        /// <summary>
        /// Construct the device by obtainin the device properties and the sub data.
        /// 
        /// NOTE: 
        /// There is a difference with the device id and the id.
        /// The id indicates the object id within the windows portable device.
        /// The device id indicates the object id within the operating system.
        /// 
        /// The initial id for all windows portable devices is hard coded to "DEVICE"
        /// </summary>
        /// <param name="deviceId"></param>
        public Device(string deviceId) : base("DEVICE")
        {
            DeviceId = deviceId;
            ComDeviceObject = new PortableDeviceClass();
            Connect();
            IPortableDeviceValues deviceProperties = ExtractDeviceProperties(ComDeviceObject);

            ContentType = new ContentTypeProperty(deviceProperties);
            DeviceType = new TypeProperty(deviceProperties);
            FirmwareVersion = new FirmwareVersionProperty(deviceProperties);
            FriendlyName = new FriendlyNameProperty(deviceProperties);
            Manufacturer = new ManufacturerProperty(deviceProperties);
            Model = new ModelProperty(deviceProperties);
            Name = new NameProperty(deviceProperties);
            SerialNumber = new SerialNumberProperty(deviceProperties);

            LoadDeviceData(ComDeviceObject);

            Disconnect();
        }
        /// <summary>
        /// create from unique ID, this will attach PodcastUtilities as a client to the specified device
        /// </summary>
        /// <param name="deviceId">ID</param>
        /// <returns>the device</returns>
        public IPortableDevice Create(string deviceId)
        {
            var deviceValues = (IPortableDeviceValues)new PortableDeviceTypesLib.PortableDeviceValuesClass();

            deviceValues.SetStringValue(ref PortableDevicePropertyKeys.WPD_CLIENT_NAME, "PodcastUtilities.PortableDevices");
            deviceValues.SetUnsignedIntegerValue(ref PortableDevicePropertyKeys.WPD_CLIENT_MAJOR_VERSION, 1);
            deviceValues.SetUnsignedIntegerValue(ref PortableDevicePropertyKeys.WPD_CLIENT_MINOR_VERSION, 0);
            deviceValues.SetUnsignedIntegerValue(ref PortableDevicePropertyKeys.WPD_CLIENT_REVISION, 1);

            var device = new PortableDeviceClass();
            try
            {
                device.Open(deviceId, deviceValues);
            }
            catch (System.Exception)
            {
                //Device has been detached meanwhile
                device = new PortableDeviceClass();
            }
            return device;
        }
示例#38
0
        private void ExtractSupportedFormat(PortableDeviceClass portableDeviceClass, Guid contentType)
        {
            if (portableDeviceClass == null)
                throw new PortableDeviceException("");

            IPortableDeviceCapabilities capabilities;
            portableDeviceClass.Capabilities(out capabilities);

            if (capabilities == null)
            {
                Trace.WriteLine("Cannot extract capabilities from device");
                throw new PortableDeviceException("Cannot extract capabilities from device");
            }

            var pValues = (IPortableDeviceValues) new PortableDeviceValuesClass();

            //Functional objects variables
            IPortableDevicePropVariantCollection formats;
            uint countObjects = 1;
            var values = new tag_inner_PROPVARIANT();
            string formatName;
            Guid currentFormat;
            capabilities.GetSupportedFormats(ref contentType, out formats);

            formats.GetCount(ref countObjects);
            for (uint i = 0; i < countObjects; i++)
            {
                formats.GetAt(i, ref values);

                pValues.SetValue(ref PortableDevicePKeys.WPD_COMMAND_CAPABILITIES_GET_SUPPORTED_FORMATS, ref values);
                pValues.GetStringValue(ref PortableDevicePKeys.WPD_COMMAND_CAPABILITIES_GET_SUPPORTED_FORMATS, out formatName);
                currentFormat = new Guid(formatName);
                this.formats[currentFormat] = PortableDeviceHelpers.GetKeyNameFromGuid(currentFormat);
            }
        }
示例#39
0
 /// <summary>
 /// This method loads the sub folders and files within the device.
 /// NOTE: It only loads the subfolder and file information.
 /// No actual binary is loaded as this could potentially be a very
 /// piece of data in memory.
 /// </summary>
 /// <param name="portableDeviceItem"></param>
 private void LoadDeviceData(PortableDeviceClass portableDeviceItem)
 {
     IPortableDeviceContent content;
     portableDeviceItem.Content(out content);
     LoadDeviceItems(content);
 }
示例#40
0
        /// <summary>
        /// This method gets the list of properties from the properties list that pertain only to the device.
        /// </summary>
        /// <param name="portableDeviceItem"></param>
        /// <returns></returns>
        private IPortableDeviceValues ExtractDeviceProperties(PortableDeviceClass portableDeviceItem)
        {
            IPortableDeviceContent content;
            IPortableDeviceProperties properties;
            portableDeviceItem.Content(out content);
            content.Properties(out properties);

            // Retrieve the values for the properties

            IPortableDeviceValues propertyValues;
            properties.GetValues(Id, null, out propertyValues);

            return propertyValues;
        }
        private void ExtractContentType(PortableDeviceClass portableDeviceClass, Guid functionalCategory)
        {
            if (portableDeviceClass == null)
                throw new ArgumentNullException("portableDeviceClass");

            try
            {
                PortableDeviceApiLib.IPortableDeviceCapabilities capabilities;
                portableDeviceClass.Capabilities(out capabilities);

                if (capabilities == null)
                {
                    System.Diagnostics.Trace.WriteLine("Cannot extract capabilities from device");
                    throw new PortableDeviceException("Cannot extract capabilities from device");
                }


                PortableDeviceApiLib.IPortableDeviceValues pValues = (PortableDeviceApiLib.IPortableDeviceValues)new PortableDeviceTypesLib.PortableDeviceValuesClass();


                //Functional objects variables
                IPortableDevicePropVariantCollection contentTypes;
                uint countObjects = 1;
                tag_inner_PROPVARIANT values = new tag_inner_PROPVARIANT();
                string contentTypeName;
                Guid currentContentTypeGuid;
                capabilities.GetSupportedContentTypes(ref functionalCategory, out contentTypes);

                contentTypes.GetCount(ref countObjects);
                for (uint i = 0; i < countObjects; i++)
                {
                    contentTypes.GetAt(i, ref values);

                    pValues.SetValue(ref PortableDevicePKeys.WPD_COMMAND_CAPABILITIES_GET_SUPPORTED_CONTENT_TYPES, ref values);
                    pValues.GetStringValue(ref PortableDevicePKeys.WPD_COMMAND_CAPABILITIES_GET_SUPPORTED_CONTENT_TYPES, out contentTypeName);
                    currentContentTypeGuid = new Guid(contentTypeName);
                    this.contentTypes.Add(currentContentTypeGuid, new ContentType(
                        portableDeviceClass,
                        currentContentTypeGuid,
                        PortableDeviceHelpers.GetKeyNameFromGuid(currentContentTypeGuid)));
                }

            }
            catch (Exception ex)
            {
                throw new PortableDeviceException("Error on extract functional object", ex);
            }
        }
示例#42
0
        /// <summary>
        /// リソースを破棄します。
        /// </summary>
        /// <param name="isDisposing">マネージリソースを破棄する場合は true。それ以外は false。</param>
        private void Dispose( bool isDisposing )
        {
            if( this._isDisposed ) { return; }
            this._isDisposed = true;

            this.Close();

            if( isDisposing )
            {
                this._device = null;
            }
        }
        /// <summary>
        ///     Extract command supported by device
        /// </summary>
        /// <param name="portableDeviceClass"></param>
        internal void ExtractCommands(PortableDeviceClass portableDeviceClass)
        {
            IPortableDeviceCapabilities capabilities;
            portableDeviceClass.Capabilities(out capabilities);

            IPortableDeviceKeyCollection values;
            capabilities.GetSupportedCommands(out values);

            var key = new _tagpropertykey();
            _tagpropertykey tt;

            uint count = 1;
            values.GetCount(ref count);
            for (uint i = 0; i < count; i++)
            {
                values.GetAt(i, ref key);

                string currentName = null;
                foreach (FieldInfo fi in typeof (PortableDevicePKeys).GetFields())
                {
                    tt = (_tagpropertykey) fi.GetValue(null);
                    if (key.fmtid == tt.fmtid && key.pid == tt.pid)
                        currentName = fi.Name;
                }

                commands.Add(currentName ?? key.pid + " " + key.fmtid, key);
            }
        }
        /// <summary>
        /// Extract command supported by device
        /// </summary>
        /// <param name="portableDeviceClass"></param>
        internal void ExtractCommands(PortableDeviceClass portableDeviceClass)
        {
            PortableDeviceApiLib.IPortableDeviceCapabilities capabilities;
            portableDeviceClass.Capabilities(out capabilities);

            PortableDeviceApiLib.IPortableDeviceKeyCollection values;
            capabilities.GetSupportedCommands(out values);

            _tagpropertykey key = new _tagpropertykey();
            _tagpropertykey tt;
            string currentName;

            uint count = 1;
            values.GetCount(ref count);
            for (uint i = 0; i < count; i++)
            {
                values.GetAt(i, ref key);

                currentName = string.Empty;
                foreach (FieldInfo fi in typeof(PortableDevicePKeys).GetFields())
                {
                    tt = (_tagpropertykey)fi.GetValue(null);
                    if (key.fmtid == tt.fmtid && key.pid == tt.pid)
                        currentName = fi.Name;
                }

                if (!string.IsNullOrEmpty(currentName))
                    this.commands.Add(currentName, key);
                else
                    this.commands.Add(key.pid + " " + key.fmtid, key);

            }
        }
        /// <summary>
        ///     Extract device capabilities
        /// </summary>
        /// <param name="portableDeviceClass"></param>
        internal void ExtractDeviceCapabilities(PortableDeviceClass portableDeviceClass)
        {
            if (portableDeviceClass == null)
                throw new ArgumentNullException("portableDeviceClass");

            try
            {
                IPortableDeviceCapabilities capabilities;
                portableDeviceClass.Capabilities(out capabilities);

                if (capabilities == null)
                {
                    Trace.WriteLine("Cannot extract capabilities from device");
                    throw new PortableDeviceException("Cannot extract capabilities from device");
                }

                IPortableDevicePropVariantCollection functionalCategories;
                capabilities.GetFunctionalCategories(out functionalCategories);

                if (functionalCategories == null)
                {
                    throw new PortableDeviceException("Failed to extract functionnal categories");
                }

                uint countCategories = 1;
                functionalCategories.GetCount(ref countCategories);
                var values = new tag_inner_PROPVARIANT();

                string categoryName;
                Guid currentGuid;
                for (uint i = 0; i < countCategories; i++)
                {
                    functionalCategories.GetAt(i, ref values);
                    var pValues = (IPortableDeviceValues) new PortableDeviceValuesClass();

                    pValues.SetValue(ref PortableDevicePKeys.WPD_COMMAND_CAPABILITIES_GET_SUPPORTED_FUNCTIONAL_CATEGORIES, ref values);
                    pValues.GetStringValue(ref PortableDevicePKeys.WPD_COMMAND_CAPABILITIES_GET_SUPPORTED_FUNCTIONAL_CATEGORIES, out categoryName);
                    currentGuid = new Guid(categoryName);
                    this.functionalCategories.Add(currentGuid, new FunctionalCategory(
                                                                   portableDeviceClass,
                                                                   currentGuid,
                                                                   PortableDeviceHelpers.GetKeyNameFromGuid(currentGuid)));
                }
            }
            catch (Exception ex)
            {
                throw new PortableDeviceException("Error on extract device capabilities", ex);
            }
        }
        /// <summary>
        ///     Extract event supported by device
        /// </summary>
        /// <param name="portableDeviceClass"></param>
        internal void ExtractEvents(PortableDeviceClass portableDeviceClass)
        {
            IPortableDeviceCapabilities capabilities;
            portableDeviceClass.Capabilities(out capabilities);

            IPortableDevicePropVariantCollection events;
            capabilities.GetSupportedEvents(out events);

            uint countEvents = 0;
            events.GetCount(ref countEvents);

            var pValues = (IPortableDeviceValues) new PortableDeviceValuesClass();
            var evt = new tag_inner_PROPVARIANT();

            Guid eventName;
            IPortableDeviceValues eventOptions;
            PortableDeviceEventDescription eventDescription;

            for (uint i = 0; i < countEvents; i++)
            {
                events.GetAt(i, ref evt);
                pValues.SetValue(ref PortableDevicePKeys.WPD_EVENT_PARAMETER_EVENT_ID, ref evt);
                pValues.GetGuidValue(ref PortableDevicePKeys.WPD_EVENT_PARAMETER_EVENT_ID, out eventName);

                eventDescription = new PortableDeviceEventDescription(eventName, PortableDeviceHelpers.GetKeyNameFromGuid(eventName));

                //Retrieve options
                try
                {
                    // Event option isn't always present, so ...
                    eventOptions = (IPortableDeviceValues) new PortableDeviceValuesClass();
                    capabilities.GetEventOptions(ref eventName, out eventOptions);

                    //eventOptions.GetBoolValue(ref PortableDevicePKeys.WPD_EVENT_OPTION_IS_AUTOPLAY_EVENT, out isAutoPlayEvent);
                    //eventOptions.GetBoolValue(ref PortableDevicePKeys.WPD_EVENT_OPTION_IS_BROADCAST_EVENT, out isBroadcastEvent);

                    //eventDescription.AddOptions(new PortableDeviceEventOption()
                    //{
                    //    Guid = PortableDevicePKeys.WPD_EVENT_OPTION_IS_BROADCAST_EVENT.fmtid,
                    //    Name = PortableDeviceHelpers.GetKeyNameFromGuid(PortableDevicePKeys.WPD_EVENT_OPTION_IS_BROADCAST_EVENT.fmtid),
                    //    Value = isBroadcastEvent,
                    //    ValueType = TypeCode.Boolean
                    //});

                    //eventDescription.AddOptions(new PortableDeviceEventOption()
                    //{
                    //    Guid = PortableDevicePKeys.WPD_EVENT_OPTION_IS_AUTOPLAY_EVENT.fmtid,
                    //    Name = PortableDeviceHelpers.GetKeyNameFromGuid(PortableDevicePKeys.WPD_EVENT_OPTION_IS_AUTOPLAY_EVENT.fmtid),
                    //    Value = isAutoPlayEvent,
                    //    ValueType = TypeCode.Boolean
                    //});
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.Message);
                    Debug.WriteLine(ex.StackTrace);
                }

                this.events.Add(eventDescription, PortableDevicePKeys.WPD_EVENT_PARAMETER_EVENT_ID);
            }
        }
 public PortableDevice(string deviceId)
 {
     this._device = new PortableDeviceClass();
     this.DeviceId = deviceId;
 }