Exemplo n.º 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;
                }
            }
        }
Exemplo n.º 2
0
 private static void SetDeviceTypePropertiesFromFullDeviceType(SsdpDevice device, string value)
 {
     if (String.IsNullOrEmpty(value) || !value.Contains(":"))
     {
         device.DeviceType = value;
     }
     else
     {
         var parts = value.Split(':');
         if (parts.Length == 5)
         {
             int deviceVersion = 1;
             if (Int32.TryParse(parts[4], out deviceVersion))
             {
                 device.DeviceTypeNamespace = parts[1];
                 device.DeviceType          = parts[3];
                 device.DeviceVersion       = deviceVersion;
             }
             else
             {
                 device.DeviceType = value;
             }
         }
         else
         {
             device.DeviceType = value;
         }
     }
 }
Exemplo n.º 3
0
        private static void AddCustomProperty(XmlReader reader, SsdpDevice device)
        {
            var newProp = new SsdpDeviceProperty()
            {
                Namespace = reader.Prefix, Name = reader.LocalName
            };
            int depth = reader.Depth;

            reader.Read();
            while (reader.NodeType == XmlNodeType.Whitespace || reader.NodeType == XmlNodeType.Comment)
            {
                reader.Read();
            }

            if (reader.NodeType != XmlNodeType.CDATA && reader.NodeType != XmlNodeType.Text)
            {
                while (!reader.EOF && (reader.NodeType != XmlNodeType.EndElement || reader.Name != newProp.Name || reader.Prefix != newProp.Namespace || reader.Depth != depth))
                {
                    reader.Read();
                }
                if (!reader.EOF)
                {
                    reader.Read();
                }
                return;
            }

            newProp.Value = reader.Value;

            // We don't support complex nested types or repeat/multi-value properties
            if (!device.CustomProperties.Contains(newProp.FullName))
            {
                device.CustomProperties.Add(newProp);
            }
        }
Exemplo n.º 4
0
        private static void LoadServices(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 == "serviceList"))
                {
                    reader.Read();
                }

                if (reader.LocalName == "service")
                {
                    var service = new SsdpService(reader.ReadOuterXml());
                    device.AddService(service);
                }
                else
                {
                    break;
                }
            }
        }
Exemplo n.º 5
0
 private static void WriteCustomProperties(XmlWriter writer, SsdpDevice device)
 {
     foreach (var prop in device.CustomProperties)
     {
         writer.WriteElementString(prop.Namespace, prop.Name, SsdpConstants.SsdpDeviceDescriptionXmlNamespace, prop.Value);
     }
 }
