From d6c791af681fdcc84c5a79a7b30d35db9231e404 Mon Sep 17 00:00:00 2001 From: Rory& Date: Wed, 11 Jun 2025 07:38:05 +0200 Subject: Add initial demo --- testFrontend/SafeNSound.Demo/Program.cs | 50 +++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 testFrontend/SafeNSound.Demo/Program.cs (limited to 'testFrontend/SafeNSound.Demo/Program.cs') 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"); +builder.RootComponents.Add("head::after"); + +builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) }); +builder.Services.AddSingleton(); +builder.Services.AddSingleton(); + + +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 -- cgit 1.5.1