/// <summary>
        /// Callback for event from device
        /// </summary>
        /// <param name="pEventParameters"></param>
        public void OnEvent(IPortableDeviceValues pEventParameters)
        {
            string pnpDeviceId;
              pEventParameters.GetStringValue(ref PortableDevicePKeys.WPD_EVENT_PARAMETER_PNP_DEVICE_ID, out pnpDeviceId);
              if (this.device.DeviceId != pnpDeviceId)
            return;

              Guid eventGuid;
              pEventParameters.GetGuidValue(ref PortableDevicePKeys.WPD_EVENT_PARAMETER_EVENT_ID, out eventGuid);

              PortableDeviceEventType deviceEventType = new PortableDeviceEventType() {EventGuid = eventGuid};

              if (eventGuid == PortableDeviceGuids.WPD_EVENT_OBJECT_ADDED)
              {
            string objectId;
            pEventParameters.GetStringValue(ref PortableDevicePKeys.WPD_OBJECT_ID, out objectId);
            string objectName;
            pEventParameters.GetStringValue(ref PortableDevicePKeys.WPD_OBJECT_NAME, out objectName);
            PortableDeviceObject deviceObject = new PortableDeviceObject(objectId) {Name = objectName};
            deviceEventType.DeviceObject = deviceObject;
              }

              // the original api isn't finise, i use a siple workaroud, but this need to be fixed using event factory
              //this.device.RaiseEvent(PortableDeviceEventTypeFactory.Instance.CreateEventType(eventGuid));
              this.device.RaiseEvent(deviceEventType);
        }
Ejemplo n.º 2
0
 public CPasswordSiloInformation(IPortableDeviceValues results)
 {
     results.GetBufferValue(ENHANCED_STORAGE_PROPERTY_PASSWORD_SILO_INFO, out Vanara.InteropServices.SafeCoTaskMemHandle pbBuffer, out int cbBuffer);
     SiloInfo     = pbBuffer.DangerousGetHandle().ToStructure <ENHANCED_STORAGE_PASSWORD_SILO_INFORMATION>(cbBuffer);
     dwAuthnState = (ENHANCED_STORAGE_AUTHN_STATE)results.GetUnsignedIntegerValue(ENHANCED_STORAGE_PROPERTY_AUTHENTICATION_STATE);
     UserHint     = results.GetStringValue(ENHANCED_STORAGE_PROPERTY_USER_HINT);
     UserName     = results.GetStringValue(ENHANCED_STORAGE_PROPERTY_USER_NAME);
     AdminHint    = results.GetStringValue(ENHANCED_STORAGE_PROPERTY_ADMIN_HINT);
     SiloName     = results.GetStringValue(ENHANCED_STORAGE_PROPERTY_SILO_NAME);
 }
