/// <summary> /// Raise event from device /// </summary> internal void RaiseEvent(PortableDeviceEventType eventType) { if (this.DeviceEvent != null) { this.DeviceEvent(this, new PortableDeviceEventArgs(eventType)); } }
/// <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> /// Initialize a new instance of the <see cref="PortableDeviceEventArgs" /> class /// </summary> /// <param name="eventType">The event type</param> public PortableDeviceEventArgs(PortableDeviceEventType eventType) : this() { EventType = eventType; }