/// <summary> /// Creates a new service added event arguments. /// </summary> /// <param name="deviceArgs">The underlying device args from which the service came.</param> /// <param name="service">The underlying COM service that was added.</param> internal ServiceAddedEventArgs(DeviceAddedEventArgs deviceArgs, IUPnPService service) { mbInterfaceGuidAvailable = deviceArgs.InterfaceGuidAvailable; if (mbInterfaceGuidAvailable) mgInterfaceGuid = deviceArgs.InterfaceGuid; mdCOMDevice = deviceArgs.COMDevice; msCOMService = service; }
private void lvDevices_ItemActivate(object sender, EventArgs e) { // Browse the selected device IUPnPDevice device = (IUPnPDevice)lvDevices.Items[lvDevices.SelectedIndices[0]].Tag; BrowseDevice(device); }
/// <summary> /// Gets all readable info as text for a device. /// </summary> /// <param name="device">The com device to get the info for.</param> /// <param name="indent">The indent for the information.</param> /// <returns>The readable info for the device.</returns> public static string ReadableInfo(this IUPnPDevice device, int indent = 0) { return(string.Format( "{1}Name: {2} ({3}){0}" + "{1}Description: {4}{0}" + "{1}Manufacturer: {5} ({6}){0}" + "{1}Model: {7} - {8} ({9}){0}" + "{1}Serial: {10}{0}" + "{1}Unique Device Name: {11}{0}" + "{1}UPC: {12}{0}" + "{1}Description URL: {13}{0}" + "{1}Devices{14}" + "{1}Services{15}", Environment.NewLine, new String(' ', indent * 4), device.FriendlyName, device.Type, device.Description, device.ManufacturerName, device.ManufacturerURL, device.ModelName, device.ModelNumber, device.ModelURL, device.SerialNumber, device.UniqueDeviceName, device.UPC, device.GetDocumentURL(), device.Children.ReadableInfo(indent), device.Services.ReadableInfo(indent))); }
/// <summary> /// Gets the root description for a com native device. /// </summary> /// <param name="device">The device to get root description for.</param> /// <returns>The root description for the device.</returns> internal RootDescription this[IUPnPDevice device] { get { RootDescription lrdDesc; string lsKey = KeyFor(device); if (Logging.Enabled) Logging.Log(this, string.Format("Getting RootDescription from cache for: '{0}' root of '{1}' key '{2}'", device.RootDevice.FriendlyName, device.FriendlyName, lsKey), 1); try { if (!mdCache.TryGetValue(lsKey, out lrdDesc)) { if (Logging.Enabled) Logging.Log(this, "Cache missed"); lrdDesc = device.RootDeviceDescription(); if (Logging.Enabled) Logging.Log(this, "Adding to cache"); mdCache[lsKey] = lrdDesc; } else if (Logging.Enabled) Logging.Log(this, "Cache hit"); return lrdDesc; } finally { if (Logging.Enabled) Logging.Log(this, "Finished getting RootDescription from cache", -1); } } }
/// <summary> /// Creates a new service added event arguments. /// </summary> /// <param name="device">The underlying COM device that was added.</param> /// <param name="interfaceGuid">The network interface guid.</param> /// <param name="service">The service which was added.</param> internal ServiceAddedEventArgs(IUPnPDevice device, Guid interfaceGuid, IUPnPService service) { mdCOMDevice = device; msCOMService = service; mgInterfaceGuid = interfaceGuid; mbInterfaceGuidAvailable = true; }
/// <summary> /// Creates a new service added event arguments. /// </summary> /// <param name="deviceArgs">The underlying device args from which the service came.</param> /// <param name="service">The underlying COM service that was added.</param> internal ServiceAddedEventArgs(DeviceAddedEventArgs deviceArgs, IUPnPService service) { mbInterfaceGuidAvailable = deviceArgs.InterfaceGuidAvailable; if (mbInterfaceGuidAvailable) { mgInterfaceGuid = deviceArgs.InterfaceGuid; } mdCOMDevice = deviceArgs.COMDevice; msCOMService = service; }
/// <summary> /// Revmoves the cache for a com native device. /// </summary> /// <param name="device">The device to remove the cache for.</param> internal void RemoveCacheFor(IUPnPDevice device) { string lsKey = KeyFor(device); if (Logging.Enabled) { Logging.Log(this, string.Format("Removing RootDescription cache for: '{0}' root of '{1}' key '{2}'", device.RootDevice.FriendlyName, device.FriendlyName, lsKey)); } mdCache.Remove(lsKey); }
/// <summary> /// Gets the device description for a device. /// </summary> /// <param name="device">The device to get the description for.</param> /// <param name="rootDescription">The root description for the device.</param> /// <returns>The device description or null if not found in the root description.</returns> public static DeviceDescription Description(this IUPnPDevice device, RootDescription rootDescription) { if (rootDescription != null) { return(rootDescription.FindDevice(device.UniqueDeviceName)); } else { return(null); } }
/// <summary> /// Gets the document URL for a native com device. /// </summary> /// <param name="device">The native com device to get the document URL for.</param> /// <returns>The URL for the document.</returns> public static string GetDocumentURL(this IUPnPDevice device) { if (device is IUPnPDeviceDocumentAccess) { return(((IUPnPDeviceDocumentAccess)device).GetDocumentURL()); } else { return(String.Empty); } }
/// <summary> /// Gets the description for a service. /// </summary> /// <param name="service">The native com service.</param> /// <param name="device">The native com device.</param> /// <param name="rootDescription">The root description for the services device.</param> /// <returns>The service description.</returns> public static ServiceDescription Description( this IUPnPService service, IUPnPDevice device, RootDescription rootDescription) { if (Logging.Enabled) Logging.Log(service, String.Format("Getting ServiceDescription for {0} -> {1}", device.FriendlyName, service.Id), 1); try { DeviceServiceDescription ldsdDesc = service.DeviceServiceDescription(device, rootDescription); if (ldsdDesc != null) { ServiceDescription lsdDesc = ldsdDesc.GetDescription(rootDescription); if (lsdDesc != null) { if (Logging.Enabled) { if (Logging.Enabled) Logging.Log(service, "ServiceDescription:", 1); try { if (Logging.Enabled) Logging.Log(service, lsdDesc.ToString()); } finally { if (Logging.Enabled) Logging.Log(service, "End ServiceDescription", -1); } } } else if (Logging.Enabled) Logging.Log(service, "ServiceDescription not found"); return lsdDesc; } else { if (Logging.Enabled) Logging.Log(service, "Failed - Device Service Description Not Located"); return null; } } finally { if (Logging.Enabled) Logging.Log(service, String.Format("Finished getting ServiceDescription for {0} -> {1}", device.FriendlyName, service.Id), -1); } }
/// <summary> /// Removes the cache for a native dvice and service. /// </summary> /// <param name="device">The native device.</param> /// <param name="service">The native service.</param> internal void RemoveCacheFor(IUPnPDevice device, IUPnPService service) { string lsKey = KeyFor(device, service); if (Logging.Enabled) Logging.Log(this, string.Format("Getting ServiceDescription cache for: '{0}' root of '{1}' key '{2}'", device.RootDevice.FriendlyName, service.Id, lsKey), 1); ServiceDescription lsdDesc = null; if (mdCache.TryGetValue(lsKey, out lsdDesc)) mdURLCache.Remove(lsdDesc.DocumentURL); mdCache.Remove(lsKey); }
/// <summary> /// Gets the service description for a native device and service. /// </summary> /// <param name="device">The native device.</param> /// <param name="service">The native service.</param> /// <returns>The service description for the cache or null if not available.</returns> internal ServiceDescription this[IUPnPDevice device, IUPnPService service] { get { ServiceDescription lsdDesc; string lsKey = KeyFor(device, service); if (Logging.Enabled) { Logging.Log(this, string.Format("Getting ServiceDescription from cache for: '{0}' root of '{1}' key '{2}'", device.RootDevice.FriendlyName, service.Id, lsKey), 1); } try { if (!mdCache.TryGetValue(lsKey, out lsdDesc)) { if (Logging.Enabled) { Logging.Log(this, "Cache missed"); } lsdDesc = service.Description(device, RootDescriptionCache.Cache[device.RootDevice]); if (lsdDesc != null) { if (Logging.Enabled) { Logging.Log(this, "Adding to cache"); } mdCache[lsKey] = lsdDesc; mdURLCache[lsdDesc.DocumentURL] = lsdDesc; } else if (Logging.Enabled) { Logging.Log(this, "Failed, nothing to add to cache"); } } return(lsdDesc); } finally { if (Logging.Enabled) { Logging.Log(this, "Finished getting ServiceDescription from cache", -1); } } } }
// Checks if device supports Content Directory service and opens a browser on it private void BrowseDevice(IUPnPDevice device) { // Get service enumerator IntPtr pE = device.Services._NewEnum; IEnumUnknown pEnum = (IEnumUnknown)Marshal.GetObjectForIUnknown(pE); Marshal.Release(pE); // Enumerate services. Look for one that has ContentDirectory in its description uint cItems; IUPnPService svc = null; IUPnPService svcContent = null; bool couldBrowse = false; while (pEnum.Next(1, out pE, out cItems) == 0 && cItems == 1) { svc = (IUPnPService)Marshal.GetObjectForIUnknown(pE); Marshal.Release(pE); object results;// = new object[3]; object retVal; if (svc.ServiceTypeIdentifier.IndexOf("ContentDirectory", StringComparison.OrdinalIgnoreCase) >= 0) { // Check if the service supports Browse verb // This is not really neccessary, but just a precaution svcContent = svc; int hr = svc.InvokeAction("Browse", new object[] { "0", "BrowseDirectChildren", "*", 0, 0, "" }, out results, out retVal); if (hr == 0) { couldBrowse = true; } hr = 0; } } if (!couldBrowse || svcContent == null) { MessageBox.Show("Found no browsable content"); } else { // We have found the Content Directory Browser browser = new Browser(svcContent); browser.ShowDialog(); } }
/// <summary> /// Gets the root description for a com native device. /// </summary> /// <param name="device">The device to get root description for.</param> /// <returns>The root description for the device.</returns> internal RootDescription this[IUPnPDevice device] { get { RootDescription lrdDesc; string lsKey = KeyFor(device); if (Logging.Enabled) { Logging.Log(this, string.Format("Getting RootDescription from cache for: '{0}' root of '{1}' key '{2}'", device.RootDevice.FriendlyName, device.FriendlyName, lsKey), 1); } try { if (!mdCache.TryGetValue(lsKey, out lrdDesc)) { if (Logging.Enabled) { Logging.Log(this, "Cache missed"); } lrdDesc = device.RootDeviceDescription(); if (Logging.Enabled) { Logging.Log(this, "Adding to cache"); } mdCache[lsKey] = lrdDesc; } else if (Logging.Enabled) { Logging.Log(this, "Cache hit"); } return(lrdDesc); } finally { if (Logging.Enabled) { Logging.Log(this, "Finished getting RootDescription from cache", -1); } } } }
public IntPtr DeviceAdded(int lFindData, IUPnPDevice pDevice) { try { Debug.WriteLine("DeviceAdded"); if (!fStopEvents) { m_frm._evtDeviceFound.Reset(); m_frm.Invoke(new DeviceFoundHandler(m_frm.DeviceFound), new object[] { this, Marshal.GetIUnknownForObject(pDevice) }); m_frm._evtDeviceFound.WaitOne(); } } catch (Exception e) { Debug.WriteLine(e.Message); } return(IntPtr.Zero); }
/// <summary> /// Removes the cache for a native dvice and service. /// </summary> /// <param name="device">The native device.</param> /// <param name="service">The native service.</param> internal void RemoveCacheFor(IUPnPDevice device, IUPnPService service) { string lsKey = KeyFor(device, service); if (Logging.Enabled) { Logging.Log(this, string.Format("Getting ServiceDescription cache for: '{0}' root of '{1}' key '{2}'", device.RootDevice.FriendlyName, service.Id, lsKey), 1); } ServiceDescription lsdDesc = null; if (mdCache.TryGetValue(lsKey, out lsdDesc)) { mdURLCache.Remove(lsdDesc.DocumentURL); } mdCache.Remove(lsKey); }
/// <summary> /// Adds devices from a devices child devices. /// </summary> /// <param name="device">The device to add the children for.</param> /// <param name="interfaceGuid">The network interface Guid of the device or Guid.Empty if unknown.</param> /// <param name="includingChildDevices">True to recursively get all devices or false to get immediate devices.</param> internal void AddFrom(IUPnPDevice device, Guid interfaceGuid, bool includingChildDevices = false) { if (device.HasChildren) { foreach (UPnPDevice ldDevice in device.Children) { Add(new Device(ldDevice, interfaceGuid)); } } if (includingChildDevices) { foreach (IUPnPDevice ldDevice in device.Children) { AddFrom(ldDevice, interfaceGuid, includingChildDevices); } } }
/// <summary> /// Finds a device by UDN synchronously. /// </summary> /// <param name="udn">The UDN for the device (cannot be null or empty).</param> /// <param name="addressFamily">The address family to search in. (Vista or above only).</param> /// <returns>The device if one is found or null if not found.</returns> /// <exception cref="System.ArgumentException">Thrown when udn is null or empty.</exception> public static Device FindDeviceByUDN( string udn, AddressFamilyFlags addressFamily = AddressFamilyFlags.IPvBoth) { if (String.IsNullOrEmpty(udn)) { throw new ArgumentException("cannot be null or empty string", "udn"); } IUPnPDevice ldDevice = FindNativeDeviceByUDN(udn, addressFamily); if (ldDevice != null) { return(new Device(ldDevice, Guid.Empty)); } else { return(null); } }
/// <summary> /// Finds services for a device. /// </summary> /// <param name="device">The device to get the services for.</param> /// <param name="interfaceGuid">The network guid for any new devices if available.</param> /// <param name="serviceType">The service type for the services to search for.</param> /// <returns>The services found.</returns> public static Services FindServices(this IUPnPDevice device, Guid interfaceGuid, string serviceType) { Services lsServices = new Services(); foreach (IUPnPService lsService in device.Services) { if (lsService.ServiceTypeIdentifier == serviceType) { lsServices.Add(new Service(device, interfaceGuid, lsService)); } } foreach (IUPnPDevice ldDevice in device.Children) { lsServices.AddRange(ldDevice.FindServices(interfaceGuid, serviceType)); } return(lsServices); }
/// <summary> /// Finds all (recursively) services of a certain type for a specific device by udn. /// </summary> /// <param name="udn">The udn of the device to search for services in (cannot be null or empty).</param> /// <param name="serviceType">The partial or full service type of the service.</param> /// <param name="addressFamily">The address family to search in. (Vista or above only).</param> /// <returns>A list of services containing the found services on the device.</returns> /// <exception cref="System.ArgumentException">Thrown when udn is null or empty.</exception> public static Services FindServicesByUDN( string udn, string serviceType, AddressFamilyFlags addressFamily = AddressFamilyFlags.IPvBoth) { if (String.IsNullOrEmpty(udn)) { throw new ArgumentException("cannot be null or empty string", "udn"); } IUPnPDevice ldDevice = FindNativeDeviceByUDN(udn, addressFamily); if (ldDevice != null) { return(ldDevice.FindServices(Guid.Empty, serviceType)); } else { return(new Services()); } }
// Handles the device discovery event public void DeviceFound(object sender, IntPtr pDev) { // Marshal interface to the current thread IUPnPDevice device = (IUPnPDevice)Marshal.GetObjectForIUnknown(pDev); Debug.WriteLine("Found device: " + device.FriendlyName); // Check if the device already in the list // Devices are compared by UniqueDeviceName foreach (ListViewItem item in lvDevices.Items) { if ((item.Tag as IUPnPDevice).UniqueDeviceName == device.UniqueDeviceName) { Debug.WriteLine("Already known"); return; } } // Get device icon // For simplicity we always ask for a 64x64 icon string url; Debug.WriteLine("Getting icon"); int ret = device.IconURL("image/png", 64, 64, 16, out url); Image imgIcon = new Bitmap(64, 64); if (ret == 0 && url != null) { imgIcon = GetIcon(url); } Debug.WriteLine("Adding"); il.Images.Add(imgIcon); ListViewItem newItem = new ListViewItem(device.FriendlyName); newItem.Tag = device; newItem.ImageIndex = il.Images.Count - 1; lvDevices.Items.Add(newItem); _evtDeviceFound.Set(); }
/// <summary> /// Gets the service description for a native device and service. /// </summary> /// <param name="device">The native device.</param> /// <param name="service">The native service.</param> /// <returns>The service description for the cache or null if not available.</returns> internal ServiceDescription this[IUPnPDevice device, IUPnPService service] { get { ServiceDescription lsdDesc; string lsKey = KeyFor(device, service); if (Logging.Enabled) Logging.Log(this, string.Format("Getting ServiceDescription from cache for: '{0}' root of '{1}' key '{2}'", device.RootDevice.FriendlyName, service.Id, lsKey), 1); try { if (!mdCache.TryGetValue(lsKey, out lsdDesc)) { if (Logging.Enabled) Logging.Log(this, "Cache missed"); lsdDesc = service.Description(device, RootDescriptionCache.Cache[device.RootDevice]); if (lsdDesc != null) { if (Logging.Enabled) Logging.Log(this, "Adding to cache"); mdCache[lsKey] = lsdDesc; mdURLCache[lsdDesc.DocumentURL] = lsdDesc; } else if (Logging.Enabled) Logging.Log(this, "Failed, nothing to add to cache"); } return lsdDesc; } finally { if (Logging.Enabled) Logging.Log(this, "Finished getting ServiceDescription from cache", -1); } } }
/// <summary> /// Creates a new device added event arguments. /// </summary> /// <param name="device">The underlying COM device that was added.</param> internal DeviceAddedEventArgs(IUPnPDevice device) { mbInterfaceGuidAvailable = false; mdCOMDevice = device; }
/// <summary> /// Creates a new device. /// </summary> /// <param name="comDevice">The Native COM Device for which this device is linked to.</param> /// <param name="interfaceGuid">The Network interface Guid ID for the device or Guid.Empty for unknown.</param> internal Device(IUPnPDevice comDevice, Guid interfaceGuid) { mbInterfaceGuidAvailable = !interfaceGuid.Equals(Guid.Empty); mgInterfaceGuid = interfaceGuid; mdCOMDevice = comDevice; }
int IUPnPDeviceFinderCallback.DeviceAdded(int lFindData, IUPnPDevice pDevice) { DeviceAdded((UPnPDevice)pDevice); return 0; }
/// <summary> /// Adds services from a native device. /// </summary> /// <param name="device">The device to add the services for.</param> /// <param name="interfaceGuid">The network interface Guid for the device.</param> /// <param name="serviceType">The service type to add or null for all.</param> /// <param name="includingChildDevices">True to add all child devices services.</param> internal void AddFrom(IUPnPDevice device, Guid interfaceGuid, string serviceType = null, bool includingChildDevices = false) { if (Logging.Enabled) { Logging.Log( this, string.Format( "Adding services for device: '{0}', ServiceType:'{1}' ChildDevices:'{2}'", device.FriendlyName, (serviceType == null ? "(null)" : serviceType), includingChildDevices), 1); } try { if (Logging.Enabled) { Logging.Log(this, "Scanning services", 1); } try { foreach (IUPnPService lsService in device.Services) { try { if (Logging.Enabled) { Logging.Log(this, string.Format("Service found: ID:'{0}', Type:'{1}'", lsService.Id, lsService.ServiceTypeIdentifier)); } if (serviceType == null || lsService.ServiceTypeIdentifier == serviceType) { if (Logging.Enabled) { Logging.Log(this, "Service accepted - matched"); } Add(new Service(device, interfaceGuid, lsService)); if (Logging.Enabled) { Logging.Log(this, "Service added"); } } else if (Logging.Enabled) { Logging.Log(this, "Service rejected - not matched"); } } catch (Exception loE) { if (Logging.Enabled) { Logging.Log(this, string.Format("Error occurred while adding service: '{0}'", loE.ToString())); } } } } catch (Exception loE) { if (Logging.Enabled) { Logging.Log(this, string.Format("Error occurred while scanning services: '{0}'", loE.ToString())); } } if (Logging.Enabled) { Logging.Log(this, "Finished scanning services", -1); } if (includingChildDevices) { if (Logging.Enabled) { Logging.Log(this, "Scanning child devices", 1); } try { foreach (IUPnPDevice ldDevice in device.Children) { try { if (Logging.Enabled) { Logging.Log(this, string.Format("Device found: Name:'{0}', UDN:'{1}'", ldDevice.FriendlyName, ldDevice.UniqueDeviceName)); } AddFrom(ldDevice, interfaceGuid, serviceType, includingChildDevices); } catch (Exception loE) { if (Logging.Enabled) { Logging.Log(this, string.Format("Error occurred while adding device: '{0}'", loE.ToString())); } } } } catch (Exception loE) { if (Logging.Enabled) { Logging.Log(this, string.Format("Error occurred while scanning child devices: '{0}'", loE.ToString())); } } if (Logging.Enabled) { Logging.Log(this, "Finished scanning child devices", -1); } } } finally { if (Logging.Enabled) { Logging.Log(this, "Finished adding services for device", -1); } } }
/// <summary> /// Creates a new services list from a native device. /// </summary> /// <param name="device">The device to add the services for.</param> /// <param name="interfaceGuid">The network interface Guid for the device.</param> /// <param name="serviceType">The service type to add or null for all.</param> /// <param name="includingChildDevices">True to add all child devices services.</param> internal Services(IUPnPDevice device, Guid interfaceGuid, string serviceType = null, bool includingChildDevices = false) : base() { AddFrom(device, interfaceGuid, serviceType, includingChildDevices); }
/// <summary> /// Add a UPnPDevice to this device /// </summary> /// <param name="device">Device</param> public void AddDevice(IUPnPDevice device) { AddDevice(device.GetUPnPDevice()); }
public int DeviceAdded(int lFindData, IUPnPDevice pDevice) { DeviceFound?.Invoke(lFindData, pDevice); return(default(int)); }
int IUPnPDeviceFinderCallback.DeviceAdded(int lFindData, IUPnPDevice pDevice) { DeviceAdded((UPnPDevice)pDevice); return(0); }
/// <summary> /// Creates a new list of devices from a devices child devices. /// </summary> /// <param name="device">The device to add the children for.</param> /// <param name="interfaceGuid">The network interface Guid of the device or Guid.Empty if unknown.</param> /// <param name="includingChildDevices">True to recursively get all devices or false to get immediate devices.</param> internal Devices(IUPnPDevice device, Guid interfaceGuid, bool includingChildDevices = false) : base() { AddFrom(device, interfaceGuid, includingChildDevices); }
/// <summary> /// Creates a new service object. /// </summary> /// <param name="comDevice">The immediate native device for the object.</param> /// <param name="interfaceGuid">The network interface Guid or Guid.Empty for none.</param> /// <param name="comService">The native service for the service.</param> internal Service(IUPnPDevice comDevice, Guid interfaceGuid, IUPnPService comService) : this(new Device(comDevice, interfaceGuid), comService) { }
/// <summary> /// Creates a new device. /// </summary> /// <param name="comDevice">The Native COM Device for which this device is linked to.</param> /// <param name="interfaceGuid">The Network interface Guid ID for the device or Guid.Empty for unknown.</param> internal Device(IUPnPDevice comDevice, Guid interfaceGuid) { mbInterfaceGuidAvailable = !interfaceGuid.Equals(Guid.Empty); mgInterfaceGuid = interfaceGuid; mdCOMDevice = comDevice; }
/// <summary> /// Gets the root description for a device. /// </summary> /// <param name="device">The device to get the root description.</param> /// <returns>The root description for the device.</returns> public static RootDescription RootDeviceDescription(this IUPnPDevice device) { if (Logging.Enabled) { Logging.Log(device, String.Format("Getting RootDeviceDescription for {0}", device.FriendlyName), 1); } try { string lsURL = device.GetDocumentURL(); if (lsURL.Length > 0) { if (Logging.Enabled) { Logging.Log(device, String.Format("Getting Document URL: '{0}'", lsURL)); } try { using (XmlTextReader lrReader = Utils.GetXMLTextReader(lsURL)) { if (Logging.Enabled) { Logging.Log(device, "Finding start node"); } while (lrReader.Read()) { if (RootDescription.IsStartNodeFor(lrReader)) { break; } } if (RootDescription.IsStartNodeFor(lrReader)) { if (Logging.Enabled) { Logging.Log(device, "Start node found, processing description"); } return(new RootDescription(lsURL, lrReader)); } else { if (Logging.Enabled) { Logging.Log(device, "Start node NOT found"); } return(null); } } } catch (Exception loE) { if (Logging.Enabled) { Logging.Log(device, String.Format("Downloading and processing of URL failed with error: {0}", loE.ToString())); } throw; } } else { if (Logging.Enabled) { Logging.Log(device, String.Format("Document URL Invalid: '{0}'", lsURL)); } return(null); } } finally { if (Logging.Enabled) { Logging.Log(device, System.String.Format("Finished getting RootDeviceDescription for {0}", device.FriendlyName), -1); } } }
/// <summary> /// Gets the key for a native device and service. /// </summary> /// <param name="device">The native device.</param> /// <param name="service">The native service.</param> /// <returns>The key for the device and service.</returns> private string KeyFor(IUPnPDevice device, IUPnPService service) { return(device.RootDevice.UniqueDeviceName + "|" + service.Id); }
/// <summary> /// Creates a new device added event arguments. /// </summary> /// <param name="device">The underlying COM device that was added.</param> /// <param name="baseArgs">The base args to get other event information from.</param> internal DeviceAddedEventArgs(IUPnPDevice device, DeviceAddedEventArgs baseArgs) { mbInterfaceGuidAvailable = baseArgs.InterfaceGuidAvailable; mgInterfaceGuid = baseArgs.mgInterfaceGuid; mdCOMDevice = device; }
//commands when device was found internal void DeviceFound(int lFindData, IUPnPDevice pDevice) { DLNADevices.Add(new DLNADevice((UPnPDevice)pDevice)); }
/// <summary> /// Creates a new device added event arguments. /// </summary> /// <param name="device">The underlying COM device that was added.</param> /// <param name="interfaceGuid">The network interface guid.</param> internal DeviceAddedEventArgs(IUPnPDevice device, Guid interfaceGuid) { mdCOMDevice = device; mgInterfaceGuid = interfaceGuid; mbInterfaceGuidAvailable = true; }
/// <summary> /// Gets the description for a service. /// </summary> /// <param name="service">The native com service.</param> /// <param name="device">The native com device.</param> /// <param name="rootDescription">The root description for the services device.</param> /// <returns>The service description.</returns> public static ServiceDescription Description( this IUPnPService service, IUPnPDevice device, RootDescription rootDescription) { if (Logging.Enabled) { Logging.Log(service, String.Format("Getting ServiceDescription for {0} -> {1}", device.FriendlyName, service.Id), 1); } try { DeviceServiceDescription ldsdDesc = service.DeviceServiceDescription(device, rootDescription); if (ldsdDesc != null) { ServiceDescription lsdDesc = ldsdDesc.GetDescription(rootDescription); if (lsdDesc != null) { if (Logging.Enabled) { if (Logging.Enabled) { Logging.Log(service, "ServiceDescription:", 1); } try { if (Logging.Enabled) { Logging.Log(service, lsdDesc.ToString()); } } finally { if (Logging.Enabled) { Logging.Log(service, "End ServiceDescription", -1); } } } } else if (Logging.Enabled) { Logging.Log(service, "ServiceDescription not found"); } return(lsdDesc); } else { if (Logging.Enabled) { Logging.Log(service, "Failed - Device Service Description Not Located"); } return(null); } } finally { if (Logging.Enabled) { Logging.Log(service, String.Format("Finished getting ServiceDescription for {0} -> {1}", device.FriendlyName, service.Id), -1); } } }
/// <summary> /// Gets the key for a native device and service. /// </summary> /// <param name="device">The native device.</param> /// <param name="service">The native service.</param> /// <returns>The key for the device and service.</returns> private string KeyFor(IUPnPDevice device, IUPnPService service) { return device.RootDevice.UniqueDeviceName + "|" + service.Id; }
/// <summary> /// Gets the device service description for a service. /// </summary> /// <param name="service">The service to get the description for.</param> /// <param name="device">The device to get the description for.</param> /// <param name="rootDescription">The root description for the device.</param> /// <returns>The device service description.</returns> public static DeviceServiceDescription DeviceServiceDescription( this IUPnPService service, IUPnPDevice device, RootDescription rootDescription) { if (Logging.Enabled) Logging.Log(service, String.Format("Getting DeviceServiceDescription for {0} -> {1}", device.FriendlyName, service.Id), 1); try { if (Logging.Enabled) { if (Logging.Enabled) Logging.Log(service, "Using RootDescription:", 1); try { if (Logging.Enabled) Logging.Log(service, rootDescription.ToString()); } finally { if (Logging.Enabled) Logging.Log(service, "End RootDescription", -1); } } DeviceServiceDescription ldsdDesc = null; if (rootDescription != null) { if (Logging.Enabled) Logging.Log(service, string.Format("Finding device by UDN: '{0}'", device.UniqueDeviceName)); DeviceDescription lddDevice = rootDescription.FindDevice(device.UniqueDeviceName); if (lddDevice != null) { if (Logging.Enabled) Logging.Log(service, string.Format("Device Found, finding DeviceServiceDescription by Service ID: '{0}'", service.Id)); if (Logging.Enabled) { if (Logging.Enabled) Logging.Log(service, "DeviceDescription:", 1); try { if (Logging.Enabled) Logging.Log(service, lddDevice.ToString()); } finally { if (Logging.Enabled) Logging.Log(service, "End DeviceDescription", -1); } } lddDevice.DeviceServices.TryGetValue(service.Id, out ldsdDesc); if (ldsdDesc != null) { if (Logging.Enabled) { if (Logging.Enabled) Logging.Log(service, "DeviceServiceDescription found:", 1); try { if (Logging.Enabled) Logging.Log(service, ldsdDesc.ToString()); } finally { if (Logging.Enabled) Logging.Log(service, "End DeviceServiceDescription", -1); } } } else if (Logging.Enabled) Logging.Log(service, "DeviceServiceDescripton not found"); } else if (Logging.Enabled) Logging.Log(service, "Device not found"); } else if (Logging.Enabled) Logging.Log(service, "Invalid rootDescription parameter"); return ldsdDesc; } finally { if (Logging.Enabled) Logging.Log(service, String.Format("Finished getting DeviceServiceDescription for {0} -> {1}", device.FriendlyName, service.Id), -1); } }
/// <summary> /// Gets the device service description for a service. /// </summary> /// <param name="service">The service to get the description for.</param> /// <param name="device">The device to get the description for.</param> /// <param name="rootDescription">The root description for the device.</param> /// <returns>The device service description.</returns> public static DeviceServiceDescription DeviceServiceDescription( this IUPnPService service, IUPnPDevice device, RootDescription rootDescription) { if (Logging.Enabled) { Logging.Log(service, String.Format("Getting DeviceServiceDescription for {0} -> {1}", device.FriendlyName, service.Id), 1); } try { if (Logging.Enabled) { if (Logging.Enabled) { Logging.Log(service, "Using RootDescription:", 1); } try { if (Logging.Enabled) { Logging.Log(service, rootDescription.ToString()); } } finally { if (Logging.Enabled) { Logging.Log(service, "End RootDescription", -1); } } } DeviceServiceDescription ldsdDesc = null; if (rootDescription != null) { if (Logging.Enabled) { Logging.Log(service, string.Format("Finding device by UDN: '{0}'", device.UniqueDeviceName)); } DeviceDescription lddDevice = rootDescription.FindDevice(device.UniqueDeviceName); if (lddDevice != null) { if (Logging.Enabled) { Logging.Log(service, string.Format("Device Found, finding DeviceServiceDescription by Service ID: '{0}'", service.Id)); } if (Logging.Enabled) { if (Logging.Enabled) { Logging.Log(service, "DeviceDescription:", 1); } try { if (Logging.Enabled) { Logging.Log(service, lddDevice.ToString()); } } finally { if (Logging.Enabled) { Logging.Log(service, "End DeviceDescription", -1); } } } lddDevice.DeviceServices.TryGetValue(service.Id, out ldsdDesc); if (ldsdDesc != null) { if (Logging.Enabled) { if (Logging.Enabled) { Logging.Log(service, "DeviceServiceDescription found:", 1); } try { if (Logging.Enabled) { Logging.Log(service, ldsdDesc.ToString()); } } finally { if (Logging.Enabled) { Logging.Log(service, "End DeviceServiceDescription", -1); } } } } else if (Logging.Enabled) { Logging.Log(service, "DeviceServiceDescripton not found"); } } else if (Logging.Enabled) { Logging.Log(service, "Device not found"); } } else if (Logging.Enabled) { Logging.Log(service, "Invalid rootDescription parameter"); } return(ldsdDesc); } finally { if (Logging.Enabled) { Logging.Log(service, String.Format("Finished getting DeviceServiceDescription for {0} -> {1}", device.FriendlyName, service.Id), -1); } } }
/// <summary> /// Creates a new service added event arguments. /// </summary> /// <param name="device">The underlying COM device that was added.</param> /// <param name="service">The underlying COM service that was added.</param> internal ServiceAddedEventArgs(IUPnPDevice device, IUPnPService service) { mbInterfaceGuidAvailable = false; mdCOMDevice = device; msCOMService = service; }
/// <summary> /// Creates a new service added event arguments. /// </summary> /// <param name="device">The underlying COM device that was added.</param> /// <param name="service">The underlying COM service that was added.</param> internal ServiceAddedEventArgs(IUPnPDevice device, IUPnPService service) { mbInterfaceGuidAvailable = false; mdCOMDevice = device; msCOMService = service; }
/// <summary> /// Revmoves the cache for a com native device. /// </summary> /// <param name="device">The device to remove the cache for.</param> internal void RemoveCacheFor(IUPnPDevice device) { string lsKey = KeyFor(device); if (Logging.Enabled) Logging.Log(this, string.Format("Removing RootDescription cache for: '{0}' root of '{1}' key '{2}'", device.RootDevice.FriendlyName, device.FriendlyName, lsKey)); mdCache.Remove(lsKey); }
/// <summary> /// Creates a new service added event arguments. /// </summary> /// <param name="device">The underlying COM device that was added.</param> /// <param name="interfaceGuid">The network interface guid.</param> /// <param name="service">The service which was added.</param> internal ServiceAddedEventArgs(IUPnPDevice device, Guid interfaceGuid, IUPnPService service) { mdCOMDevice = device; msCOMService = service; mgInterfaceGuid = interfaceGuid; mbInterfaceGuidAvailable = true; }
/// <summary> /// Gets the key for a device. /// </summary> /// <param name="device">The com native device to get the key for.</param> /// <returns>The key for a device.</returns> internal string KeyFor(IUPnPDevice device) { return device.RootDevice.UniqueDeviceName; }