Пример #1
0
        private static void LoadIcons(XmlReader reader, SsdpDevice device)
        {
            while (!reader.EOF && reader.NodeType != XmlNodeType.Element)
            {
                reader.Read();
            }

            while (!reader.EOF)
            {
                while (!reader.EOF && reader.NodeType != XmlNodeType.Element && !(reader.NodeType == XmlNodeType.EndElement && reader.Name == "iconList"))
                {
                    reader.Read();
                }

                if (reader.LocalName == "icon")
                {
                    var icon = new SsdpDeviceIcon();
                    LoadIconProperties(reader, icon);
                    device.Icons.Add(icon);
                }
                else
                {
                    break;
                }
            }
        }
Пример #2
0
        private static void LoadIconProperties(XmlReader reader, SsdpDeviceIcon icon)
        {
            while (!reader.EOF && (reader.LocalName != "icon" || reader.NodeType != XmlNodeType.Element))
            {
                reader.Read();
            }

            while (!reader.EOF)
            {
                if (reader.NodeType == XmlNodeType.EndElement && reader.Name == "icon")
                {
                    reader.Read();
                    break;
                }

                switch (reader.LocalName)
                {
                case "depth":
                    icon.ColorDepth = reader.ReadElementContentAsInt();
                    break;

                case "height":
                    icon.Height = reader.ReadElementContentAsInt();
                    break;

                case "width":
                    icon.Width = reader.ReadElementContentAsInt();
                    break;

                case "mimetype":
                    icon.MimeType = reader.ReadElementContentAsString();
                    break;

                case "url":
                    icon.Url = StringToUri(reader.ReadElementContentAsString());
                    break;

                default:
                    reader.Read();
                    break;
                }
            }
        }
Пример #3
0
        public void UPnP10DeviceValidator_FailsNegativeWidth()
        {
            var rootDevice = new SsdpRootDevice()
            {
                FriendlyName = "Basic Device 1",
                Manufacturer = "Test Manufacturer",
                ManufacturerUrl = new Uri("http://testmanufacturer.com"),
                ModelDescription = "A test model device",
                ModelName = "Test Model",
                ModelNumber = "Model #1234",
                ModelUrl = new Uri("http://modelurl.com"),
                SerialNumber = "SN-123",
                Uuid = System.Guid.NewGuid().ToString(),
                Location = new Uri("http://testdevice:1700/xml"),
            };

            var testDevice = new SsdpEmbeddedDevice()
            {
                DeviceType = "TestEmbeddedDevice",
                FriendlyName = "Embedded Device 1",
                DeviceTypeNamespace = "testdevice-org",
                Manufacturer = "Test Manufacturer",
                ManufacturerUrl = new Uri("http://testmanufacturer.com"),
                ModelDescription = "A test model device",
                ModelName = "Test Model",
                ModelNumber = "Model #1234",
                ModelUrl = new Uri("http://modelurl.com"),
                SerialNumber = "SN-123",
                Uuid = System.Guid.NewGuid().ToString()
            };
            rootDevice.AddDevice(testDevice);

            var icon = new SsdpDeviceIcon()
            {
                ColorDepth = 32,
                Width = -1,
                Height = 48,
                MimeType = "image/png",
                Url = new Uri("someimage.png", UriKind.Relative)
            };
            testDevice.Icons.Add(icon);

            var validator = new Upnp10DeviceValidator();
            var results = validator.GetValidationErrors(testDevice);
            Assert.IsNotNull(results);
            Assert.AreEqual(1, results.Count());
            Assert.IsTrue(results.First().IndexOf("width", StringComparison.OrdinalIgnoreCase) >= 0);
        }
Пример #4
0
        private SsdpRootDevice CreateSampleRootDevice()
        {
            var retVal = new SsdpRootDevice()
            {
                CacheLifetime = TimeSpan.FromMinutes(30),
                DeviceType = "TestDeviceType",
                DeviceTypeNamespace = "test-device-ns",
                FriendlyName = "Test Device 1",
                Location = new Uri("http://testdevice:1700/xml"),
                Manufacturer = "Test Manufacturer",
                ManufacturerUrl = new Uri("http://testman.com"),
                ModelDescription = "A test device",
                ModelName = "Test Model",
                ModelNumber = "1234",
                ModelUrl = new Uri("http://testmodel.com"),
                PresentationUrl = new Uri("http://testmodel.com/presentation"),
                SerialNumber = "TM-12345",
                Upc = "123456789012",
                UrlBase = new Uri("http://testdevice:1700"),
                Uuid = Guid.NewGuid().ToString()
            };

            var customProp = new SsdpDeviceProperty() { Namespace = "custom-ns", Name = "TestProp1", Value = "Test" };
            retVal.CustomProperties.Add(customProp);
            customProp = new SsdpDeviceProperty() { Namespace = "custom-ns", Name = "TestProp2", Value = "Test" };
            retVal.CustomProperties.Add(customProp);

            var icon = new SsdpDeviceIcon() { ColorDepth = 32, Height = 48, Width = 48, MimeType = "image/png", Url = new Uri("icons/48", UriKind.Relative) };
            retVal.Icons.Add(icon);
            icon = new SsdpDeviceIcon() { ColorDepth = 32, Height = 120, Width = 120, MimeType = "image/png", Url = new Uri("icons/120", UriKind.Relative) };
            retVal.Icons.Add(icon);

            return retVal;
        }
Пример #5
0
        private static void LoadIcons(XmlReader reader, SsdpDevice device)
        {
            while (!reader.EOF)
            {
                while (!reader.EOF && reader.NodeType != XmlNodeType.Element)
                {
                    reader.Read();
                }

                if (reader.LocalName != "icon") break;

                while (reader.Name == "icon")
                {
                    var icon = new SsdpDeviceIcon();
                    LoadIconProperties(reader, icon);
                    device.Icons.Add(icon);

                    reader.Read();
                }
            }
        }
Пример #6
0
        private static void LoadIconProperties(XmlReader reader, SsdpDeviceIcon icon)
        {
            while (!reader.EOF)
            {
                if (reader.NodeType != XmlNodeType.Element)
                {
                    if (reader.NodeType == XmlNodeType.EndElement && reader.Name == "icon") break;

                    reader.Read();
                    continue;
                }

                switch (reader.LocalName)
                {
                    case "depth":
                        icon.ColorDepth = reader.ReadElementContentAsInt();
                        break;

                    case "height":
                        icon.Height = reader.ReadElementContentAsInt();
                        break;

                    case "width":
                        icon.Width = reader.ReadElementContentAsInt();
                        break;

                    case "mimetype":
                        icon.MimeType = reader.ReadElementContentAsString();
                        break;

                    case "url":
                        icon.Url = StringToUri(reader.ReadElementContentAsString());
                        break;

                }

                reader.Read();
            }
        }