示例#1
0
        public void SsdpService_NullServiceTypeReturnsNull()
        {
            var service = new SsdpService();

            service.ServiceType = null;
            Assert.AreEqual(null, service.ServiceType);
        }
示例#2
0
        public void ToDescriptionDocument_DeserialiseServiceList()
        {
            var rootDevice = CreateSampleRootDevice();

            rootDevice.AddDevice(CreateEmbeddedDevice(rootDevice));
            rootDevice.AddDevice(CreateEmbeddedDevice(rootDevice));

            var service = new SsdpService()
            {
                ControlUrl           = new Uri("/test/control", UriKind.Relative),
                EventSubUrl          = new Uri("/test/events", UriKind.Relative),
                ScpdUrl              = new Uri("/test", UriKind.Relative),
                ServiceType          = "mytestservicetype",
                ServiceTypeNamespace = "my-test-namespace",
                ServiceVersion       = 1,
                Uuid = System.Guid.NewGuid().ToString()
            };

            rootDevice.AddService(service);
            var service2 = new SsdpService()
            {
                ControlUrl           = new Uri("/test/control", UriKind.Relative),
                EventSubUrl          = new Uri("/test/events", UriKind.Relative),
                ScpdUrl              = new Uri("/test", UriKind.Relative),
                ServiceType          = "mytestservicetype",
                ServiceTypeNamespace = "my-test-namespace",
                ServiceVersion       = 1,
                Uuid = System.Guid.NewGuid().ToString()
            };

            rootDevice.AddService(service2);

            var service3 = new SsdpService()
            {
                ControlUrl           = new Uri("/test/control", UriKind.Relative),
                EventSubUrl          = new Uri("/test/events", UriKind.Relative),
                ScpdUrl              = new Uri("/test", UriKind.Relative),
                ServiceType          = "mytestservicetype",
                ServiceTypeNamespace = "my-test-namespace",
                ServiceVersion       = 1,
                Uuid = System.Guid.NewGuid().ToString()
            };

            rootDevice.Devices.First().AddService(service3);

            var descriptionDocument = rootDevice.ToDescriptionDocument();
            var doc = XDocument.Parse(descriptionDocument);

            var deserialisedDevice = new SsdpRootDevice(rootDevice.Location, rootDevice.CacheLifetime, doc.ToString());

            AssertDevicesAreSame(rootDevice.Devices.First(), deserialisedDevice.Devices.First());
            AssertDevicesAreSame(rootDevice.Devices.Last(), deserialisedDevice.Devices.Last());
            Assert.AreEqual(2, deserialisedDevice.Services.Count());
            Assert.AreEqual(1, deserialisedDevice.Devices.First().Services.Count());
            AssertServicesAreSame(service, deserialisedDevice.Services.First());
            AssertServicesAreSame(service2, deserialisedDevice.Services.Last());
            AssertServicesAreSame(service3, deserialisedDevice.Devices.First().Services.First());

            Assert.AreEqual(descriptionDocument, deserialisedDevice.ToDescriptionDocument());
        }
示例#3
0
        private static void ValidateService(SsdpService service, List <string> retVal)
        {
            if (String.IsNullOrEmpty(service.ServiceType))
            {
                retVal.Add("ServiceType is missing");
            }
            else if (service.ServiceType.Contains("#"))
            {
                retVal.Add("ServiceType cannot contain #");
            }

            if (String.IsNullOrEmpty(service.Uuid))
            {
                retVal.Add("ServiceId is missing");
            }

            if (service.ScpdUrl == null)
            {
                retVal.Add("ScpdUrl is missing");
            }

            if (service.ControlUrl == null)
            {
                retVal.Add("ControlUrl is missing");
            }
        }
示例#4
0
        public void SsdpService_EmptyServiceTypeReturnsEmpty()
        {
            var service = new SsdpService();

            service.ServiceType = String.Empty;
            Assert.AreEqual(String.Empty, service.ServiceType);
        }
示例#5
0
        public void SsdpService_FullServiceTypesReturnsExpectedString()
        {
            var service = new SsdpService();

            service.ServiceType          = "testservicetype";
            service.ServiceTypeNamespace = "my-test-namespace";
            Assert.AreEqual("urn:my-test-namespace:service:testservicetype:1", service.FullServiceType);
        }
示例#6
0
        public void SsdpService_FullServiceTypesReplacesDotsInVendorNamespace()
        {
            var service = new SsdpService();

            service.ServiceType          = "testservicetype";
            service.ServiceTypeNamespace = "my.test.namespace.org";
            Assert.AreEqual("urn:my-test-namespace-org:service:testservicetype:1", service.FullServiceType);
        }
示例#7
0
        public void SsdpService_FullServiceTypesReturnsStringWithNullValues()
        {
            var service = new SsdpService();

            service.ServiceType          = null;
            service.ServiceTypeNamespace = null;
            Assert.AreEqual("urn::service::1", service.FullServiceType);
        }
