private void FetchDeviceInformation(string theIPAddress)
        {
            var    DevInfoUrl = "http://" + theIPAddress + "/devinfo.xml";
            string xmlStr     = string.Empty;

            do
            {
                try
                {
                    using (var wc = new WebClient())
                    {
                        xmlStr = wc.DownloadString(DevInfoUrl);
                    }
                }
                catch (Exception ex)
                {
                    Log?.Invoke(EventLogEntryCodes.FetchException, new string[] { theIPAddress, ex.Message });
                    FetchError?.Invoke();
                    Task.Delay(3000).Wait();
                }
            } while (xmlStr == string.Empty && (!m_TokenSource.Token.IsCancellationRequested));

            if (m_TokenSource.Token.IsCancellationRequested)
            {
                return;
            }
            else
            {
                Log?.Invoke(EventLogEntryCodes.FetchSuccessful, new string[] { theIPAddress });

                var xmlDoc = new XmlDocument();
                xmlDoc.LoadXml(xmlStr);

                XmlNode MACNode     = xmlDoc.DocumentElement.SelectSingleNode("/lines/macaddr");
                XmlNode LocNode     = xmlDoc.DocumentElement.SelectSingleNode("/lines/loc");
                XmlNode FwverNode   = xmlDoc.DocumentElement.SelectSingleNode("/lines/fwver");
                XmlNode ModelNode   = xmlDoc.DocumentElement.SelectSingleNode("/lines/model");
                XmlNode DevNameNode = xmlDoc.DocumentElement.SelectSingleNode("/lines/devname");

                FetchCompleted?.Invoke(new DeviceInformation
                {
                    MACAddress   = MACNode.InnerText,
                    Name         = DevNameNode.InnerText,
                    Location     = LocNode.InnerText,
                    Firmware     = FwverNode.InnerText,
                    ProductModel = ModelNode.InnerText
                });
            }
        }
Пример #2
0
 private void ReadSession()
 {
     while (_running)
     {
         try
         {
             var json = _webClient.DownloadString(_sessionUrl);
             if (json != null && json.Length > 0)
             {
                 lock (sessionJsonLock)
                 {
                     sessionJson = json;
                 }
             }
         }
         catch (Exception e)
         {
             FetchError?.Invoke(this, e);
         }
     }
 }