Ejemplo n.º 1
0
        public async Task <SSDPDeviceInformation> GetDeviceInformation(string url)
        {
            var information = new SSDPDeviceInformation();

            try
            {
                var client   = new HttpClient();
                var response = await client.GetAsync(new Uri(url));

                if (response.StatusCode == HttpStatusCode.OK)
                {
                    var xDocument = XDocument.Parse(await response.Content.ReadAsStringAsync());
                    if (xDocument.Root != null)
                    {
                        XNamespace rootNamespace = xDocument.Root.Name.Namespace;
                        XElement   device        = xDocument.Root.Element(rootNamespace + "device");
                        if (device != null)
                        {
                            XElement model        = device.Element(rootNamespace + "modelName");
                            XElement manufacturer = device.Element(rootNamespace + "manufacturer");
                            XElement friendlyName = device.Element(rootNamespace + "friendlyName");
                            XElement udn          = device.Element(rootNamespace + "UDN");
                            XElement deviceType   = device.Element(rootNamespace + "deviceType");

                            if (model != null && !String.IsNullOrEmpty(model.Value))
                            {
                                information.Model = model.Value;
                            }
                            if (manufacturer != null && !String.IsNullOrEmpty(manufacturer.Value))
                            {
                                information.Manufacturer = manufacturer.Value;
                            }
                            if (friendlyName != null && !String.IsNullOrEmpty(friendlyName.Value))
                            {
                                information.Name = friendlyName.Value;
                            }
                            if (udn != null && !String.IsNullOrEmpty(udn.Value))
                            {
                                information.UDN = udn.Value;
                            }
                            if (deviceType != null && !String.IsNullOrEmpty(deviceType.Value))
                            {
                                information.Type = deviceType.Value;
                            }
                        }
                    }
                }
            }
            catch (Exception)
            {
            }

            return(information);
        }
Ejemplo n.º 2
0
Archivo: SSDP.cs Proyecto: 4nd413/NCast
        public async Task<SSDPDeviceInformation> GetDeviceInformation(string url)
        {
            var information = new SSDPDeviceInformation();

            try
            {
                var client = new HttpClient();
                var response = await client.GetAsync(new Uri(url));
                if (response.StatusCode == HttpStatusCode.OK)
                {
                    var xDocument = XDocument.Parse(await response.Content.ReadAsStringAsync());
                    if (xDocument.Root != null)
                    {
                        XNamespace rootNamespace = xDocument.Root.Name.Namespace;
                        XElement device = xDocument.Root.Element(rootNamespace + "device");
                        if (device != null)
                        {
                            XElement model = device.Element(rootNamespace + "modelName");
                            XElement manufacturer = device.Element(rootNamespace + "manufacturer");
                            XElement friendlyName = device.Element(rootNamespace + "friendlyName");
                            XElement udn = device.Element(rootNamespace + "UDN");
                            XElement deviceType = device.Element(rootNamespace + "deviceType");

                            if (model != null && !String.IsNullOrEmpty(model.Value)) information.Model = model.Value;
                            if (manufacturer != null && !String.IsNullOrEmpty(manufacturer.Value)) information.Manufacturer = manufacturer.Value;
                            if (friendlyName != null && !String.IsNullOrEmpty(friendlyName.Value)) information.Name = friendlyName.Value;
                            if (udn != null && !String.IsNullOrEmpty(udn.Value)) information.UDN = udn.Value;
                            if (deviceType != null && !String.IsNullOrEmpty(deviceType.Value)) information.Type = deviceType.Value;
                        }
                    }
                  
                }

            }
            catch (Exception)
            {
            }

            return information;
        }