Exemplo n.º 6
0
        private void LoadChildDevices(XmlReader reader, SsdpDevice device)
        {
            while (!reader.EOF && reader.NodeType != XmlNodeType.Element)
            {
                reader.Read();
            }

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

                if (reader.LocalName == "device")
                {
                    var childDevice = new SsdpEmbeddedDevice();
                    LoadDeviceProperties(reader, childDevice);
                    device.AddDevice(childDevice);
                }
                else
                {
                    break;
                }
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Constructs a new instance for the specified <see cref="SsdpDevice"/>.
        /// </summary>
        /// <param name="device">The <see cref="SsdpDevice"/> associated with the event this argument class is being used for.</param>
        /// <exception cref="ArgumentNullException">Thrown if the <paramref name="device"/> argument is null.</exception>
        public DeviceEventArgs(SsdpDevice device)
        {
            if (device == null)
            {
                throw new ArgumentNullException(nameof(device));
            }

            _Device = device;
        }
Exemplo n.º 8
0
 private static void SetUuidFromUdn(SsdpDevice device)
 {
     if (device.Udn != null && device.Udn.StartsWith("uuid:", StringComparison.OrdinalIgnoreCase))
     {
         device.Uuid = device.Udn.Substring(5).Trim();
     }
     else
     {
         device.Uuid = device.Udn;
     }
 }
Exemplo n.º 9
0
 private static void WriteServices(XmlWriter writer, SsdpDevice device)
 {
     if (device.Services.Any())
     {
         writer.WriteStartElement("serviceList");
         foreach (var service in device.Services)
         {
             WriteService(writer, service);
         }
         writer.WriteEndElement();
     }
 }
Exemplo n.º 10
0
        private static void AddCustomProperty(XmlReader reader, SsdpDevice device)
        {
            var newProp = new SsdpDeviceProperty()
            {
                Namespace = reader.Prefix, Name = reader.LocalName, Value = reader.ReadElementContentAsString()
            };

            // We don't support complex nested types or repeat/multi-value properties
            if (!device.CustomProperties.Contains(newProp.FullName))
            {
                device.CustomProperties.Add(newProp);
            }
        }
Exemplo n.º 11
0
        private void WriteChildDevices(XmlWriter writer, SsdpDevice parentDevice)
        {
            if (parentDevice.Devices.Any())
            {
                writer.WriteStartElement("deviceList");

                foreach (var device in parentDevice.Devices)
                {
                    WriteDeviceDescriptionXml(writer, device);
                }

                writer.WriteEndElement();
            }
        }
Exemplo n.º 12
0
        /// <summary>
        /// Returns the root device associated with a device instance derived from <see cref="SsdpDevice"/>.
        /// </summary>
        /// <param name="device">The device instance to find the <see cref="SsdpRootDevice"/> for.</param>
        /// <remarks>
        /// <para>The <paramref name="device"/> must be or inherit from <see cref="SsdpRootDevice"/> or <see cref="SsdpEmbeddedDevice"/>, otherwise an <see cref="System.InvalidCastException"/> will occur.</para>
        /// <para>May return null if the <paramref name="device"/> instance is an embedded device not yet associated with a <see cref="SsdpRootDevice"/> instance yet.</para>
        /// <para>If <paramref name="device"/> is an instance of <see cref="SsdpRootDevice"/> (or derives from it), returns the same instance cast to <see cref="SsdpRootDevice"/>.</para>
        /// </remarks>
        /// <returns>The <see cref="SsdpRootDevice"/> instance associated with the device instance specified, or null otherwise.</returns>
        /// <exception cref="System.ArgumentNullException">Thrown if <paramref name="device"/> is null.</exception>
        /// <exception cref="System.InvalidCastException">Thrown if <paramref name="device"/> is not an instance of or dervied from either <see cref="SsdpRootDevice"/> or <see cref="SsdpEmbeddedDevice"/>.</exception>
        public static SsdpRootDevice ToRootDevice(this SsdpDevice device)
        {
            if (device == null)
            {
                throw new System.ArgumentNullException("device");
            }

            var rootDevice = device as SsdpRootDevice;

            if (rootDevice == null)
            {
                rootDevice = ((SsdpEmbeddedDevice)device).RootDevice;
            }

            return(rootDevice);
        }
Exemplo n.º 13
0
        private void LoadDeviceProperties(XmlReader reader, SsdpDevice device)
        {
            ReadUntilDeviceNode(reader);

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

                if (!SetPropertyFromReader(reader, device))
                {
                    reader.Read();
                }
            }
        }
Exemplo n.º 14
0
        private static void WriteIcons(XmlWriter writer, SsdpDevice device)
        {
            if (device.Icons.Any())
            {
                writer.WriteStartElement("iconList");

                foreach (var icon in device.Icons)
                {
                    writer.WriteStartElement("icon");

                    writer.WriteElementString("mimetype", icon.MimeType);
                    writer.WriteElementString("width", icon.Width.ToString());
                    writer.WriteElementString("height", icon.Height.ToString());
                    writer.WriteElementString("depth", icon.ColorDepth.ToString());
                    writer.WriteElementString("url", icon.Url.ToString());

                    writer.WriteEndElement();
                }

                writer.WriteEndElement();
            }
        }
