App.xaml.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. using System;
  2. using System.Linq;
  3. using Perspex;
  4. using Perspex.Controls;
  5. using Perspex.Diagnostics;
  6. using Perspex.Markup.Xaml;
  7. using Perspex.Logging.Serilog;
  8. using Serilog;
  9. namespace ControlCatalog
  10. {
  11. class App : Application
  12. {
  13. public App()
  14. {
  15. RegisterServices();
  16. InitializeSubsystems(GetPlatformId());
  17. InitializeLogging();
  18. InitializeComponent();
  19. }
  20. public static void AttachDevTools(Window window)
  21. {
  22. #if DEBUG
  23. DevTools.Attach(window);
  24. #endif
  25. }
  26. static void Main(string[] args)
  27. {
  28. var app = new App();
  29. var window = new MainWindow();
  30. window.Show();
  31. app.Run(window);
  32. }
  33. private void InitializeComponent()
  34. {
  35. PerspexXamlLoader.Load(this);
  36. }
  37. private void InitializeLogging()
  38. {
  39. #if DEBUG
  40. SerilogLogger.Initialize(new LoggerConfiguration()
  41. .MinimumLevel.Warning()
  42. .WriteTo.Trace(outputTemplate: "{Area}: {Message}")
  43. .CreateLogger());
  44. #endif
  45. }
  46. private int GetPlatformId()
  47. {
  48. var args = Environment.GetCommandLineArgs();
  49. if (args.Contains("--gtk"))
  50. {
  51. return (int)PlatformID.Unix;
  52. }
  53. else
  54. {
  55. return (int)Environment.OSVersion.Platform;
  56. }
  57. }
  58. }
  59. }