예제 #1
0
파일: Form1.cs 프로젝트: u1035/TPIMon
 private void RequestModemPage(object url)
 {
     try
     {
         WebRequest request = WebRequest.Create(url.ToString());
         request.Timeout = TPIMon.Properties.Settings.Default.NET_TIMEOUT;
         WebResponse response = request.GetResponse();
         Stream      data     = response.GetResponseStream();
         string      html     = String.Empty;
         using (StreamReader sr = new StreamReader(data))
         {
             html = sr.ReadToEnd();
         }
         CTPIInfo info = parser.ParseHTML(html);
         if (info != null)
         {
             textBox1.AppendText("\r\n" + info.ToTabbedString("                       "));
             lock (TPIs)
             {
                 TPIs.Add(info.ID, info);
             }
         }
         response.Close();
     }
     catch (Exception ex)
     {
         if (ex == null)
         {
             textBox1.Text += "\r\nНе удалось получить страницу " + url;
         }
         //textBox1.Text += "\r\n" + ex.Message;
     }
 }
예제 #2
0
파일: CTPIParser.cs 프로젝트: u1035/TPIMon
        public CTPIInfo ParseHTML(String html)
        {
            CTPIInfo result = new CTPIInfo();

            int    tag_begin = 0;
            int    tag_end   = 0;
            double volt      = 9;


            if ((html.Contains("<id>")) && (html.Contains("</id>")))
            {
                tag_begin = html.IndexOf("<id>") + 10;
                tag_end   = html.IndexOf("</id>");
                result.ID = html.Substring(tag_begin, tag_end - tag_begin);
            }
            else
            {
                return(null);
            }

            if ((html.Contains("<voltage>")) && (html.Contains("</voltage>")))
            {
                tag_begin = html.IndexOf("<voltage>") + 15;
                tag_end   = html.IndexOf("</voltage>");
                string voltage = html.Substring(tag_begin, tag_end - tag_begin);
                double.TryParse(voltage, out volt);
                result.Voltage = volt / 1000;
            }
            else
            {
                return(null);
            }

            if ((html.Contains("<x>")) && (html.Contains("</x>")))
            {
                tag_begin    = html.IndexOf("<x>") + 9;
                tag_end      = html.IndexOf("</x>");
                result.gps_x = html.Substring(tag_begin, tag_end - tag_begin);
            }
            else
            {
                return(null);
            }

            if ((html.Contains("<y>")) && (html.Contains("</y>")))
            {
                tag_begin    = html.IndexOf("<y>") + 9;
                tag_end      = html.IndexOf("</y>");
                result.gps_y = html.Substring(tag_begin, tag_end - tag_begin);
            }
            else
            {
                return(null);
            }

            if ((html.Contains("<gpstimestamp>")) && (html.Contains("</gpstimestamp>")))
            {
                tag_begin       = html.IndexOf("<gpstimestamp>") + 20;
                tag_end         = html.IndexOf("</gpstimestamp>");
                result.gps_time = html.Substring(tag_begin, tag_end - tag_begin);
            }
            else
            {
                return(null);
            }



            if (index_page.Contains("Modem " + result.ID + "SIGNONLINE"))
            {
                result.Online = true;
            }

            return(result);
        }