public void TestInformationGathering()
        {
            Console.WriteLine("Test to gather information from a device.");
            UPnP u = new UPnP();
            u.SetupSockets();

            bool wait = true;
            u.DeviceDiscovered += delegate(Device d)
            {
                d.InformationGathered += delegate(Device dig, bool was_successful)
                {
                    if (was_successful)
                    {
                        Console.WriteLine("");
                        Console.WriteLine("-- Gathered device information --");
                        Console.WriteLine("Device Type: "+Enum.GetName(typeof(Device.DeviceTypes),dig.DeviceType));
                        Console.WriteLine("SpecVersion: " + dig.SpecVersionMajor + "." + dig.SpecVersionMinor);
                        Console.WriteLine("URLBase: " + dig.UrlBase);
                        if (dig.RootDevice != null)
                        {
                            Console.WriteLine("presentationURL: " + dig.RootDevice.PresentationUrl);
                            Console.WriteLine("friendlyName: " + dig.RootDevice.FriendlyName);
                            Console.WriteLine("manufacturer: " + dig.RootDevice.Manufacturer);
                            Console.WriteLine("manufacturerURL: " + dig.RootDevice.ManufacturerUrl);
                            Console.WriteLine("modelDescription: " + dig.RootDevice.ModelDescription);
                            Console.WriteLine("modelName: " + dig.RootDevice.ModelName);
                            Console.WriteLine("Number of Sub Devices: " + dig.RootDevice.Devices.Count);
                            Console.WriteLine("Sub UUID: " + dig.RootDevice.UniversalUniqueID);
                        }
                        //Console.WriteLine("Server: " + r.Server);
                        Console.WriteLine("UUID: " + dig.UniversalUniqueID);
                        Console.WriteLine("-- Gathered device information --");
                        Console.WriteLine("");
                        wait = false;
                    }
                    else Console.WriteLine("failed to gather device information");

                };
                d.GatherInformation();//TODO this could also be done by upnp after it fired the discovered event

                string message_border = "-- Discovered a " + Enum.GetName(typeof(Device.DeviceTypes), d.DeviceType) + " --";
                Console.WriteLine("");
                Console.WriteLine(message_border);
                Console.WriteLine("Server: " + d.Server);
                Console.WriteLine("Host: " + d.Host + ":" + d.Port);
                Console.WriteLine("UUID: " + d.UniversalUniqueID);
                Console.WriteLine("Location: " + d.Location);
                Console.WriteLine("Unique Service Name: " + d.UniqueServiceName);
                Console.WriteLine(message_border);
                Console.WriteLine("");
                //Assert.IsTrue(!string.IsNullOrEmpty(ex_ip_completed.MyIP), "no ip address fetched");
            };
            u.StartDiscovery();
            Console.WriteLine("Waiting for data");
            DateTime start = DateTime.Now;
            while (wait)
            {
                if (DateTime.Now - start > new TimeSpan(0, 0, 60))
                {
                    Console.WriteLine("");
                    Console.WriteLine("Operation took too long");
                    wait = false;
                    Assert.Fail("Operation took too long");
                }
                Console.Write(".");
                Thread.Sleep(250);
            }
            Console.WriteLine("UPnP Device Information Gathering Test successful.");

            u.CloseSockets();
        }
        public void TestMediaRendererDiscovery()
        {
            Console.WriteLine("Test to discover an upnp media renderer.");
            UPnP u = new UPnP();
            u.SetupSockets();

            bool wait = true;
            u.DeviceDiscovered += delegate(Device d)
            {
                if (d.DeviceType == Device.DeviceTypes.MediaRenderer)
                {
                    MediaRenderer mr = (MediaRenderer)d;
                    Console.WriteLine("");
                    Console.WriteLine("-- Discovered a media renderer --");
                    Console.WriteLine("Server: " + mr.Server);
                    Console.WriteLine("Host: " + mr.Host + ":" + mr.Port);
                    Console.WriteLine("UUID: " + mr.UniversalUniqueID);
                    Console.WriteLine("Location: " + mr.Location);
                    Console.WriteLine("Unique Service Name: " + mr.UniqueServiceName);
                    Console.WriteLine("-- Discovered a media renderer --");
                    Console.WriteLine("");
                    //Assert.IsTrue(!string.IsNullOrEmpty(ex_ip_completed.MyIP), "no ip address fetched");
                    wait = false;
                }
            };
            u.StartDiscovery();
            Console.WriteLine("Waiting for data");
            DateTime start = DateTime.Now;
            while (wait)
            {
                if (DateTime.Now - start > new TimeSpan(0, 0, 60))
                {
                    Console.WriteLine("");
                    Console.WriteLine("Operation took too long");
                    wait = false;
                    Assert.Fail("Operation took too long");
                }
                Console.Write(".");
                Thread.Sleep(250);
            }
            Console.WriteLine("UPnP Media Renderer Discovery Test successful.");

            u.CloseSockets();
        }
        public void TestBinaryLightSwitchPowerOn()
        {
            Console.WriteLine("Test to switch the power of a binary light on.");
            UPnP u = new UPnP();
            u.SetupSockets();

            bool wait = true;
            u.DeviceDiscovered += delegate(Device d)
            {
                if (d.DeviceType == Device.DeviceTypes.BinaryLight)
                {
                    BinaryLight bl = (BinaryLight)d;
                    bl.SwitchingPowerCompleted += delegate(BinaryLight sp, bool was_successful)
                    {
                        if (was_successful)
                            Console.WriteLine("Switched some light on.");
                        wait = !was_successful;
                    };

                    bl.InformationGathered += delegate(Device dibl, bool was_successful)
                    {
                        BinaryLight blig = (BinaryLight)dibl;
                        if (was_successful)
                        {
                            Console.WriteLine("");
                            Console.WriteLine("-- Gathered binary light information --");
                            Console.WriteLine("SpecVersion: " + blig.SpecVersionMajor + "." + blig.SpecVersionMinor);
                            Console.WriteLine("URLBase: " + blig.UrlBase);
                            if (blig.RootDevice != null)
                            {
                                Console.WriteLine("presentationURL: " + blig.RootDevice.PresentationUrl);
                                Console.WriteLine("friendlyName: " + blig.RootDevice.FriendlyName);
                                Console.WriteLine("manufacturer: " + blig.RootDevice.Manufacturer);
                                Console.WriteLine("manufacturerURL: " + blig.RootDevice.ManufacturerUrl);
                                Console.WriteLine("modelDescription: " + blig.RootDevice.ModelDescription);
                                Console.WriteLine("modelName: " + blig.RootDevice.ModelName);
                                Console.WriteLine("Number of Sub Devices: " + blig.RootDevice.Devices.Count);
                                Console.WriteLine("Sub UUID: " + blig.RootDevice.UniversalUniqueID);
                                blig.SwitchPower(BinaryLight.PowerStates.On);
                            }
                            //Console.WriteLine("Server: " + r.Server);
                            Console.WriteLine("UUID: " + blig.UniversalUniqueID);
                            Console.WriteLine("-- Gathered binary light information --");
                            Console.WriteLine("");
                        }
                        else Console.WriteLine("failed to gather binary light information");
                    };
                    bl.GatherInformation();//TODO this could also be done by upnp after it fired the discovered event

                    Console.WriteLine("");
                    Console.WriteLine("-- Discovered a binary light --");
                    Console.WriteLine("Server: " + bl.Server);
                    Console.WriteLine("Host: " + bl.Host + ":" + bl.Port);
                    Console.WriteLine("UUID: " + bl.UniversalUniqueID);
                    Console.WriteLine("Location: " + bl.Location);
                    Console.WriteLine("Unique Service Name: " + bl.UniqueServiceName);
                    Console.WriteLine("-- Discovered a binary light --");
                    Console.WriteLine("");
                    //Assert.IsTrue(!string.IsNullOrEmpty(ex_ip_completed.MyIP), "no ip address fetched");
                }
            };
            u.StartDiscovery();
            Console.WriteLine("Waiting for data");
            DateTime start = DateTime.Now;
            while (wait)
            {
                if (DateTime.Now - start > new TimeSpan(0, 0, 300))
                {
                    Console.WriteLine("");
                    Console.WriteLine("Operation took too long");
                    wait = false;
                    Assert.Fail("Operation took too long");
                }
                Console.Write(".");
                Thread.Sleep(250);
            }
            Console.WriteLine("UPnP Binary Light Switch Power On Test successful.");

            u.CloseSockets();
        }
        public void TestDiscovery()
        {
            Console.WriteLine("Test to discover supported upnp devices.");
            UPnP u = new UPnP();
            u.SetupSockets();

            bool wait = true;
            int found = 0;
            u.DeviceDiscovered += delegate(Device d)
            {
                string message_border = "-- Discovered a " + Enum.GetName(typeof(Device.DeviceTypes), d.DeviceType) + " --";
                Console.WriteLine("");
                Console.WriteLine(message_border);
                Console.WriteLine("Server: " + d.Server);
                Console.WriteLine("Host: " + d.Host + ":" + d.Port);
                Console.WriteLine("UUID: " + d.UniversalUniqueID);
                Console.WriteLine("Location: " + d.Location);
                Console.WriteLine("Unique Service Name: " + d.UniqueServiceName);
                Console.WriteLine(message_border);
                Console.WriteLine("");
                //Assert.IsTrue(!string.IsNullOrEmpty(ex_ip_completed.MyIP), "no ip address fetched");
                //wait = false;
                found++;

            };

            u.StartDiscovery();
            Console.WriteLine("Waiting for data");
            DateTime start = DateTime.Now;
            while (wait)
            {
                if (DateTime.Now - start > new TimeSpan(0, 0, 15))
                {
                    if (found == 0)
                    {
                        Console.WriteLine("");
                        Console.WriteLine("Operation took too long");
                        Assert.Fail("Operation took too long");
                    }
                    wait = false;
                }
                Console.Write(".");
                Thread.Sleep(250);
            }
            Console.WriteLine("");
            if (found > 0) Console.WriteLine("Found " + found + " UPnP Devices.");
            Assert.IsTrue(found>0,"Test failed: No devices found.");
            Console.WriteLine("UPnP Device Discovery Test successful.");

            u.CloseSockets();
        }
        public void TestAddLocalDevice()
        {
            Console.WriteLine("Test to add a local upnp device.");
            UPnP u = new UPnP();
            u.SetupSockets();
            MediaBrowser mb = new MediaBrowser();
            bool wait = true;
            //     wait = false;
            mb.RootDevice.FriendlyName = "vpMediaTestserver";
            mb.BrowseRequestReceived += delegate(MediaBrowser media_browser,string object_id,string browse_flag,int starting_index,int requested_count,string sort_criteria)
            {
                Console.WriteLine("Browse request received: \nobject_id: "+object_id+"\nbrowse_flag: "+browse_flag+"\nstarting_index: "+starting_index+"\nrequested_count: "+requested_count+"\nsort_criteria: "+sort_criteria+"\n");
                MediaBrowser.BrowseResult result = new MediaBrowser.BrowseResult();
                if (object_id == "0")
                {
                    result.TotalMatches = 3;
                    result.AddFolder("Queue", "queue", "0", true, false, 3, "UNKNOWN", -1);
                    result.AddItem("test item", "pez2001", "http://www.voyagerproject.de/stuff/phat_sweet_drill_mix.wav.mp3", "audio/mpeg", "test", "0", false, -1, "UNKNOWN");
                    result.AddItem("test item 2", "pez2001", "http://www.voyagerproject.org/wp-content/uploads/2006/05/treiwund%20+%20graf%20contra2.mp3", "audio/mpeg", "test", "0", false, -1, "UNKNOWN");
                }
                else if (object_id == "queue")
                {
                    result.TotalMatches = 3;
                    result.AddFolder("Root", "0", "0", true, false, 3, "UNKNOWN", -1);
                    result.AddItem("test item b", "pez2001", "http://www.voyagerproject.de/stuff/phat_sweet_drill_mix.wav.mp3", "audio/mpeg", "test", "0", false, -1, "UNKNOWN");
                    result.AddItem("test item b 2", "pez2001", "http://www.voyagerproject.org/wp-content/uploads/2006/05/treiwund%20+%20graf%20contra2.mp3", "audio/mpeg", "test", "0", false, -1, "UNKNOWN");
                }
                return (result);
            };
            u.AddLocalDevice(mb);
            Console.WriteLine("Waiting for data");
            DateTime start = DateTime.Now;
            while (wait)
            {
                if (DateTime.Now - start > new TimeSpan(0, 0, 60))
                {
                    Console.WriteLine("");
                    Console.WriteLine("Operation took too long");
                    wait = false;
                    Assert.Fail("Operation took too long");
                }
                Console.Write(".");
                Thread.Sleep(250);
            }
            Console.WriteLine("UPnP Local Device Add Test successful.");

            u.CloseSockets();
        }
        public void TestAnnounceDevice()
        {
            Console.WriteLine("Test to announce an upnp device.");
            UPnP u = new UPnP();
            u.SetupSockets();
            MediaBrowser mb = new MediaBrowser();

            bool wait = true;
            //     wait = false;
            u.AnnounceDevice(mb,true);
            Console.WriteLine("Waiting for data");
            DateTime start = DateTime.Now;
            while (wait)
            {
                if (DateTime.Now - start > new TimeSpan(0, 0, 60))
                {
                    Console.WriteLine("");
                    Console.WriteLine("Operation took too long");
                    wait = false;
                    Assert.Fail("Operation took too long");
                }
                Console.Write(".");
                Thread.Sleep(250);
            }
            Console.WriteLine("UPnP Device Announcing Test successful.");

            u.CloseSockets();
        }
        public void TestRouterStatusUpdating()
        {
            Console.WriteLine("Test to update status from a router.");
            UPnP u = new UPnP();
            u.SetupSockets();

            bool wait = true;
             u.DeviceDiscovered += delegate(Device d)
            {
                if (d.DeviceType == Device.DeviceTypes.Router)
                {
                    Router r = (Router)d;
                    r.StatusUpdated += delegate(Router ur, bool was_successful)
                     {
                         if (was_successful)
                         {
                             Console.WriteLine("");
                             Console.WriteLine("-- router status updated --");
                             //Console.WriteLine("Server: " + r.Server);
                             Console.WriteLine("UUID: " + r.UniversalUniqueID);
                             Console.WriteLine("-- router status updated --");
                             Console.WriteLine("");
                             wait = false;
                         }
                         else Console.WriteLine("failed to update router status");

                     };

                    r.InformationGathered += delegate(Device dir, bool was_successful)
                    {
                        Router ir = (Router)dir;
                        if (was_successful)
                        {
                            Console.WriteLine("");
                            Console.WriteLine("-- Gathered router information --");
                            //Console.WriteLine("Server: " + r.Server);
                            Console.WriteLine("UUID: " + ir.UniversalUniqueID);
                            Console.WriteLine("-- Gathered router information --");
                            Console.WriteLine("");
                            ir.UpdateStatusInfo();
                        }
                        else Console.WriteLine("failed to gather router information");

                    };
                    r.GatherInformation();//TODO this could also be done by upnp after it fired the discovered event

                    Console.WriteLine("");
                    Console.WriteLine("-- Discovered a router --");
                    Console.WriteLine("Server: " + r.Server);
                    Console.WriteLine("Host: " + r.Host + ":" + r.Port);
                    Console.WriteLine("UUID: " + r.UniversalUniqueID);
                    Console.WriteLine("Location: " + r.Location);
                    Console.WriteLine("Unique Service Name: " + r.UniqueServiceName);
                    Console.WriteLine("-- Discovered a router --");
                    Console.WriteLine("");
                    //Assert.IsTrue(!string.IsNullOrEmpty(ex_ip_completed.MyIP), "no ip address fetched");
                }
            };
            u.StartDiscovery();
            Console.WriteLine("Waiting for data");
            DateTime start = DateTime.Now;
            while (wait)
            {
                if (DateTime.Now - start > new TimeSpan(0, 0, 60))
                {
                    Console.WriteLine("");
                    Console.WriteLine("Operation took too long");
                    wait = false;
                    Assert.Fail("Operation took too long");
                }
                Console.Write(".");
                Thread.Sleep(250);
            }
            Console.WriteLine("UPnP Router Updating Status Test successful.");

            u.CloseSockets();
        }
        public void TestRouterRequestConnection()
        {
            Console.WriteLine("Test to connect a router.");
            UPnP u = new UPnP();
            u.SetupSockets();

            bool wait = true;
            u.DeviceDiscovered += delegate(Device d)
            {
                if (d.DeviceType == Device.DeviceTypes.Router)
                {
                    Router r = (Router)d;

                    r.ConnectionRequestCompleted += delegate(Router fr, bool was_successful)
                    {
                        if (was_successful)
                            Console.WriteLine("Connected Router.");
                        wait = !was_successful;
                    };

                    r.InformationGathered += delegate(Device dir, bool was_successful)
                    {
                        Router ir = (Router)dir;
                        if (was_successful)
                        {
                            Console.WriteLine("");
                            Console.WriteLine("-- Gathered router information --");
                            Console.WriteLine("SpecVersion: " + ir.SpecVersionMajor + "." + ir.SpecVersionMinor);
                            Console.WriteLine("URLBase: " + ir.UrlBase);
                            if (ir.RootDevice != null)
                            {
                                Console.WriteLine("presentationURL: " + ir.RootDevice.PresentationUrl);
                                Console.WriteLine("friendlyName: " + ir.RootDevice.FriendlyName);
                                Console.WriteLine("manufacturer: " + ir.RootDevice.Manufacturer);
                                Console.WriteLine("manufacturerURL: " + ir.RootDevice.ManufacturerUrl);
                                Console.WriteLine("modelDescription: " + ir.RootDevice.ModelDescription);
                                Console.WriteLine("modelName: " + ir.RootDevice.ModelName);
                                Console.WriteLine("Number of Sub Devices: " + ir.RootDevice.Devices.Count);
                                Console.WriteLine("Sub UUID: " + ir.RootDevice.UniversalUniqueID);
                                //Thread.Sleep(3000);
                                ir.RequestConnection();
                            }
                            //Console.WriteLine("Server: " + r.Server);
                            Console.WriteLine("UUID: " + ir.UniversalUniqueID);
                            Console.WriteLine("-- Gathered router information --");
                            Console.WriteLine("");
                        }
                        else Console.WriteLine("failed to gather router information");
                    };
                    r.GatherInformation();//TODO this could also be done by upnp after it fired the discovered event

                    Console.WriteLine("");
                    Console.WriteLine("-- Discovered a router --");
                    Console.WriteLine("Server: " + r.Server);
                    Console.WriteLine("Host: " + r.Host + ":" + r.Port);
                    Console.WriteLine("UUID: " + r.UniversalUniqueID);
                    Console.WriteLine("Location: " + r.Location);
                    Console.WriteLine("Unique Service Name: " + r.UniqueServiceName);
                    Console.WriteLine("-- Discovered a router --");
                    Console.WriteLine("");
                    //Assert.IsTrue(!string.IsNullOrEmpty(ex_ip_completed.MyIP), "no ip address fetched");
                }
            };
            u.StartDiscovery();
            Console.WriteLine("Waiting for data");
            DateTime start = DateTime.Now;
            while (wait)
            {
                if (DateTime.Now - start > new TimeSpan(0, 0, 60))
                {
                    Console.WriteLine("");
                    Console.WriteLine("Operation took too long");
                    wait = false;
                    Assert.Fail("Operation took too long");
                }
                Console.Write(".");
                Thread.Sleep(250);
            }
            Console.WriteLine("UPnP Router Connecting Test successful.");

            u.CloseSockets();
        }
        public void TestRouterCheckForExistingPortMapping()
        {
            Console.WriteLine("Test to check a portmapping on a router for its existance.");
            UPnP u = new UPnP();
            u.SetupSockets();

            bool wait = true;
            bool test_failed = false;
            string test_failed_reason = "";

            u.DeviceDiscovered += delegate(Device d)
            {
                if (d.DeviceType == Device.DeviceTypes.Router)
                {
                    Router r = (Router)d;
                    int prots = 0;
                    r.PortMappingCheckCompleted += delegate(Router apm, Router.PortMapping pm, bool exists, bool was_successful)
                    {
                        if (was_successful)
                            Console.WriteLine("Checked Portmapping.");
                        //Assert.IsTrue(was_successful && exists, "Checking for existing Portmapping failed.");
                        if (was_successful && exists)
                        {
                            Console.WriteLine("-- Portmapping exists --");
                            Console.WriteLine("External Port: " + pm.ExternalPort);
                            Console.WriteLine("Internal Client: " + pm.InternalClient);
                            Console.WriteLine("Internal Port: " + pm.InternalPort);
                            Console.WriteLine("Protocol: " + pm.Protocol);
                            Console.WriteLine("Lease Duration: " + pm.LeaseDuration);
                            Console.WriteLine("Enabled: " + pm.Enabled);
                            Console.WriteLine("Description: " + pm.Description);
                            Console.WriteLine("-- Portmapping exists --");
                            prots++;
                        }
                        else
                        {
                            if (!exists)
                            {
                                test_failed_reason = "Portmapping doesn't exist";
                                test_failed = true;
                            }
                            if (!was_successful)
                            {
                                test_failed = true;
                                test_failed_reason = "Portmapping request failed. ";
                            }
                        }
                        if (prots == 2)
                            wait = !was_successful;
                    };

                    r.InformationGathered += delegate(Device dir, bool was_successful)
                    {
                        Router ir = (Router)dir;
                        if (was_successful)
                        {
                            Console.WriteLine("");
                            Console.WriteLine("-- Gathered router information --");
                            Console.WriteLine("SpecVersion: " + ir.SpecVersionMajor + "." + ir.SpecVersionMinor);
                            Console.WriteLine("URLBase: " + ir.UrlBase);
                            if (ir.RootDevice != null)
                            {
                                Console.WriteLine("presentationURL: " + ir.RootDevice.PresentationUrl);
                                Console.WriteLine("friendlyName: " + ir.RootDevice.FriendlyName);
                                Console.WriteLine("manufacturer: " + ir.RootDevice.Manufacturer);
                                Console.WriteLine("manufacturerURL: " + ir.RootDevice.ManufacturerUrl);
                                Console.WriteLine("modelDescription: " + ir.RootDevice.ModelDescription);
                                Console.WriteLine("modelName: " + ir.RootDevice.ModelName);
                                Console.WriteLine("Number of Sub Devices: " + ir.RootDevice.Devices.Count);
                                Console.WriteLine("Sub UUID: " + ir.RootDevice.UniversalUniqueID);
                                //Thread.Sleep(3000);
                                ir.CheckForExistingPortMapping("", 5588, "TCP");
                                ir.CheckForExistingPortMapping("", 5588, "UDP");
                            }
                            //Console.WriteLine("Server: " + r.Server);
                            Console.WriteLine("UUID: " + ir.UniversalUniqueID);
                            Console.WriteLine("-- Gathered router information --");
                            Console.WriteLine("");
                        }
                        else Console.WriteLine("failed to gather router information");
                    };
                    r.GatherInformation();//TODO this could also be done by upnp after it fired the discovered event

                    Console.WriteLine("");
                    Console.WriteLine("-- Discovered a router --");
                    Console.WriteLine("Server: " + r.Server);
                    Console.WriteLine("Host: " + r.Host + ":" + r.Port);
                    Console.WriteLine("UUID: " + r.UniversalUniqueID);
                    Console.WriteLine("Location: " + r.Location);
                    Console.WriteLine("Unique Service Name: " + r.UniqueServiceName);
                    Console.WriteLine("-- Discovered a router --");
                    Console.WriteLine("");
                    //Assert.IsTrue(!string.IsNullOrEmpty(ex_ip_completed.MyIP), "no ip address fetched");
                }
            };
            u.StartDiscovery();
            Console.WriteLine("Waiting for data");
            DateTime start = DateTime.Now;
            while (wait)
            {
                if (DateTime.Now - start > new TimeSpan(0, 0, 300))
                {
                    Console.WriteLine("");
                    Console.WriteLine("Operation took too long");
                    wait = false;
                    Assert.Fail("Operation took too long");
                }
                Console.Write(".");
                Thread.Sleep(250);
                Assert.IsFalse(test_failed, "Test failed: " + test_failed_reason);
            }
            Console.WriteLine("UPnP Router Check Port Mapping Test successful.");

            u.CloseSockets();
        }
