using System; using System.Reactive.Concurrency; using System.Reactive.Disposables; using System.Windows; using System.Windows.Threading; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; using NLog.Extensions.Logging; using NLog.Targets; using ReactiveUI; using Wabbajack.DTOs; using Wabbajack.DTOs.Interventions; using Wabbajack.Interventions; using Wabbajack.LoginManagers; using Wabbajack.Models; using Wabbajack.Services.OSIntegrated; using Wabbajack.UserIntervention; using Wabbajack.Util; namespace Wabbajack { /// /// Interaction logic for App.xaml /// public partial class App { private readonly IServiceProvider _serviceProvider; private readonly IHost _host; public App() { RxApp.MainThreadScheduler = new DispatcherScheduler(Dispatcher.CurrentDispatcher); _host = Host.CreateDefaultBuilder(Array.Empty()) .ConfigureLogging(AddLogging) .ConfigureServices((host, services) => { ConfigureServices(services); }) .Build(); _serviceProvider = _host.Services; } private void AddLogging(ILoggingBuilder loggingBuilder) { var config = new NLog.Config.LoggingConfiguration(); var fileTarget = new FileTarget("file") { 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} ############" }; var consoleTarget = new ConsoleTarget("console"); var uiTarget = new LogStream { Name = "ui", Layout = "${message:withexception=false}", }; loggingBuilder.Services.AddSingleton(uiTarget); config.AddRuleForAllLevels(fileTarget); config.AddRuleForAllLevels(consoleTarget); config.AddRuleForAllLevels(uiTarget); loggingBuilder.ClearProviders(); loggingBuilder.SetMinimumLevel(LogLevel.Trace); loggingBuilder.AddNLog(config); } private static IServiceCollection ConfigureServices(IServiceCollection services) { services.AddOSIntegrated(); services.AddSingleton(); services.AddSingleton(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); // Login Handlers services.AddTransient(); services.AddTransient(); services.AddTransient(); // Login Managers services.AddAllSingleton(); services.AddAllSingleton(); services.AddAllSingleton(); services.AddSingleton(); services.AddSingleton(); return services; } private void OnStartup(object sender, StartupEventArgs e) { RxApp.MainThreadScheduler.Schedule(0, (_, _) => { var mainWindow = _serviceProvider.GetRequiredService(); mainWindow!.Show(); return Disposable.Empty; }); } private void OnExit(object sender, ExitEventArgs e) { using (_host) { _host.StopAsync(); } base.OnExit(e); } } }