Files
Blueberry/Blueberry/App.xaml.cs

92 lines
3.2 KiB
C#

using Blueberry;
using Blueberry.Redmine;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using System.IO;
using System.Windows;
using System.Windows.Threading;
namespace BlueMine
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
private static readonly IHost _host = Host
.CreateDefaultBuilder()
.ConfigureLogging(builder => {
builder.AddConsole();
builder.SetMinimumLevel(LogLevel.Debug);
})
.ConfigureAppConfiguration(c => { c.SetBasePath(Path.GetDirectoryName(AppContext.BaseDirectory) ?? throw new NullReferenceException()); })
.ConfigureServices((context, services) =>
{
services.AddSingleton<RedmineSettingsManager>();
services.AddSingleton(sp =>
{
var manager = sp.GetRequiredService<RedmineSettingsManager>();
return manager.Load();
});
//services.AddTransient<RedmineAuthHandler>();
//services.AddHttpClient("client", client => client.BaseAddress = new Uri("http://localhost/")).RemoveAllLoggers();
services.AddHttpClient("client").RemoveAllLoggers();
services.Configure<LoggerFilterOptions>(opts =>
{
opts.AddFilter("System.Net.Http.HttpClient", LogLevel.Warning);
});
// .AddHttpMessageHandler<RedmineAuthHandler>();
services.AddSingleton<RedmineManager>();
services.AddSingleton<HoursWindow>();
services.AddSingleton<MainWindow>();
}).Build();
/// <summary>
/// Gets services.
/// </summary>
public static IServiceProvider Services
{
get { return _host.Services; }
}
/// <summary>
/// Occurs when the application is loading.
/// </summary>
private async void OnStartup(object sender, StartupEventArgs e)
{
await _host.StartAsync();
var mainWindow = _host.Services.GetRequiredService<MainWindow>();
mainWindow.Show();
}
/// <summary>
/// Occurs when the application is closing.
/// </summary>
private async void OnExit(object sender, ExitEventArgs e)
{
await _host.StopAsync();
_host.Dispose();
if (await UpdateManager.IsUpdateAvailable())
{
await UpdateManager.WaitUntilDownloadCompleteAndUpdate();
}
}
/// <summary>
/// Occurs when an exception is thrown by an application but not handled.
/// </summary>
private void OnDispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
{
// For more info see https://docs.microsoft.com/en-us/dotnet/api/system.windows.application.dispatcherunhandledexception?view=windowsdesktop-6.0
}
}
}