This commit is contained in:
老九 2021-10-28 22:15:29 +08:00
parent 7c2e717eda
commit 31655bf890
10 changed files with 81 additions and 63 deletions

View File

@ -2,7 +2,8 @@
<PropertyGroup> <PropertyGroup>
<Version>2.0.5</Version> <Version>2.0.5</Version>
<TargetFramework>net6.0</TargetFramework> <TargetFramework>net6.0</TargetFramework>
<IsWebConfigTransformDisabled>true</IsWebConfigTransformDisabled> <DisableImplicitNamespaceImports>true</DisableImplicitNamespaceImports>
<IsWebConfigTransformDisabled>true</IsWebConfigTransformDisabled>
<EnableCompressionInSingleFile>true</EnableCompressionInSingleFile> <EnableCompressionInSingleFile>true</EnableCompressionInSingleFile>
<Description>github加速神器</Description> <Description>github加速神器</Description>
<Copyright>https://github.com/dotnetcore/FastGithub</Copyright> <Copyright>https://github.com/dotnetcore/FastGithub</Copyright>

View File

@ -30,6 +30,17 @@ namespace FastGithub.FlowAnalyze
} }
private static void Add(ConcurrentQueue<QueueItem> quques, int length) private static void Add(ConcurrentQueue<QueueItem> quques, int length)
{
var ticks = Flush(quques);
quques.Enqueue(new QueueItem(ticks, length));
}
/// <summary>
/// 刷新队列
/// </summary>
/// <param name="quques"></param>
/// <returns></returns>
private static long Flush(ConcurrentQueue<QueueItem> quques)
{ {
var ticks = Environment.TickCount64; var ticks = Environment.TickCount64;
while (quques.TryPeek(out var item)) while (quques.TryPeek(out var item))
@ -43,17 +54,23 @@ namespace FastGithub.FlowAnalyze
quques.TryDequeue(out _); quques.TryDequeue(out _);
} }
} }
quques.Enqueue(new QueueItem(ticks, length)); return ticks;
} }
/// <summary> /// <summary>
/// 获取速率 /// 获取速率
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
public FlowRate GetFlowRate() public FlowRate GetFlowRate()
{ {
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;
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 { ReadRate = readRate, WriteRate = writeRate }; return new FlowRate { ReadRate = readRate, WriteRate = writeRate };
} }
} }

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup> </PropertyGroup>

View File

