예제 #1
0
 /// <summary>
 /// 定时更新数据
 /// </summary>
 private void InitUpdateTheard()
 {
     if (updateTimer == null)
     {
         updateSpan  = TimeSpan.FromSeconds(2);
         updateTimer = ThreadPoolTimer.CreatePeriodicTimer(async(source) => {
             if (wanInfo == null)
             {
                 wanInfo = await RouterAPI.GetWANinfo();
             }
             netRate    = await RouterAPI.GetNetRate();
             cpuMemInfo = await RouterAPI.GetCpuMemInfo();
             clients    = await RouterAPI.GetClients();
             devRate    = await RouterAPI.GetDeviceRate();
             banList    = await RouterAPI.FireWall.GetBanList();
             if (wlanInfo == null)
             {
                 wlanInfo = await RouterAPI.GetWLANInfo();
             }
             await Dispatcher.RunAsync(CoreDispatcherPriority.High, () => {
                 UpdateUI();
             });
         }, updateSpan);
     }
 }
예제 #2
0
        private void UpdateUI()
        {
            //广域网及路由器信息
            if (wanInfo != null)
            {
                textBlock_model.Text         = wanInfo.model;
                textBlock_title.Text         = wanInfo.name;
                textBlock_devName.Text       = wanInfo.name;
                textBlock_ipAdd.Text         = wanInfo.ipaddr;
                textBlock_state.Text         = wanInfo.statusstr;
                textBlock_ddns.Text          = wanInfo.ddns;
                grid_waninfo.Visibility      = Visibility.Visible;
                listview_wanInfo.DataContext = wanInfo;
                if (!App.ContactStart)
                {
                    button_pinContact.Visibility = Visibility.Visible;
                }
            }

            //网络速率
            if (netRate != null)
            {
                textBlock_rateWAN_tx.Text = (netRate.internet_tx / 1024 / 1024).ToString();
                textBlock_rateWAN_rx.Text = (netRate.internet_rx / 1024 / 1024).ToString();

                textBlock_rate5G_tx.Text = (netRate.wl5g_tx / 1024 / 1024).ToString();
                textBlock_rate5G_rx.Text = (netRate.wl5g_rx / 1024 / 1024).ToString();

                textBlock_rate2G_tx.Text = (netRate.wl2g_tx / 1024 / 1024).ToString();
                textBlock_rate2G_rx.Text = (netRate.wl2g_rx / 1024 / 1024).ToString();
                netRate = null;
                grid_netrate.Visibility = Visibility.Visible;
            }

            //客户端数量
            if (clients != null)
            {
                textBlock_wlNum.Text  = (clients.WL2G.Count + clients.WL5G.Count).ToString();
                textBlock_lanNum.Text = clients.LAN.Count.ToString();
                if (clientGroup == null)
                {
                    clientGroup = clients.GetGroup();
                    this.itemcollectSource.Source = clientGroup;
                    ZoomOutView.ItemsSource       = itemcollectSource.View.CollectionGroups;
                    ZoomInView.ItemsSource        = itemcollectSource.View;
                }
                else
                {
                    clientGroup[0].AsyncList(clients.LAN);
                    clientGroup[1].AsyncList(clients.WL5G);
                    clientGroup[2].AsyncList(clients.WL2G);
                }
                clients = null;
                grid_state.Visibility = Visibility.Visible;
            }

            //CPU及内存占用情况
            if (cpuMemInfo != null)
            {
                long cpu_all   = cpuMemInfo.cpu_usage.cpu1_total + cpuMemInfo.cpu_usage.cpu2_total;
                long cpu_usage = cpuMemInfo.cpu_usage.cpu1_usage + cpuMemInfo.cpu_usage.cpu2_usage;
                progress_cpu.Maximum = cpu_all;
                progress_cpu.Value   = cpu_usage;
                textBlock_cpu.Text   = (cpu_usage * 100 / cpu_all).ToString("f1");

                progress_mem.Maximum = cpuMemInfo.memory_usage.mem_total;
                progress_mem.Value   = cpuMemInfo.memory_usage.mem_used;
                textBlock_mem.Text   = (progress_mem.Value * 100 / progress_mem.Maximum).ToString("f1");

                radial_cpu1.Maximum = cpuMemInfo.cpu_usage.cpu1_total;
                radial_cpu1.Value   = cpuMemInfo.cpu_usage.cpu1_usage;
                radial_cpu2.Maximum = cpuMemInfo.cpu_usage.cpu2_total;
                radial_cpu2.Value   = cpuMemInfo.cpu_usage.cpu2_usage;

                textBlock_cpu1.Text = (radial_cpu1.Value * 100 / radial_cpu1.Maximum).ToString("f1");
                textBlock_cpu2.Text = (radial_cpu2.Value * 100 / radial_cpu2.Maximum).ToString("f1");
                cpuMemInfo          = null;
                grid_cpu.Visibility = Visibility.Visible;
            }

            //更新客户端速率
            if (devRate != null && clientGroup != null)
            {
                var macs = devRate.Keys.ToArray();
                foreach (var mac in macs)
                {
                    for (int i = 0; i < clientGroup.Count; i++)
                    {
                        for (int j = 0; j < clientGroup[i].Clients.Count; j++)
                        {
                            if (mac == clientGroup[i].Clients[j].mac)
                            {
                                clientGroup[i].Clients[j].UpdateRate(devRate[mac]);
                                break;
                            }
                        }
                    }
                }
                devRate = null;
            }

            if (banList != null && clientGroup != null)
            {
                for (int i = 0; i < clientGroup.Count; i++)
                {
                    for (int j = 0; j < clientGroup[i].Clients.Count; j++)
                    {
                        clientGroup[i].Clients[j].UpdateBanState(banList);
                    }
                }
                banList = null;
            }

            if (wlanInfo != null)
            {
                listview_wlaninfo.DataContext = wlanInfo;
            }
            progress_main.IsIndeterminate = false;
        }