Program.cs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. using System.Text;
  2. using Microsoft.Extensions.DependencyInjection;
  3. using Microsoft.Extensions.Hosting;
  4. using Microsoft.Extensions.Logging;
  5. using Microsoft.Extensions.Logging.Console;
  6. using WarcViewerBlazorWinForm.Backend.Logging;
  7. using WarcViewerBlazorWinForm.Library.AssemblyInject;
  8. using WarcViewerBlazorWinForm.Library.EventBus;
  9. namespace WarcViewerBlazorWinForm
  10. {
  11. internal class Program
  12. {
  13. /// <summary>
  14. /// The main entry point for the application.
  15. /// </summary>
  16. [STAThread]
  17. private static void Main()
  18. {
  19. // To customize application configuration such as set high DPI settings or default font,
  20. // see https://aka.ms/applicationconfiguration.
  21. ApplicationConfiguration.Initialize();
  22. Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
  23. //TestCases.Run().Wait;
  24. var builder = Host.CreateDefaultBuilder();
  25. var mainForm = new ViewerMainForm();
  26. var loggingIntoEventBus = new LoggingIntoEventBus();
  27. builder.ConfigureServices((ctx, services) =>
  28. {
  29. //¿ØÖÆ̨ÈÕÖ¾¸ñʽ
  30. services.AddLogging(opt =>
  31. {
  32. opt.AddSimpleConsole(p =>
  33. {
  34. p.TimestampFormat = "[dd HH:mm:ss] ";
  35. p.SingleLine = true;
  36. p.ColorBehavior = LoggerColorBehavior.Enabled;
  37. })
  38. .AddDebug()
  39. .AddProvider(loggingIntoEventBus);
  40. services.AddSingleton(opt);
  41. });
  42. services.AddWindowsFormsBlazorWebView();
  43. services.AddAssemblyInject<Program>();
  44. services.AddBootstrapBlazor();
  45. services.AddSingleton(mainForm);
  46. });
  47. var host = builder.Build();
  48. var serviceProvider = host.Services;
  49. loggingIntoEventBus.EventBus = serviceProvider.GetRequiredService<IEventBus>();
  50. mainForm.ServiceProvider = serviceProvider;
  51. host.Start();
  52. Application.Run(mainForm);
  53. host.StopAsync().Wait();
  54. }
  55. }
  56. }