@ -93,7 +93,10 @@ namespace FastGithub
var httpsPort = ReverseProxyPort.Https; var httpsPort = ReverseProxyPort.Https;
kestrel.Listen(IPAddress.Loopback, httpsPort, listen => kestrel.Listen(IPAddress.Loopback, httpsPort, listen =>
{ {
listen.UseFlowAnalyze(); if (OperatingSystem.IsWindows())
{
listen.UseFlowAnalyze();
}
listen.UseHttps(https => listen.UseHttps(https =>
{ {
https.ServerCertificateSelector = (ctx, domain) => certService.GetOrCreateServerCert(domain); https.ServerCertificateSelector = (ctx, domain) => certService.GetOrCreateServerCert(domain);

View File

@ -1,4 +1,6 @@
using System.Windows; using Microsoft.Win32;
using System.Diagnostics;
using System.Windows;
namespace FastGithub.UI namespace FastGithub.UI
{ {
@ -7,5 +9,12 @@ namespace FastGithub.UI
/// </summary> /// </summary>
public partial class App : Application public partial class App : Application
{ {
protected override void OnStartup(StartupEventArgs e)
{
var emulation = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION", true);
var key = $"{Process.GetCurrentProcess().ProcessName}.exe";
emulation.SetValue(key, 9000, RegistryValueKind.DWord);
base.OnStartup(e);
}
} }
} }

View File

@ -8,12 +8,13 @@
<OutputType>WinExe</OutputType> <OutputType>WinExe</OutputType>
<RootNamespace>FastGithub.UI</RootNamespace> <RootNamespace>FastGithub.UI</RootNamespace>
<AssemblyName>FastGithub.UI</AssemblyName> <AssemblyName>FastGithub.UI</AssemblyName>
<TargetFrameworkVersion>v4.5.1</TargetFrameworkVersion> <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment> <FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> <ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic> <Deterministic>true</Deterministic>
<TargetFrameworkProfile />
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget> <PlatformTarget>AnyCPU</PlatformTarget>

View File

@ -5,7 +5,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:FastGithub.UI" xmlns:local="clr-namespace:FastGithub.UI"
mc:Ignorable="d" mc:Ignorable="d"
Title="FastGithub" Height="640" Width="960" WindowStartupLocation="CenterScreen"> Title="FastGithub" Height="480" Width="640" WindowStartupLocation="CenterScreen">
<Window.Resources> <Window.Resources>
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
@ -93,6 +93,7 @@
<Condition Binding="{Binding TabStripPlacement, RelativeSource={RelativeSource FindAncestor, AncestorLevel=1, AncestorType={x:Type TabControl}}}" Value="Top"/> <Condition Binding="{Binding TabStripPlacement, RelativeSource={RelativeSource FindAncestor, AncestorLevel=1, AncestorType={x:Type TabControl}}}" Value="Top"/>
</MultiDataTrigger.Conditions> </MultiDataTrigger.Conditions>
<Setter Property="FocusVisualStyle" Value="{x:Null}" />
<Setter Property="Foreground" TargetName="txt" Value="#37aefe"/> <Setter Property="Foreground" TargetName="txt" Value="#37aefe"/>
</MultiDataTrigger> </MultiDataTrigger>
<MultiDataTrigger> <MultiDataTrigger>
@ -129,6 +130,7 @@
<Condition Binding="{Binding IsSelected, RelativeSource={RelativeSource Self}}" Value="true"/> <Condition Binding="{Binding IsSelected, RelativeSource={RelativeSource Self}}" Value="true"/>
<Condition Binding="{Binding TabStripPlacement, RelativeSource={RelativeSource FindAncestor, AncestorLevel=1, AncestorType={x:Type TabControl}}}" Value="Top"/> <Condition Binding="{Binding TabStripPlacement, RelativeSource={RelativeSource FindAncestor, AncestorLevel=1, AncestorType={x:Type TabControl}}}" Value="Top"/>
</MultiDataTrigger.Conditions> </MultiDataTrigger.Conditions>
<Setter Property="FocusVisualStyle" Value="{x:Null}" />
<Setter Property="Panel.ZIndex" Value="1"/> <Setter Property="Panel.ZIndex" Value="1"/>
<Setter Property="Foreground" TargetName="txt" Value="#37aefe"/> <Setter Property="Foreground" TargetName="txt" Value="#37aefe"/>
<Setter Property="BorderThickness" TargetName="_underline" Value="0 0 0 2"/> <Setter Property="BorderThickness" TargetName="_underline" Value="0 0 0 2"/>

View File

@ -1,49 +1,44 @@
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// <auto-generated> // <auto-generated>
// 此代码由工具生成。 // 此代码由工具生成。
// 运行时版本: 4.0.30319.42000 // 运行时版本:4.0.30319.42000
// //
// 对此文件的更改可能导致不正确的行为,如果 // 对此文件的更改可能导致不正确的行为,并且如果
// 重新生成代码,则所做更改将丢失。 // 重新生成代码,这些更改将会丢失。
// </auto-generated> // </auto-generated>
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
namespace FastGithub.UI.Properties namespace FastGithub.UI.Properties {
{ using System;
/// <summary> /// <summary>
/// 强类型资源类,用于查找本地化字符串等。 /// 一个强类型资源类,用于查找本地化字符串等。
/// </summary> /// </summary>
// 此类是由 StronglyTypedResourceBuilder // 此类是由 StronglyTypedResourceBuilder
// 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。 // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。
// 若要添加或除成员,请编辑 .ResX 文件,然后重新运行 ResGen // 若要添加或除成员,请编辑 .ResX 文件,然后重新运行 ResGen
// (以 /str 作为命令选项),或重新生成 VS 项目。 // (以 /str 作为命令选项),或重新生成 VS 项目。
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources internal class Resources {
{
private static global::System.Resources.ResourceManager resourceMan; private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture; private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Resources() internal Resources() {
{
} }
/// <summary> /// <summary>
/// 返回此类使用的缓存 ResourceManager 实例。 /// 返回此类使用的缓存 ResourceManager 实例。
/// </summary> /// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager internal static global::System.Resources.ResourceManager ResourceManager {
{ get {
get if (object.ReferenceEquals(resourceMan, null)) {
{
if ((resourceMan == null))
{
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("FastGithub.UI.Properties.Resources", typeof(Resources).Assembly); global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("FastGithub.UI.Properties.Resources", typeof(Resources).Assembly);
resourceMan = temp; resourceMan = temp;
} }
@ -56,14 +51,11 @@ namespace FastGithub.UI.Properties
/// 使用此强类型资源类的所有资源查找执行重写。 /// 使用此强类型资源类的所有资源查找执行重写。
/// </summary> /// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture internal static global::System.Globalization.CultureInfo Culture {
{ get {
get
{
return resourceCulture; return resourceCulture;
} }
set set {
{
resourceCulture = value; resourceCulture = value;
} }
} }

View File

@ -1,28 +1,24 @@
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// <auto-generated> // <auto-generated>
// This code was generated by a tool. // 此代码由工具生成。
// Runtime Version:4.0.30319.42000 // 运行时版本:4.0.30319.42000
// //
// Changes to this file may cause incorrect behavior and will be lost if // 对此文件的更改可能会导致不正确的行为,并且如果
// the code is regenerated. // 重新生成代码,这些更改将会丢失。
// </auto-generated> // </auto-generated>
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
namespace FastGithub.UI.Properties namespace FastGithub.UI.Properties {
{
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.10.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
{
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
public static Settings Default public static Settings Default {
{ get {
get
{
return defaultInstance; return defaultInstance;
} }
} }

View File

@ -45,10 +45,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Content Update="wwwroot\flow.html"> <Content Update="wwwroot\**">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Update="wwwroot\cert.html">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content> </Content>
</ItemGroup> </ItemGroup>