示例#8
0
        public void SsdpDevice_Constructor_DeserialisesComplexDeviceDocumentAndSkipsComplexCustomProperties()
        {
            var service = new SsdpService(ServiceXmlDescription);

            Assert.AreEqual("urn:schemas-upnp-org:service:SystemProperties:1", service.FullServiceType);
            Assert.AreEqual("urn:upnp-org:serviceId:SystemProperties", service.ServiceId);
            Assert.AreEqual(new Uri("/SystemProperties/Control", UriKind.Relative), service.ControlUrl);
            Assert.AreEqual(new Uri("/SystemProperties/Event", UriKind.Relative), service.EventSubUrl);
            Assert.AreEqual(new Uri("/xml/SystemProperties1.xml", UriKind.Relative), service.ScpdUrl);
        }
示例#9
0
        public void SsdpDevice_AddService_DuplicateAddDoesNothing()
        {
            var rootDevice = new SsdpRootDevice();

            var service = new SsdpService();

            rootDevice.AddService(service);
            rootDevice.AddService(service);
            Assert.AreEqual(1, rootDevice.Services.Count());
        }
示例#10
0
 private void AssertServicesAreSame(SsdpService service, SsdpService service2)
 {
     Assert.AreEqual(service.ControlUrl, service2.ControlUrl);
     Assert.AreEqual(service.EventSubUrl, service2.EventSubUrl);
     Assert.AreEqual(service.FullServiceType, service2.FullServiceType);
     Assert.AreEqual(service.ScpdUrl, service2.ScpdUrl);
     Assert.AreEqual(service.ServiceId, service2.ServiceId);
     Assert.AreEqual(service.ServiceType, service2.ServiceType);
     Assert.AreEqual(service.ServiceTypeNamespace, service2.ServiceTypeNamespace);
     Assert.AreEqual(service.ServiceVersion, service2.ServiceVersion);
     Assert.AreEqual(service.Uuid, service2.Uuid);
 }
示例#11
0
        private static void PublishDevices()
        {
            if (_DevicePublisher != null)
            {
                Console.WriteLine("Stopping previous publisher.");
                _DevicePublisher.Dispose();
            }

            // Create a device publisher
            _DevicePublisher = new SsdpDevicePublisher();

            // Create the device(s) we want to publish.
            var rootDevice = new SsdpRootDevice()
            {
                CacheLifetime = TimeSpan.FromMinutes(30),
                FriendlyName  = "Sample RSSDP Device",
                Manufacturer  = "RSSDP",
                ModelNumber   = "123",
                ModelName     = "RSSDP Sample Device",
                SerialNumber  = "123",
                Uuid          = System.Guid.NewGuid().ToString()
            };

            rootDevice.CustomResponseHeaders.Add(new CustomHttpHeader("X-MachineName", Environment.MachineName));

            var service = new SsdpService()
            {
                Uuid                 = System.Guid.NewGuid().ToString(),
                ServiceType          = "test-service-type",
                ServiceTypeNamespace = "rssdp-test-namespace",
                ControlUrl           = new Uri("/test/control", UriKind.Relative),
                EventSubUrl          = new Uri("/test/event", UriKind.Relative),
                ScpdUrl              = new Uri("/test", UriKind.Relative)
            };

            rootDevice.AddService(service);

            // Now publish by adding them to the publisher.
            _DevicePublisher.AddDevice(rootDevice);

            Console.WriteLine("Publishing devices: ");
            WriteOutDevices(rootDevice);
            Console.WriteLine();
        }
示例#12
0
        public void SsdpDevice_AddService_RaisesServiceAdded()
        {
            var rootDevice = new SsdpRootDevice();

            bool        eventRaised  = false;
            SsdpService eventService = null;

            rootDevice.ServiceAdded += (sender, e) =>
            {
                eventRaised  = true;
                eventService = e.Service;
            };

            var service = new SsdpService();

            rootDevice.AddService(service);
            Assert.IsTrue(eventRaised);
            Assert.AreEqual(service, eventService);
        }
示例#13
0
 public void SsdpService_ConstructorThrowsArgumentNullIfXmlStringNull()
 {
     var device = new SsdpService(null);
 }
