Пример #1
0
        public List <stNet.UPNPHostList> DiscoverBasicdevice()
        {
            List <stNet.UPNPHostList> dict  = new List <stNet.UPNPHostList>();
            IList <string>            hosts = this.Discover();

            if (hosts.Count == 0)
            {
                return(null);
            }
            int cnt = 0;

            foreach (string host in (List <string>)hosts)
            {
                stNet.UPNPHostList resp = this.deviceBasicRequest(host);
                if (
                    (resp != null) &&
                    (!string.IsNullOrWhiteSpace(resp.urlBase))
                    )
                {
                    resp.Id = cnt++;
                    dict.Add(resp);
                }
            }
            GC.SuppressFinalize(hosts);
            return(dict);
        }
Пример #2
0
        public stNet.UPNPHostList deviceInternetGatewayRequest(string uri)
        {
            stNet.UPNPHostList strarr = new stNet.UPNPHostList()
            {
                Id         = 0,
                Name       = null,
                Desc       = null,
                Copy       = null,
                Version    = null,
                urlRoot    = null,
                urlBase    = null,
                urlControl = null,
                urlEvent   = null
            };

            try
            {
                XmlNode       node;
                XmlDocument   desc = new XmlDocument();
                List <string> tnsList;
                string        tnsService = "//tns:service[tns:serviceType=\"urn:schemas-upnp-org:service:WANIPConnection:1\"]/tns:{0}/text()";
                string        outValue;

                desc.Load(WebRequest.Create(uri).GetResponse().GetResponseStream());
                XmlNamespaceManager nsMgr = new XmlNamespaceManager(desc.NameTable);
                nsMgr.AddNamespace("tns", urnSheme);
                if (
                    ((node = desc.SelectSingleNode(tnsDeviceType, nsMgr)) == null) ||
                    (!node.Value.Contains("InternetGatewayDevice"))
                    )
                {
                    GC.SuppressFinalize(desc);
                    return(strarr);
                }

                /* SpeedTest URLRoot */
                strarr.urlRoot = uri;
                /* SpeedTest URLBase */
                strarr.urlBase = GetNodeValue(desc, nsMgr, this.tnsURL);
                /* Server Name */
                strarr.Name = GetNodeValue(desc, nsMgr, this.tnsName);
                /* Server Description */
                strarr.Desc = GetNodeValue(desc, nsMgr, this.tnsDesc);
                /* Server Version */
                strarr.Version = GetNodeValue(desc, nsMgr, this.tnsVersion);
                /* Server Copyright */
                strarr.Copy = GetNodeValue(desc, nsMgr, this.tnsCopy);
                /* Server Control URL */
                tnsList = new List <string>()
                {
                    string.Format(
                        tnsService,
                        "controlURL"
                        )
                };
                if (string.IsNullOrWhiteSpace(outValue = GetNodeValue(desc, nsMgr, tnsList)))
                {
                    tnsList.Clear();
                    GC.SuppressFinalize(desc);
                    return(strarr);
                }
                strarr.urlControl = this.ConcatUrl(uri, outValue);
                /* Server Event URL */
                tnsList.Clear();
                tnsList = new List <string>()
                {
                    string.Format(
                        tnsService,
                        "eventSubURL"
                        )
                };
                if (string.IsNullOrWhiteSpace(outValue = GetNodeValue(desc, nsMgr, tnsList)))
                {
                    tnsList.Clear();
                    GC.SuppressFinalize(desc);
                    return(strarr);
                }
                strarr.urlEvent = this.ConcatUrl(uri, outValue);
                tnsList.Clear();
                GC.SuppressFinalize(desc);
                return(strarr);
            }
            catch (Exception ex)
            {
                this.IMsg.ToLogAndLine(
                    System.Reflection.MethodBase.GetCurrentMethod(),
                    string.Format(
                        Properties.Resources.upnpError,
                        ex.Message
                        )
                    );
                return(strarr);
            }
        }
Пример #3
0
        public stNet.UPNPHostList deviceBasicRequest(string uri)
        {
            stNet.UPNPHostList strarr = new stNet.UPNPHostList()
            {
                urlBase    = null,
                urlControl = null,
                urlEvent   = null,
                Desc       = null
            };

            try
            {
                XmlNode     node;
                XmlDocument desc = new XmlDocument();

                #if STDEBUG
                desc.LoadXml(UPNPTestData.xmlTest);
                #else
                desc.Load(WebRequest.Create(uri).GetResponse().GetResponseStream());
                #endif

                XmlNamespaceManager nsMgr = new XmlNamespaceManager(desc.NameTable);
                nsMgr.AddNamespace("tns", urnSheme);
                if (
                    ((node = desc.SelectSingleNode(tnsDeviceType, nsMgr)) == null) ||
                    (!node.Value.Contains("device:Basic:1"))
                    )
                {
                    GC.SuppressFinalize(desc);
                    return(strarr);
                }
                if (!string.IsNullOrWhiteSpace(this.strUUID))
                {
                    if (
                        ((node = desc.SelectSingleNode(tnsUdn, nsMgr)) != null) &&
                        (!node.Value.Contains(this.strUUID))
                        )
                    {
                        GC.SuppressFinalize(desc);
                        return(strarr);
                    }
                }
                /* SpeedTest URLRoot */
                strarr.urlRoot = uri;
                /* SpeedTest URLBase */
                strarr.urlBase = GetNodeValue(desc, nsMgr, this.tnsURL);
                /* Server Name */
                strarr.Name = GetNodeValue(desc, nsMgr, this.tnsName);
                /* Server Description */
                strarr.Desc = GetNodeValue(desc, nsMgr, this.tnsDesc);
                /* Server Version */
                strarr.Version = GetNodeValue(desc, nsMgr, this.tnsVersion);
                /* Server Copyright */
                strarr.Copy = GetNodeValue(desc, nsMgr, this.tnsCopy);

                GC.SuppressFinalize(desc);
                return(strarr);
            }
            catch (Exception e)
            {
                this.IMsg.ToLogAndLine(
                    System.Reflection.MethodBase.GetCurrentMethod(),
                    string.Format(
                        Properties.Resources.upnpError,
                        e.Message
                        )
                    );
                return(strarr);
            }
        }