/// <summary> /// Finds all services synchronously. /// </summary> /// <param name="addressFamily">The address family to search in. (Vista or above only).</param> /// <param name="resolveNetworkInterfaces">True to resolve network interface Guids.</param> /// <returns>A Services list containing the found services.</returns> public static Services FindServices( AddressFamilyFlags addressFamily = AddressFamilyFlags.IPvBoth, bool resolveNetworkInterfaces = false) { bool lbCompleted = true; return(FindServices( null, int.MaxValue, int.MaxValue, out lbCompleted, addressFamily, resolveNetworkInterfaces)); }
/// <summary> /// Finds a native device by UDN. /// </summary> /// <param name="udn">The UDN for the device.</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> internal static IUPnPDevice FindNativeDeviceByUDN( string udn, AddressFamilyFlags addressFamily = AddressFamilyFlags.IPvBoth) { UPnPDeviceFinder lfFinder = new UPnPDeviceFinder(); if (lfFinder is IUPnPAddressFamilyControl) { ((IUPnPAddressFamilyControl)lfFinder).SetAddressFamily((int)addressFamily); } return(lfFinder.FindByUDN(udn)); }
/// <summary> /// Finds native devices by device or service type. /// </summary> /// <param name="deviceOrServiceType">The partial or full device or service type to search for.</param> /// <param name="addressFamily">The address family to search in. (Vista or above only).</param> /// <returns>A UPnP Devices collection containing the found devices.</returns> internal static IUPnPDevices FindNativeDevices( string deviceOrServiceType, AddressFamilyFlags addressFamily = AddressFamilyFlags.IPvBoth) { UPnPDeviceFinder lfFinder = new UPnPDeviceFinder(); if (lfFinder is IUPnPAddressFamilyControl) { ((IUPnPAddressFamilyControl)lfFinder).SetAddressFamily((int)addressFamily); } return(lfFinder.FindByType(deviceOrServiceType, 0)); }
/// <summary> /// Finds services by service type asynchronously using a timeout period. /// </summary> /// <param name="serviceType">The service type to search for or null for all.</param> /// <param name="timeoutMS">The maximum timeout time in milliseconds to wait.</param> /// <param name="maxDevices">The maximum number of devices to find before returning.</param> /// <param name="servicesFound"> /// The delegate to call when async operation is complete.<para />NOTE: this delegate is executed /// in a different to the calling thread.</param> /// <param name="addressFamily">The address family to search in. (Vista or above only).</param> /// <param name="resolveNetworkInterfaces">True to resolve network interface Guids.</param> /// <returns>A Devices list containing the found devices.</returns> public static void FindServicesAsync( string serviceType, int timeoutMS, int maxDevices, ServicesFoundDelegate servicesFound, AddressFamilyFlags addressFamily = AddressFamilyFlags.IPvBoth, bool resolveNetworkInterfaces = false) { FindDevicesAsync( serviceType, timeoutMS, maxDevices, (devices, completed) => { servicesFound(devices.FindServices(serviceType, true), completed); }, addressFamily, resolveNetworkInterfaces); }
/// <summary> /// Finds services by service type synchronously using a timeout period. /// </summary> /// <param name="serviceType">The service type to search for or null for all.</param> /// <param name="timeoutMS">The maximum timeout time in milliseconds to wait.</param> /// <param name="maxDevices">The maximum number of devices to find before returning.</param> /// <param name="searchCompleted">True if the search completed and all available devices were returned.</param> /// <param name="addressFamily">The address family to search in. (Vista or above only).</param> /// <param name="resolveNetworkInterfaces">True to resolve network interface Guids.</param> /// <returns>A Services list containing the found services.</returns> public static Services FindServices( string serviceType, int timeoutMS, int maxDevices, out bool searchCompleted, AddressFamilyFlags addressFamily = AddressFamilyFlags.IPvBoth, bool resolveNetworkInterfaces = false) { Devices ldDevices = FindDevices( serviceType, timeoutMS, maxDevices, out searchCompleted, addressFamily, resolveNetworkInterfaces); return(ldDevices.FindServices(serviceType, true)); }
/// <summary> /// Finds devices by device or service type asynchronously using a timeout period. /// </summary> /// <param name="uriString">The URI string to search for or null for all devices.</param> /// <param name="timeoutMS">The maximum timeout time in milliseconds to wait.</param> /// <param name="maxDevices">The maximum number of devices to find before returning.</param> /// <param name="devicesFound"> /// The delegate to call when async operation is complete. <para /> NOTE: this delegate is executed /// in a different to the calling thread.</param> /// <param name="addressFamily">The address family to search in. (Vista or above only).</param> /// <param name="resolveNetworkInterfaces">True to resolve network interface Guids.</param> /// <returns>A Devices list containing the found devices.</returns> /// <exception cref="System.ArgumentNullException">Thrown when devicesFound delegate is null.</exception> public static void FindDevicesAsync( string uriString, int timeoutMS, int maxDevices, DevicesFoundDelegate devicesFound, AddressFamilyFlags addressFamily = AddressFamilyFlags.IPvBoth, bool resolveNetworkInterfaces = false) { if (devicesFound == null) { throw new ArgumentNullException("devicesFound"); } Object[] loParams = new object[] { uriString, timeoutMS, maxDevices, addressFamily, resolveNetworkInterfaces, devicesFound }; Devices ldDevices = null; bool lbSearchCompleted = false; Thread ltCurrent = Thread.CurrentThread; Thread ltThread = new Thread( (object args) => { try { object[] loArgs = (object[])args; ldDevices = Discovery.FindDevices( (string)loArgs[0], (int)loArgs[1], (int)loArgs[2], out lbSearchCompleted, (AddressFamilyFlags)loArgs[3], (bool)loArgs[4]); } finally { devicesFound(ldDevices, lbSearchCompleted); } } ); ltThread.Start(loParams); }
/// <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 devices by URI synchronously waiting for the entire search to complete. /// </summary> /// <param name="deviceOrServiceType">The partial or full device or service type to search for (cannot be null or empty).</param> /// <param name="addressFamily">The address family to search in. (Vista or above only).</param> /// <returns>A Devices list containing the found devices.</returns> /// <exception cref="System.ArgumentException">Thrown when deviceOrServiceType is null or empty.</exception> public static Devices FindDevices( string deviceOrServiceType, AddressFamilyFlags addressFamily = AddressFamilyFlags.IPvBoth) { if (String.IsNullOrEmpty(deviceOrServiceType)) { throw new ArgumentException("cannot be null or empty string", "deviceOrServiceType"); } IUPnPDevices ldDevices = FindNativeDevices(deviceOrServiceType, 0); if (ldDevices != null) { return(new Devices(ldDevices, Guid.Empty)); } else { return(null); } }
/// <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()); } }
/// <summary> /// Finds devices by device or service type synchronously using a timeout period. /// </summary> /// <param name="uriString">The URI string to search for or null / empty for all.</param> /// <param name="timeoutMS">The maximum timeout time in milliseconds to wait or -1 for wait forever.</param> /// <param name="maxDevices">The maximum number of devices to find before returning or 0 for as many as possible.</param> /// <param name="searchCompleted">True if the search completed and all available devices were returned.</param> /// <param name="addressFamily">The address family to search in. (Vista or above only).</param> /// <param name="resolveNetworkInterfaces">True to resolve network interface Guids.</param> /// <returns>A Devices list containing the found devices.</returns> public static Devices FindDevices( string uriString, int timeoutMS, int maxDevices, out bool searchCompleted, AddressFamilyFlags addressFamily = AddressFamilyFlags.IPvBoth, bool resolveNetworkInterfaces = false) { Discovery ldDiscovery = new Discovery(uriString, addressFamily, resolveNetworkInterfaces); Devices ldDevices = new Devices(); bool lbSearchCompleted = false; ManualResetEvent lmreComplete = new ManualResetEvent(false); ldDiscovery.DeviceAdded += (sender, args) => { ldDevices.Add(args.Device); if (maxDevices > 0 && ldDevices.Count >= maxDevices) { lmreComplete.Set(); } }; ldDiscovery.SearchComplete += (sender, args) => { lbSearchCompleted = true; lmreComplete.Set(); }; ldDiscovery.Start(); lmreComplete.WaitOne(timeoutMS); searchCompleted = lbSearchCompleted; ldDiscovery.Dispose(); return(ldDevices); }
/// <summary> /// Finds services by service type synchronously using a timeout period. /// </summary> /// <param name="serviceType">The service type to search for or null for all.</param> /// <param name="timeoutMS">The maximum timeout time in milliseconds to wait.</param> /// <param name="maxDevices">The maximum number of devices to find before returning.</param> /// <param name="searchCompleted">True if the search completed and all available devices were returned.</param> /// <param name="addressFamily">The address family to search in. (Vista or above only).</param> /// <param name="resolveNetworkInterfaces">True to resolve network interface Guids.</param> /// <returns>A Services list containing the found services.</returns> public static Services FindServices( string serviceType, int timeoutMS, int maxDevices, out bool searchCompleted, AddressFamilyFlags addressFamily = AddressFamilyFlags.IPvBoth, bool resolveNetworkInterfaces = false) { Devices ldDevices = FindDevices( serviceType, timeoutMS, maxDevices, out searchCompleted, addressFamily, resolveNetworkInterfaces); return ldDevices.FindServices(serviceType, true); }
/// <summary> /// Finds all services synchronously. /// </summary> /// <param name="addressFamily">The address family to search in. (Vista or above only).</param> /// <param name="resolveNetworkInterfaces">True to resolve network interface Guids.</param> /// <returns>A Services list containing the found services.</returns> public static Services FindServices( AddressFamilyFlags addressFamily = AddressFamilyFlags.IPvBoth, bool resolveNetworkInterfaces = false) { bool lbCompleted = true; return FindServices( null, int.MaxValue, int.MaxValue, out lbCompleted, addressFamily, resolveNetworkInterfaces); }
/// <summary> /// Finds devices by device or service type asynchronously using a timeout period. /// </summary> /// <param name="uriString">The URI string to search for or null for all devices.</param> /// <param name="timeoutMS">The maximum timeout time in milliseconds to wait.</param> /// <param name="maxDevices">The maximum number of devices to find before returning.</param> /// <param name="devicesFound"> /// The delegate to call when async operation is complete. <para /> NOTE: this delegate is executed /// in a different to the calling thread.</param> /// <param name="addressFamily">The address family to search in. (Vista or above only).</param> /// <param name="resolveNetworkInterfaces">True to resolve network interface Guids.</param> /// <returns>A Devices list containing the found devices.</returns> /// <exception cref="System.ArgumentNullException">Thrown when devicesFound delegate is null.</exception> public static void FindDevicesAsync( string uriString, int timeoutMS, int maxDevices, DevicesFoundDelegate devicesFound, AddressFamilyFlags addressFamily = AddressFamilyFlags.IPvBoth, bool resolveNetworkInterfaces = false) { if(devicesFound == null) throw new ArgumentNullException("devicesFound"); Object[] loParams = new object[] { uriString, timeoutMS, maxDevices, addressFamily, resolveNetworkInterfaces, devicesFound }; Devices ldDevices = null; bool lbSearchCompleted = false; Thread ltCurrent = Thread.CurrentThread; Thread ltThread = new Thread( (object args) => { try { object[] loArgs = (object[])args; ldDevices = Discovery.FindDevices( (string)loArgs[0], (int)loArgs[1], (int)loArgs[2], out lbSearchCompleted, (AddressFamilyFlags)loArgs[3], (bool)loArgs[4]); } finally { devicesFound(ldDevices, lbSearchCompleted); } } ); ltThread.Start(loParams); }
/// <summary> /// Finds devices by URI synchronously waiting for the entire search to complete. /// </summary> /// <param name="deviceOrServiceType">The partial or full device or service type to search for (cannot be null or empty).</param> /// <param name="addressFamily">The address family to search in. (Vista or above only).</param> /// <returns>A Devices list containing the found devices.</returns> /// <exception cref="System.ArgumentException">Thrown when deviceOrServiceType is null or empty.</exception> public static Devices FindDevices( string deviceOrServiceType, AddressFamilyFlags addressFamily = AddressFamilyFlags.IPvBoth) { if (String.IsNullOrEmpty(deviceOrServiceType)) throw new ArgumentException("cannot be null or empty string", "deviceOrServiceType"); IUPnPDevices ldDevices = FindNativeDevices(deviceOrServiceType, 0); if (ldDevices != null) return new Devices(ldDevices, Guid.Empty); else return null; }
/// <summary> /// Finds devices by device or service type synchronously using a timeout period. /// </summary> /// <param name="uriString">The URI string to search for or null / empty for all.</param> /// <param name="timeoutMS">The maximum timeout time in milliseconds to wait or -1 for wait forever.</param> /// <param name="maxDevices">The maximum number of devices to find before returning or 0 for as many as possible.</param> /// <param name="searchCompleted">True if the search completed and all available devices were returned.</param> /// <param name="addressFamily">The address family to search in. (Vista or above only).</param> /// <param name="resolveNetworkInterfaces">True to resolve network interface Guids.</param> /// <returns>A Devices list containing the found devices.</returns> public static Devices FindDevices( string uriString, int timeoutMS, int maxDevices, out bool searchCompleted, AddressFamilyFlags addressFamily = AddressFamilyFlags.IPvBoth, bool resolveNetworkInterfaces = false) { Discovery ldDiscovery = new Discovery(uriString, addressFamily, resolveNetworkInterfaces); Devices ldDevices = new Devices(); bool lbSearchCompleted = false; ManualResetEvent lmreComplete = new ManualResetEvent(false); ldDiscovery.DeviceAdded += (sender, args) => { ldDevices.Add(args.Device); if (maxDevices > 0 && ldDevices.Count >= maxDevices) lmreComplete.Set(); }; ldDiscovery.SearchComplete += (sender, args) => { lbSearchCompleted = true; lmreComplete.Set(); }; ldDiscovery.Start(); lmreComplete.WaitOne(timeoutMS); searchCompleted = lbSearchCompleted; ldDiscovery.Dispose(); return ldDevices; }
/// <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 a native device by UDN. /// </summary> /// <param name="udn">The UDN for the device.</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> internal static IUPnPDevice FindNativeDeviceByUDN( string udn, AddressFamilyFlags addressFamily = AddressFamilyFlags.IPvBoth) { UPnPDeviceFinder lfFinder = new UPnPDeviceFinder(); if (lfFinder is IUPnPAddressFamilyControl) ((IUPnPAddressFamilyControl)lfFinder).SetAddressFamily((int)addressFamily); return lfFinder.FindByUDN(udn); }
/// <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(); }
/// <summary> /// Creates a new discovery class. /// </summary> /// <param name="searchURI"> /// The URI string to filter deviecs by or null / empty for all. /// Gets or sets the Search URI to filter devices by. /// A search uri can be a Device.Type, Device.UDN, or Service.ServiceTypeIdentifier in the form /// of urn:schemas-upnp-org:deviceTypeName:deviceTypeVersion, uuid:00000000-0000-0000-0000-000000000000, or /// urn:schemas-upnp-org:service:serviceTypeName:serviceTypeVersion. /// </param> /// <param name="addressFamily">The address family of the interfaces to search in (Vista and above only).</param> /// <param name="resolveNetworkInterfaces">True to resolve network interface Guids.</param> public Discovery(string searchURI, AddressFamilyFlags addressFamily = AddressFamilyFlags.IPvBoth, bool resolveNetworkInterfaces = false) { mbResolveNetworkInterface = resolveNetworkInterfaces; msSearchURI = searchURI; mafAddressFamily = addressFamily; }
/// <summary> /// Finds native devices by device or service type. /// </summary> /// <param name="deviceOrServiceType">The partial or full device or service type to search for.</param> /// <param name="addressFamily">The address family to search in. (Vista or above only).</param> /// <returns>A UPnP Devices collection containing the found devices.</returns> internal static IUPnPDevices FindNativeDevices( string deviceOrServiceType, AddressFamilyFlags addressFamily = AddressFamilyFlags.IPvBoth) { UPnPDeviceFinder lfFinder = new UPnPDeviceFinder(); if (lfFinder is IUPnPAddressFamilyControl) ((IUPnPAddressFamilyControl)lfFinder).SetAddressFamily((int)addressFamily); return lfFinder.FindByType(deviceOrServiceType, 0); }