Exemplo n.º 1
0
        private void Run()
        {
            log4net.Config.BasicConfigurator.Configure();

            Console.Title = "Press 'q' to quit; 'l' to list devices";

            Console.WriteLine("Starting...");

            using (var upnp = new UPnP())
            {
                upnp.Start();

                var cp = new ControlPoint(true);

                cp.DeviceAdded    += new ControlPoint.DeviceAddedDelegate(cp_DeviceAdded);
                cp.DeviceRemoved  += new ControlPoint.DeviceRemovedDelegate(cp_DeviceRemoved);
                cp.ActionResponse += new ControlPoint.ActionResponseDelegate(cp_ActionResponse);

                upnp.AddControlPoint(cp);

                #region handle keyboard

                for (bool quit = false; !quit;)
                {
                    switch (Console.ReadKey(true).KeyChar)
                    {
                    case 'q':
                        quit = true;

                        break;

                    case 'l':
                    {
                        var devs = cp.Devices;

                        Console.WriteLine("Devices (" + devs.Length + "):");

                        foreach (var d in devs)
                        {
                            Console.WriteLine("  " + d.FriendlyName);
                        }

                        break;
                    }
                    }
                }

                #endregion

                cp.DeviceAdded   -= new ControlPoint.DeviceAddedDelegate(cp_DeviceAdded);
                cp.DeviceRemoved -= new ControlPoint.DeviceRemovedDelegate(cp_DeviceRemoved);

                upnp.Stop();
            }

            Console.WriteLine("Stopped.");
        }
Exemplo n.º 2
0
Arquivo: Program.cs Projeto: B0k0/xbmc
        private void Run()
        {
            log4net.Config.BasicConfigurator.Configure();

            Console.Title = "Press 'q' to quit; 'l' to list devices";

            Console.WriteLine("Starting...");

            using (var upnp = new UPnP())
            {
                upnp.Start();

                var cp = new ControlPoint(true);

                cp.DeviceAdded += new ControlPoint.DeviceAddedDelegate(cp_DeviceAdded);
                cp.DeviceRemoved += new ControlPoint.DeviceRemovedDelegate(cp_DeviceRemoved);
                cp.ActionResponse += new ControlPoint.ActionResponseDelegate(cp_ActionResponse);

                upnp.AddControlPoint(cp);

                #region handle keyboard

                for (bool quit = false; !quit; )
                {
                    switch (Console.ReadKey(true).KeyChar)
                    {
                        case 'q':
                            quit = true;

                            break;

                        case 'l':
                            {
                                var devs = cp.Devices;

                                Console.WriteLine("Devices (" + devs.Length + "):");

                                foreach (var d in devs)
                                {
                                    Console.WriteLine("  " + d.FriendlyName);
                                }

                                break;
                            }
                    }
                }

                #endregion

                cp.DeviceAdded -= new ControlPoint.DeviceAddedDelegate(cp_DeviceAdded);
                cp.DeviceRemoved -= new ControlPoint.DeviceRemovedDelegate(cp_DeviceRemoved);

                upnp.Stop();
            }

            Console.WriteLine("Stopped.");
        }