Files
ThingsGateway/src/ThingsGateway.Photino/Program.cs
Diego 1fd6cc2b5e release:6.0.5.9
refactor: 封装furion swagger文档
refactor:简化代码
refactor:更新依赖包
2024-08-18 04:03:01 +08:00

105 lines
3.4 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//------------------------------------------------------------------------------
// 此代码版权声明为全文件覆盖,如有原作者特别声明,会在下方手动补充
// 此代码版权除特别声明外的代码归作者本人Diego所有
// 源代码使用协议遵循本仓库的开源协议及附加协议
// Gitee源代码仓库https://gitee.com/diego2098/ThingsGateway
// Github源代码仓库https://github.com/kimdiego2098/ThingsGateway
// 使用文档https://kimdiego2098.github.io/
// QQ群605534569
//------------------------------------------------------------------------------
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Photino.Blazor;
using System.Text;
using System.Text.Encodings.Web;
using System.Text.Unicode;
using ThingsGateway.Admin.NetCore;
namespace ThingsGateway.Photino;
internal class Program
{
[STAThread]
private static void Main(string[] args)
{
//当前工作目录设为程序集的基目录
System.IO.Directory.SetCurrentDirectory(AppContext.BaseDirectory);
// 增加中文编码支持
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
#if Pro
MenuConfigs.Default.MenuItems.AddRange(ThingsGateway.Debug.ProRcl.ProMenuConfigs.Default.MenuItems);
#endif
var builder = PhotinoBlazorAppBuilder.CreateDefault(args);
builder.Services.ConfigureServicesWithoutWeb();
// 添加配置服务
builder.Services.AddSingleton<IConfiguration>(NetCoreApp.Configuration);
// 增加中文编码支持网页源码显示汉字
builder.Services.AddSingleton(HtmlEncoder.Create(UnicodeRanges.All));
builder.RootComponents.Add<Routes>("#app");
var app = builder.Build();
app.Services.UseServicesWithoutWeb();
app.MainWindow.ContextMenuEnabled = false;
#if !DEBUG
app.MainWindow.DevToolsEnabled = false;
#endif
app.MainWindow.GrantBrowserPermissions = true;
app.MainWindow.SetUseOsDefaultLocation(false);
app.MainWindow.SetUseOsDefaultSize(false);
app.MainWindow.SetSize(new System.Drawing.Size(1920, 1080));
app.MainWindow.SetTitle("ThingsGateway");
app.MainWindow.SetIconFile("favicon.ico");
AppDomain.CurrentDomain.UnhandledException += (sender, error) =>
{
};
StartHostedService(app.Services);
app.Run();
StopHostedService(app.Services);
}
public static void StartHostedService(IServiceProvider serviceProvider)
{
var applicationLifetime = serviceProvider.GetRequiredService<ApplicationLifetime>();
var hostedServiceExecutor = serviceProvider.GetRequiredService<HostedServiceExecutor>();
// Fire IHostedService.Start
hostedServiceExecutor.StartAsync(default).ConfigureAwait(false).GetAwaiter().GetResult();
applicationLifetime.NotifyStarted();
}
public static void StopHostedService(IServiceProvider serviceProvider)
{
var applicationLifetime = serviceProvider.GetRequiredService<ApplicationLifetime>();
applicationLifetime.StopApplication();
var _hostedServiceExecutor = serviceProvider.GetRequiredService<HostedServiceExecutor>();
_hostedServiceExecutor.StopAsync(default).ConfigureAwait(false).GetAwaiter().GetResult();
applicationLifetime.NotifyStopped();
}
}