Exemplo n.º 15
0
        /// <summary>
        /// Writes this device to the specified <see cref="System.Xml.XmlWriter"/> as a device node and it's content.
        /// </summary>
        /// <param name="writer">The <see cref="System.Xml.XmlWriter"/> to output to.</param>
        /// <param name="device">The <see cref="SsdpDevice"/> to write out.</param>
        /// <exception cref="System.ArgumentNullException">Thrown if the <paramref name="writer"/> or <paramref name="device"/> argument is null.</exception>
        protected virtual void WriteDeviceDescriptionXml(XmlWriter writer, SsdpDevice device)
        {
            if (writer == null)
            {
                throw new ArgumentNullException("writer");
            }
            if (device == null)
            {
                throw new ArgumentNullException("device");
            }

            writer.WriteStartElement("device");

            if (!String.IsNullOrEmpty(device.FullDeviceType))
            {
                WriteNodeIfNotEmpty(writer, "deviceType", device.FullDeviceType);
            }

            WriteNodeIfNotEmpty(writer, "friendlyName", device.FriendlyName);
            WriteNodeIfNotEmpty(writer, "manufacturer", device.Manufacturer);
            WriteNodeIfNotEmpty(writer, "manufacturerURL", device.ManufacturerUrl);
            WriteNodeIfNotEmpty(writer, "modelDescription", device.ModelDescription);
            WriteNodeIfNotEmpty(writer, "modelName", device.ModelName);
            WriteNodeIfNotEmpty(writer, "modelNumber", device.ModelNumber);
            WriteNodeIfNotEmpty(writer, "modelURL", device.ModelUrl);
            WriteNodeIfNotEmpty(writer, "presentationURL", device.PresentationUrl);
            WriteNodeIfNotEmpty(writer, "serialNumber", device.SerialNumber);
            WriteNodeIfNotEmpty(writer, "UDN", device.Udn);
            WriteNodeIfNotEmpty(writer, "UPC", device.Upc);

            WriteCustomProperties(writer, device);
            WriteIcons(writer, device);
            WriteChildDevices(writer, device);
            WriteServices(writer, device);

            writer.WriteEndElement();
        }
Exemplo n.º 16
0
 private static void SetDeviceTypePropertiesFromFullDeviceType(SsdpDevice device, string value)
 {
     if (String.IsNullOrEmpty(value) || !value.Contains(":"))
         device.DeviceType = value;
     else
     {
         var parts = value.Split(':');
         if (parts.Length == 5)
         {
             int deviceVersion = 1;
             if (Int32.TryParse(parts[4], out deviceVersion))
             {
                 device.DeviceTypeNamespace = parts[1];
                 device.DeviceType = parts[3];
                 device.DeviceVersion = deviceVersion;
             }
             else
                 device.DeviceType = value;
         }
         else
             device.DeviceType = value;
     }
 }
Exemplo n.º 17
0
        private ReceivedUdpData GetMockSearchResponseWithCustomCacheHeader(SsdpDevice device, string stHeader, string cacheHeader)
        {
            var responseText = String.Format(@"HTTP/1.1 200 OK
            EXT:
            DATE: {4}{0}
            ST:{1}
            SERVER: TestOS/1.0 UPnP/1.0 RSSDP/1.0
            USN:{2}
            LOCATION:{3}

            ", //Blank line at end important, do not remove.
             String.IsNullOrEmpty(cacheHeader) ? String.Empty : Environment.NewLine + cacheHeader,
             stHeader,
             String.Format("{0}:{1}", device.Udn, device.FullDeviceType),
             device.ToRootDevice().Location,
             DateTime.UtcNow.ToString("r")
             );

            var retVal = new ReceivedUdpData()
            {
                Buffer = System.Text.ASCIIEncoding.UTF8.GetBytes(responseText),
                ReceivedFrom = new UdpEndPoint() { IPAddress = SsdpConstants.MulticastLocalAdminAddress, Port = SsdpConstants.MulticastPort }
            };
            retVal.ReceivedBytes = retVal.Buffer.Length;

            return retVal;
        }
Exemplo n.º 18
0
 private ReceivedUdpData GetMockSearchResponse(SsdpDevice device, string stHeader)
 {
     return GetMockSearchResponseWithCustomCacheHeader(device, stHeader, String.Format("CACHE-CONTROL: public, max-age={0}", device.ToRootDevice().CacheLifetime.TotalSeconds));
 }
Exemplo n.º 19
0
        private ReceivedUdpData GetMockByeByeNotification(SsdpDevice device)
        {
            var data = String.Format(@"NOTIFY * HTTP/1.1
            HOST: 239.255.255.250:1900
            DATE: {0}
            NT: {1}
            NTS: ssdp:byebye
            SERVER: TestOS/1.0 UPnP/1.0 RSSDP/1.0
            USN: {2}

            ",
            DateTime.UtcNow.ToString("r"),
            device.Udn,
            String.Format("{0}::{1}", device.Udn, device.FullDeviceType)
             );

            var retVal = new ReceivedUdpData()
            {
                Buffer = System.Text.UTF8Encoding.UTF8.GetBytes(data),
                ReceivedFrom = new UdpEndPoint()
                {
                    IPAddress = SsdpConstants.MulticastLocalAdminAddress,
                    Port = 1900
                }
            };
            retVal.ReceivedBytes = retVal.Buffer.Length;

            return retVal;
        }
