Net8Blazor/NET8Blazor/PhotinoNetApp/Program.cs
2024-02-05 19:34:01 +01:00

48 lines
1.5 KiB
C#

using System.Drawing;
using System.Reflection;
using Microsoft.Extensions.FileProviders;
using PhotinoNET;
using PhotinoNetApp.Components;
var builder = WebApplication.CreateBuilder();
builder.Services.AddRazorComponents()
.AddInteractiveServerComponents();
builder.Services.AddSingleton<IFileProvider>(new ManifestEmbeddedFileProvider(Assembly.GetAssembly(type: typeof(Program))!, "/", "Microsoft.Extensions.FileProviders.Embedded.Manifest.xml", DateTimeOffset.Now));
// builder.WebHost.UseWebRoot("wwwroot");
builder.WebHost.UseStaticWebAssets();
builder.WebHost.UseUrls("http://localhost:5000");
var app = builder.Build();
// app.UseStaticFiles();
app.UseStaticFiles(new StaticFileOptions
{
FileProvider = app.Services.GetService<IFileProvider>(),
// RequestPath = "/PhotinoNetApp",
ServeUnknownFileTypes = true,
});
app.UseAntiforgery();
app.MapRazorComponents<App>()
.AddInteractiveServerRenderMode();
foreach (var file in Assembly.GetExecutingAssembly().GetManifestResourceNames())
if (file.Contains("wwwroot"))
app.Logger.LogWarning($"Public file: {file}");
using var webServerCancellation = new CancellationTokenSource();
var webServerTask = app.RunAsync(webServerCancellation.Token);
var window = new PhotinoWindow()
.SetTitle("Test App")
.SetUseOsDefaultSize(false)
.SetSize(new Size(1024, 900))
.Center()
.SetResizable(true)
.Load("http://localhost:5000");
window.WaitForClose();
webServerCancellation.Cancel();
await webServerTask;