2021-04-02 21:45:14 +02:00
|
|
|
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
using System;
|
2021-05-14 13:29:07 +02:00
|
|
|
using System.Diagnostics;
|
2021-04-07 12:32:17 +02:00
|
|
|
using System.Globalization;
|
2021-04-02 21:45:14 +02:00
|
|
|
using System.Net.Http;
|
|
|
|
|
using System.Threading.Tasks;
|
2021-04-04 15:44:52 +02:00
|
|
|
using MediatR;
|
2021-04-07 12:32:17 +02:00
|
|
|
using Microsoft.JSInterop;
|
2021-04-03 15:43:31 +02:00
|
|
|
using Radzen;
|
2021-04-07 12:32:17 +02:00
|
|
|
using WotBlitzStatisticsPro.Blazor.Model;
|
2021-04-04 15:44:52 +02:00
|
|
|
using WotBlitzStatisticsPro.Blazor.Services;
|
2021-04-02 21:45:14 +02:00
|
|
|
|
|
|
|
|
namespace WotBlitzStatisticsPro.Blazor
|
|
|
|
|
{
|
|
|
|
|
public class Program
|
|
|
|
|
{
|
|
|
|
|
public static async Task Main(string[] args)
|
|
|
|
|
{
|
|
|
|
|
var builder = WebAssemblyHostBuilder.CreateDefault(args);
|
|
|
|
|
builder.RootComponents.Add<App>("#app");
|
2021-04-07 12:32:17 +02:00
|
|
|
builder.Services.AddLocalization(options => options.ResourcesPath = "Resources");
|
2021-04-02 21:45:14 +02:00
|
|
|
|
|
|
|
|
builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
|
|
|
|
|
|
2021-04-03 15:43:31 +02:00
|
|
|
builder.Services.AddScoped<DialogService>();
|
2021-05-16 22:04:42 +02:00
|
|
|
builder.Services.AddScoped<NotificationService>();
|
2021-04-04 15:44:52 +02:00
|
|
|
builder.Services.AddScoped<ISearchDialogService, SearchDialogService>();
|
|
|
|
|
|
|
|
|
|
builder.Services.AddMediatR(typeof(Program));
|
2021-04-03 15:43:31 +02:00
|
|
|
|
2021-04-06 18:17:22 +02:00
|
|
|
builder.Services.AddSingleton<NavigationMessagesInterceptor>();
|
2021-04-07 12:32:17 +02:00
|
|
|
builder.Services.AddScoped<ILocalStorageService, LocalStorageService>();
|
2021-05-16 22:04:42 +02:00
|
|
|
builder.Services.AddSingleton<INotificationsService, NotificationsService>();
|
2021-04-06 18:17:22 +02:00
|
|
|
|
2021-05-14 11:37:45 +02:00
|
|
|
// StrawberryShake GraphQL Client
|
|
|
|
|
builder.Services
|
|
|
|
|
.AddWotBlitzStatisticsProClient()
|
2021-05-14 13:29:07 +02:00
|
|
|
.ConfigureHttpClient(client => client.BaseAddress = new Uri($"{builder.HostEnvironment.BaseAddress}graphql/"));
|
2021-05-14 11:37:45 +02:00
|
|
|
|
2021-05-15 17:36:35 +02:00
|
|
|
// ToDo: Asp Net hosting environment variables don't work here. I don't know why
|
|
|
|
|
//var useMock = Environment.GetEnvironmentVariable("USE_GRAPH_QL_MOCK");
|
|
|
|
|
//if (useMock != null && useMock == "true")
|
|
|
|
|
//{
|
2021-05-31 16:09:16 +02:00
|
|
|
builder.Services.AddTransient<IGraphQlBackendService, GraphQlBackendMockService>();
|
2021-05-15 17:36:35 +02:00
|
|
|
//}
|
|
|
|
|
//else
|
|
|
|
|
//{
|
2021-05-31 16:09:16 +02:00
|
|
|
//builder.Services.AddTransient<IGraphQlBackendService, GraphQlBackendService>();
|
2021-05-15 17:36:35 +02:00
|
|
|
//}
|
2021-05-14 11:37:45 +02:00
|
|
|
|
2021-04-07 12:32:17 +02:00
|
|
|
var host = builder.Build();
|
|
|
|
|
// Reading Current Culture from LocalStorage
|
|
|
|
|
var localStorageService = host.Services.GetRequiredService<ILocalStorageService>();
|
|
|
|
|
var settings = await localStorageService.GetItemAsync<UserSettings>(UserSettings.UserSettingsLocalStorageKey);
|
|
|
|
|
if (settings != null)
|
|
|
|
|
{
|
|
|
|
|
var culture = new CultureInfo(settings.Culture);
|
|
|
|
|
CultureInfo.DefaultThreadCurrentCulture = culture;
|
|
|
|
|
CultureInfo.DefaultThreadCurrentUICulture = culture;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await host.RunAsync();
|
2021-04-02 21:45:14 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|