示例#14
0
文件: Startup.cs 项目: cpwood/Ukor
        private void ConfigureSsdp(
            IOptions <LocalServerOptions> localServerOptions,
            SsdpLogger logger)
        {
            var device = new SsdpRootDevice()
            {
                CacheLifetime       = TimeSpan.FromHours(1),
                Location            = new Uri($"{localServerOptions.Value.RootUrl}/"),
                UrlBase             = new Uri($"{localServerOptions.Value.RootUrl}/"),
                DeviceType          = "urn:roku-com:device:player:1-0:1",
                DeviceTypeNamespace = "schemas-upnp-org",
                DeviceVersion       = 1,
                Uuid             = "29600009-5406-1005-8080-1234567890ab",
                Udn              = "uuid:29600009-5406-1005-8080-1234567890ab",
                FriendlyName     = "Ukor Server",
                Manufacturer     = "Roku",
                ManufacturerUrl  = new Uri("http://www.roku.com/"),
                ModelDescription = "Roku Streaming Player Network Media",
                ModelName        = "Ukor Server",
                ModelNumber      = "3810EU",
                ModelUrl         = new Uri("http://www.roku.com/"),
                SerialNumber     = "YH009E000001",
                Usn              = "uuid:roku:ecp:YH009E000001",
                NotificationType = "roku:ecp"
            };

            device.CustomResponseHeaders.Add(new CustomHttpHeader("Server", "Roku/9.2.0, UPnP/1.0"));
            device.CustomResponseHeaders.Add(new CustomHttpHeader("device-group.roku.com", "1E3DE502613555ACA315"));
            device.CustomResponseHeaders.Add(new CustomHttpHeader("WAKEUP", "MAC=ac:ae:01:02:03:04, Timeout=10"));

            var ecpService = new SsdpService
            {
                ServiceType          = "ecp",
                ServiceTypeNamespace = "roku-com",
                ServiceVersion       = 1,
                Uuid       = "ecp1-0",
                ScpdUrl    = new Uri("ecp_SCPD.xml", UriKind.Relative),
                ControlUrl = new Uri("roku:0")
            };

            device.AddService(ecpService);

            var dialService = new SsdpService
            {
                ServiceType          = "dial",
                ServiceTypeNamespace = "dial-multiscreen-org",
                ServiceVersion       = 1,
                Uuid       = "dial1-0",
                ScpdUrl    = new Uri("dial_SCPD.xml", UriKind.Relative),
                ControlUrl = new Uri("roku:1")
            };

            device.AddService(dialService);

            _publisher =
                new SsdpDevicePublisher {
                StandardsMode = SsdpStandardsMode.Relaxed, Log = logger
            };

            _publisher.AddDevice(device);
            _publisher.NotificationBroadcastInterval = TimeSpan.FromMinutes(10);
        }
示例#15
0
 private void SendByeByeNotification(SsdpDevice device, SsdpService service)
 {
     SendByeByeNotification(device, service.FullServiceType, device.Udn + "::" + service.FullServiceType);
 }
示例#16
0
 public void SsdpService_ConstructorThrowsArgumentNullIfXmlStringEmpty()
 {
     var device = new SsdpService(String.Empty);
 }
示例#17
0
 public void SsdpService_ConstructsOkWithDefaultConstructor()
 {
     var device = new SsdpService();
 }
示例#18
0
        private static void PublishDevices()
        {
            if (_DevicePublisher != null)
            {
                Console.WriteLine("Stopping previous publisher.");
                _DevicePublisher.Dispose();
            }

            if (_HttpServer != null)
            {
                _HttpServer.Close();
            }

            // Create a device publisher
            _DevicePublisher = new SsdpDevicePublisher();

            //These settings make RSSDP play nicely with Windows Explorer
            //and some badly behaved clients.
            _DevicePublisher.StandardsMode = SsdpStandardsMode.Relaxed;

            // Create the device(s) we want to publish.
            var url = new Uri("http://" + Environment.MachineName + ":8181/");

            var rootDevice = new SsdpRootDevice()
            {
                CacheLifetime    = TimeSpan.FromMinutes(30),
                FriendlyName     = "Sample RSSDP Device",
                Manufacturer     = "RSSDP",
                ModelNumber      = "123",
                ModelName        = "RSSDP Sample Device",
                ModelDescription = "Test Device from RSSDP Console App",
                ManufacturerUrl  = new Uri("https://github.com/Yortw/RSSDP"),
                SerialNumber     = "123",
                Uuid             = System.Guid.NewGuid().ToString(),
                UrlBase          = url
            };

            rootDevice.CustomResponseHeaders.Add(new CustomHttpHeader("X-MachineName", Environment.MachineName));

            var service = new SsdpService()
            {
                Uuid                 = System.Guid.NewGuid().ToString(),
                ServiceType          = "test-service-type",
                ServiceTypeNamespace = "rssdp-test-namespace",
                ControlUrl           = new Uri("/test/control", UriKind.Relative),
                EventSubUrl          = new Uri("/test/event", UriKind.Relative),
                ScpdUrl              = new Uri("/test", UriKind.Relative)
            };

            rootDevice.AddService(service);

            rootDevice.Location = new Uri(url, "ddd");

            //Some 3rd party tools won't show the device unless they can get
            //the device description document, so this sample uses a really simple HTTP
            //server just to serve that.
            StartHttpServerForDdd(rootDevice, url);

            // Now publish by adding them to the publisher.
            _DevicePublisher.AddDevice(rootDevice);

            Console.WriteLine("Publishing devices: ");
            WriteOutDevices(rootDevice);
            Console.WriteLine();
        }