Ejemplo n.º 3
0
            public void OnEvent(IPortableDeviceValues pEventParameters)
            {
                Guid eventId;

                if (pEventParameters == null)
                {
                    return;
                }
                pEventParameters.GetGuidValue(ref WpdProperty.WPD_EVENT_PARAMETER_EVENT_ID, out eventId);
                Debug.WriteLine("[WpdEvent] Guid: " + eventId.ToString());

                ushort mtpEventCode = 0;
                object eventValue   = null;

                if (eventId.Equals(WPD_EVENT_OBJECT_ADDED))
                {
                    mtpEventCode = WpdMtpLib.MtpEvent.ObjectAdded;
                    string objectIdStr;
                    pEventParameters.GetStringValue(WpdProperty.WPD_OBJECT_ID, out objectIdStr);
                    Debug.WriteLine("[WpdEvent][ObjectAdded] ObjectID: " + objectIdStr);
                    uint objectId = uint.Parse(objectIdStr.Trim('o'), NumberStyles.HexNumber);
                    eventValue = objectId;
                }
                else if (eventId.Equals(WPD_EVENT_DEVICE_REMOVED))
                {
                    Debug.WriteLine("[WpdEvent] Device Removed. Terminate.");
                    mtpCommand.device.Unadvise(mtpCommand.eventCookie);
                    mtpCommand.device = null;
                    mtpCommand.DeviceEvent(WpdMtpLib.DeviceEvent.Removed, eventValue);
                }
                else if (eventId.Equals(WPD_EVENT_OBJECT_UPDATED) || eventId.Equals(WPD_EVENT_DEVICE_CAPABILITIES_UPDATED))
                {
                    string objectIdStr;
                    pEventParameters.GetStringValue(WpdProperty.WPD_OBJECT_ID, out objectIdStr);
                    Debug.WriteLine("[WpdEvent][ObjectUpdated] ObjectID                : " + objectIdStr);
                    string objectNameStr;
                    pEventParameters.GetStringValue(WpdProperty.WPD_OBJECT_NAME, out objectNameStr);
                    Debug.WriteLine("[WpdEvent][ObjectUpdated] ObjectName              : " + objectNameStr);
                    if (objectIdStr == "DEVICE")
                    {
                        mtpEventCode = WpdMtpLib.MtpEvent.DevicePropChanged;
                    }
                }
                else if (isGuidMtpVendorExtendedEvents(eventId))
                {
                    // MtpEventコードを取得する
                    mtpEventCode = BitConverter.ToUInt16(eventId.ToByteArray(), 2);
                }

                if (mtpEventCode != 0 && mtpCommand.MtpEvent != null)
                {
                    Debug.WriteLine("[WpdEvent] eventCode: 0x" + mtpEventCode.ToString("x4"));
                    mtpCommand.MtpEvent(mtpEventCode, eventValue);
                }
            }
        private static string GetObjectId(IPortableDeviceValues values)
        {
            string value;

            values.GetStringValue(ref PortableDevicePKeys.WPD_OBJECT_ID, out value);
            return(value);
        }
Ejemplo n.º 5
0
 public static bool TryGetStringValue(this IPortableDeviceValues values, PropertyKey key, out string value)
 {
     if (values.HasKeyValue(key))
     {
         values.GetStringValue(ref key, out value);
         return(true);
     }
     value = string.Empty;
     return(false);
 }
