示例#1
0
文件: UPNP.cs 项目: hawkinsml/sugar
        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());
        }
示例#2
0
        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);
        }
示例#5
0
        /// <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));
        }
示例#6
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;
                }
            }
        }
示例#7
0
文件: WeMo.cs 项目: hawkinsml/sugar
        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 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);
                }
            }
        }
示例#10
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());
        }
示例#11
0
文件: WeMo.cs 项目: hawkinsml/sugar
        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);
            }
        }
示例#12
0
        /// <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);
        }
示例#13
0
        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;
        }
示例#14
0
        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;
        }
示例#15
0
        /// <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);
        }
示例#16
0
文件: Class1.cs 项目: Cobster/WeMo
        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();
        }