private void dowork(object o, DoWorkEventArgs args) { BackgroundWorker b = o as BackgroundWorker; StringBuilder sb = new StringBuilder(); var finder = new UPnPDeviceFinder(); var foundDevices = new List <UPnPDevice>(); var deviceType = "upnp:rootdevice"; var devices = finder.FindByType(deviceType, 1); foreach (UPnPDevice upnpDevice in devices) { sb.AppendHtmlLine("FriendlyName: " + upnpDevice.FriendlyName); sb.AppendHtmlLine("Description: " + upnpDevice.Description); sb.AppendHtmlLine("PresentationURL: " + upnpDevice.PresentationURL); string port = new Uri(upnpDevice.PresentationURL).Port.ToString(); string baseUrl = new Uri(upnpDevice.PresentationURL).DnsSafeHost.ToString(); sb.AppendHtmlLine("Type: " + upnpDevice.Type); sb.AppendHtmlLine("Port: " + port); sb.AppendHtmlLine("baseUrl: " + baseUrl); sb.AppendLine("<hr/>"); } WebPage.DisplayWebPage("Universal Plug and Play devices", sb.ToString()); }
public static bool Discover() { service = null; UPnPDeviceFinder finder = (UPnPDeviceFinder)Activator.CreateInstance(Type.GetTypeFromCLSID(new Guid("E2085F28-FEB7-404A-B8E7-E659BDEAAA02"))); service = CheckDevices(finder.FindByType("urn:schemas-upnp-org:device:InternetGatewayDevice:1", 0)); return(service != null); }
public static List<MediaServer> All() { List<MediaServer> mediaServers = new List<MediaServer>(); UPnPDeviceFinder deviceFinder = new UPnPDeviceFinder(); UPnPDevices mediaServerDevices = deviceFinder.FindByType("urn:schemas-upnp-org:device:MediaServer:1", 0); foreach (UPnPDevice mediaServerDevice in mediaServerDevices) { mediaServers.Add(new MediaServer(mediaServerDevice, mediaServerDevice.FriendlyName)); } return mediaServers; }
public static List <MediaServer> All() { List <MediaServer> mediaServers = new List <MediaServer>(); UPnPDeviceFinder deviceFinder = new UPnPDeviceFinder(); UPnPDevices mediaServerDevices = deviceFinder.FindByType("urn:schemas-upnp-org:device:MediaServer:1", 0); foreach (UPnPDevice mediaServerDevice in mediaServerDevices) { mediaServers.Add(new MediaServer(mediaServerDevice, mediaServerDevice.FriendlyName)); } return(mediaServers); }
/// <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)); }
public void Refresh() { UPnPDeviceFinder finder = new UPnPDeviceFinder(); UPnPDevices devs = finder.FindByType("upnp:rootdevice", 0); lock (this) { this.devices.Clear(); foreach (UPnPDevice device in GetAllDevices(devs.OfType <UPnPDevice>())) { this.devices[device.UniqueDeviceName] = device; } } }
private void runGetAllDevices() { BackgroundWorker bw = new BackgroundWorker(); // this allows our worker to report progress during work bw.WorkerReportsProgress = true; // what to do in the background thread bw.DoWork += new DoWorkEventHandler( delegate(object o, DoWorkEventArgs args) { BackgroundWorker b = o as BackgroundWorker; var finder = new UPnPDeviceFinder(); var foundDevices = new List <UPnPDevice>(); var deviceType = "upnp:rootdevice"; var devices = finder.FindByType(deviceType, 1); foreach (UPnPDevice upnpDevice in devices) { string port = new Uri(upnpDevice.PresentationURL).Port.ToString(); string baseUrl = new Uri(upnpDevice.PresentationURL).DnsSafeHost.ToString(); Console.WriteLine("Type: " + upnpDevice.Type); Console.WriteLine("Port: " + port); Console.WriteLine("baseUrl: " + baseUrl); } // b.ReportProgress(i * 10); }); // what to do when progress changed (update the progress bar for example) bw.ProgressChanged += new ProgressChangedEventHandler( delegate(object o, ProgressChangedEventArgs args) { Console.WriteLine(string.Format("{0}% Completed", args.ProgressPercentage)); }); // what to do when worker completes its task (notify the user) bw.RunWorkerCompleted += new RunWorkerCompletedEventHandler( delegate(object o, RunWorkerCompletedEventArgs args) { Console.WriteLine("Finished!"); }); bw.RunWorkerAsync(); }
private void FillList() { var finder = new UPnPDeviceFinder(); var devices = finder.FindByType("upnp:rootdevice", 0); Console.WriteLine("FillList"); //var devices = ScoutHelper.UpnpGetDevices(); foreach (UPnPDevice upnpDevice in devices) { if (IsHueBridge(upnpDevice)) { var device = CreateDevice(upnpDevice); currentDeviceList.InsertDevice(device); } } }
private IEnumerable <WeMoDevice> Find() { UPnPDeviceFinder finder = new UPnPDeviceFinder(); UPnPDevices found = finder.FindByType("urn:Belkin:device:controllee:1", 0); var devices = found.Cast <UPnPDevice>().Select(device => { var uri = new Uri(device.PresentationURL); return(new WeMoDevice { Name = device.FriendlyName, IpAddress = uri.Host, Port = uri.Port }); }); return(devices.ToList()); }
private void GetAllDevices() { var finder = new UPnPDeviceFinder(); var foundDevices = new List <UPnPDevice>(); var deviceType = "upnp:rootdevice"; var devices = finder.FindByType(deviceType, 1); foreach (UPnPDevice upnpDevice in devices) { string port = new Uri(upnpDevice.PresentationURL).Port.ToString(); string baseUrl = new Uri(upnpDevice.PresentationURL).DnsSafeHost.ToString(); Console.WriteLine("Type: " + upnpDevice.Type); Console.WriteLine("Port: " + port); Console.WriteLine("baseUrl: " + baseUrl); } }
/// <summary> /// Gets the devices by upnp. /// </summary> /// <returns></returns> public static List <WeMoDevice> GetDevicesByUpnp() { UPnPDeviceFinder finder = new UPnPDeviceFinder(); List <WeMoDevice> foundDevices = new List <WeMoDevice>(); // // Query all UPNP root devices // string deviceType = "upnp:rootdevice"; UPnPDevices devices = finder.FindByType(deviceType, 1); // // Iterate devices and create proper parent types based on WeMo device type and store in collection // foreach (UPnPDevice device in devices) { string type = device.Type; //Console.WriteLine("Found " + type); if (type.StartsWith("urn:Belkin:")) { switch (GetDeviceType(device)) { case WeMoDeviceType.Switch: WeMoSwitch wemoSwitch = new WeMoSwitch(device); foundDevices.Add(wemoSwitch); break; case WeMoDeviceType.Sensor: WeMoSensor wemoSensor = new WeMoSensor(device); foundDevices.Add(wemoSensor); break; default: // TODO: Decide what to do with non Sensor/Switch devices break; } } } return(foundDevices); }
private static void UpnpScan(object source, ElapsedEventArgs e) { //lets stop the timer while we do our work upnpScanTimer.Enabled = false; var finder = new UPnPDeviceFinder(); var devices = finder.FindByType("upnp:rootdevice", 0); lock (lockObject) { upnpDevices.Clear(); foreach (UPnPDevice device in devices) { upnpDevices.Add(device); //logger.Log("UPnPDevice: model={0} present={1} type={2} sn={3} upc={4} udn={5}", device.ModelURL, device.PresentationURL, device.Type, device.SerialNumber, device.UPC, device.UniqueDeviceName); } } //lets re-start the timer now upnpScanTimer.Enabled = true; }
/// <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); }
private IEnumerable<WeMoDevice> Find() { UPnPDeviceFinder finder = new UPnPDeviceFinder(); UPnPDevices found = finder.FindByType("urn:Belkin:device:controllee:1", 0); var devices = found.Cast<UPnPDevice>().Select(device => { var uri = new Uri(device.PresentationURL); return new WeMoDevice { Name = device.FriendlyName, IpAddress = uri.Host, Port = uri.Port }; }); return devices.ToList(); }