Exemplo n.º 20
0
        private ReceivedUdpData GetMockAliveNotification(SsdpDevice device)
        {
            var rootDevice = device.ToRootDevice();

            var data = String.Format(@"NOTIFY * HTTP/1.1
            HOST: 239.255.255.250:1900
            Date: {0}
            NT: {1}
            NTS: ssdp:alive
            SERVER: TestOS/1.0 UPnP/1.0 RSSDP/1.0
            USN: {2}
            LOCATION: {3}
            CACHE-CONTROL: public, max-age={4}

            ",
            DateTime.UtcNow.ToString("r"),
            device.Udn,
            String.Format("{0}::{1}", device.Udn, device.FullDeviceType),
            rootDevice.Location,
            rootDevice.CacheLifetime.TotalSeconds
             );

            var retVal = new ReceivedUdpData()
            {
                Buffer = System.Text.UTF8Encoding.UTF8.GetBytes(data),
                ReceivedFrom = new UdpEndPoint()
                {
                    IPAddress = SsdpConstants.MulticastLocalAdminAddress,
                    Port = 1900
                }
            };
            retVal.ReceivedBytes = retVal.Buffer.Length;

            return retVal;
        }
Exemplo n.º 21
0
        private void LoadChildDevices(XmlReader reader, SsdpDevice device)
        {
            while (!reader.EOF && reader.NodeType != XmlNodeType.Element)
            {
                reader.Read();
            }

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

                if (reader.LocalName == "device")
                {
                    var childDevice = new SsdpEmbeddedDevice();
                    LoadDeviceProperties(reader, childDevice);
                    device.AddDevice(childDevice);
                }
                else
                    break;
            }
        }
Exemplo n.º 22
0
        private bool SetPropertyFromReader(XmlReader reader, SsdpDevice device)
        {
            switch (reader.LocalName)
            {
                case "friendlyName":
                    device.FriendlyName = reader.ReadElementContentAsString();
                    break;

                case "manufacturer":
                    device.Manufacturer = reader.ReadElementContentAsString();
                    break;

                case "manufacturerURL":
                    device.ManufacturerUrl = StringToUri(reader.ReadElementContentAsString());
                    break;

                case "modelDescription":
                    device.ModelDescription = reader.ReadElementContentAsString();
                    break;

                case "modelName":
                    device.ModelName = reader.ReadElementContentAsString();
                    break;

                case "modelNumber":
                    device.ModelNumber = reader.ReadElementContentAsString();
                    break;

                case "modelURL":
                    device.ModelUrl = StringToUri(reader.ReadElementContentAsString());
                    break;

                case "presentationURL":
                    device.PresentationUrl = StringToUri(reader.ReadElementContentAsString());
                    break;

                case "serialNumber":
                    device.SerialNumber = reader.ReadElementContentAsString();
                    break;

                case "UDN":
                    device.Udn = reader.ReadElementContentAsString();
                    SetUuidFromUdn(device);
                    break;

                case "UPC":
                    device.Upc = reader.ReadElementContentAsString();
                    break;

                case "deviceType":
                    SetDeviceTypePropertiesFromFullDeviceType(device, reader.ReadElementContentAsString());
                    break;

                case "iconList":
                    reader.Read();
                    LoadIcons(reader, device);
                    break;

                case "deviceList":
                    reader.Read();
                    LoadChildDevices(reader, device);
                    break;

                case "serviceList":
                    reader.Skip();
                    break;

                default:
                    if (reader.NodeType == XmlNodeType.Element && reader.Name != "device" && reader.Name != "icon")
                    {
                        AddCustomProperty(reader, device);
                        break;
                    }
                    else
                        return false;
            }
            return true;
        }
