Ejemplo n.º 1
0
        /// <summary>
        /// インスタンスを初期化します。
        /// </summary>
        /// <param name="key">識別子。</param>
        /// <param name="info">プロパティ値の情報。</param>
        /// <param name="values">値。</param>
        internal WpdPropertyValue( _tagpropertykey key, tag_inner_PROPVARIANT info, IPortableDeviceValues values )
        {
            this.Key      = key;
            this.HasValue = true;

            switch( ( PropVariantTypes )info.vt )
            {
            case PropVariantTypes.VT_BOOL:
                this.Type      = WpdPropertyValueType.Bool;
                this.ValueBool = WpdPropertyValue.ReadBool( key, values );
                break;

            case PropVariantTypes.VT_DATE:
                this.Type          = WpdPropertyValueType.DateTime;
                this.ValueDateTime = WpdPropertyValue.ReadDateTime( key, values );
                break;

            case PropVariantTypes.VT_CLSID:
                this.Type      = WpdPropertyValueType.Guid;
                this.ValueGuid = WpdPropertyValue.ReadGuid( key, values );
                break;

            case PropVariantTypes.VT_I4:
                this.Type       = WpdPropertyValueType.Int32;
                this.ValueInt32 = WpdPropertyValue.ReadInt32( key, values );
                break;

            case PropVariantTypes.VT_I8:
                this.Type       = WpdPropertyValueType.Int64;
                this.ValueInt64 = WpdPropertyValue.ReadInt64( key, values );
                break;

            case PropVariantTypes.VT_BSTR:
            case PropVariantTypes.VT_LPSTR:
            case PropVariantTypes.VT_LPWSTR:
                this.Type        = WpdPropertyValueType.String;
                this.ValueString = WpdPropertyValue.ReadString( key, values );
                break;

            case PropVariantTypes.VT_UI4:
                this.Type        = WpdPropertyValueType.UInt32;
                this.ValueUInt32 = WpdPropertyValue.ReadUInt32( key, values );
                break;

            case PropVariantTypes.VT_UI8:
                this.Type        = WpdPropertyValueType.UInt64;
                this.ValueUInt64 = WpdPropertyValue.ReadUInt64( key, values );
                break;

            default:
                this.Type     = WpdPropertyValueType.Unknown;
                this.HasValue = false;
                break;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// インスタンスを初期化します。
        /// </summary>
        /// <param name="values">イベント データのコレクション。</param>
        internal WpdEventArgs( IPortableDeviceValues values )
        {
            uint count = 0;
            values.GetCount( ref count );
            if( count < 1 )
            {
                this.Values = new List< WpdPropertyValue >( 0 );
                return;
            }

            this.Values = new List< WpdPropertyValue >( ( int )count );
            var key     = new _tagpropertykey();
            var info    = new tag_inner_PROPVARIANT();

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

                var value = new WpdPropertyValue( key, info, values );
                if( value.Key.Equals( WpdProperties.WPD_EVENT_PARAMETER_PNP_DEVICE_ID ) )
                {
                    this.DeviceId = value.ValueString;
                }
                else if( value.Key.Equals( WpdProperties.WPD_OBJECT_ID ) )
                {
                    this.ObjectId = value.ValueString;
                }
                else if( value.Key.Equals( WpdProperties.WPD_OBJECT_PARENT_ID ) )
                {
                    this.ParentObjectId = value.ValueString;
                }
                else if( value.Key.Equals( WpdProperties.WPD_EVENT_PARAMETER_EVENT_ID ) )
                {
                    if( value.ValueGuid != null ) { this.Type = TypeConvertUtility.GuidToEventType( value.ValueGuid.Value ); }
                }
                else
                {
                    this.Values.Add( value );
                }
            }
        }
Ejemplo n.º 3
0
        private string GetStringProperty(_tagpropertykey propertyKey)
        {
            //Ensure we are connected to device
            CheckIfIsConnected();

            IPortableDeviceContent content;
            IPortableDeviceProperties properties;
            PortableDeviceApiLib.IPortableDeviceValues propertyValues;

            this.portableDeviceClass.Content(out content);
            content.Properties(out properties);

            properties.GetValues("DEVICE", null, out propertyValues);

            string val = string.Empty;
            propertyValues.GetStringValue(ref propertyKey, out val);

            return val;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// lookup the given key and return the long property associated with the object
        /// </summary>
        /// <param name="deviceContent">unmanged device</param>
        /// <param name="objectId">object id</param>
        /// <param name="key">name of the property key</param>
        /// <returns>long value</returns>
        public ulong GetUnsignedLargeIntegerProperty(IPortableDeviceContent deviceContent, string objectId, _tagpropertykey key)
        {
            var deviceValues = GetDeviceValues(deviceContent, key, objectId);

            ulong value;

            deviceValues.GetUnsignedLargeIntegerValue(ref key, out value);

            return(value);
        }
Ejemplo n.º 5
0
        private static IPortableDeviceValues GetDeviceValues(IPortableDeviceContent deviceContent, _tagpropertykey key, string objectId)
        {
            IPortableDeviceProperties deviceProperties;

            deviceContent.Properties(out deviceProperties);

            var keyCollection = (IPortableDeviceKeyCollection) new PortableDeviceTypesLib.PortableDeviceKeyCollectionClass();

            keyCollection.Add(key);

            IPortableDeviceValues deviceValues;

            deviceProperties.GetValues(objectId, keyCollection, out deviceValues);
            return(deviceValues);
        }
Ejemplo n.º 6
0
        protected IPortableDeviceValues GetRequiredPropertiesForContentType(string fileName,
                                                string parentObjectId)
        {
            IPortableDeviceValues values =
                new PortableDeviceTypesLib.PortableDeviceValues()
                as IPortableDeviceValues;

            var WPD_OBJECT_PARENT_ID = new _tagpropertykey();
            WPD_OBJECT_PARENT_ID.fmtid =
                new Guid(0xEF6B490D, 0x5CD8, 0x437A, 0xAF, 0xFC,
                            0xDA, 0x8B, 0x60, 0xEE, 0x4A, 0x3C);
            WPD_OBJECT_PARENT_ID.pid = 3;
            values.SetStringValue(ref WPD_OBJECT_PARENT_ID, parentObjectId);

            FileInfo fileInfo = new FileInfo(fileName);
            var WPD_OBJECT_SIZE = new _tagpropertykey();
            WPD_OBJECT_SIZE.fmtid =
                new Guid(0xEF6B490D, 0x5CD8, 0x437A, 0xAF, 0xFC,
                            0xDA, 0x8B, 0x60, 0xEE, 0x4A, 0x3C);
            WPD_OBJECT_SIZE.pid = 11;
            values.SetUnsignedLargeIntegerValue(WPD_OBJECT_SIZE, (ulong)fileInfo.Length);

            var WPD_OBJECT_ORIGINAL_FILE_NAME = new _tagpropertykey();
            WPD_OBJECT_ORIGINAL_FILE_NAME.fmtid =
                new Guid(0xEF6B490D, 0x5CD8, 0x437A, 0xAF, 0xFC,
                            0xDA, 0x8B, 0x60, 0xEE, 0x4A, 0x3C);
            WPD_OBJECT_ORIGINAL_FILE_NAME.pid = 12;
            values.SetStringValue(WPD_OBJECT_ORIGINAL_FILE_NAME, Path.GetFileName(fileName));

            var WPD_OBJECT_NAME = new _tagpropertykey();
            WPD_OBJECT_NAME.fmtid =
                new Guid(0xEF6B490D, 0x5CD8, 0x437A, 0xAF, 0xFC,
                            0xDA, 0x8B, 0x60, 0xEE, 0x4A, 0x3C);
            WPD_OBJECT_NAME.pid = 4;
            values.SetStringValue(WPD_OBJECT_NAME, Path.GetFileName(fileName));

            //From Original Tutorial:
            //  "Remark: To keep it easy I extracted the filename and
            //   path of the book and used that to set both the
            //   WPD_OBJECT_ORIGINAL_FILE_NAME and
            //   WPD_OBJECT_NAME properties.

            return values;
        }
Ejemplo n.º 7
0
        /// <summary>
        /// lookup the given key and return the string property associated with the object
        /// </summary>
        /// <param name="deviceContent">unmanged device</param>
        /// <param name="objectId">object id</param>
        /// <param name="key">name of the property key</param>
        /// <returns>string value</returns>
        public string GetStringProperty(IPortableDeviceContent deviceContent, string objectId, _tagpropertykey key)
        {
            var deviceValues = GetDeviceValues(deviceContent, key, objectId);

            string value;

            deviceValues.GetStringValue(ref key, out value);

            return(value);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// This method copies the file from the device to the destination path.
        /// </summary>
        /// <param name="destinationPath"></param>
        private void TransferFile(string destinationPath)
        {
            // TODO: Clean this up.

            IPortableDeviceResources resources;
            DeviceContent.Transfer(out resources);

            IStream wpdStream = null;
            uint optimalTransferSize = 0;

            var property = new _tagpropertykey
                               {
                                   fmtid = new Guid("E81E79BE-34F0-41BF-B53F-F1A06AE87842"),
                                   pid = 0
                               };

            System.Runtime.InteropServices.ComTypes.IStream sourceStream = null;
            try
            {
                resources.GetStream(Id, ref property, 0, ref optimalTransferSize, out wpdStream);
                sourceStream = (System.Runtime.InteropServices.ComTypes.IStream)wpdStream;

                FileStream targetStream = new FileStream(
                    Path.Combine(destinationPath, OriginalFileName.Value),
                    FileMode.Create,
                    FileAccess.Write);

                unsafe
                {
                    try
                    {
                        var buffer = new byte[1024];
                        int bytesRead;
                        do
                        {
                            sourceStream.Read(buffer, 1024, new IntPtr(&bytesRead));
                            targetStream.Write(buffer, 0, bytesRead);
                        } while (bytesRead > 0);
                    }
                    finally
                    {
                        targetStream.Close();
                    }
                }
            }
            finally
            {
                Marshal.ReleaseComObject(sourceStream);
                Marshal.ReleaseComObject(wpdStream);
            }
        }
Ejemplo n.º 9
0
        public static IWpdProperty Create(_tagpropertykey key, tag_inner_PROPVARIANT variant)
        {
            var ptrValue = Marshal.AllocHGlobal(Marshal.SizeOf(variant));

            try
            {
                Marshal.StructureToPtr(variant, ptrValue, false);
                var pv = WpdProperty.MarshalToStructure <PROPVARIANT>(ptrValue);

                var ve = (VarEnum)pv.vt;

                switch (ve)
                {
                case VarEnum.VT_I1:
                    return(new WpdProperty <sbyte>(key, variant, ve, pv.AsSByte()));

                case VarEnum.VT_UI1:
                    return(new WpdProperty <byte>(key, variant, ve, pv.AsByte()));

                case VarEnum.VT_I2:
                    return(new WpdProperty <short>(key, variant, ve, pv.AsInt16()));

                case VarEnum.VT_UI2:
                    return(new WpdProperty <ushort>(key, variant, ve, pv.AsUInt16()));

                case VarEnum.VT_I4:
                case VarEnum.VT_INT:
                case VarEnum.VT_ERROR:
                    return(new WpdProperty <int>(key, variant, ve, pv.AsInt32()));

                case VarEnum.VT_UI4:
                case VarEnum.VT_UINT:
                    return(new WpdProperty <uint>(key, variant, ve, pv.AsUInt32()));

                case VarEnum.VT_I8:
                    return(new WpdProperty <long>(key, variant, ve, pv.AsInt64()));

                case VarEnum.VT_UI8:
                    return(new WpdProperty <ulong>(key, variant, ve, pv.AsUInt64()));

                case VarEnum.VT_R4:
                    return(new WpdProperty <float>(key, variant, ve, pv.AsFloat()));

                case VarEnum.VT_R8:
                    return(new WpdProperty <double>(key, variant, ve, pv.AsDouble()));

                case VarEnum.VT_BOOL:
                    return(new WpdProperty <bool>(key, variant, ve, pv.AsBool()));

                case VarEnum.VT_CY:
                    return(new WpdProperty <decimal>(key, variant, ve, pv.AsDecimal()));

                case VarEnum.VT_DATE:
                case VarEnum.VT_FILETIME:
                    return(new WpdProperty <DateTime>(key, variant, ve, pv.AsDateTime()));

                case VarEnum.VT_BSTR:
                case VarEnum.VT_LPSTR:
                case VarEnum.VT_LPWSTR:
                    return(new WpdProperty <string>(key, variant, ve, pv.AsString()));

                case VarEnum.VT_BLOB:
                    return(new WpdProperty <byte[]>(key, variant, ve, pv.AsByteBuffer()));

                case VarEnum.VT_UNKNOWN:
                    return(new WpdProperty <object>(key, variant, ve, pv.AsIUnknown()));

                case VarEnum.VT_DISPATCH:
                case VarEnum.VT_PTR:
                    return(new WpdProperty <IntPtr>(key, variant, ve, pv.AsIntPtr()));

                case VarEnum.VT_CLSID:
                    return(new WpdProperty <Guid>(key, variant, ve, pv.AsGuid()));

                case VarEnum.VT_EMPTY:
                    return(new WpdProperty <object>(key, variant, ve, null));

                default:
                    return(new WpdProperty <object>(key, variant, ve, pv.AsIntPtr()));
                }
            }
            finally
            {
                Marshal.FreeHGlobal(ptrValue);
            }
        }
        /// <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);

            }
        }
Ejemplo n.º 11
0
 /// <summary>
 /// プロパティ値から、真偽値を読み取ります。
 /// </summary>
 /// <param name="key">識別子。</param>
 /// <param name="values">プロパティ値。</param>
 /// <returns>成功時は読み取った値。それ以外は null。</returns>
 public static bool? ReadBool( _tagpropertykey key, IPortableDeviceValues values )
 {
     try
     {
         int value;
         values.GetBoolValue( key, out value );
         return ( value != 0 );
     }
     catch( Exception exp )
     {
         Debug.WriteLine( exp.Message );
         return null;
     }
 }
Ejemplo n.º 12
0
        private void TransferFile(string destination, bool overwrite)
        {
            IPortableDeviceResources resources;

            DeviceContent.Transfer(out resources);

            IStream wpdStream           = null;
            uint    optimalTransferSize = 0;

            var property = new _tagpropertykey
            {
                fmtid = new Guid("E81E79BE-34F0-41BF-B53F-F1A06AE87842"),
                pid   = 0
            };

            System.Runtime.InteropServices.ComTypes.IStream sourceStream = null;
            try
            {
                resources.GetStream(Id, ref property, 0, ref optimalTransferSize, out wpdStream);
                sourceStream = (System.Runtime.InteropServices.ComTypes.IStream)wpdStream;
                FileMode mode;
                if (overwrite)
                {
                    mode = FileMode.Create;
                }
                else
                {
                    mode = FileMode.CreateNew;
                }
                FileStream targetStream = new FileStream(
                    destination,
                    mode,
                    FileAccess.Write);

                unsafe
                {
                    try
                    {
                        var buffer = new byte[1024];
                        int bytesRead;
                        do
                        {
                            sourceStream.Read(buffer, 1024, new IntPtr(&bytesRead));
                            targetStream.Write(buffer, 0, 1024);
                        } while (bytesRead > 0);
                    }
                    finally
                    {
                        targetStream.Close();
                    }
                }
            }
            catch (IOException)
            {
                throw new Exception("Destination file already exist!");
            }
            finally
            {
                Marshal.ReleaseComObject(sourceStream);
                Marshal.ReleaseComObject(wpdStream);
            }
        }
Ejemplo n.º 13
0
        public Hashtable GetDeviceProperties(string deviceId, string objectId)
        {
            Hashtable properties = new Hashtable();

            PortableDeviceClass    deviceClass = new PortableDeviceClass();
            IPortableDeviceContent deviceContent;

            deviceClass.Open(deviceId, _hClientDeviceValues);
            deviceClass.Content(out deviceContent);

            IPortableDeviceProperties deviceProperties;

            deviceContent.Properties(out deviceProperties);

            IPortableDeviceValues deviceValues;

            deviceProperties.GetValues(objectId, null, out deviceValues);

            uint devicePropertyCount = 0;

            deviceValues.GetCount(ref devicePropertyCount);

            for (uint i = 0; i < devicePropertyCount; i++)
            {
                _tagpropertykey       tagPropertyKey = new _tagpropertykey();
                tag_inner_PROPVARIANT tagPropVariant = new tag_inner_PROPVARIANT();

                deviceValues.GetAt(i, ref tagPropertyKey, ref tagPropVariant);

                IntPtr ptrValue = Marshal.AllocHGlobal(Marshal.SizeOf(tagPropVariant));

                Marshal.StructureToPtr(tagPropVariant, ptrValue, false);

                PropVariant pvValue = (PropVariant)Marshal.PtrToStructure(ptrValue, typeof(PropVariant));

                if (pvValue.variantType == VariantTypes.VT_LPWSTR)
                {
                    string stringValue = Marshal.PtrToStringUni(pvValue.pointerValue);
                    properties.Add(PropertyManager.GetKeyName(tagPropertyKey.pid, tagPropertyKey.fmtid), stringValue);
                }
                else if (pvValue.variantType == VariantTypes.VT_DATE)
                {
                    DateTime datetime = DateTime.FromOADate(pvValue.dateValue);
                    properties.Add(PropertyManager.GetKeyName(tagPropertyKey.pid, tagPropertyKey.fmtid), datetime);
                }
                else if (pvValue.variantType == VariantTypes.VT_UI4)
                {
                    uint intValue = pvValue.byteValue;
                    properties.Add(PropertyManager.GetKeyName(tagPropertyKey.pid, tagPropertyKey.fmtid), intValue);
                }
                else if (pvValue.variantType == VariantTypes.VT_UI8)
                {
                    long intValue = pvValue.longValue;
                    properties.Add(PropertyManager.GetKeyName(tagPropertyKey.pid, tagPropertyKey.fmtid), intValue);
                }
                else if (pvValue.variantType == VariantTypes.VT_UINT)
                {
                    long intValue = pvValue.longValue;
                    properties.Add(PropertyManager.GetKeyName(tagPropertyKey.pid, tagPropertyKey.fmtid), intValue);
                }
            }
            return(properties);
        }
Ejemplo n.º 14
0
        public void DownloadFile(NwdPortableDeviceFile file,
                                 string saveToFolderPath)
        {
            if (!_isConnected)
            {
                Connect();
            }

            IPortableDeviceContent content;
            this._device.Content(out content);

            IPortableDeviceResources resources;
            content.Transfer(out resources);

            PortableDeviceApiLib.IStream wpdStream;
            uint optimalTransferSize = 0;

            var property = new _tagpropertykey();
            property.fmtid = new Guid(0xE81E79BE, 0x34F0, 0x41BF,
                                      0xB5, 0x3F, 0xF1, 0xA0,
                                      0x6A, 0xE8, 0x78, 0x42);
            property.pid = 0;

            resources.GetStream(file.Id,
                                ref property,
                                0,
                                ref optimalTransferSize,
                                out wpdStream);

            System.Runtime.InteropServices.ComTypes.IStream sourceStream =
                (System.Runtime.InteropServices.ComTypes.IStream)wpdStream;

            var filename = Path.GetFileName(file.Name); //uses the name with extension (differs from tutorial version)
            FileStream targetStream =
                new FileStream(Path.Combine(saveToFolderPath, filename),
                               FileMode.Create,
                               FileAccess.Write);

            unsafe
            {
                //TODO: play with this value (bufferSize)
                // (I get different entries missing/invalid based on the
                // number used, there has to be a connection, probably
                // an encoding thing, need more research)

                // int bufferSize = 1024;
                //int bufferSize = 4096;
                int bufferSize = 8192;

                var buffer = new byte[bufferSize];
                int bytesRead;
                do
                {
                    sourceStream.Read(buffer, bufferSize, new IntPtr(&bytesRead));
                    targetStream.Write(buffer, 0, bytesRead);
                    targetStream.Flush();

                } while (bytesRead > 0);

                targetStream.Close();

            }
            //TODO: LICENSE NOTES
            //see comments on: https://cgeers.wordpress.com/2011/08/13/wpd-transferring-content/
            Marshal.ReleaseComObject(sourceStream);
            Marshal.ReleaseComObject(wpdStream);

            Disconnect();
        }
Ejemplo n.º 15
0
        protected static new NwdPortableDeviceObject WrapObject(IPortableDeviceProperties properties,
                       string objectId)
        {
            IPortableDeviceKeyCollection keys;
            properties.GetSupportedProperties(objectId, out keys);

            IPortableDeviceValues values;
            properties.GetValues(objectId, keys, out values);

            //Get the name of the object
            string name;
            var property = new _tagpropertykey();
            property.fmtid = new Guid(0xEF6B490D, 0x5CD8, 0x437A,
                                      0xAF, 0xFC, 0xDA, 0x8B, 0x60,
                                      0xEE, 0x4A, 0x3C);
            property.pid = 4;
            values.GetStringValue(property, out name);

            // Get the type of the object
            Guid contentType;
            property = new _tagpropertykey();
            property.fmtid = new Guid(0xEF6B490D, 0x5CD8, 0x437A,
                                      0xAF, 0xFC, 0xDA, 0x8B, 0x60,
                                      0xEE, 0x4A, 0x3C);
            property.pid = 7;
            values.GetGuidValue(property, out contentType);

            var folderType = new Guid(0x27E2E392, 0xA111, 0x48E0,
                                      0xAB, 0x0C, 0xE1, 0x77, 0x05,
                                      0xA0, 0x5F, 0x85);
            var functionalType = new Guid(0x99ED0160, 0x17FF, 0x4C44,
                                          0x9D, 0x98, 0x1D, 0x7A, 0x6F,
                                          0x94, 0x19, 0x21);

            if (contentType == folderType ||
                contentType == functionalType)
            {
                return new NwdPortableDeviceFolder(objectId, name);
            }
            //TODO: LICENSE NOTES
            //begin test edit
            //per: http://stackoverflow.com/questions/18059234/get-full-name-of-a-file-on-a-windows-portable-device
            property.fmtid = new Guid(0xEF6B490D, 0x5CD8, 0x437A,
                                      0xAF, 0xFC, 0xDA, 0x8B, 0x60,
                                      0xEE, 0x4A, 0x3C);
            property.pid = 12; //WPD_OBJECT_ORIGINAL_FILE_NAME
            values.GetStringValue(property, out name);
            //end test edit

            return new NwdPortableDeviceFile(objectId, name);
        }
Ejemplo n.º 16
0
        private string GetStringProperty(_tagpropertykey key)
        {
            if (!this._isConnected)
            {
                String msg = "Not connected to device.";
                throw new InvalidOperationException(msg);
            }

            // retrieve device properties
            IPortableDeviceContent content;
            IPortableDeviceProperties properties;
            this._device.Content(out content);
            content.Properties(out properties);

            // retrieve property values
            IPortableDeviceValues propertyValues;
            properties.GetValues("DEVICE", null, out propertyValues);

            // retrieve the friendly name
            string propertyValue;
            propertyValues.GetStringValue(ref key,
                                          out propertyValue);

            return propertyValue;
        }
Ejemplo n.º 17
0
        protected static void StringToPropVariant(string value,
            out PortableDeviceApiLib.tag_inner_PROPVARIANT propvarValue)
        {
            PortableDeviceApiLib.IPortableDeviceValues pValues =
                (PortableDeviceApiLib.IPortableDeviceValues)
                    new PortableDeviceTypesLib.PortableDeviceValuesClass();

            var WPD_OBJECT_ID = new _tagpropertykey();
            WPD_OBJECT_ID.fmtid =
                new Guid(0xEF6B490D, 0x5CD8, 0x437A, 0xAF, 0xFC, 0xDA,
                            0x8B, 0x60, 0xEE, 0x4A, 0x3C);
            WPD_OBJECT_ID.pid = 2;

            pValues.SetStringValue(ref WPD_OBJECT_ID, value);

            pValues.GetValue(ref WPD_OBJECT_ID, out propvarValue);
        }
Ejemplo n.º 18
0
 /// <summary>
 /// プロパティ値から、日時値を読み取ります。
 /// </summary>
 /// <param name="key">識別子。</param>
 /// <param name="values">プロパティ値。</param>
 /// <returns>成功時は読み取った値。それ以外は null。</returns>
 public static DateTime? ReadDateTime( _tagpropertykey key, IPortableDeviceValues values )
 {
     try
     {
         float value;
         values.GetFloatValue( ref key, out value );
         return DateTime.FromOADate( value );
     }
     catch( Exception exp )
     {
         Debug.WriteLine( exp.Message );
         return null;
     }
 }
Ejemplo n.º 19
0
        private void TransferFile(string destination, bool overwrite)
        {
            IPortableDeviceResources resources;
            DeviceContent.Transfer(out resources);

            IStream wpdStream = null;
            uint optimalTransferSize = 0;

            var property = new _tagpropertykey
            {
                fmtid = new Guid("E81E79BE-34F0-41BF-B53F-F1A06AE87842"),
                pid = 0
            };

            System.Runtime.InteropServices.ComTypes.IStream sourceStream = null;
            try
            {
                resources.GetStream(Id, ref property, 0, ref optimalTransferSize, out wpdStream);
                sourceStream = (System.Runtime.InteropServices.ComTypes.IStream)wpdStream;
                FileMode mode;
                if (overwrite)
                {
                    mode = FileMode.Create;
                }
                else
                {
                    mode = FileMode.CreateNew;
                }
                FileStream targetStream = new FileStream(
                destination,
                mode,
                FileAccess.Write);

                unsafe
                {
                    try
                    {
                        var buffer = new byte[1024];
                        int bytesRead;
                        do
                        {
                            sourceStream.Read(buffer, 1024, new IntPtr(&bytesRead));
                            targetStream.Write(buffer, 0, 1024);
                        } while (bytesRead > 0);
                    }
                    finally
                    {
                        targetStream.Close();
                    }
                }
            }
            catch (IOException)
            {
                throw new Exception("Destination file already exist!");
            }
            finally
            {
                Marshal.ReleaseComObject(sourceStream);
                Marshal.ReleaseComObject(wpdStream);
            }
        }
Ejemplo n.º 20
0
        /// <summary>
        /// lookup the given key and return the guid property associated with the object
        /// </summary>
        /// <param name="deviceContent">unmanged device</param>
        /// <param name="objectId">object id</param>
        /// <param name="key">name of the property key</param>
        /// <returns>guid value</returns>
        public Guid GetGuidProperty(IPortableDeviceContent deviceContent, string objectId, _tagpropertykey key)
        {
            var deviceValues = GetDeviceValues(deviceContent, key, objectId);

            Guid value;
            deviceValues.GetGuidValue(ref key, out value);

            return value;
        }
Ejemplo n.º 21
0
 public static IWpdProperty Create(_tagpropertykey key, float variantValue)
 {
     return(WpdProperty.Create(key, PROPVARIANT.Create_tag_inner_PROPVARIANT(variantValue)));
 }
Ejemplo n.º 22
0
        /// <summary>
        /// lookup the given key and return the date property associated with the object
        /// </summary>
        /// <param name="deviceContent">unmanged device</param>
        /// <param name="objectId">object id</param>
        /// <param name="key">name of the property key</param>
        /// <returns>date value</returns>
        public DateTime GetDateProperty(IPortableDeviceContent deviceContent, string objectId, _tagpropertykey key)
        {
            var deviceValues = GetDeviceValues(deviceContent, key, objectId);

            tag_inner_PROPVARIANT value;
            deviceValues.GetValue(ref key, out value);

            return PropVariant.FromValue(value).ToDate();
        }
Ejemplo n.º 23
0
        /// <summary>
        /// lookup the given key and return the string property associated with the object
        /// </summary>
        /// <param name="deviceContent">unmanged device</param>
        /// <param name="objectId">object id</param>
        /// <param name="key">name of the property key</param>
        /// <returns>string value</returns>
        public string GetStringProperty(IPortableDeviceContent deviceContent, string objectId, _tagpropertykey key)
        {
            var deviceValues = GetDeviceValues(deviceContent, key, objectId);

            string value;
            deviceValues.GetStringValue(ref key, out value);

            return value;
        }
Ejemplo n.º 24
0
        protected static PortableDeviceObject WrapObject(IPortableDeviceProperties properties,
                       string objectId)
        {
            IPortableDeviceKeyCollection keys;
            properties.GetSupportedProperties(objectId, out keys);

            IPortableDeviceValues values;
            properties.GetValues(objectId, keys, out values);

            //Get the name of the object
            string name;
            var property = new _tagpropertykey();
            property.fmtid = new Guid(0xEF6B490D, 0x5CD8, 0x437A,
                                      0xAF, 0xFC, 0xDA, 0x8B, 0x60,
                                      0xEE, 0x4A, 0x3C);
            property.pid = 4;
            values.GetStringValue(property, out name);

            // Get the type of the object
            Guid contentType;
            property = new _tagpropertykey();
            property.fmtid = new Guid(0xEF6B490D, 0x5CD8, 0x437A,
                                      0xAF, 0xFC, 0xDA, 0x8B, 0x60,
                                      0xEE, 0x4A, 0x3C);
            property.pid = 7;
            values.GetGuidValue(property, out contentType);

            var folderType = new Guid(0x27E2E392, 0xA111, 0x48E0,
                                      0xAB, 0x0C, 0xE1, 0x77, 0x05,
                                      0xA0, 0x5F, 0x85);
            var functionalType = new Guid(0x99ED0160, 0x17FF, 0x4C44,
                                          0x9D, 0x98, 0x1D, 0x7A, 0x6F,
                                          0x94, 0x19, 0x21);

            if (contentType == folderType ||
                contentType == functionalType)
            {
                return new PortableDeviceFolder(objectId, name);
            }

            return new PortableDeviceFile(objectId, name);
        }
Ejemplo n.º 25
0
        /// <summary>
        /// lookup the given key and return the long property associated with the object
        /// </summary>
        /// <param name="deviceContent">unmanged device</param>
        /// <param name="objectId">object id</param>
        /// <param name="key">name of the property key</param>
        /// <returns>long value</returns>
        public ulong GetUnsignedLargeIntegerProperty(IPortableDeviceContent deviceContent, string objectId, _tagpropertykey key)
        {
            var deviceValues = GetDeviceValues(deviceContent, key, objectId);

            ulong value;
            deviceValues.GetUnsignedLargeIntegerValue(ref key, out value);

            return value;
        }
Ejemplo n.º 26
0
 /// <summary>
 /// プロパティ値から、GUID 値を読み取ります。
 /// </summary>
 /// <param name="key">識別子。</param>
 /// <param name="values">プロパティ値。</param>
 /// <returns>成功時は読み取った値。それ以外は null。</returns>
 public static Guid? ReadGuid( _tagpropertykey key, IPortableDeviceValues values )
 {
     try
     {
         Guid value;
         values.GetGuidValue( key, out value );
         return value;
     }
     catch( Exception exp )
     {
         Debug.WriteLine( exp.Message );
         return null;
     }
 }
Ejemplo n.º 27
0
        private static IPortableDeviceValues GetDeviceValues(IPortableDeviceContent deviceContent, _tagpropertykey key, string objectId)
        {
            IPortableDeviceProperties deviceProperties;
            deviceContent.Properties(out deviceProperties);

            var keyCollection = (IPortableDeviceKeyCollection)new PortableDeviceTypesLib.PortableDeviceKeyCollectionClass();
            keyCollection.Add(key);

            IPortableDeviceValues deviceValues;
            deviceProperties.GetValues(objectId, keyCollection, out deviceValues);
            return deviceValues;
        }
Ejemplo n.º 28
0
 /// <summary>
 /// プロパティ値から、符号付き 32 ビット整数値を読み取ります。
 /// </summary>
 /// <param name="key">識別子。</param>
 /// <param name="values">プロパティ値。</param>
 /// <returns>成功時は読み取った値。それ以外は null。</returns>
 public static int? ReadInt32( _tagpropertykey key, IPortableDeviceValues values )
 {
     try
     {
         int value;
         values.GetSignedIntegerValue( key, out value );
         return value;
     }
     catch( Exception exp )
     {
         Debug.WriteLine( exp.Message );
         return null;
     }
 }
Ejemplo n.º 29
0
        /// <summary>
        /// lookup the given key and return the guid property associated with the object
        /// </summary>
        /// <param name="deviceContent">unmanged device</param>
        /// <param name="objectId">object id</param>
        /// <param name="key">name of the property key</param>
        /// <returns>guid value</returns>
        public Guid GetGuidProperty(IPortableDeviceContent deviceContent, string objectId, _tagpropertykey key)
        {
            var deviceValues = GetDeviceValues(deviceContent, key, objectId);

            Guid value;

            deviceValues.GetGuidValue(ref key, out value);

            return(value);
        }
Ejemplo n.º 30
0
 /// <summary>
 /// プロパティ値から、文字列値を読み取ります。
 /// </summary>
 /// <param name="key">識別子。</param>
 /// <param name="values">プロパティ値。</param>
 /// <returns>成功時は読み取った値。それ以外は null。</returns>
 public static string ReadString( _tagpropertykey key, IPortableDeviceValues values )
 {
     try
     {
         string value;
         values.GetStringValue( key, out value );
         return String.IsNullOrEmpty( value ) ? String.Empty : value;
     }
     catch( Exception exp )
     {
         Debug.WriteLine( exp.Message );
         return String.Empty;
     }
 }
Ejemplo n.º 31
0
        /// <summary>
        /// lookup the given key and return the date property associated with the object
        /// </summary>
        /// <param name="deviceContent">unmanged device</param>
        /// <param name="objectId">object id</param>
        /// <param name="key">name of the property key</param>
        /// <returns>date value</returns>
        public DateTime GetDateProperty(IPortableDeviceContent deviceContent, string objectId, _tagpropertykey key)
        {
            var deviceValues = GetDeviceValues(deviceContent, key, objectId);

            tag_inner_PROPVARIANT value;

            deviceValues.GetValue(ref key, out value);

            return(PropVariant.FromValue(value).ToDate());
        }
Ejemplo n.º 32
0
 /// <summary>
 /// プロパティ値から、符号なし 64 ビット整数値を読み取ります。
 /// </summary>
 /// <param name="key">識別子。</param>
 /// <param name="values">プロパティ値。</param>
 /// <returns>成功時は読み取った値。それ以外は null。</returns>
 public static ulong? ReadUInt64( _tagpropertykey key, IPortableDeviceValues values )
 {
     try
     {
         ulong value;
         values.GetUnsignedLargeIntegerValue( key, out value );
         return value;
     }
     catch( Exception exp )
     {
         Debug.WriteLine( exp.Message );
         return null;
     }
 }
Ejemplo n.º 33
0
        /// <summary>
        /// Execute the specified command
        /// </summary>
        /// <param name="command"></param>
        public void ExecuteCommand(_tagpropertykey command)
        {
            IPortableDeviceValues commandValues = (IPortableDeviceValues)new PortableDeviceTypesLib.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)
            this.portableDeviceClass.SendCommand(0, commandValues, out results);

        }
