类型重命名

This commit is contained in:
陈国伟 2021-11-01 13:36:37 +08:00
parent e478f0855c
commit df017ed29c
9 changed files with 43 additions and 29 deletions

View File

@ -65,10 +65,10 @@ namespace FastGithub.FlowAnalyze
/// <summary> /// <summary>
/// 获取速率 /// 获取流量分析
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
public FlowRate GetFlowRate() public FlowStatistics GetFlowStatistics()
{ {
Flush(this.readQueue); Flush(this.readQueue);
var readRate = (double)this.readQueue.Sum(item => item.Length) / INTERVAL_SECONDS; var readRate = (double)this.readQueue.Sum(item => item.Length) / INTERVAL_SECONDS;
@ -76,7 +76,7 @@ namespace FastGithub.FlowAnalyze
Flush(this.writeQueue); Flush(this.writeQueue);
var writeRate = (double)this.writeQueue.Sum(item => item.Length) / INTERVAL_SECONDS; var writeRate = (double)this.writeQueue.Sum(item => item.Length) / INTERVAL_SECONDS;
return new FlowRate return new FlowStatistics
{ {
TotalRead = this.totalRead, TotalRead = this.totalRead,
TotalWrite = this.totalWrite, TotalWrite = this.totalWrite,

View File

@ -1,6 +1,9 @@
namespace FastGithub.FlowAnalyze namespace FastGithub.FlowAnalyze
{ {
public record FlowRate /// <summary>
/// 流量统计
/// </summary>
public record FlowStatistics
{ {
/// <summary> /// <summary>
/// 获取总读上行 /// 获取总读上行
@ -12,8 +15,14 @@
/// </summary> /// </summary>
public long TotalWrite { get; init; } public long TotalWrite { get; init; }
/// <summary>
/// 获取读取速率
/// </summary>
public double ReadRate { get; init; } public double ReadRate { get; init; }
/// <summary>
/// 获取写入速率
/// </summary>
public double WriteRate { get; init; } public double WriteRate { get; init; }
} }
} }

View File

@ -16,6 +16,6 @@
/// 获取速率 /// 获取速率
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
FlowRate GetFlowRate(); FlowStatistics GetFlowStatistics();
} }
} }

View File

@ -88,7 +88,7 @@
<DependentUpon>App.xaml</DependentUpon> <DependentUpon>App.xaml</DependentUpon>
<SubType>Code</SubType> <SubType>Code</SubType>
</Compile> </Compile>
<Compile Include="FlowRate.cs" /> <Compile Include="FlowStatistics.cs" />
<Compile Include="FlowChart.xaml.cs"> <Compile Include="FlowChart.xaml.cs">
<DependentUpon>FlowChart.xaml</DependentUpon> <DependentUpon>FlowChart.xaml</DependentUpon>
</Compile> </Compile>

View File

