/// <summary> /// 执行速度事件 /// </summary> /// <param name="speed">速度</param> /// <param name="speedEvent">速度事件</param> private void DoSpeedEvent(double speed, NetworkMonitorEvent speedEvent) { if (speedEvent != null && speed >= 0) { SpeedUnitType unitType = SpeedUnitType.BPS; switch (GetSpeedUnit(ref speed, 0)) { case 0: unitType = SpeedUnitType.BPS; break; case 1: unitType = SpeedUnitType.KBPS; break; case 2: unitType = SpeedUnitType.MBPS; break; case 3: unitType = SpeedUnitType.GBPS; break; case 4: unitType = SpeedUnitType.TBPS; break; } speedEvent?.Invoke(Math.Round(speed, 2), unitType); } }
/// <summary> /// 更新网络信息 /// </summary> /// <param name="download">下载速度</param> /// <param name="upload">上传速度</param> /// <param name="unitType">单位</param> private void DownloadSpeedEvent(double download, SpeedUnitType unitType) { this.Dispatcher.Invoke(new Action(() => { try { this.download.Content = this.ConvertString(download); this.dunit.Content = unitType.GetStringValue(); this.downloadSpeed.Content = this.download.Content + " " + this.dunit.Content; } catch { } })); }
/// <summary> /// 更新网络信息 /// </summary> /// <param name="download">下载速度</param> /// <param name="upload">上传速度</param> /// <param name="unitType">单位</param> private void UpdateSpeedEvent(double upload, SpeedUnitType unitType) { this.Dispatcher.Invoke(new Action(() => { try { this.update.Content = this.ConvertString(upload); this.uunit.Content = unitType.GetStringValue(); this.updateSpeed.Content = this.update.Content + " " + this.uunit.Content; } catch { } })); }
private SpeedUnitTypeDto ConvertTo(SpeedUnitType speedUnitType) => speedUnitType switch {