Example #10
0
        public void TestMediaRendererSetPlaybackUrlWithMiniWebServer()
        {
            Console.WriteLine("Test to set a playback url of a media renderer with a mini web server.");
            UPnP u = new UPnP();
            u.SetupSockets();
            MiniWebServer server = new MiniWebServer();
            server.Port = 80;
            server.SetupListeningSocket();

            bool wait = true;
            server.RequestReceived += delegate(MiniWebServer request_server, MiniWebServer.Request request)
            {
                Console.WriteLine("Request received: ");
                Console.WriteLine("URL: " + request.Url);
                Console.WriteLine("Method: " + request.Method);
                Console.WriteLine("Version: " + request.Version);
                Console.WriteLine("Headers:");
                foreach (string key in request.Headers.Keys)
                {
                    Console.WriteLine("[" + key + "]" + ":[" + request.Headers.Get(key) + "]");
                }
                if (request.Url == "/")
                {
                    string page = "";
                    //string type = "text/plain";
                    page = "<html>\n<head>\n<title>MiniWebServer Test Page</title>\n</head>\n<body bgcolor=\"#333355\">Test Page of the Miniwebserver running on port: " + server.Port + "<br><a href=\"/test.mp3\">Test Mp3</a></body>\n</html>\n";
                    string type = "text/html";
                    request.RequestClient.Answer(page, type);
                }
                else if (request.Url == "/test.mp3")
                {
                    byte[] mp3 = File.ReadAllBytes("..\\..\\..\\TestDateien\\test.mp3");
                    string type = "audio/mpeg";
                    request.RequestClient.Answer(mp3, type);
                }
            };

            u.DeviceDiscovered += delegate(Device d)
            {
                if (d.DeviceType == Device.DeviceTypes.MediaRenderer)
                {
                    MediaRenderer mr = (MediaRenderer)d;
                    mr.SettingPlaybackUrlCompleted += delegate(MediaRenderer sp, bool was_successful)
                    {
                        if (was_successful)
                            Console.WriteLine("Set a playback url.");
                        //wait = !was_successful;
                    };
                    mr.PressingButtonCompleted += delegate(MediaRenderer sp, MediaRenderer.Button pressed, bool was_successful)
                    {
                        if (was_successful)
                            Console.WriteLine("Pressed the " + Enum.GetName(typeof(MediaRenderer.Button), pressed) + " button.");
                        wait = !was_successful;
                    };

                    mr.InformationGathered += delegate(Device dimr, bool was_successful)
                    {
                        MediaRenderer mir = (MediaRenderer)dimr;
                        if (was_successful)
                        {
                            Console.WriteLine("");
                            Console.WriteLine("-- Gathered media renderer information --");
                            Console.WriteLine("SpecVersion: " + mir.SpecVersionMajor + "." + mir.SpecVersionMinor);
                            Console.WriteLine("URLBase: " + mir.UrlBase);
                            if (mir.RootDevice != null)
                            {
                                Console.WriteLine("presentationURL: " + mir.RootDevice.PresentationUrl);
                                Console.WriteLine("friendlyName: " + mir.RootDevice.FriendlyName);
                                Console.WriteLine("manufacturer: " + mir.RootDevice.Manufacturer);
                                Console.WriteLine("manufacturerURL: " + mir.RootDevice.ManufacturerUrl);
                                Console.WriteLine("modelDescription: " + mir.RootDevice.ModelDescription);
                                Console.WriteLine("modelName: " + mir.RootDevice.ModelName);
                                Console.WriteLine("Number of Sub Devices: " + mir.RootDevice.Devices.Count);
                                Console.WriteLine("Sub UUID: " + mir.RootDevice.UniversalUniqueID);
                                //Thread.Sleep(3000);
                                mir.SetPlaybackUrl("http://" + ip + "/test.mp3");
                                Thread.Sleep(1000);
                                mir.Press(MediaRenderer.Button.Play);
                            }
                            //Console.WriteLine("Server: " + r.Server);
                            Console.WriteLine("UUID: " + mir.UniversalUniqueID);
                            Console.WriteLine("-- Gathered media renderer information --");
                            Console.WriteLine("");
                        }
                        else Console.WriteLine("failed to gather media renderer information");
                    };
                    mr.GatherInformation();//TODO this could also be done by upnp after it fired the discovered event

                    Console.WriteLine("");
                    Console.WriteLine("-- Discovered a media renderer --");
                    Console.WriteLine("Server: " + mr.Server);
                    Console.WriteLine("Host: " + mr.Host + ":" + mr.Port);
                    Console.WriteLine("UUID: " + mr.UniversalUniqueID);
                    Console.WriteLine("Location: " + mr.Location);
                    Console.WriteLine("Unique Service Name: " + mr.UniqueServiceName);
                    Console.WriteLine("-- Discovered a media renderer --");
                    Console.WriteLine("");
                    //Assert.IsTrue(!string.IsNullOrEmpty(ex_ip_completed.MyIP), "no ip address fetched");
                }
            };
            u.StartDiscovery();
            Console.WriteLine("Waiting for data");
            DateTime start = DateTime.Now;
            while (wait)
            {
                if (DateTime.Now - start > new TimeSpan(0, 0, 300))
                {
                    Console.WriteLine("");
                    Console.WriteLine("Operation took too long");
                    wait = false;
                    Assert.Fail("Operation took too long");
                }
                Console.Write(".");
                Thread.Sleep(250);
            }
            Console.WriteLine("UPnP Media Renderer Set Playback URL With Mini Web Server Test successful.");

            u.CloseSockets();
        }