Exemplo n.º 23
0
        private bool SetPropertyFromReader(XmlReader reader, SsdpDevice device)
        {
            switch (reader.LocalName)
            {
            case "friendlyName":
                device.FriendlyName = reader.ReadElementContentAsString();
                break;

            case "manufacturer":
                device.Manufacturer = reader.ReadElementContentAsString();
                break;

            case "manufacturerURL":
                device.ManufacturerUrl = StringToUri(reader.ReadElementContentAsString());
                break;

            case "modelDescription":
                device.ModelDescription = reader.ReadElementContentAsString();
                break;

            case "modelName":
                device.ModelName = reader.ReadElementContentAsString();
                break;

            case "modelNumber":
                device.ModelNumber = reader.ReadElementContentAsString();
                break;

            case "modelURL":
                device.ModelUrl = StringToUri(reader.ReadElementContentAsString());
                break;

            case "presentationURL":
                device.PresentationUrl = StringToUri(reader.ReadElementContentAsString());
                break;

            case "serialNumber":
                device.SerialNumber = reader.ReadElementContentAsString();
                break;

            case "UDN":
                device.Udn = reader.ReadElementContentAsString();
                SetUuidFromUdn(device);
                break;

            case "UPC":
                device.Upc = reader.ReadElementContentAsString();
                break;

            case "deviceType":
                SetDeviceTypePropertiesFromFullDeviceType(device, reader.ReadElementContentAsString());
                break;

            case "iconList":
                reader.Read();
                LoadIcons(reader, device);
                break;

            case "deviceList":
                reader.Read();
                LoadChildDevices(reader, device);
                break;

            case "serviceList":
                reader.Skip();
                break;

            default:
                if (reader.NodeType == XmlNodeType.Element && reader.Name != "device" && reader.Name != "icon")
                {
                    AddCustomProperty(reader, device);
                    break;
                }
                else
                {
                    return(false);
                }
            }
            return(true);
        }
Exemplo n.º 24
0
        /// <summary>
        /// Writes this device to the specified <see cref="System.Xml.XmlWriter"/> as a device node and it's content.
        /// </summary>
        /// <param name="writer">The <see cref="System.Xml.XmlWriter"/> to output to.</param>
        /// <param name="device">The <see cref="SsdpDevice"/> to write out.</param>
        /// <exception cref="System.ArgumentNullException">Thrown if the <paramref name="writer"/> or <paramref name="device"/> argument is null.</exception>
        protected virtual void WriteDeviceDescriptionXml(XmlWriter writer, SsdpDevice device)
        {
            if (writer == null) throw new ArgumentNullException("writer");
            if (device == null) throw new ArgumentNullException("device");

            writer.WriteStartElement("device");

            if (!String.IsNullOrEmpty(device.FullDeviceType))
                WriteNodeIfNotEmpty(writer, "deviceType", device.FullDeviceType);

            WriteNodeIfNotEmpty(writer, "friendlyName", device.FriendlyName);
            WriteNodeIfNotEmpty(writer, "manufacturer", device.Manufacturer);
            WriteNodeIfNotEmpty(writer, "manufacturerURL", device.ManufacturerUrl);
            WriteNodeIfNotEmpty(writer, "modelDescription", device.ModelDescription);
            WriteNodeIfNotEmpty(writer, "modelName", device.ModelName);
            WriteNodeIfNotEmpty(writer, "modelNumber", device.ModelNumber);
            WriteNodeIfNotEmpty(writer, "modelURL", device.ModelUrl);
            WriteNodeIfNotEmpty(writer, "presentationURL", device.PresentationUrl);
            WriteNodeIfNotEmpty(writer, "serialNumber", device.SerialNumber);
            WriteNodeIfNotEmpty(writer, "UDN", device.Udn);
            WriteNodeIfNotEmpty(writer, "UPC", device.Upc);

            WriteCustomProperties(writer, device);
            WriteIcons(writer, device);
            WriteChildDevices(writer, device);

            writer.WriteEndElement();
        }
Exemplo n.º 25
0
 private static void WriteCustomProperties(XmlWriter writer, SsdpDevice device)
 {
     foreach (var prop in device.CustomProperties)
     {
         writer.WriteElementString(prop.Namespace, prop.Name, SsdpConstants.SsdpDeviceDescriptionXmlNamespace, prop.Value);
     }
 }
Exemplo n.º 26
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();
                }
            }
        }
Exemplo n.º 27
0
        private static void WriteIcons(XmlWriter writer, SsdpDevice device)
        {
            if (device.Icons.Any())
            {
                writer.WriteStartElement("iconList");

                foreach (var icon in device.Icons)
                {
                    writer.WriteStartElement("icon");

                    writer.WriteElementString("mimetype", icon.MimeType);
                    writer.WriteElementString("width", icon.Width.ToString());
                    writer.WriteElementString("height", icon.Height.ToString());
                    writer.WriteElementString("depth", icon.ColorDepth.ToString());
                    writer.WriteElementString("url", icon.Url.ToString());

                    writer.WriteEndElement();
                }

                writer.WriteEndElement();
            }
        }
