From 5f97c381abfeee6d50f33a3c8edd2ed80ca84c43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=9B=BD=E4=BC=9F?= <366193849@qq.com> Date: Thu, 11 Nov 2021 12:39:50 +0800 Subject: [PATCH] =?UTF-8?q?UI=E5=8A=A8=E7=94=BB=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FastGithub.UI/FlowChart.xaml | 4 ++-- FastGithub.UI/FlowChart.xaml.cs | 20 +++++++++++--------- FastGithub.UI/UdpLogListBox.xaml.cs | 19 +++++++++++++------ FastGithub/AppHostedService.cs | 1 + 4 files changed, 27 insertions(+), 17 deletions(-) diff --git a/FastGithub.UI/FlowChart.xaml b/FastGithub.UI/FlowChart.xaml index 15bb9dd..c96a499 100644 --- a/FastGithub.UI/FlowChart.xaml +++ b/FastGithub.UI/FlowChart.xaml @@ -18,12 +18,12 @@ - + - + diff --git a/FastGithub.UI/FlowChart.xaml.cs b/FastGithub.UI/FlowChart.xaml.cs index 6774f84..3c37132 100644 --- a/FastGithub.UI/FlowChart.xaml.cs +++ b/FastGithub.UI/FlowChart.xaml.cs @@ -18,14 +18,16 @@ namespace FastGithub.UI { Title = "上行速率", PointGeometry = null, - Values = new ChartValues() + LineSmoothness = 1D, + Values = new ChartValues() }; private readonly LineSeries writeSeries = new LineSeries() { Title = "下行速率", PointGeometry = null, - Values = new ChartValues() + LineSmoothness = 1D, + Values = new ChartValues() }; private static DateTime GetDateTime(double timestamp) => new DateTime(1970, 1, 1).Add(TimeSpan.FromMilliseconds(timestamp)).ToLocalTime(); @@ -33,7 +35,7 @@ namespace FastGithub.UI private static double GetTimestamp(DateTime dateTime) => dateTime.ToUniversalTime().Subtract(new DateTime(1970, 1, 1)).TotalMilliseconds; - public SeriesCollection Series { get; } = new SeriesCollection(Mappers.Xy().X(item => item.Timestamp).Y(item => item.Rate)); + public SeriesCollection Series { get; } = new SeriesCollection(Mappers.Xy().X(item => item.Timestamp).Y(item => item.Rate)); public Func XFormatter { get; } = timestamp => GetDateTime(timestamp).ToString("HH:mm:ss"); @@ -47,10 +49,10 @@ namespace FastGithub.UI this.Series.Add(this.writeSeries); this.DataContext = this; - this.InitFlowChart(); + this.InitFlowChartAsync(); } - private async void InitFlowChart() + private async void InitFlowChartAsync() { using var httpClient = new HttpClient(); while (this.Dispatcher.HasShutdownStarted == false) @@ -83,8 +85,8 @@ namespace FastGithub.UI this.textBlockWrite.Text = FlowStatistics.ToNetworkSizeString(flowStatistics.TotalWrite); var timestamp = GetTimestamp(DateTime.Now); - this.readSeries.Values.Add(new RateItem(flowStatistics.ReadRate, timestamp)); - this.writeSeries.Values.Add(new RateItem(flowStatistics.WriteRate, timestamp)); + this.readSeries.Values.Add(new RateTick(flowStatistics.ReadRate, timestamp)); + this.writeSeries.Values.Add(new RateTick(flowStatistics.WriteRate, timestamp)); if (this.readSeries.Values.Count > 60) { @@ -93,13 +95,13 @@ namespace FastGithub.UI } } - private class RateItem + private class RateTick { public double Rate { get; } public double Timestamp { get; } - public RateItem(double rate, double timestamp) + public RateTick(double rate, double timestamp) { this.Rate = rate; this.Timestamp = timestamp; diff --git a/FastGithub.UI/UdpLogListBox.xaml.cs b/FastGithub.UI/UdpLogListBox.xaml.cs index 47038d3..7aef0ac 100644 --- a/FastGithub.UI/UdpLogListBox.xaml.cs +++ b/FastGithub.UI/UdpLogListBox.xaml.cs @@ -1,4 +1,5 @@ -using System.Collections.ObjectModel; +using System; +using System.Collections.ObjectModel; using System.Windows.Controls; namespace FastGithub.UI @@ -19,16 +20,22 @@ namespace FastGithub.UI } private async void InitUdpLoggerAsync() - { + { while (this.Dispatcher.HasShutdownStarted == false) { - var log = await UdpLogger.GetUdpLogAsync(); - if (log != null) + try + { + var log = await UdpLogger.GetUdpLogAsync(); + if (log != null) + { + this.LogList.Add(log); + } + } + catch (Exception) { - this.LogList.Add(log); } } - } + } private void MenuItem_Copy_Click(object sender, System.Windows.RoutedEventArgs e) { diff --git a/FastGithub/AppHostedService.cs b/FastGithub/AppHostedService.cs index fe326bc..4cb8f00 100644 --- a/FastGithub/AppHostedService.cs +++ b/FastGithub/AppHostedService.cs @@ -149,6 +149,7 @@ namespace FastGithub } finally { + this.logger.LogInformation($"正在主动关闭,因为父进程已退出"); await this.host.StopAsync(cancellationToken); } }