Example #11
0
        public void TestMediaRendererSetPlaybackUrl()
        {
            Console.WriteLine("Test to set a playback url of a media renderer.");
            UPnP u = new UPnP();
            u.SetupSockets();

            bool wait = true;
            u.DeviceDiscovered += delegate(Device d)
            {
                if (d.DeviceType == Device.DeviceTypes.MediaRenderer)
                {
                    MediaRenderer mr = (MediaRenderer)d;
                    mr.SettingPlaybackUrlCompleted += delegate(MediaRenderer sp, bool was_successful)
                    {
                        if (was_successful)
                            Console.WriteLine("Set a playback url.");
                        //wait = !was_successful;
                    };
                    mr.PressingButtonCompleted += delegate(MediaRenderer sp, MediaRenderer.Button pressed, bool was_successful)
                    {
                        if (was_successful)
                            Console.WriteLine("Pressed the " + Enum.GetName(typeof(MediaRenderer.Button), pressed) + " button.");
                        wait = !was_successful;
                    };

                    mr.InformationGathered += delegate(Device dimr, bool was_successful)
                    {
                        MediaRenderer mir = (MediaRenderer)dimr;
                        if (was_successful)
                        {
                            Console.WriteLine("");
                            Console.WriteLine("-- Gathered media renderer information --");
                            Console.WriteLine("SpecVersion: " + mir.SpecVersionMajor + "." + mir.SpecVersionMinor);
                            Console.WriteLine("URLBase: " + mir.UrlBase);
                            if (mir.RootDevice != null)
                            {
                                Console.WriteLine("presentationURL: " + mir.RootDevice.PresentationUrl);
                                Console.WriteLine("friendlyName: " + mir.RootDevice.FriendlyName);
                                Console.WriteLine("manufacturer: " + mir.RootDevice.Manufacturer);
                                Console.WriteLine("manufacturerURL: " + mir.RootDevice.ManufacturerUrl);
                                Console.WriteLine("modelDescription: " + mir.RootDevice.ModelDescription);
                                Console.WriteLine("modelName: " + mir.RootDevice.ModelName);
                                Console.WriteLine("Number of Sub Devices: " + mir.RootDevice.Devices.Count);
                                Console.WriteLine("Sub UUID: " + mir.RootDevice.UniversalUniqueID);
                                //Thread.Sleep(3000);
                                mir.SetPlaybackUrl("http://www.voyagerproject.de/stuff/phat_sweet_drill_mix.wav.mp3");
                                Thread.Sleep(1000);
                                mir.Press(MediaRenderer.Button.Play);
                            }
                            //Console.WriteLine("Server: " + r.Server);
                            Console.WriteLine("UUID: " + mir.UniversalUniqueID);
                            Console.WriteLine("-- Gathered media renderer information --");
                            Console.WriteLine("");
                        }
                        else Console.WriteLine("failed to gather media renderer information");
                    };
                    mr.GatherInformation();//TODO this could also be done by upnp after it fired the discovered event

                    Console.WriteLine("");
                    Console.WriteLine("-- Discovered a media renderer --");
                    Console.WriteLine("Server: " + mr.Server);
                    Console.WriteLine("Host: " + mr.Host + ":" + mr.Port);
                    Console.WriteLine("UUID: " + mr.UniversalUniqueID);
                    Console.WriteLine("Location: " + mr.Location);
                    Console.WriteLine("Unique Service Name: " + mr.UniqueServiceName);
                    Console.WriteLine("-- Discovered a media renderer --");
                    Console.WriteLine("");
                    //Assert.IsTrue(!string.IsNullOrEmpty(ex_ip_completed.MyIP), "no ip address fetched");
                }
            };
            u.StartDiscovery();
            Console.WriteLine("Waiting for data");
            DateTime start = DateTime.Now;
            while (wait)
            {
                if (DateTime.Now - start > new TimeSpan(0, 0, 300))
                {
                    Console.WriteLine("");
                    Console.WriteLine("Operation took too long");
                    wait = false;
                    Assert.Fail("Operation took too long");
                }
                Console.Write(".");
                Thread.Sleep(250);
            }
            Console.WriteLine("UPnP Media Renderer Set Playback URL Test successful.");

            u.CloseSockets();
        }