public void OnEvent(IPortableDeviceValues pEventParameters) { pEventParameters.GetStringValue(WpdHelper.pKey.WPD_EVENT_PARAMETER_PNP_DEVICE_ID, out deviceId); pEventParameters.GetStringValue(WpdHelper.pKey.WPD_EVENT_PARAMETER_EVENT_ID, out eventId); if (eventId.Contains(WpdHelper.pGuid.WPD_EVENT_DEVICE_RESET.ToString().ToUpper()) || eventId.Contains(WpdHelper.pGuid.WPD_EVENT_DEVICE_REMOVED.ToString().ToUpper())) { if (WpdHelper.UnexpectedClosed != null) { WpdHelper.UnexpectedClosed(); } } else { /* * if (eventId.Contains(WpdHelper.pGuid.WPD_EVENT_OBJECT_ADDED.ToString().ToUpper())) * { * eventId = "1"; * } * else if (eventId.Contains(WpdHelper.pGuid.WPD_EVENT_OBJECT_REMOVED.ToString().ToUpper())) * { * eventId = "2"; * } * else if (eventId.Contains(WpdHelper.pGuid.WPD_EVENT_OBJECT_UPDATED.ToString().ToUpper())) * { * eventId = "3"; * } * */ } }
/// <summary> /// 获取对象名 /// </summary> public string GetObjectName(IPortableDeviceValues objectValues) { string objectName; objectValues.GetStringValue(ref pKey.WPD_OBJECT_NAME, out objectName); return(objectName); }
/// <summary> /// Extract device capabilities /// </summary> /// <param name="portableDeviceClass"></param> internal void ExtractDeviceCapabilities(PortableDeviceClass portableDeviceClass) { if (portableDeviceClass == null) { throw new ArgumentNullException("portableDeviceClass"); } try { PortableDeviceApiLib.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); tag_inner_PROPVARIANT values = new tag_inner_PROPVARIANT(); PortableDeviceApiLib.IPortableDeviceValues pValues = (PortableDeviceApiLib.IPortableDeviceValues) new PortableDeviceTypesLib.PortableDeviceValuesClass(); string categoryName; Guid currentGuid; for (uint i = 0; i < countCategories; i++) { functionalCategories.GetAt(i, ref values); 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); } }
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); } }
private void ExtractSupportedFormat(PortableDeviceClass portableDeviceClass, Guid contentType) { if (portableDeviceClass == null) { throw new PortableDeviceException(""); } 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 formats; uint countObjects = 1; tag_inner_PROPVARIANT 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.Add(currentFormat, PortableDeviceHelpers.GetKeyNameFromGuid(currentFormat)); } }