Ejemplo n.º 34
0
        /// <summary>
        /// オブジェクトのプロパティ値を列挙します。
        /// </summary>
        /// <param name="id">オブジェクトの識別子。</param>
        /// <param name="properties">プロパティ情報。</param>
        /// <returns>プロパティ値のコレクション。</returns>
        internal static IEnumerable<WpdPropertyValue> EnumValues( string id, IPortableDeviceProperties properties )
        {
            IPortableDeviceKeyCollection keys;
            properties.GetSupportedProperties( id, out keys );

            IPortableDeviceValues values;
            properties.GetValues( id, keys, out values );

            uint count = 0;
            values.GetCount( ref count );

            var key  = new _tagpropertykey();
            var info = new tag_inner_PROPVARIANT();

            for( uint i = 0; i < count; ++i )
            {
                values.GetAt( i, ref key, ref info );
                yield return new WpdPropertyValue( key, info, values );
            }
        }
Ejemplo n.º 35
0
        private int GetIntegerProperty(_tagpropertykey propertyKey)
        {
            //Ensure we are connected to device
            CheckIfIsConnected();

            IPortableDeviceContent content;
            IPortableDeviceProperties properties;
            PortableDeviceApiLib.IPortableDeviceValues propertyValues;

            this.portableDeviceClass.Content(out content);
          
            content.Properties(out properties);
            properties.GetValues("DEVICE", null, out propertyValues);
          float val = -1;
            propertyValues.GetFloatValue(ref propertyKey, out val);
            return Convert.ToInt32(val);
        }
