-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
116 lines (101 loc) · 4.65 KB
/
Copy pathProgram.cs
File metadata and controls
116 lines (101 loc) · 4.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
using System;
using Avalonia;
using Avalonia.Labs.Notifications;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Serilog;
using WarframeMarketTracker.Services;
using WarframeMarketTracker.ViewModels;
using WarframeMarketTracker.Views;
namespace WarframeMarketTracker;
internal static class Program
{
public const string AppName = "Warframe Market Tracker";
[STAThread]
public static void Main(string[] args)
{
var configuration = new ConfigurationBuilder()
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: false)
.Build();
Log.Logger = new LoggerConfiguration()
.ReadFrom.Configuration(configuration)
#if DEBUG
.WriteTo.Console()
#endif
.WriteTo.File("logs/app-.log",
rollingInterval: RollingInterval.Day,
retainedFileCountLimit: 5,
outputTemplate: "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level:u3}] ({SourceContext}) {Message:lj}{NewLine}{Exception}")
.CreateLogger();
try
{
var host = Host.CreateDefaultBuilder(args)
.UseSerilog()
.ConfigureServices((_, services) =>
{
const string userAgent = $"{nameof(WarframeMarketTracker)}/{BuildInfo.AppVersion}";
// 1. Setup named HTTP Clients
services.AddHttpClient("WfmApi", c =>
{
c.BaseAddress = new Uri("https://api.warframe.market/v2/");
c.DefaultRequestHeaders.UserAgent.ParseAdd(userAgent);
c.DefaultRequestHeaders.Accept.ParseAdd("application/json");
});
services.AddHttpClient("WfmAssets", c =>
{
c.BaseAddress = new Uri("https://warframe.market/static/assets/");
c.DefaultRequestHeaders.UserAgent.ParseAdd(userAgent);
});
services.AddHttpClient("GitHub", c =>
{
c.BaseAddress = new Uri("https://api.github.com/");
c.DefaultRequestHeaders.UserAgent.ParseAdd(userAgent);
c.DefaultRequestHeaders.Accept.ParseAdd("application/vnd.github+json");
c.Timeout = TimeSpan.FromSeconds(5);
});
// 2. Services & State
services.AddTransient<IWarframeMarketService, WarframeMarketService>();
services.AddSingleton<IItemCache, ItemCache>();
services.AddSingleton<ITrackedItemRegistry, TrackedItemRegistry>();
services.AddSingleton<ITrackedItemStore, TrackedItemStore>();
services.AddSingleton<IThumbnailCache, ThumbnailCache>();
// 3. Background Services
services.AddHostedService<ItemCacheHydrationService>();
services.AddHostedService<MarketPollingService>();
// 4. Components & UI
services.AddSingleton<IUserInterfaceNotificationService, UserInterfaceNotificationService>();
services.AddSingleton<INotificationService, NativeNotificationService>();
services.AddSingleton<IDialogService, DialogService>();
services.AddTransient<AboutWindowViewModel>();
services.AddSingleton<Func<AboutWindowViewModel>>(sp => sp.GetRequiredService<AboutWindowViewModel>);
services.AddSingleton<MainWindowViewModel>();
services.AddSingleton(sp => new Lazy<MainWindowViewModel>(sp.GetRequiredService<MainWindowViewModel>));
services.AddSingleton<MainWindow>();
})
.Build();
// Start the background services (API poller, etc.)
host.Start();
BuildAvaloniaApp(host.Services)
.StartWithClassicDesktopLifetime(args);
host.StopAsync().GetAwaiter().GetResult();
}
catch (Exception ex)
{
Log.Fatal(ex, "Host terminated unexpectedly");
}
finally
{
Log.CloseAndFlush();
}
}
private static AppBuilder BuildAvaloniaApp(IServiceProvider services)
=> AppBuilder.Configure(() => new App(services))
.UsePlatformDetect()
#if DEBUG
.WithDeveloperTools()
#endif
.WithInterFont()
.WithAppNotifications(NativeNotificationService.AppNotificationOptions)
.LogToTrace();
}