From 3123c29c4dea1775d2ca820f92c9e826ed6157e4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E9=99=88=E5=9B=BD=E4=BC=9F?= <366193849@qq.com>
Date: Fri, 5 Nov 2021 09:46:10 +0800
Subject: [PATCH] =?UTF-8?q?=E9=BB=98=E8=AE=A4udp=E6=97=A5=E5=BF=97?=
=?UTF-8?q?=E7=AB=AF=E5=8F=A3?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
FastGithub.UI/App.xaml | 9 ----
FastGithub.UI/FastGithub.UI.csproj | 9 ++++
FastGithub.UI/{App.xaml.cs => Program.cs} | 57 +++++++----------------
FastGithub/FastGithub.csproj | 2 +-
FastGithub/Program.cs | 27 +++++------
5 files changed, 38 insertions(+), 66 deletions(-)
delete mode 100644 FastGithub.UI/App.xaml
rename FastGithub.UI/{App.xaml.cs => Program.cs} (65%)
diff --git a/FastGithub.UI/App.xaml b/FastGithub.UI/App.xaml
deleted file mode 100644
index c3e27a4..0000000
--- a/FastGithub.UI/App.xaml
+++ /dev/null
@@ -1,9 +0,0 @@
-
-
-
-
-
diff --git a/FastGithub.UI/FastGithub.UI.csproj b/FastGithub.UI/FastGithub.UI.csproj
index 77b647b..19b43b5 100644
--- a/FastGithub.UI/FastGithub.UI.csproj
+++ b/FastGithub.UI/FastGithub.UI.csproj
@@ -11,6 +11,7 @@
app.manifest
MIT
False
+
@@ -18,6 +19,14 @@
+
+
+
+
+
+
+
+
diff --git a/FastGithub.UI/App.xaml.cs b/FastGithub.UI/Program.cs
similarity index 65%
rename from FastGithub.UI/App.xaml.cs
rename to FastGithub.UI/Program.cs
index 527a1bc..fd0276b 100644
--- a/FastGithub.UI/App.xaml.cs
+++ b/FastGithub.UI/Program.cs
@@ -8,18 +8,24 @@ using System.Windows;
namespace FastGithub.UI
{
- ///
- /// App.xaml 的交互逻辑
- ///
- public partial class App : Application
+ class Program
{
- private readonly Mutex globalMutex;
- private readonly bool isFirstInstance;
-
- public App()
+ [STAThread]
+ static void Main(string[] args)
{
- this.globalMutex = new Mutex(true, "Global\\FastGithub.UI", out this.isFirstInstance);
AppDomain.CurrentDomain.AssemblyResolve += OnAssemblyResolve;
+ using var mutex = new Mutex(true, "Global\\FastGithub.UI", out var isFirstInstance);
+ if (isFirstInstance == false)
+ {
+ return;
+ }
+
+ StartFastGithub();
+ SetWebBrowserVersion(9000);
+
+ var app = new Application();
+ app.StartupUri = new Uri("MainWindow.xaml", UriKind.Relative);
+ app.Run();
}
///
@@ -36,33 +42,12 @@ namespace FastGithub.UI
return default;
}
- var stream = GetResourceStream(new Uri($"Resource/{name}.dll", UriKind.Relative)).Stream;
+ var stream = Application.GetResourceStream(new Uri($"Resource/{name}.dll", UriKind.Relative)).Stream;
var buffer = new byte[stream.Length];
stream.Read(buffer, 0, buffer.Length);
return Assembly.Load(buffer);
}
-
- ///
- /// 程序启动
- ///
- ///
- protected override void OnStartup(StartupEventArgs e)
- {
- if (this.isFirstInstance == false)
- {
- this.Shutdown();
- }
- else
- {
- StartFastGithub();
- SetWebBrowserVersion(9000);
- }
-
- base.OnStartup(e);
- }
-
-
///
/// 设置浏览器版本
///
@@ -95,15 +80,5 @@ namespace FastGithub.UI
};
Process.Start(startInfo);
}
-
- ///
- /// 程序退出
- ///
- ///
- protected override void OnExit(ExitEventArgs e)
- {
- this.globalMutex.Dispose();
- base.OnExit(e);
- }
}
}
diff --git a/FastGithub/FastGithub.csproj b/FastGithub/FastGithub.csproj
index 193c4a5..7b6b6d4 100644
--- a/FastGithub/FastGithub.csproj
+++ b/FastGithub/FastGithub.csproj
@@ -18,7 +18,7 @@
-
+
diff --git a/FastGithub/Program.cs b/FastGithub/Program.cs
index eb3c037..4bb4e00 100644
--- a/FastGithub/Program.cs
+++ b/FastGithub/Program.cs
@@ -46,6 +46,18 @@ namespace FastGithub
}
}
})
+ .UseSerilog((hosting, logger) =>
+ {
+ var template = "{Timestamp:O} [{Level:u3}]{NewLine}{SourceContext}{NewLine}{Message:lj}{NewLine}{Exception}{NewLine}";
+ logger
+ .ReadFrom.Configuration(hosting.Configuration)
+ .Enrich.FromLogContext()
+ .WriteTo.Console(outputTemplate: template)
+ .WriteTo.File(Path.Combine("logs", @"log.txt"), rollingInterval: RollingInterval.Day, outputTemplate: template);
+
+ var udpLoggerPort = hosting.Configuration.GetValue(nameof(AppOptions.UdpLoggerPort), 38457);
+ logger.WriteTo.UDPSink(IPAddress.Loopback, udpLoggerPort);
+ })
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup();
@@ -65,21 +77,6 @@ namespace FastGithub
kestrel.ListenHttpProxy();
}
});
- webBuilder.UseSerilog((hosting, logger) =>
- {
- var template = "{Timestamp:O} [{Level:u3}]{NewLine}{SourceContext}{NewLine}{Message:lj}{NewLine}{Exception}{NewLine}";
- logger
- .ReadFrom.Configuration(hosting.Configuration)
- .Enrich.FromLogContext()
- .WriteTo.Console(outputTemplate: template)
- .WriteTo.File(Path.Combine("logs", @"log.txt"), rollingInterval: RollingInterval.Day, outputTemplate: template);
-
- var udpLoggerPort = hosting.Configuration.GetValue(nameof(AppOptions.UdpLoggerPort), 0);
- if (udpLoggerPort > 0)
- {
- logger.WriteTo.UDPSink(IPAddress.Loopback, udpLoggerPort);
- }
- });
});
}
}