@ -31,7 +31,7 @@ namespace FastGithub.UI
public List<string> Labels { get; } = new List<string>(); public List<string> Labels { get; } = new List<string>();
public Func<double, string> YFormatter { get; } = value => $"{FlowRate.ToNetworkSizeString((long)value)}/s"; public Func<double, string> YFormatter { get; } = value => $"{FlowStatistics.ToNetworkSizeString((long)value)}/s";
public FlowChart() public FlowChart()
{ {
@ -51,7 +51,7 @@ namespace FastGithub.UI
{ {
try try
{ {
await this.GetFlowRateAsync(httpClient); await this.GetFlowStatisticsAsync(httpClient);
} }
catch (Exception) catch (Exception)
{ {
@ -63,17 +63,17 @@ namespace FastGithub.UI
} }
} }
private async Task GetFlowRateAsync(HttpClient httpClient) private async Task GetFlowStatisticsAsync(HttpClient httpClient)
{ {
var response = await httpClient.GetAsync("http://127.0.0.1/flowRates"); var response = await httpClient.GetAsync("http://127.0.0.1/flowStatistics");
var json = await response.EnsureSuccessStatusCode().Content.ReadAsStringAsync(); var json = await response.EnsureSuccessStatusCode().Content.ReadAsStringAsync();
var flowRate = Newtonsoft.Json.JsonConvert.DeserializeObject<FlowRate>(json); var flowStatistics = Newtonsoft.Json.JsonConvert.DeserializeObject<FlowStatistics>(json);
this.textBlockRead.Text = FlowRate.ToNetworkSizeString(flowRate.TotalRead); this.textBlockRead.Text = FlowStatistics.ToNetworkSizeString(flowStatistics.TotalRead);
this.textBlockWrite.Text = FlowRate.ToNetworkSizeString(flowRate.TotalWrite); this.textBlockWrite.Text = FlowStatistics.ToNetworkSizeString(flowStatistics.TotalWrite);
this.readSeries.Values.Add(flowRate.ReadRate); this.readSeries.Values.Add(flowStatistics.ReadRate);
this.writeSeries.Values.Add(flowRate.WriteRate); this.writeSeries.Values.Add(flowStatistics.WriteRate);
this.Labels.Add(DateTime.Now.ToString("HH:mm:ss")); this.Labels.Add(DateTime.Now.ToString("HH:mm:ss"));
if (this.Labels.Count > 60) if (this.Labels.Count > 60)

View File

@ -1,6 +1,9 @@
namespace FastGithub.UI namespace FastGithub.UI
{ {
public class FlowRate /// <summary>
/// 流量统计
/// </summary>
public class FlowStatistics
{ {
/// <summary> /// <summary>
/// 获取总读上行 /// 获取总读上行
@ -12,10 +15,16 @@
/// </summary> /// </summary>
public long TotalWrite { get; set; } public long TotalWrite { get; set; }
/// <summary>
/// 获取上行速率
/// </summary>
public double ReadRate { get; set; } public double ReadRate { get; set; }
public double WriteRate { get; set; } /// <summary>
/// 获取下行速率
/// </summary>
public double WriteRate { get; set; }
public static string ToNetworkSizeString(long value) public static string ToNetworkSizeString(long value)
{ {

View File

@ -68,15 +68,15 @@ namespace FastGithub
appBuilder.UseRouting(); appBuilder.UseRouting();
appBuilder.UseEndpoints(endpoint => appBuilder.UseEndpoints(endpoint =>
{ {
endpoint.MapGet("/flowRates", context => endpoint.MapGet("/flowStatistics", context =>
{ {
var loggingFeature = context.Features.Get<IRequestLoggingFeature>(); var loggingFeature = context.Features.Get<IRequestLoggingFeature>();
if (loggingFeature != null) if (loggingFeature != null)
{ {
loggingFeature.Enable = false; loggingFeature.Enable = false;
} }
var flowRate = context.RequestServices.GetRequiredService<IFlowAnalyzer>().GetFlowRate(); var flowStatistics = context.RequestServices.GetRequiredService<IFlowAnalyzer>().GetFlowStatistics();
return context.Response.WriteAsJsonAsync(flowRate); return context.Response.WriteAsJsonAsync(flowStatistics);
}); });
}); });
}); });

View File

@ -376,9 +376,7 @@ code {
<h3 id="2-%E9%83%A8%E7%BD%B2%E6%96%B9%E5%BC%8F">2 部署方式</h3> <h3 id="2-%E9%83%A8%E7%BD%B2%E6%96%B9%E5%BC%8F">2 部署方式</h3>
<h4 id="21-windows-x64">2.1 windows-x64</h4> <h4 id="21-windows-x64">2.1 windows-x64</h4>
<ul> <ul>
<li>双击运行fastgithub.exe程序</li> <li>双击运行FastGithub.UI.exe</li>
<li><code>fastgithub.exe start</code> // 以windows服务安装并启动</li>
<li><code>fastgithub.exe stop</code> // 以windows服务卸载并删除</li>
</ul> </ul>
<h4 id="22-linux-x64">2.2 linux-x64</h4> <h4 id="22-linux-x64">2.2 linux-x64</h4>
<ul> <ul>
@ -388,7 +386,7 @@ code {
</ul> </ul>
<h4 id="23-macos-x64">2.3 macOS-x64</h4> <h4 id="23-macos-x64">2.3 macOS-x64</h4>
<ul> <ul>
<li>双击运行fastgithub程序</li> <li>双击运行fastgithub</li>
<li>安装cacert/fastgithub.cer并设置信任</li> <li>安装cacert/fastgithub.cer并设置信任</li>
<li>设置系统自动代理为<code>http://127.0.0.1:38457</code>或手动代理http/https为<code>127.0.0.1:38457</code></li> <li>设置系统自动代理为<code>http://127.0.0.1:38457</code>或手动代理http/https为<code>127.0.0.1:38457</code></li>
<li><a href="https://github.com/dotnetcore/FastGithub/blob/master/MacOSXConfig.md">具体配置详情</a></li> <li><a href="https://github.com/dotnetcore/FastGithub/blob/master/MacOSXConfig.md">具体配置详情</a></li>

View File

@ -8,9 +8,7 @@ github加速神器解决github打不开、用户头像无法加载、releases
### 2 部署方式 ### 2 部署方式
#### 2.1 windows-x64 #### 2.1 windows-x64
* 双击运行fastgithub.exe程序 * 双击运行FastGithub.UI.exe
* `fastgithub.exe start` // 以windows服务安装并启动
* `fastgithub.exe stop` // 以windows服务卸载并删除
#### 2.2 linux-x64 #### 2.2 linux-x64
* 执行`./fastgithub` * 执行`./fastgithub`
@ -18,7 +16,7 @@ github加速神器解决github打不开、用户头像无法加载、releases
* 设置系统自动代理为`http://127.0.0.1:38457`或手动代理http/https为`127.0.0.1:38457` * 设置系统自动代理为`http://127.0.0.1:38457`或手动代理http/https为`127.0.0.1:38457`
#### 2.3 macOS-x64 #### 2.3 macOS-x64
* 双击运行fastgithub程序 * 双击运行fastgithub
* 安装cacert/fastgithub.cer并设置信任 * 安装cacert/fastgithub.cer并设置信任
* 设置系统自动代理为`http://127.0.0.1:38457`或手动代理http/https为`127.0.0.1:38457` * 设置系统自动代理为`http://127.0.0.1:38457`或手动代理http/https为`127.0.0.1:38457`
* [具体配置详情](https://github.com/dotnetcore/FastGithub/blob/master/MacOSXConfig.md) * [具体配置详情](https://github.com/dotnetcore/FastGithub/blob/master/MacOSXConfig.md)