Ejemplo n.º 36
0
        public void DownloadFile(PortableDeviceFile file,
                                 string saveToFolderPath)
        {
            IPortableDeviceContent content;
            this._device.Content(out content);

            IPortableDeviceResources resources;
            content.Transfer(out resources);

            PortableDeviceApiLib.IStream wpdStream;
            uint optimalTransferSize = 0;

            var property = new _tagpropertykey();
            property.fmtid = new Guid(0xE81E79BE, 0x34F0, 0x41BF,
                                      0xB5, 0x3F, 0xF1, 0xA0,
                                      0x6A, 0xE8, 0x78, 0x42);
            property.pid = 0;

            resources.GetStream(file.Id,
                                ref property,
                                0,
                                ref optimalTransferSize,
                                out wpdStream);

            System.Runtime.InteropServices.ComTypes.IStream sourceStream =
                (System.Runtime.InteropServices.ComTypes.IStream)wpdStream;

            var filename = Path.GetFileName(file.Id);
            FileStream targetStream =
                new FileStream(Path.Combine(saveToFolderPath, filename),
                               FileMode.Create,
                               FileAccess.Write);

            unsafe
            {
                var buffer = new byte[1024];
                int bytesRead;
                do
                {
                    sourceStream.Read(buffer, 1024, new IntPtr(&bytesRead));
                    targetStream.Write(buffer, 0, 1024);
                } while (bytesRead > 0);

                targetStream.Close();
            }

            Marshal.ReleaseComObject(sourceStream);
            Marshal.ReleaseComObject(wpdStream);
        }