summary refs log tree commit diff
path: root/testFrontend/SafeNSound.Demo/Program.cs
diff options
context:
space:
mode:
Diffstat (limited to 'testFrontend/SafeNSound.Demo/Program.cs')
-rw-r--r--testFrontend/SafeNSound.Demo/Program.cs50
1 files changed, 50 insertions, 0 deletions
diff --git a/testFrontend/SafeNSound.Demo/Program.cs b/testFrontend/SafeNSound.Demo/Program.cs
new file mode 100644

index 0000000..07f222c --- /dev/null +++ b/testFrontend/SafeNSound.Demo/Program.cs
@@ -0,0 +1,50 @@ +using System.Net; +using System.Text.Json; +using System.Text.Json.Serialization; +using Blazored.LocalStorage; +using Microsoft.AspNetCore.Components.Web; +using Microsoft.AspNetCore.Components.WebAssembly.Hosting; +using SafeNSound.Demo; +using SafeNSound.Sdk; + +var builder = WebAssemblyHostBuilder.CreateDefault(args); +builder.RootComponents.Add<App>("#app"); +builder.RootComponents.Add<HeadOutlet>("head::after"); + +builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) }); +builder.Services.AddSingleton<SafeNSoundConfiguration>(); +builder.Services.AddSingleton<SafeNSoundAuthentication>(); + + +try { + builder.Configuration.AddJsonStream(await new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) }.GetStreamAsync("/appsettings.json")); +#if DEBUG + builder.Configuration.AddJsonStream(await new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) }.GetStreamAsync("/appsettings.Development.json")); +#endif +} +catch (HttpRequestException e) { + if (e.StatusCode == HttpStatusCode.NotFound) + Console.WriteLine("Could not load appsettings, server returned 404."); + else + Console.WriteLine("Could not load appsettings: " + e); +} +catch (Exception e) { + Console.WriteLine("Could not load appsettings: " + e); +} + +builder.Logging.AddConfiguration( + builder.Configuration.GetSection("Logging")); + +builder.Services.AddBlazoredLocalStorage(config => { + config.JsonSerializerOptions.DictionaryKeyPolicy = JsonNamingPolicy.CamelCase; + config.JsonSerializerOptions.DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull; + config.JsonSerializerOptions.IgnoreReadOnlyProperties = true; + config.JsonSerializerOptions.PropertyNameCaseInsensitive = true; + config.JsonSerializerOptions.PropertyNamingPolicy = JsonNamingPolicy.CamelCase; + config.JsonSerializerOptions.ReadCommentHandling = JsonCommentHandling.Skip; + config.JsonSerializerOptions.WriteIndented = false; +}); + +WrappedHttpClient.LogRequests = false; + +await builder.Build().RunAsync(); \ No newline at end of file