Ejemplo n.º 6
0
        /// <summary>
        /// 获取制造商
        /// </summary>
        /// <param name="DeviceValues"></param>
        /// <returns></returns>
        private static string GetManufacturer(IPortableDeviceValues DeviceValues)
        {
            _tagpropertykey property = new _tagpropertykey()
            {
                fmtid = new Guid("26d4979a-e643-4626-9e2b-736dc0c92fdc"), pid = 7
            };
            string manufacturer;

            DeviceValues.GetStringValue(ref property, out manufacturer);
            return(manufacturer);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 获取型号
        /// </summary>
        /// <param name="DeviceValues"></param>
        /// <returns></returns>
        private static string GetModel(IPortableDeviceValues DeviceValues)
        {
            _tagpropertykey property = new _tagpropertykey()
            {
                fmtid = new Guid("26d4979a-e643-4626-9e2b-736dc0c92fdc"), pid = 8
            };
            string model;

            DeviceValues.GetStringValue(ref property, out model);
            return(model);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// 获取固件版本
        /// </summary>
        /// <param name="DeviceValues"></param>
        /// <returns></returns>
        private static string GetFirmwareVersion(IPortableDeviceValues DeviceValues)
        {
            _tagpropertykey deviceTypeKey = new _tagpropertykey()
            {
                fmtid = new Guid("26d4979a-e643-4626-9e2b-736dc0c92fdc"), pid = 3
            };
            string firmwareVersion;

            DeviceValues.GetStringValue(ref deviceTypeKey, out firmwareVersion);
            return(firmwareVersion);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// 获取序列号
        /// </summary>
        /// <param name="DeviceValues"></param>
        /// <returns></returns>
        private static string GetSerialNumber(IPortableDeviceValues DeviceValues)
        {
            _tagpropertykey property = new _tagpropertykey()
            {
                fmtid = new Guid("26d4979a-e643-4626-9e2b-736dc0c92fdc"), pid = 9
            };
            string name;

            DeviceValues.GetStringValue(ref property, out name);
            return(name);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// 获取设备名
        /// </summary>
        /// <param name="DeviceValues"></param>
        /// <returns></returns>
        private static string GetDeviceName(IPortableDeviceValues DeviceValues)
        {
            _tagpropertykey property = new _tagpropertykey()
            {
                fmtid = new Guid("ef6b490d-5cd8-437a-affc-da8b60ee4a3c"), pid = 4
            };
            string name;

            DeviceValues.GetStringValue(ref property, out name);
            return(name);
        }
        /// <summary>
        ///     Callback for event from device
        /// </summary>
        /// <param name="pEventParameters"></param>
        public void OnEvent(IPortableDeviceValues pEventParameters)
        {
            string pnpDeviceId;
            pEventParameters.GetStringValue(ref PortableDevicePKeys.WPD_EVENT_PARAMETER_PNP_DEVICE_ID, out pnpDeviceId);
            if (device.DeviceId != pnpDeviceId)
                return;

            Guid eventGuid;
            pEventParameters.GetGuidValue(ref PortableDevicePKeys.WPD_EVENT_PARAMETER_EVENT_ID, out eventGuid);

            device.RaiseEvent(PortableDeviceEventTypeFactory.Instance.CreateEventType(eventGuid));
        }
Ejemplo n.º 12
0
        /// <summary>
        /// 获取名称属性
        /// </summary>
        /// <param name="deviceValues"></param>
        /// <returns></returns>
        private static string GetNameProperty(IPortableDeviceValues deviceValues)
        {
            _tagpropertykey nameKey = new _tagpropertykey();

            nameKey.fmtid = new Guid("EF6B490D-5CD8-437A-AFFC-DA8B60EE4A3C"); //guid唯一值
            nameKey.pid   = 4;                                                //索引

            string nameProperty = null;

            deviceValues.GetStringValue(ref nameKey, out nameProperty);
            return(nameProperty);
        }
Ejemplo n.º 13
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);
     }
 }
        /// <summary>
        /// Callback for event from device
        /// </summary>
        /// <param name="pEventParameters"></param>
        public void OnEvent(IPortableDeviceValues pEventParameters)
        {
            string pnpDeviceId;

            pEventParameters.GetStringValue(ref PortableDevicePKeys.WPD_EVENT_PARAMETER_PNP_DEVICE_ID, out pnpDeviceId);
            if (this.device.DeviceId != pnpDeviceId)
            {
                return;
            }

            Guid eventGuid;

            pEventParameters.GetGuidValue(ref PortableDevicePKeys.WPD_EVENT_PARAMETER_EVENT_ID, out eventGuid);

            PortableDeviceEventType deviceEventType = new PortableDeviceEventType()
            {
                EventGuid = eventGuid
            };

            if (eventGuid == PortableDeviceGuids.WPD_EVENT_OBJECT_ADDED)
            {
                string objectId;
                pEventParameters.GetStringValue(ref PortableDevicePKeys.WPD_OBJECT_ID, out objectId);
                string objectName;
                pEventParameters.GetStringValue(ref PortableDevicePKeys.WPD_OBJECT_NAME, out objectName);
                PortableDeviceObject deviceObject = new PortableDeviceObject(objectId)
                {
                    Name = objectName
                };
                deviceEventType.DeviceObject = deviceObject;
            }

            // the original api isn't finise, i use a siple workaroud, but this need to be fixed using event factory
            //this.device.RaiseEvent(PortableDeviceEventTypeFactory.Instance.CreateEventType(eventGuid));
            this.device.RaiseEvent(deviceEventType);
        }
        /// <summary>
        ///     Callback for event from device
        /// </summary>
        /// <param name="pEventParameters"></param>
        public void OnEvent(IPortableDeviceValues pEventParameters)
        {
            string pnpDeviceId;

            pEventParameters.GetStringValue(ref PortableDevicePKeys.WPD_EVENT_PARAMETER_PNP_DEVICE_ID, out pnpDeviceId);
            if (device.DeviceId != pnpDeviceId)
            {
                return;
            }

            Guid eventGuid;

            pEventParameters.GetGuidValue(ref PortableDevicePKeys.WPD_EVENT_PARAMETER_EVENT_ID, out eventGuid);

            device.RaiseEvent(PortableDeviceEventTypeFactory.Instance.CreateEventType(eventGuid));
        }
Ejemplo n.º 16
0
        /// <summary>
        /// 获取名称属性
        /// </summary>
        /// <param name="deviceValues"></param>
        /// <returns></returns>
        private static string GetFullNameProperty(IPortableDeviceValues deviceValues)
        {
            try
            {
                _tagpropertykey nameKey = new _tagpropertykey();
                nameKey.fmtid = new Guid(0xEF6B490D, 0x5CD8, 0x437A, 0xAF, 0xFC, 0xDA, 0x8B, 0x60, 0xEE, 0x4A, 0x3C); //guid唯一值
                nameKey.pid   = 12;                                                                                   //索引

                string nameProperty = null;
                deviceValues.GetStringValue(ref nameKey, out nameProperty);
                return(nameProperty);
            }
            catch (Exception)
            {
                return(GetNameProperty(deviceValues));
            }
        }
        private static void InitializeInstance(PortableDeviceObject obj, IPortableDeviceValues values)
        {
            string name;

            values.GetStringValue(ref PortableDevicePKeys.WPD_OBJECT_NAME, out name);

            Guid guid;

            values.GetGuidValue(ref PortableDevicePKeys.WPD_OBJECT_CONTENT_TYPE, out guid);
            string contentType = PortableDeviceHelpers.GetKeyNameFromGuid(guid);

            values.GetGuidValue(ref PortableDevicePKeys.WPD_OBJECT_FORMAT, out guid);
            string formatType = PortableDeviceHelpers.GetKeyNameFromGuid(guid);

            obj.Name        = name;
            obj.ContentType = contentType;
            obj.Format      = formatType;
        }
Ejemplo n.º 18
0
        /// <summary>
        /// 获取访问时间属性
        /// </summary>
        /// <param name="deviceValues"></param>
        /// <returns></returns>
        private static string GetFileDateAuthoredProperty(IPortableDeviceValues deviceValues)
        {
            _tagpropertykey nameKey = new _tagpropertykey();

            nameKey.fmtid = new Guid(0xEF6B490D, 0x5CD8, 0x437A, 0xAF, 0xFC, 0xDA, 0x8B, 0x60, 0xEE, 0x4A, 0x3C); //guid唯一值
            nameKey.pid   = 20;                                                                                   //索引

            string sizeProperty = string.Empty;

            try
            {
                deviceValues.GetStringValue(ref nameKey, out sizeProperty);
            }
            catch
            {
                return("");
            }

            return(sizeProperty);
        }
        private PortableDeviceObject CreateGenericObject(IPortableDeviceValues values)
        {
            string filename;
            int    size;

            try
            {
                values.GetStringValue(ref PortableDevicePKeys.WPD_OBJECT_ORIGINAL_FILE_NAME, out filename);
                values.GetSignedIntegerValue(ref PortableDevicePKeys.WPD_OBJECT_SIZE, out size);
            }
            catch
            {
                return(CreateObject <PortableDeviceObject>(values));
            }

            var obj = CreateObject <PortableDeviceFileObject>(values);

            obj.FileName = filename;
            obj.Size     = size;
            return(obj);
        }
Ejemplo n.º 20
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;
     }
 }