2022-01-27 07:25:55 +00:00
|
|
|
|
using System;
|
2022-01-09 13:33:22 +00:00
|
|
|
|
using System.Windows;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
using Microsoft.Extensions.Hosting;
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
2022-01-21 13:54:22 +00:00
|
|
|
|
using NLog.Extensions.Logging;
|
|
|
|
|
using NLog.Targets;
|
2022-01-20 08:34:38 +00:00
|
|
|
|
using Wabbajack.App.Blazor.State;
|
2022-01-16 13:46:16 +00:00
|
|
|
|
using Wabbajack.App.Blazor.Utility;
|
2022-01-09 13:33:22 +00:00
|
|
|
|
using Wabbajack.Services.OSIntegrated;
|
2022-01-27 07:25:55 +00:00
|
|
|
|
using Blazored.Modal;
|
|
|
|
|
using Blazored.Toast;
|
2022-01-30 05:47:49 +00:00
|
|
|
|
using Wabbajack.App.Blazor.Browser.ViewModels;
|
2022-01-09 13:33:22 +00:00
|
|
|
|
|
2022-01-20 08:34:38 +00:00
|
|
|
|
namespace Wabbajack.App.Blazor;
|
|
|
|
|
|
|
|
|
|
public partial class App
|
2022-01-09 13:33:22 +00:00
|
|
|
|
{
|
2022-01-20 08:34:38 +00:00
|
|
|
|
private readonly IServiceProvider _serviceProvider;
|
|
|
|
|
|
|
|
|
|
public App()
|
2022-01-09 13:33:22 +00:00
|
|
|
|
{
|
2022-01-21 13:41:37 +00:00
|
|
|
|
_serviceProvider = Host.CreateDefaultBuilder(Array.Empty<string>())
|
2022-01-21 13:54:22 +00:00
|
|
|
|
.ConfigureLogging(SetupLogging)
|
2022-01-21 13:41:37 +00:00
|
|
|
|
.ConfigureServices(services => ConfigureServices(services))
|
|
|
|
|
.Build()
|
|
|
|
|
.Services;
|
2022-01-27 07:12:33 +00:00
|
|
|
|
_serviceProvider.GetRequiredService<SystemParametersConstructor>();
|
2022-01-20 08:34:38 +00:00
|
|
|
|
}
|
2022-01-09 13:33:22 +00:00
|
|
|
|
|
2022-01-21 13:54:22 +00:00
|
|
|
|
private static void SetupLogging(ILoggingBuilder loggingBuilder)
|
|
|
|
|
{
|
|
|
|
|
var config = new NLog.Config.LoggingConfiguration();
|
|
|
|
|
|
|
|
|
|
var fileTarget = new FileTarget("file")
|
|
|
|
|
{
|
2022-01-27 07:22:24 +00:00
|
|
|
|
FileName = "logs/Wabbajack.current.log",
|
|
|
|
|
ArchiveFileName = "logs/Wabbajack.{##}.log",
|
|
|
|
|
ArchiveOldFileOnStartup = true,
|
|
|
|
|
MaxArchiveFiles = 10,
|
|
|
|
|
Layout = "${processtime} [${level:uppercase=true}] (${logger}) ${message:withexception=true}",
|
|
|
|
|
Header = "############ Wabbajack log file - ${longdate} ############"
|
2022-01-21 13:54:22 +00:00
|
|
|
|
};
|
2022-01-28 10:29:38 +00:00
|
|
|
|
|
2022-01-21 13:54:22 +00:00
|
|
|
|
var consoleTarget = new ConsoleTarget("console");
|
2022-01-28 10:29:38 +00:00
|
|
|
|
|
|
|
|
|
var uiTarget = new UiLoggerTarget
|
2022-01-27 07:22:24 +00:00
|
|
|
|
{
|
|
|
|
|
Name = "ui",
|
|
|
|
|
Layout = "${message}",
|
|
|
|
|
};
|
|
|
|
|
|
2022-01-21 14:44:05 +00:00
|
|
|
|
var blackholeTarget = new NullTarget("blackhole");
|
2022-01-21 15:11:44 +00:00
|
|
|
|
|
|
|
|
|
if (!string.Equals("TRUE", Environment.GetEnvironmentVariable("DEBUG_BLAZOR", EnvironmentVariableTarget.Process), StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
config.AddRule(NLog.LogLevel.Trace, NLog.LogLevel.Debug, blackholeTarget, "Microsoft.AspNetCore.Components.*", true);
|
|
|
|
|
}
|
2022-01-27 07:22:24 +00:00
|
|
|
|
|
2022-01-21 13:54:22 +00:00
|
|
|
|
config.AddRuleForAllLevels(fileTarget);
|
|
|
|
|
config.AddRuleForAllLevels(consoleTarget);
|
|
|
|
|
config.AddRuleForAllLevels(uiTarget);
|
2022-01-27 07:22:24 +00:00
|
|
|
|
|
2022-01-21 13:54:22 +00:00
|
|
|
|
loggingBuilder.ClearProviders();
|
|
|
|
|
loggingBuilder.SetMinimumLevel(LogLevel.Trace);
|
|
|
|
|
loggingBuilder.AddNLog(config);
|
|
|
|
|
}
|
2022-01-27 07:22:24 +00:00
|
|
|
|
|
2022-01-20 08:34:38 +00:00
|
|
|
|
private static IServiceCollection ConfigureServices(IServiceCollection services)
|
|
|
|
|
{
|
|
|
|
|
services.AddOSIntegrated();
|
|
|
|
|
services.AddBlazorWebView();
|
2022-01-27 07:25:55 +00:00
|
|
|
|
services.AddBlazoredModal();
|
|
|
|
|
services.AddBlazoredToast();
|
2022-01-20 08:34:38 +00:00
|
|
|
|
services.AddTransient<MainWindow>();
|
2022-01-30 05:47:49 +00:00
|
|
|
|
services.AddTransient<NexusLogin>();
|
2022-02-09 05:40:46 +00:00
|
|
|
|
services.AddTransient<VectorPlexus>();
|
|
|
|
|
services.AddTransient<LoversLab>();
|
2022-02-10 23:57:44 +00:00
|
|
|
|
services.AddTransient<BethesdaNetLogin>();
|
2022-01-20 08:34:38 +00:00
|
|
|
|
services.AddSingleton<SystemParametersConstructor>();
|
2022-01-21 13:54:22 +00:00
|
|
|
|
services.AddSingleton<IStateContainer, StateContainer>();
|
2022-01-20 08:34:38 +00:00
|
|
|
|
return services;
|
|
|
|
|
}
|
2022-01-09 13:33:22 +00:00
|
|
|
|
|
2022-01-20 08:34:38 +00:00
|
|
|
|
private void OnStartup(object sender, StartupEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
var mainWindow = _serviceProvider.GetRequiredService<MainWindow>();
|
2022-01-21 13:41:37 +00:00
|
|
|
|
mainWindow.Show();
|
2022-01-20 08:34:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnExit(object sender, ExitEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Current.Shutdown();
|
2022-01-09 13:33:22 +00:00
|
|
|
|
}
|
2022-01-20 08:34:38 +00:00
|
|
|
|
}
|