/// <summary> /// Extract device capabilities /// </summary> /// <param name="portableDeviceClass"></param> internal void ExtractDeviceCapabilities(PortableDeviceClass portableDeviceClass) { if (portableDeviceClass == null) { throw new ArgumentNullException("portableDeviceClass"); } try { 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); var values = new tag_inner_PROPVARIANT(); string categoryName; Guid currentGuid; for (uint i = 0; i < countCategories; i++) { functionalCategories.GetAt(i, ref values); var pValues = (IPortableDeviceValues) new PortableDeviceValuesClass(); 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(""); } IPortableDeviceCapabilities capabilities; portableDeviceClass.Capabilities(out capabilities); if (capabilities == null) { Trace.WriteLine("Cannot extract capabilities from device"); throw new PortableDeviceException("Cannot extract capabilities from device"); } var pValues = (IPortableDeviceValues) new PortableDeviceValuesClass(); //Functional objects variables IPortableDevicePropVariantCollection formats; uint countObjects = 1; var 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[currentFormat] = PortableDeviceHelpers.GetKeyNameFromGuid(currentFormat); } }
private PortableDeviceObject ExtractInformation(PortableDeviceApiLib.IPortableDeviceProperties properties, string objectId) { PortableDeviceApiLib.IPortableDeviceKeyCollection keys; properties.GetSupportedProperties(objectId, out keys); PortableDeviceApiLib.IPortableDeviceValues values; properties.GetValues(objectId, keys, out values); string tmpVal; string name; values.GetStringValue(ref PortableDevicePKeys.WPD_OBJECT_NAME, out name); values.GetStringValue(ref PortableDevicePKeys.WPD_OBJECT_CONTENT_TYPE, out tmpVal); var guid = new Guid(tmpVal); string contentType = PortableDeviceHelpers.GetKeyNameFromGuid(guid); values.GetStringValue(ref PortableDevicePKeys.WPD_OBJECT_FORMAT, out tmpVal); string formatType = PortableDeviceHelpers.GetKeyNameFromGuid(new Guid(tmpVal)); return(Factories.PortableDeviceObjectFactory.Instance.CreateInstance(guid, objectId, name, contentType, formatType)); }
/// <summary> /// Extract event supported by device /// </summary> /// <param name="portableDeviceClass"></param> internal void ExtractEvents(PortableDeviceClass portableDeviceClass) { IPortableDeviceCapabilities capabilities; portableDeviceClass.Capabilities(out capabilities); IPortableDevicePropVariantCollection events; capabilities.GetSupportedEvents(out events); uint countEvents = 0; events.GetCount(ref countEvents); var pValues = (IPortableDeviceValues) new PortableDeviceValuesClass(); var evt = new tag_inner_PROPVARIANT(); Guid eventName; IPortableDeviceValues eventOptions; PortableDeviceEventDescription eventDescription; for (uint i = 0; i < countEvents; i++) { events.GetAt(i, ref evt); pValues.SetValue(ref PortableDevicePKeys.WPD_EVENT_PARAMETER_EVENT_ID, ref evt); pValues.GetGuidValue(ref PortableDevicePKeys.WPD_EVENT_PARAMETER_EVENT_ID, out eventName); eventDescription = new PortableDeviceEventDescription(eventName, PortableDeviceHelpers.GetKeyNameFromGuid(eventName)); //Retrieve options try { // Event option isn't always present, so ... eventOptions = (IPortableDeviceValues) new PortableDeviceValuesClass(); capabilities.GetEventOptions(ref eventName, out eventOptions); //eventOptions.GetBoolValue(ref PortableDevicePKeys.WPD_EVENT_OPTION_IS_AUTOPLAY_EVENT, out isAutoPlayEvent); //eventOptions.GetBoolValue(ref PortableDevicePKeys.WPD_EVENT_OPTION_IS_BROADCAST_EVENT, out isBroadcastEvent); //eventDescription.AddOptions(new PortableDeviceEventOption() //{ // Guid = PortableDevicePKeys.WPD_EVENT_OPTION_IS_BROADCAST_EVENT.fmtid, // Name = PortableDeviceHelpers.GetKeyNameFromGuid(PortableDevicePKeys.WPD_EVENT_OPTION_IS_BROADCAST_EVENT.fmtid), // Value = isBroadcastEvent, // ValueType = TypeCode.Boolean //}); //eventDescription.AddOptions(new PortableDeviceEventOption() //{ // Guid = PortableDevicePKeys.WPD_EVENT_OPTION_IS_AUTOPLAY_EVENT.fmtid, // Name = PortableDeviceHelpers.GetKeyNameFromGuid(PortableDevicePKeys.WPD_EVENT_OPTION_IS_AUTOPLAY_EVENT.fmtid), // Value = isAutoPlayEvent, // ValueType = TypeCode.Boolean //}); } catch (Exception ex) { Debug.WriteLine(ex.Message); Debug.WriteLine(ex.StackTrace); } this.events.Add(eventDescription, PortableDevicePKeys.WPD_EVENT_PARAMETER_EVENT_ID); } }