12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- using Microsoft.AspNetCore.Components.WebView.WindowsForms;
- using WarcViewerBlazorWinForm.UI;
- namespace WarcViewerBlazorWinForm
- {
- public partial class ViewerMainForm : Form
- {
- public IServiceProvider? ServiceProvider { get; set; }
- public ViewerMainForm()
- {
- InitializeComponent();
- }
- private async void ViewerMainForm_Shown(object sender, EventArgs e)
- {
- if (ServiceProvider == null) throw new InvalidOperationException($"Must set {nameof(ServiceProvider)} before show!");
- MainBlazorWebView.HostPage = "wwwroot\\index.html";
- MainBlazorWebView.Services = ServiceProvider;
- MainBlazorWebView.RootComponents.Add<App>("#app");
- #if DEBUG
- await ShowF12();
- #endif
- }
- public async Task ShowF12()
- {
- await MainBlazorWebView.WebView.EnsureCoreWebView2Async();
- MainBlazorWebView.WebView.CoreWebView2.OpenDevToolsWindow();
- }
- public string? OpenFileWarc()
- {
- return OpenFile("All supported warc files (*.warc;*.7z;*.zip)|*.warc;*.7z;*.zip", "Open WARC file");
- }
- public string? OpenFile(string filter = "All files (*.*)|*.*", string? title = null)
- {
- var dlg = new OpenFileDialog
- {
- Multiselect = false,
- Title = title,
- Filter = filter,
- CheckFileExists = true,
- };
- var result = dlg.ShowDialog(this);
- return result == DialogResult.OK
- ? dlg.FileName : null;
- }
- }
- }
|