App.xaml.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. using log4net;
  2. using Microsoft.Extensions.DependencyInjection;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Configuration;
  6. using System.Data;
  7. using System.Linq;
  8. using System.Runtime.CompilerServices;
  9. using System.Threading.Tasks;
  10. using System.Windows;
  11. namespace NEIntelligentControl2
  12. {
  13. /// <summary>
  14. /// 新能源智能发电集中控制系统
  15. /// </summary>
  16. public partial class App : Application
  17. {
  18. /// <summary>
  19. /// 依赖注入
  20. /// </summary>
  21. public static IServiceProvider ServiceProvider { get; set; }
  22. private ILog log = LogManager.GetLogger("File");
  23. private void Application_Startup(object sender, StartupEventArgs e)
  24. {
  25. var serviceCollection = new ServiceCollection();
  26. ConfigureServices(serviceCollection);
  27. ServiceProvider = serviceCollection.BuildServiceProvider();
  28. var mainWindow = ServiceProvider.GetRequiredService<MainWindow>();
  29. mainWindow.Show();
  30. }
  31. private void Application_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
  32. {
  33. try
  34. {
  35. e.Handled = true;
  36. log.Error("应用程序出现重大错误,但可继续运行!", e.Exception);
  37. }
  38. catch (Exception ex)
  39. {
  40. log.Fatal("应用程序出现致命错误,已经结束运行!", e.Exception);
  41. }
  42. }
  43. /// <summary>
  44. /// 获取服务
  45. /// </summary>
  46. /// <typeparam name="T">类型</typeparam>
  47. /// <returns>服务</returns>
  48. public static T GetService<T>()
  49. {
  50. return (T)ServiceProvider.GetService(typeof(T));
  51. }
  52. /// <summary>
  53. /// 依赖注入
  54. /// </summary>
  55. private void ConfigureServices(IServiceCollection services)
  56. {
  57. services.AddSingleton<Models.Pages.IPageAction, Models.Pages.PageManager>()
  58. .AddSingleton<Service.WebSocket.MessageBridge>()
  59. .AddSingleton<Models.Messages.WEBHelper>()
  60. .AddSingleton<Service.Windturbine.CacheManager>()
  61. .AddSingleton<Service.WebSocket.UrlManager>()
  62. .AddSingleton<Service.User.UserManager>()
  63. .AddSingleton<Service.Voice.VoiceManager>()
  64. .AddSingleton<Service.AGC.AGCManager>()
  65. .AddSingleton<Service.Alarm.AlarmManager>()
  66. .AddSingleton<Service.Windturbine.InfoManager>()
  67. .AddSingleton<Service.Windturbine.SuggestionManager>()
  68. .AddSingleton<Service.Windturbine.ControlManager>()
  69. .AddSingleton<Models.Pages.TagManager>()
  70. .AddSingleton<Service.Station.StationManager>()
  71. .AddSingleton<MainWindow>()
  72. .AddTransient<Windows.ConfirmWindow>()
  73. .AddTransient<Windows.WindturbineInfoWindow>()
  74. .AddTransient<Windows.UserWindow>()
  75. .AddTransient< Pages.User.PageLogin>()
  76. .AddTransient< Pages.User.PageUserEdit>()
  77. .AddSingleton<Pages.Matrix.PageMatrix>()
  78. .AddTransient<Pages.AGC.PageAGC>()
  79. .AddSingleton<Pages.Help.PageHelp>()
  80. .AddSingleton<Pages.BoostStation.PageBoostStation>()
  81. .AddSingleton<Pages.BoostStation.PageBoostStation2>()
  82. .AddTransient<Pages.BoostStation.PageStation>()
  83. .AddTransient<Pages.BoostStation.PageStation2>()
  84. .AddSingleton<Pages.Home.HomePage>()
  85. .AddSingleton<Pages.Home.StateTimePage>()
  86. .AddSingleton<Pages.Alarm.PageAlarmCenter>()
  87. .AddTransient<Pages.Matrix.PageMatrixAll>()
  88. .AddTransient<Pages.Home.PageWindturbineAGC>()
  89. .AddTransient<Pages.Matrix.PageMatrixStation>()
  90. .AddTransient<Windows.ParameterComparisonWindow>()
  91. .AddTransient<Windows.Alarm.DeviceDetailAlarmWindow>()
  92. .AddTransient<Windows.Alarm.HistoryAlarmWindow>()
  93. .AddTransient<Windows.Alarm.HistoryFaultWindow>()
  94. .AddTransient<Windows.Alarm.RealTimeAlarmWindow>()
  95. .AddTransient<Windows.ControlTrackWindow>()
  96. .AddTransient<Windows.RecomendWindow>()
  97. .AddTransient<Windows.HistoryDataWindow>()
  98. .AddTransient<Windows.PV.InverterInfoWindow>()
  99. .AddTransient<Windows.PV.SUN2000InfoWindow>();
  100. }
  101. }
  102. }