优化主窗口VM加载

This commit is contained in:
Aigio Liu
2021-04-30 18:28:34 +08:00
parent 7d73d53759
commit d01dbd249d
8 changed files with 241 additions and 150 deletions
+33 -15
View File
@@ -123,29 +123,29 @@ namespace System.Application.UI
public override void Initialize()
{
#if DEBUG
StartTrace.Restart("App.Initialize");
#if StartupTrace
StartupTrace.Restart("App.Initialize");
#endif
AvaloniaXamlLoader.Load(this);
#if DEBUG
StartTrace.Restart("App.LoadXAML");
#if StartupTrace
StartupTrace.Restart("App.LoadXAML");
#endif
Name = ThisAssembly.AssemblyTrademark;
ViewModelBase.IsInDesignMode = ApplicationLifetime == null;
if (ViewModelBase.IsInDesignMode) Startup.Init(DILevel.MainProcess);
#if DEBUG
StartTrace.Restart("App.SetP");
#if StartupTrace
StartupTrace.Restart("App.SetP");
#endif
var windowService = IWindowService.Instance;
windowService.Init();
#if DEBUG
StartTrace.Restart("WindowService.Init");
#if StartupTrace
StartupTrace.Restart("WindowService.Init");
#endif
SettingsHost.Load();
#if DEBUG
StartTrace.Restart("SettingsHost.Init");
#if StartupTrace
StartupTrace.Restart("SettingsHost.Init");
#endif
#if !UI_DEMO
@@ -157,10 +157,13 @@ namespace System.Application.UI
}
#endif
Theme = (AppTheme)UISettings.Theme.Value;
#if StartupTrace
StartupTrace.Restart("Theme");
#endif
UISettings.Theme.Subscribe(x => Theme = (AppTheme)x);
UISettings.Language.Subscribe(x => R.ChangeLanguage(x));
#if DEBUG
StartTrace.Restart("Theme + UISettings.Subscribe");
#if StartupTrace
StartupTrace.Restart("UISettings.Subscribe");
#endif
switch (windowService.MainWindow)
{
@@ -185,8 +188,8 @@ namespace System.Application.UI
};
break;
}
#if DEBUG
StartTrace.Restart("Set MainWindow");
#if StartupTrace
StartupTrace.Restart("Set MainWindow");
#endif
}
@@ -294,14 +297,26 @@ namespace System.Application.UI
void Desktop_Startup(object? sender, ControlledApplicationLifetimeStartupEventArgs e)
{
#if StartupTrace
StartupTrace.Restart("Desktop_Startup.Start");
#endif
#if WINDOWS
VisualStudioAppCenterSDK.Init();
#endif
#if StartupTrace
StartupTrace.Restart("AppCenterSDK.Init");
#endif
AppHelper.Initialized?.Invoke();
#if StartupTrace
StartupTrace.Restart("Desktop_Startup.AppHelper.Initialized?");
#endif
if (Program.IsMainProcess)
{
Startup.ActiveUserPost(ActiveUserType.OnStartup);
IAppUpdateService.Instance.CheckUpdate(showIsExistUpdateFalse: false);
#if StartupTrace
StartupTrace.Restart("Desktop_Startup.MainProcess");
#endif
}
var startupToastIntercept = DI.Get_Nullable<StartupToastIntercept>();
@@ -309,6 +324,9 @@ namespace System.Application.UI
{
startupToastIntercept.IsStartuped = true;
}
#if StartupTrace
StartupTrace.Restart("Desktop_Startup.SetIsStartuped");
#endif
}
void ApplicationLifetime_Exit(object? sender, ControlledApplicationLifetimeExitEventArgs e)
@@ -436,4 +454,4 @@ namespace System.Application.UI
#endregion
}
}
}
+37 -37
View File
@@ -1,5 +1,7 @@
using NLog;
using NLog.Common;
using NLog.Config;
using NLog.Targets;
using ReactiveUI;
using System.Application.Services;
using System.Collections.Generic;
@@ -7,6 +9,7 @@ using System.IO;
using System.Linq;
using System.Reactive;
using LogLevel = Microsoft.Extensions.Logging.LogLevel;
using NLogLevel = NLog.LogLevel;
namespace System.Application.UI
{
@@ -22,8 +25,8 @@ namespace System.Application.UI
[STAThread]
static int Main(string[] args)
{
#if DEBUG
StartTrace.Restart();
#if StartupTrace
StartupTrace.Restart();
#endif
// 目前桌面端默认使用 SystemTextJson 如果出现兼容性问题可取消下面这行代码
// Serializable.DefaultJsonImplType = Serializable.JsonImplType.NewtonsoftJson;
@@ -31,6 +34,9 @@ namespace System.Application.UI
IsCLTProcess = !IsMainProcess && args.FirstOrDefault() == "-clt";
var logDirPath = InitLogDir();
#if StartupTrace
StartupTrace.Restart("InitLogDir");
#endif
void InitCefNetApp() => CefNetApp.Init(logDirPath, args);
void InitAvaloniaApp() => BuildAvaloniaAppAndStartWithClassicDesktopLifetime(args);
@@ -57,33 +63,33 @@ namespace System.Application.UI
}
else
{
#if DEBUG
StartTrace.Restart("ProcessCheck");
#if StartupTrace
StartupTrace.Restart("ProcessCheck");
#endif
Startup.Init(IsMainProcess ? DILevel.MainProcess : DILevel.Min);
#if DEBUG
StartTrace.Restart("Startup.Init");
#if StartupTrace
StartupTrace.Restart("Startup.Init");
#endif
if (IsMainProcess)
{
var appInstance = new ApplicationInstance();
if (!appInstance.IsFirst) goto exit;
}
#if DEBUG
StartTrace.Restart("ApplicationInstance");
#if StartupTrace
StartupTrace.Restart("ApplicationInstance");
#endif
InitCefNetApp();
#if DEBUG
StartTrace.Restart("InitCefNetApp");
#if StartupTrace
StartupTrace.Restart("InitCefNetApp");
#endif
if (IsMainProcess)
{
InitAvaloniaApp();
}
#if DEBUG
StartTrace.Restart("InitAvaloniaApp");
#if StartupTrace
StartupTrace.Restart("InitAvaloniaApp");
#endif
}
}
@@ -163,33 +169,27 @@ namespace System.Application.UI
{
var logDirPath = Path.Combine(AppContext.BaseDirectory, "Logs");
IOPath.DirCreateByNotExists(logDirPath);
#if StartupTrace
StartupTrace.Restart("InitLogDir.IO");
#endif
var logDirPath_ = logDirPath + Path.DirectorySeparatorChar;
var xmlConfigStr =
"<?xml version=\"1.0\" encoding=\"utf-8\" ?>" +
"<nlog xmlns=\"http://www.nlog-project.org/schemas/NLog.xsd\"" +
" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" +
" autoReload=\"true\"" +
" internalLogFile=\"" + logDirPath_ + "internal-nlog.txt\"" +
" internalLogLevel=\"Off\">" +
" <targets>" +
" <target xsi:type=\"File\" name=\"logfile\" fileName=\"" + logDirPath_ + "nlog-all-${shortdate}.log\"" +
" layout=\"${longdate}|${level}|${logger}|${message} |${all-event-properties} ${exception:format=tostring}\" />" +
" <target xsi:type=\"Console\" name=\"logconsole\"" +
" layout=\"${longdate}|${level}|${logger}|${message} |${all-event-properties} ${exception:format=tostring}\" />" +
" </targets>" +
" <rules>" +
// Skip non-critical Microsoft logs and so log only own logs
" <logger name=\"Microsoft.*\" maxlevel=\"Info\" final=\"true\"/>" +
" <logger name=\"System.Net.Http.*\" maxlevel=\"Info\" final=\"true\" />" +
" <logger name=\"*\" minlevel=\"" + AppHelper.DefaultNLoggerMinLevel.Name + "\" writeTo=\"logfile,logconsole\"/>" +
" </rules>" +
"</nlog>"
;
var xmlConfig = XmlLoggingConfiguration.CreateFromXmlString(xmlConfigStr);
LogManager.Configuration = xmlConfig;
InternalLogger.LogFile = logDirPath_ + "internal-nlog.txt";
InternalLogger.LogLevel = NLogLevel.Error;
var objConfig = new LoggingConfiguration();
var logfile = new FileTarget("logfile")
{
FileName = logDirPath_ + "nlog-all-${shortdate}.log",
Layout = "${longdate}|${level}|${logger}|${message} |${all-event-properties} ${exception:format=tostring}",
};
objConfig.AddTarget(logfile);
objConfig.AddRule(NLogLevel.Error, NLogLevel.Fatal, logfile, "Microsoft.*");
objConfig.AddRule(NLogLevel.Error, NLogLevel.Fatal, logfile, "System.Net.Http.*");
objConfig.AddRule(AppHelper.DefaultNLoggerMinLevel, NLogLevel.Fatal, logfile, "*");
#if StartupTrace
StartupTrace.Restart("InitLogDir.CreateLoggingConfiguration");
#endif
LogManager.Configuration = objConfig;
return logDirPath;
}
@@ -1,7 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<OutputType>WinExe</OutputType>
<!--<DefineConstants>StartupTrace;$(DefineConstants)</DefineConstants>-->
<TargetFramework>net5.0</TargetFramework>
<SignAssembly>false</SignAssembly>
<!--(SignAssembly)对此程序集进行签名会导致编译失败(CompileAvaloniaXamlTask)-->
@@ -10,6 +11,10 @@
<ApplicationManifest>Properties\app.manifest</ApplicationManifest>
</PropertyGroup>
<PropertyGroup Condition=" $(DefineConstants.Contains(`StartupTrace`)) ">
<OutputType>Exe</OutputType>
</PropertyGroup>
<!--<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<AllowedReferenceRelatedFileExtensions>
-->
@@ -1,31 +0,0 @@
#if DEBUG
using System.Diagnostics;
using System.Linq;
namespace System.Application.UI
{
/// <summary>
/// 启动耗时跟踪
/// </summary>
static class StartTrace
{
static Stopwatch? sw;
public static void Restart(string? mark = null)
{
if (sw != null)
{
sw.Stop();
var msg = $"{string.Join(" ", Environment.GetCommandLineArgs().Skip(1).Take(1))}mark: {mark}, value: {sw.ElapsedMilliseconds}";
Debug.WriteLine(msg);
Console.WriteLine(msg);
sw.Restart();
}
else
{
sw = Stopwatch.StartNew();
}
}
}
}
#endif
@@ -1,7 +1,6 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Markup.Xaml;
using Avalonia.Platform;
using System.ComponentModel;
namespace System.Application.UI.Views
@@ -13,7 +12,9 @@ namespace System.Application.UI.Views
InitializeComponent();
#if DEBUG
this.AttachDevTools();
StartTrace.Restart("MainWindow.ctor");
#endif
#if StartupTrace
StartupTrace.Restart("MainWindow.ctor");
#endif
}
@@ -37,18 +37,19 @@ namespace System.Application.UI.ViewModels
#endregion
public StartPageViewModel StartPage { get; }
public CommunityProxyPageViewModel CommunityProxyPage { get; }
public ProxyScriptManagePageViewModel ProxyScriptPage { get; }
public SteamAccountPageViewModel SteamAccountPage { get; }
public GameListPageViewModel GameListPage { get; }
public LocalAuthPageViewModel LocalAuthPage { get; }
public SteamIdlePageViewModel SteamIdlePage { get; }
public ArchiSteamFarmPlusPageViewModel ASFPage { get; }
public GameRelatedPageViewModel GameRelatedPage { get; }
public OtherPlatformPageViewModel OtherPlatformPage { get; }
public StartPageViewModel StartPage => GetTabItemVM<StartPageViewModel>();
public CommunityProxyPageViewModel CommunityProxyPage => GetTabItemVM<CommunityProxyPageViewModel>();
public ProxyScriptManagePageViewModel ProxyScriptPage => GetTabItemVM<ProxyScriptManagePageViewModel>();
public SteamAccountPageViewModel SteamAccountPage => GetTabItemVM<SteamAccountPageViewModel>();
public GameListPageViewModel GameListPage => GetTabItemVM<GameListPageViewModel>();
public LocalAuthPageViewModel LocalAuthPage => GetTabItemVM<LocalAuthPageViewModel>();
public SteamIdlePageViewModel SteamIdlePage => GetTabItemVM<SteamIdlePageViewModel>();
public ArchiSteamFarmPlusPageViewModel ASFPage => GetTabItemVM<ArchiSteamFarmPlusPageViewModel>();
public GameRelatedPageViewModel GameRelatedPage => GetTabItemVM<GameRelatedPageViewModel>();
public OtherPlatformPageViewModel OtherPlatformPage => GetTabItemVM<OtherPlatformPageViewModel>();
public IReadOnlyList<TabItemViewModel> TabItems { get; set; }
readonly Dictionary<Type, Lazy<TabItemViewModel>> mTabItems = new();
public IEnumerable<TabItemViewModel> TabItems => mTabItems.Values.Select(x => x.Value);
public MainWindowViewModel() : base()
{
@@ -68,33 +69,26 @@ namespace System.Application.UI.ViewModels
}
});
var tabItems = new List<TabItemViewModel>
{
//(StartPage = new StartPageViewModel().AddTo(this)),
(CommunityProxyPage = new CommunityProxyPageViewModel().AddTo(this)),
(ProxyScriptPage = new ProxyScriptManagePageViewModel().AddTo(this)),
(SteamAccountPage = new SteamAccountPageViewModel().AddTo(this)),
(GameListPage = new GameListPageViewModel().AddTo(this)),
(LocalAuthPage = new LocalAuthPageViewModel().AddTo(this)),
//(SteamIdlePage = new SteamIdlePageViewModel().AddTo(this)),
//(ASFPage = new ArchiSteamFarmPlusPageViewModel().AddTo(this)),
//(GameRelatedPage = new GameRelatedPageViewModel().AddTo(this)),
//(OtherPlatformPage = new OtherPlatformPageViewModel().AddTo(this)),
//AddTabItem<StartPageViewModel>();
AddTabItem<CommunityProxyPageViewModel>();
AddTabItem<ProxyScriptManagePageViewModel>();
AddTabItem<SteamAccountPageViewModel>();
AddTabItem<GameListPageViewModel>();
AddTabItem<LocalAuthPageViewModel>();
//AddTabItem<SteamIdlePageViewModel>();
//AddTabItem<ArchiSteamFarmPlusPageViewModel>();
//AddTabItem<GameRelatedPageViewModel>();
//AddTabItem<OtherPlatformPageViewModel>();
#region SystemTab
SettingsPageViewModel.Instance,
AboutPageViewModel.Instance,
#endregion
};
AddTabItem(() => SettingsPageViewModel.Instance);
AddTabItem(() => AboutPageViewModel.Instance);
if (AppHelper.EnableDevtools)
{
tabItems.Add(new DebugPageViewModel().AddTo(this));
tabItems.Add(new DebugWebViewPageViewModel().AddTo(this));
AddTabItem<DebugPageViewModel>();
AddTabItem<DebugWebViewPageViewModel>();
}
TabItems = tabItems;
_SelectedItem = TabItems.First();
Task.Run(Initialize).ForgetAndDispose();
@@ -123,5 +117,19 @@ namespace System.Application.UI.ViewModels
IsInitialized = true;
}
}
void AddTabItem<TabItemVM>() where TabItemVM : TabItemViewModel, new()
{
Lazy<TabItemViewModel> value = new(() => new TabItemVM().AddTo(this));
mTabItems.Add(typeof(TabItemVM), value);
}
void AddTabItem<TabItemVM>(Func<TabItemVM> func) where TabItemVM : TabItemViewModel
{
Lazy<TabItemViewModel> value = new(func);
mTabItems.Add(typeof(TabItemVM), value);
}
TabItemVM GetTabItemVM<TabItemVM>() where TabItemVM : TabItemViewModel => (TabItemVM)mTabItems[typeof(TabItemVM)].Value;
}
}
@@ -246,11 +246,11 @@ namespace System.Application.Services.Implementation
if (newVersionInfo.HasValue())
{
if (newVersionInfo.IncrementalUpdate.Any_Nullable()) // 增量更新
if (newVersionInfo!.IncrementalUpdate.Any_Nullable()) // 增量更新
{
if (Path.DirectorySeparatorChar != '\\')
{
foreach (var item in newVersionInfo.IncrementalUpdate)
foreach (var item in newVersionInfo.IncrementalUpdate!)
{
item.FileRelativePath =
item.FileRelativePath?.Replace('\\', Path.DirectorySeparatorChar);
@@ -264,7 +264,7 @@ namespace System.Application.Services.Implementation
if (Directory.Exists(packDirPath))
{
foreach (var item in newVersionInfo.IncrementalUpdate)
foreach (var item in newVersionInfo.IncrementalUpdate!)
{
var filePath = incrementalUpdate[item];
var fileInfo = new FileInfo(filePath);
@@ -292,7 +292,7 @@ namespace System.Application.Services.Implementation
{
var fileName = item.Value;
var cacheFileName = fileName + FileExDownloadCache;
var requestUri = GetSingleFileUrl(item.Key.FileId);
var requestUri = GetSingleFileUrl(item.Key.FileId!);
var rsp = await client.Download(
isAnonymous: true,
@@ -303,7 +303,7 @@ namespace System.Application.Services.Implementation
{
File.Move(cacheFileName, fileName);
if (!UpdatePackVerification(fileName, item.Key.SHA256, i, incrementalUpdate.Count))
if (!UpdatePackVerification(fileName, item.Key.SHA256!, i, incrementalUpdate.Count))
{
Fail(SR.UpdatePackVerificationFail);
break;
@@ -336,7 +336,7 @@ namespace System.Application.Services.Implementation
var packFilePath = Path.Combine(GetPackCacheDirPath(!isSupportedResume), packFileName);
if (File.Exists(packFilePath)) // 存在压缩包文件
{
if (UpdatePackVerification(packFilePath, download.SHA256)) // (已有文件)哈希验证成功,进行覆盖安装
if (UpdatePackVerification(packFilePath, download.SHA256!)) // (已有文件)哈希验证成功,进行覆盖安装
{
OverwriteUpgrade(packFilePath, isIncrement: false);
goto end;
@@ -412,7 +412,7 @@ namespace System.Application.Services.Implementation
{
File.Move(cacheFilePath, packFilePath);
if (UpdatePackVerification(packFilePath, download.SHA256)) // (下载文件)哈希验证成功,进行覆盖安装
if (UpdatePackVerification(packFilePath, download.SHA256!)) // (下载文件)哈希验证成功,进行覆盖安装
{
OverwriteUpgrade(packFileName, isIncrement: false);
OnReportDownloading(MaxProgressValue);
+115 -25
View File
@@ -18,12 +18,10 @@ using System.Application.Services.Implementation;
using System.Application.UI;
using System.Collections.Generic;
using System.Reflection;
using System.Net;
using System.Application.Services.CloudService.Clients.Abstractions;
using System.Linq;
using CSConst = System.Application.Services.CloudService.Constants;
using System.Properties;
using System.Diagnostics;
using System.IO;
using static System.Application.AppClientAttribute;
#if __ANDROID__
@@ -31,10 +29,13 @@ using Program = System.Application.UI.MainApplication;
#elif __IOS__
using Program = System.Application.UI.AppDelegate;
#endif
#if StartupTrace
using System.Diagnostics;
#endif
namespace System.Application
{
internal static class Startup
static class Startup
{
static bool isInitialized;
@@ -48,12 +49,21 @@ namespace System.Application
isInitialized = true;
#if !__MOBILE__
FileSystemDesktop.InitFileSystem();
#if StartupTrace
StartupTrace.Restart("Startup.InitFileSystem");
#endif
#endif
if (level.HasFlag(DILevel.ServerApiClient))
{
ModelValidatorProvider.Init();
#if StartupTrace
StartupTrace.Restart("ModelValidatorProvider.Init");
#endif
}
InitDI(level);
#if StartupTrace
StartupTrace.Restart($"InitDI: {level}");
#endif
static void InitDI(DILevel level)
{
#if UI_DEMO
@@ -63,7 +73,13 @@ namespace System.Application
static void ConfigureServices(IServiceCollection services, DILevel level)
{
ConfigureRequiredServices(services);
#if StartupTrace
StartupTrace.Restart("DI.ConfigureRequiredServices");
#endif
ConfigureDemandServices(services, level);
#if StartupTrace
StartupTrace.Restart("DI.ConfigureDemandServices");
#endif
}
#endif
}
@@ -112,6 +128,10 @@ namespace System.Application
var hasHosts = level.HasFlag(DILevel.Hosts);
var hasSteam = level.HasFlag(DILevel.Steam);
#if StartupTrace
StartupTrace.Restart("DI.ConfigureDemandServices.Calc");
#endif
if (hasGUI)
{
// 添加 Toast 提示服务
@@ -159,6 +179,9 @@ namespace System.Application
#endif
#endregion
#endif
#if StartupTrace
StartupTrace.Restart("DI.ConfigureDemandServices.GUI");
#endif
}
@@ -170,6 +193,9 @@ namespace System.Application
#else
// 添加 Http 平台助手桌面端实现
services.AddDesktopHttpPlatformHelper();
#endif
#if StartupTrace
StartupTrace.Restart("DI.ConfigureDemandServices.HttpPlatformHelper");
#endif
}
@@ -181,21 +207,33 @@ namespace System.Application
#endif
// 通用 Http 服务
services.AddHttpService();
#if StartupTrace
StartupTrace.Restart("DI.ConfigureDemandServices.HttpClientFactory");
#endif
}
#if !__MOBILE__
services.TryAddScriptManager();
#endif
#if StartupTrace
StartupTrace.Restart("DI.ConfigureDemandServices.ScriptManager");
#endif
if (hasHttpProxy)
{
// 通用 Http 代理服务
services.AddHttpProxyService();
#if StartupTrace
StartupTrace.Restart("DI.ConfigureDemandServices.HttpProxy");
#endif
}
if (hasServerApiClient)
{
// 添加 app 配置项
services.TryAddOptions(AppSettings);
#if StartupTrace
StartupTrace.Restart("DI.ConfigureDemandServices.AppSettings");
#endif
#if !__MOBILE__
// 添加安全服务
services.AddSecurityService<EmbeddedAesDataProtectionProvider, LocalDataProtectionProvider>();
@@ -216,10 +254,16 @@ namespace System.Application
// 业务平台用户管理
services.TryAddUserManager();
#if StartupTrace
StartupTrace.Restart("DI.ConfigureDemandServices.ServerApiClient");
#endif
}
// 添加通知服务
AddNotificationService();
#if StartupTrace
StartupTrace.Restart("DI.ConfigureDemandServices.AddNotificationService");
#endif
void AddNotificationService()
{
#if !__MOBILE__
@@ -229,16 +273,19 @@ namespace System.Application
}
#if !__MOBILE__
if (hasGUI || hasServerApiClient)
{
// 业务用户配置文件服务()
//services.AddConfigFileService();
}
//if (hasGUI || hasServerApiClient)
//{
// // 业务用户配置文件服务()
// //services.AddConfigFileService();
//}
if (hasHosts)
{
// hosts 文件助手服务
services.AddHostsFileService();
#if StartupTrace
StartupTrace.Restart("DI.ConfigureDemandServices.HostsFileService");
#endif
}
if (hasSteam)
@@ -254,12 +301,18 @@ namespace System.Application
// Steamworks WebApi Service
services.AddSteamworksWebApiService();
#if StartupTrace
StartupTrace.Restart("DI.ConfigureDemandServices.Steam");
#endif
}
if (hasMainProcessRequired)
{
// 应用程序更新服务
services.AddAppUpdateService();
#if StartupTrace
StartupTrace.Restart("DI.ConfigureDemandServices.AppUpdateService");
#endif
}
if (HasNotifyIcon)
{
@@ -269,6 +322,9 @@ namespace System.Application
#endif
#if !UI_DEMO
services.AddNotifyIcon<NotifyIconImpl>();
#endif
#if StartupTrace
StartupTrace.Restart("DI.ConfigureDemandServices.NotifyIcon");
#endif
}
#endif
@@ -287,6 +343,9 @@ namespace System.Application
{
get
{
#if StartupTrace
var stopwatch = Stopwatch.StartNew();
#endif
var options = new AppSettings
{
AppVersion = GetResValueGuid("app-id", isSingle: false, ResValueFormat.StringGuidN),
@@ -294,6 +353,10 @@ namespace System.Application
RSASecret = GetResValue("rsa-public-key", isSingle: false, ResValueFormat.String),
};
SetApiBaseUrl(options);
#if StartupTrace
stopwatch.Stop();
Console.WriteLine($"Load AppSettings, value: {stopwatch.ElapsedMilliseconds}");
#endif
return options;
static Guid GetResValueGuid(string name, bool isSingle, ResValueFormat format) => GetResValue(name, isSingle, format).TryParseGuidN() ?? default;
static string? GetResValue(string name, bool isSingle, ResValueFormat format)
@@ -307,22 +370,22 @@ namespace System.Application
static void SetApiBaseUrl(AppSettings s)
{
#if DEBUG
if (BuildConfig.IsAigioPC)
{
try
{
var url = CSConst.Prefix_HTTPS + "localhost:5001";
var request = WebRequest.CreateHttp(url);
request.Timeout = 999;
request.GetResponse();
s.ApiBaseUrl = url;
return;
}
catch (Exception e)
{
Debug.WriteLine(e.ToString());
}
}
//if (BuildConfig.IsAigioPC)
//{
// try
// {
// var url = CSConst.Prefix_HTTPS + "localhost:5001";
// var request = WebRequest.CreateHttp(url);
// request.Timeout = 999;
// request.GetResponse();
// s.ApiBaseUrl = url;
// return;
// }
// catch (Exception e)
// {
// Debug.WriteLine(e.ToString());
// }
//}
#endif
var value =
(ThisAssembly.Debuggable || !s.GetIsOfficialChannelPackage()) ?
@@ -516,4 +579,31 @@ namespace System.Application
}
}
}
}
#if StartupTrace
/// <summary>
/// 启动耗时跟踪
/// </summary>
static class StartupTrace
{
static Stopwatch? sw;
public static void Restart(string? mark = null)
{
if (sw != null)
{
sw.Stop();
var args = string.Join(" ", Environment.GetCommandLineArgs().Skip(1).Take(1));
var msg = $"{(string.IsNullOrWhiteSpace(args) ? "" : args + " ")}mark: {mark}, value: {sw.ElapsedMilliseconds}";
Debug.WriteLine(msg);
Console.WriteLine(msg);
sw.Restart();
}
else
{
sw = Stopwatch.StartNew();
}
}
}
#endif
}