Exemplo n.º 28
0
 private bool ChildDeviceExists(SsdpDevice device)
 {
     return (from d in _Devices where device.Uuid == d.Uuid select d).Any();
 }
Exemplo n.º 29
0
        private void WriteChildDevices(XmlWriter writer, SsdpDevice parentDevice)
        {
            if (parentDevice.Devices.Any())
            {
                writer.WriteStartElement("deviceList");

                foreach (var device in parentDevice.Devices)
                {
                    WriteDeviceDescriptionXml(writer, device);
                }

                writer.WriteEndElement();
            }
        }
Exemplo n.º 30
0
 static SsdpDevice CreateSsdpDeviceModel(DiscoveredSsdpDevice discoveredSsdpDevice, Rssdp.SsdpDevice ssdpDevice)
 {
     return(new SsdpDevice
     {
         Usn = discoveredSsdpDevice.Usn,
         DescriptionLocation = discoveredSsdpDevice.DescriptionLocation?.ToString(),
         CacheLifetime = discoveredSsdpDevice.CacheLifetime,
         DeviceType = ssdpDevice.DeviceType,
         NotificationType = discoveredSsdpDevice.NotificationType,
         DeviceTypeNamespace = ssdpDevice.DeviceTypeNamespace,
     });
 }
Exemplo n.º 31
0
 private static void SetUuidFromUdn(SsdpDevice device)
 {
     if (device.Udn != null && device.Udn.StartsWith("uuid:", StringComparison.OrdinalIgnoreCase))
         device.Uuid = device.Udn.Substring(5).Trim();
     else
         device.Uuid = device.Udn;
 }
Exemplo n.º 32
0
 private static void AddCustomProperty(XmlReader reader, SsdpDevice device)
 {
     var newProp = new SsdpDeviceProperty() { Namespace = reader.Prefix, Name = reader.LocalName, Value = reader.ReadElementContentAsString() };
     // We don't support complex nested types or repeat/multi-value properties
     if (!device.CustomProperties.Contains(newProp.FullName))
         device.CustomProperties.Add(newProp);
 }
Exemplo n.º 33
0
        private void LoadDeviceProperties(XmlReader reader, SsdpDevice device)
        {
            ReadUntilDeviceNode(reader);

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

                if (!SetPropertyFromReader(reader, device))
                    reader.Read();
            }
        }
Exemplo n.º 34
0
 public void DoInvalidWrite(XmlWriter writer, SsdpDevice device)
 {
     this.WriteDeviceDescriptionXml(writer, device);
 }
Exemplo n.º 35
0
 protected override void WriteDeviceDescriptionXml(System.Xml.XmlWriter writer, SsdpDevice device)
 {
     base.WriteDeviceDescriptionXml(writer, device);
 }
Exemplo n.º 36
0
 private bool ChildDeviceExists(SsdpDevice device)
 {
     return((from d in _Devices where device.Uuid == d.Uuid select d).Any());
 }
Exemplo n.º 37
0
        private string AdditionalHeaders(SsdpDevice device)
        {
            if (device.CustomResponseHeaders.Count == 0) return String.Empty;

            StringBuilder returnValue = new StringBuilder();
            foreach (var header in device.CustomResponseHeaders)
            {
                returnValue.Append("\r\n");

                returnValue.Append(header.ToString());
            }
            return returnValue.ToString();
        }
Exemplo n.º 38
0
        /// <summary>
        /// Constructs a new instance for the specified <see cref="SsdpDevice"/>.
        /// </summary>
        /// <param name="device">The <see cref="SsdpDevice"/> associated with the event this argument class is being used for.</param>
        /// <exception cref="System.ArgumentNullException">Thrown if the <paramref name="device"/> argument is null.</exception>
        public DeviceEventArgs(SsdpDevice device)
        {
            if (device == null) throw new ArgumentNullException("device");

            _Device = device;
        }
Exemplo n.º 39
0
        private void SetProperies(SsdpDevice device, string fullDeviceType)
        {
            var service = fullDeviceType.Replace("urn:", string.Empty).Replace(":1", string.Empty);

            var serviceParts = service.Split(':');

            var deviceTypeNamespace = serviceParts[0].Replace('.', '-');

            device.DeviceTypeNamespace = deviceTypeNamespace;
            device.DeviceClass = serviceParts[1];
            device.DeviceType = serviceParts[2];
        }