Esempio n. 1
0
        //Add this method override
        protected override void OnStartup(StartupEventArgs e)
        {
            m_Mutex = new Mutex(true, "HomeGenieManagerMutex", out createdNew);
            //e.Args is the string[] of command line argruments
            //
            upnpService                 = new Dictionary <string, UPnPDevice>();
            upnpControl                 = new UPnPControlPoint();
            upnpControl.OnSearch       += upnpcontrol_OnSearch;
            upnpControl.OnCreateDevice += upnpcontrol_OnCreateDevice;
            upnpControl.FindDeviceAsync("urn:schemas-upnp-org:device:HomeAutomationServer:1");
            //
            Application.Current.ShutdownMode = System.Windows.ShutdownMode.OnLastWindowClose;
            var myDialogWindow = new LoadingDialog();

            myDialogWindow.Show();
            //
            Task loader = new Task(() =>
            {
                int t = 0;
                while (t < 10)
                {
                    if (upnpService.Count > 0)
                    {
                        Thread.Sleep(2000);
                        for (int s = 0; s < UPnPDevices.Count; s++)
                        {
                            var dev = UPnPDevices.ElementAt(s).Value;
                            if (dev.StandardDeviceType == "HomeAutomationServer")
                            {
                                System.Diagnostics.Process.Start(dev.PresentationURL);
                                t = 10;
                                break;
                            }
                        }
                    }
                    t++;
                    Thread.Sleep(1000);
                }
                //
                Thread.Sleep(2000);
                //
                myDialogWindow.Dispatcher.BeginInvoke(new Action(() =>
                {
                    if (!createdNew)
                    {
                        myDialogWindow.Close();
                        Application.Current.Shutdown();
                    }
                    else
                    {
                        var window = new MainWindow();
                        window.Show();
                        myDialogWindow.Close();
                    }
                }), null);
            });

            loader.Start();
        }
Esempio n. 2
0
 private static UPnPService CheckDevices(UPnPDevices devices)
 {
     foreach (UPnPDevice device in devices)
     {
         UPnPService service = CheckDevice(device);
         if (service != null)
         {
             return(service);
         }
     }
     return(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);
        }
Esempio n. 4
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;
                }
            }
        }
Esempio n. 5
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());
        }
Esempio n. 6
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);
        }