Esempio n. 1
0
        private void InitDeviceMap()
        {
            List <DeviceInfo> devices = TPLinkApi.GetDeviceStatus();

            foreach (DeviceInfo device in devices)
            {
                DeviceInfoEx devEx = new DeviceInfoEx();
                devEx.Update(device, true);
                DeviceMap[device.mac]            = devEx;
                devEx.DeviceOnlineStatusChanged += DevEx_DeviceOnlineStatusChanged;
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 心跳函数,依赖外部触发
        /// 触发后自动更新设备信息,并且计算网速
        /// </summary>
        public void DoHeartBeat()
        {
            foreach (DeviceInfoEx devEx in DeviceMap.Values)
            {
                devEx.Tag = 0;
            }

            //更新每个设备的在线状态
            List <DeviceInfo> devices = TPLinkApi.GetDeviceStatus();

            foreach (DeviceInfo device in devices)
            {
                if (DeviceMap.TryGetValue(device.mac, out DeviceInfoEx devEx))
                {
                    devEx.Update(device, true);
                }
                else
                {
                    devEx = new DeviceInfoEx();
                    devEx.Update(device, true);
                    DeviceMap[device.mac]            = devEx;
                    devEx.DeviceOnlineStatusChanged += DevEx_DeviceOnlineStatusChanged;
                }
                devEx.Tag = 1;
            }

            foreach (DeviceInfoEx devEx in DeviceMap.Values)
            {
                if (devEx.Tag == 0)
                {
                    devEx.Update(null, false);
                }
            }

            var speed = TPLinkApi.GetDeviceNetSpeed();

            UploadSpeed   = speed.network.wan_status.up_speed;
            DownloadSpeed = speed.network.wan_status.down_speed;
        }