/// <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); }
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; }
public static bool TryGetGuidValue(this IPortableDeviceValues values, PropertyKey key, out Guid value) { if (values.HasKeyValue(key)) { values.GetGuidValue(ref key, out value); return(true); } value = Guid.Empty; return(false); }
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 PortableDeviceObject CreateFunctionalObject(IPortableDeviceValues values) { var obj = CreateObject <PortableDeviceFunctionalObject>(values); Guid category; values.GetGuidValue(ref PortableDevicePKeys.WPD_FUNCTIONAL_OBJECT_CATEGORY, out category); obj.Category = category; return(obj); }
/// <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)); }
/// <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); } }
/// <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)); }
/// <summary> /// 获取文件属性 /// </summary> /// <param name="deviceValues"></param> /// <returns></returns> private static MTPFileNodeType GetFileTypeProperty(IPortableDeviceValues deviceValues) { Guid contentType; _tagpropertykey property = new _tagpropertykey(); property.fmtid = new Guid(0xEF6B490D, 0x5CD8, 0x437A, 0xAF, 0xFC, 0xDA, 0x8B, 0x60, 0xEE, 0x4A, 0x3C); property.pid = 7; deviceValues.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(MTPFileNodeType.Directory); } return(MTPFileNodeType.File); }
/// <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> /// プロパティ値から、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; } }