コード例 #1
0
        private void signalThread()
        {
            if (hostAvaliable(ip))
            {
                setSession();

                ParseTypes.Network   net;
                ParseTypes.BasicInfo basicInfo;
                ParseTypes.Operator  op;
                ParseTypes.Status    sta;
                ParseTypes.Traffic   tra;

                XmlSerializer serializer  = new XmlSerializer(typeof(ParseTypes.Network));
                XmlSerializer serializer2 = new XmlSerializer(typeof(ParseTypes.BasicInfo));
                XmlSerializer serializer3 = new XmlSerializer(typeof(ParseTypes.Operator));
                XmlSerializer serializer4 = new XmlSerializer(typeof(ParseTypes.Status));
                XmlSerializer serializer5 = new XmlSerializer(typeof(ParseTypes.Traffic));

                while (isWorking)
                {
                    if (hostAvaliable(ip))
                    {
                        try
                        {
                            //MessageBox.Show(webclient.DownloadString("http://192.168.8.1/api/device/signal"));
                            using (StringReader reader = new StringReader(webclient.DownloadString("http://" + ip.ToString() + "/api/device/signal")))
                            {
                                net = (ParseTypes.Network)(serializer.Deserialize(reader));
                            }
                            Thread.Sleep(200);
                            using (StringReader reader = new StringReader(webclient.DownloadString("http://" + ip.ToString() + "/api/device/information")))
                            {
                                basicInfo = (ParseTypes.BasicInfo)(serializer2.Deserialize(reader));
                            }
                            Thread.Sleep(200);
                            using (StringReader reader = new StringReader(webclient.DownloadString("http://" + ip.ToString() + "/api/monitoring/status")))
                            {
                                sta = (ParseTypes.Status)(serializer4.Deserialize(reader));
                            }
                            Thread.Sleep(200);
                            using (StringReader reader = new StringReader(webclient.DownloadString("http://" + ip.ToString() + "/api/monitoring/traffic-statistics")))
                            {
                                tra = (ParseTypes.Traffic)(serializer5.Deserialize(reader));
                            }
                            Thread.Sleep(200);
                            try

                            {
                                using (StringReader reader = new StringReader(webclient.DownloadString("http://" + ip.ToString() + "/api/net/current-plmn")))
                                {
                                    op = (ParseTypes.Operator)(serializer3.Deserialize(reader));
                                }
                            }
                            catch
                            {
                                op          = new ParseTypes.Operator();
                                op.FullName = "Unknown";
                            }

                            parseSignal(net, basicInfo, op, sta, tra);

                            if (isRestarting)
                            {
                                int i = 40;

                                sh_sh();

                                while (i != 0)
                                {
                                    chLabel(toolStripStatusLabel2, "wait " + i + " seconds to reconnect.");
                                    set_time(i);
                                    Thread.Sleep(1000);
                                    i--;
                                }

                                setSession();

                                hd_sh();
                                isRestarting = false;
                            }
                            else
                            {
                                Thread.Sleep(tick_time);
                            }
                        }
                        catch (TimeoutException)
                        {
                            this.Invoke((MethodInvoker)(() => lost_close()));
                        }
                        catch (WebException)
                        {
                            this.Invoke((MethodInvoker)(() => lost_close()));
                        }
                        catch (InvalidOperationException)
                        {
                            this.Invoke((MethodInvoker)(() => lost_close()));
                        }
                    }
                    else
                    {
                        this.Invoke((MethodInvoker)(() => lost_close()));
                    }
                }
            }
        }
コード例 #2
0
        private void parseSignal(ParseTypes.Network si, ParseTypes.BasicInfo basicInfo, ParseTypes.Operator op, ParseTypes.Status sta, ParseTypes.Traffic tra)
        {
            EnumNetworkType type = (EnumNetworkType)System.Enum.Parse(typeof(EnumNetworkType), basicInfo.workmode.Replace(" ", "_"));

            chLabel(label22, getTypeNet(int.Parse(sta.CurrentNetworkTypeEx)));

            int a = 0;

            int.TryParse(sta.SignalIcon, out a);
            signalStrength1.Strength = a;

            chLabel(label25, op.FullName);

            chLabel(label33, op.FullName);
            chLabel(label36, op.ShortName);

            chLabel(label39, calcM(tra.CurrentUploadRate) + "/sec");
            chLabel(label40, calcM(tra.CurrentDownloadRate) + "/sec");

            chLabel(toolStripStatusLabel2, getConnStatus(int.Parse(sta.ConnectionStatus)));

            chLabel(label3, si.cell_id.ToString());
            chLabel(label5, si.rsrq);
            chLabel(label6, si.rsrp);
            chLabel(label9, si.rssi);
            chLabel(label11, si.sinr);
            chLabel(label24, si.rscp);

            try
            {
                TimeSpan t = TimeSpan.FromSeconds(int.Parse(tra.CurrentConnectTime));

                string answer = string.Format("{0:D2}h {1:D2}m {2:D2}s",
                                              t.Hours,
                                              t.Minutes,
                                              t.Seconds,
                                              t.Milliseconds);

                chLabel(label45, answer);
            } catch { }

            chLabel(label41, calcM(tra.CurrentDownload));
            chLabel(label43, calcM(tra.CurrentUpload));

            chLabel(label18, basicInfo.DeviceName);
            chLabel(label19, basicInfo.Imei);
            chLabel(label20, basicInfo.SerialNumber);
            chLabel(label14, basicInfo.HardwareVersion);
            chLabel(label12, basicInfo.SoftwareVersion);

            chLabel(label28, sta.WanIPAddress);
            chLabel(label29, basicInfo.MacAddress1);
        }