public CpDeviceRecognised Recognise(CpDevice aDevice, RecogniserHandler aRecognised)
        {
            string xml;

            if (aDevice.GetAttribute("Upnp.DeviceXml", out xml))
            {
                XmlNameTable        table   = new NameTable();
                XmlNamespaceManager manager = new XmlNamespaceManager(table);
                manager.AddNamespace("ns", "urn:schemas-upnp-org:device-1-0");

                XmlDocument doc = new XmlDocument(manager.NameTable);
                try
                {
                    doc.LoadXml(xml);
                }
                catch (Exception ex)
                {
                    UserLog.WriteLine("RecogniserMediaServer.  Exception caught recognising device xml: " + ex);
                    UserLog.WriteLine(xml);
                    return(null);
                }

                XmlNode n = doc.SelectSingleNode("/ns:root/ns:device/ns:deviceType", manager);
                if (n != null && n.FirstChild != null && n.FirstChild.InnerText == kDeviceType)
                {
                    UserLog.WriteLine(DateTime.Now + ": RecogniserMediaServer: Device+             Udn{" + aDevice.Udn() + "}");

                    return(new CpDeviceRecognisedMediaServer(aDevice, aRecognised));
                }
            }

            return(null);
        }
        public CpDeviceRecognisedLinn(CpDevice aDevice, RecogniserHandler aRecognised)
            : base(aDevice)
        {
            try
            {
                iLock = new object();

                iRecognised = aRecognised;

                iInAppConfig     = false;
                iPresentationUri = string.Empty;

                iProductService = new CpProxyAvOpenhomeOrgProduct1(aDevice);
                iProductService.SetPropertyInitialEvent(InitialEvent);
                iProductService.SetPropertyProductRoomChanged(ProductRoomChanged);
                iProductService.SetPropertyProductNameChanged(ProductNameChanged);
                iProductService.SetPropertyModelNameChanged(ModelNameChanged);
                iProductService.SetPropertyProductImageUriChanged(ProductImageUriChanged);
                iProductService.SetPropertyAttributesChanged(ProductAttributesChanged);
                iProductService.Subscribe();
            }
            catch
            {
                aDevice.RemoveRef();
                throw;
            }
        }
        public CpDeviceRecognised Recognise(CpDevice aDevice, RecogniserHandler aRecognised)
        {
            string version;

            if (aDevice.GetAttribute("Upnp.Service.schemas-upnp-org.DeviceProperties", out version))
            {
                UserLog.WriteLine(DateTime.Now + ": RecogniserSonos: Device+             Udn{" + aDevice.Udn() + "}");
                try
                {
                    return(new CpDeviceRecognisedSonos(aDevice, aRecognised));
                }
                catch (Exception ex)
                {
                    UserLog.WriteLine(DateTime.Now + "RecogniserSonos:  Exception caught recognising device xml: " + ex);
                    return(null);
                }
            }

            return(null);
        }
        public CpDeviceRecognised Recognise(CpDevice aDevice, RecogniserHandler aRecognised)
        {
            if (aDevice.Udn().StartsWith(kUdnLinnPrefix))
            {
                string xml;
                if (aDevice.GetAttribute("Upnp.DeviceXml", out xml))
                {
                    XmlNameTable        table   = new NameTable();
                    XmlNamespaceManager manager = new XmlNamespaceManager(table);
                    manager.AddNamespace("ns", "urn:schemas-upnp-org:device-1-0");

                    XmlDocument doc = new XmlDocument(manager.NameTable);
                    try
                    {
                        doc.LoadXml(xml);
                    }
                    catch (Exception ex)
                    {
                        UserLog.WriteLine("RecogniserLinn.  Exception caught recognising device xml: " + ex);
                        UserLog.WriteLine(xml);
                        throw;
                    }

                    XmlNodeList nodes = doc.SelectNodes("/ns:root/ns:device/ns:serviceList/ns:service/ns:serviceType", manager);
                    foreach (XmlNode n in nodes)
                    {
                        if (n.FirstChild != null && n.FirstChild.InnerText == kProductServiceType)
                        {
                            UserLog.WriteLine(DateTime.Now + ": RecogniserLinn: Device+             Udn{" + aDevice.Udn() + "}");

                            return(new CpDeviceRecognisedLinn(aDevice, aRecognised));
                        }
                    }
                }
            }

            return(null);
        }
        public CpDeviceRecognisedMediaServer(CpDevice aDevice, RecogniserHandler aRecognised)
            : base(aDevice)
        {
            try
            {
                iRecognised = aRecognised;

                iProductImageUri = kProductImageUri;

                string xml;
                if (aDevice.GetAttribute("Upnp.DeviceXml", out xml))
                {
                    XmlNameTable        table   = new NameTable();
                    XmlNamespaceManager manager = new XmlNamespaceManager(table);
                    manager.AddNamespace("ns", "urn:schemas-upnp-org:device-1-0");

                    XmlDocument doc = new XmlDocument(manager.NameTable);
                    doc.LoadXml(xml);

                    string  baseUri = string.Empty;
                    XmlNode node    = doc.SelectSingleNode("/ns:root/ns:URLBase", manager);
                    if (node == null)
                    {
                        string location;
                        if (aDevice.GetAttribute("Upnp.Location", out location))
                        {
                            Uri uri = new Uri(location);
                            baseUri = string.Format("{0}://{1}", uri.Scheme, uri.Authority);
                        }
                    }
                    else if (node.FirstChild != null)
                    {
                        baseUri = node.FirstChild.InnerText;
                    }

                    iBaseUri = baseUri;

                    XmlNodeList nodes  = doc.SelectNodes("/ns:root/ns:device/ns:iconList/ns:icon", manager);
                    int         width  = 0;
                    int         height = 0;
                    foreach (XmlNode n in nodes)
                    {
                        bool    found = false;
                        XmlNode w     = n.SelectSingleNode("ns:width", manager);
                        XmlNode h     = n.SelectSingleNode("ns:height", manager);
                        XmlNode u     = n.SelectSingleNode("ns:url", manager);

                        if (w != null && w.FirstChild != null)
                        {
                            try
                            {
                                int i = int.Parse(w.FirstChild.InnerText);
                                if (i > width)
                                {
                                    width  = i;
                                    height = i;
                                    found  = true;
                                }
                            }
                            catch (FormatException) { }
                        }

                        if (h != null && h.FirstChild != null)
                        {
                            try
                            {
                                int i = int.Parse(h.FirstChild.InnerText);
                                if (i > height)
                                {
                                    width  = i;
                                    height = i;
                                    found  = true;
                                }
                            }
                            catch (FormatException) { }
                        }

                        if (found && u != null && u.FirstChild != null)
                        {
                            iProductImageUri = baseUri;
                            if (!iProductImageUri.EndsWith("/") && !u.FirstChild.InnerText.StartsWith("/"))
                            {
                                iProductImageUri += "/";
                            }
                            iProductImageUri += u.FirstChild.InnerText;
                        }
                    }
                }

                string name;
                if (Device.GetAttribute("Upnp.FriendlyName", out name))
                {
                    iFriendlyName = name;
                }
                else
                {
                    iFriendlyName = string.Empty;
                }

                iRecognised(this);
            }
            catch
            {
                throw;
            }
        }