Program.cs 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. using EVCB_OCPP.Domain;
  2. using EVCB_OCPP.WSServer.Message;
  3. using EVCB_OCPP.WSServer.Service;
  4. using Microsoft.EntityFrameworkCore;
  5. using Microsoft.Extensions.Configuration;
  6. using Microsoft.Extensions.DependencyInjection;
  7. using Microsoft.Extensions.Hosting;
  8. using Microsoft.Extensions.Logging;
  9. using Newtonsoft.Json;
  10. using System;
  11. using NLog;
  12. using NLog.Web;
  13. using NLog.Extensions.Logging;
  14. using System.IO;
  15. using System.Data.Common;
  16. using Microsoft.Data.SqlClient;
  17. namespace EVCB_OCPP.WSServer
  18. {
  19. class Program
  20. {
  21. static void Main(string[] args)
  22. {
  23. Console.WriteLine("====================================================================================================");
  24. Console.WriteLine("====================================================================================================");
  25. Console.WriteLine("== ==");
  26. Console.WriteLine("== ------------ ----------- ------------- ------------- ==");
  27. Console.WriteLine("== --- --- ---- ---------------- ---------------- ==");
  28. Console.WriteLine("== --- --- ---- ---- --- ---- --- ==");
  29. Console.WriteLine("== --- --- ---- ---- --- ---- --- ==");
  30. Console.WriteLine("== --- --- ---- ---- ------------- ---- ------------- ==");
  31. Console.WriteLine("== --- --- ---- ---- ----------- ---- ----------- ==");
  32. Console.WriteLine("== --- --- ---- ---- ---- ==");
  33. Console.WriteLine("== --- --- ---- ---- ---- ==");
  34. Console.WriteLine("== ----------- ----------- ---- ---- ==");
  35. Console.WriteLine("== ==");
  36. Console.WriteLine("====================================================================================================");
  37. Console.WriteLine("====================================================================================================");
  38. IHost host = Host.CreateDefaultBuilder(args)
  39. .ConfigureLogging((context, builder) => {
  40. builder.ClearProviders();
  41. NLog.LogManager.Configuration = new NLogLoggingConfiguration(context.Configuration.GetSection("NLog"));
  42. })
  43. .UseNLog()
  44. .ConfigureServices((hostContext, services) =>
  45. {
  46. services.AddPooledDbContextFactory<MainDBContext>((options) => {
  47. var cString = hostContext.Configuration.GetConnectionString("MainDBContext");
  48. //var connection = new SqlConnection(cString);
  49. //connection.Open();
  50. //var com = new SqlCommand("SET ARITHABORT ON", connection);
  51. //com.ExecuteNonQuery();
  52. //com.Dispose();
  53. //connection.Close();
  54. //options.UseSqlServer(connection, dbOptions =>
  55. //{
  56. // dbOptions.CommandTimeout(180);
  57. //});
  58. //options.LogTo(Console.WriteLine).EnableDetailedErrors();
  59. options.UseSqlServer(cString, dbOptions =>
  60. {
  61. dbOptions.EnableRetryOnFailure(int.MaxValue);
  62. dbOptions.CommandTimeout(int.MaxValue);
  63. });
  64. });
  65. services.AddPooledDbContextFactory<MeterValueDBContext>((options) => {
  66. var cString = hostContext.Configuration.GetConnectionString("MeterValueDBContext");
  67. options.UseSqlServer(cString, dbOptions => {
  68. dbOptions.EnableRetryOnFailure(int.MaxValue);
  69. dbOptions.CommandTimeout(int.MaxValue);
  70. });
  71. });
  72. services.AddPooledDbContextFactory<ConnectionLogDBContext>((options) => {
  73. var cString = hostContext.Configuration.GetConnectionString("ConnectionLogDBContext");
  74. options.UseSqlServer(cString, dbOptions => {
  75. dbOptions.EnableRetryOnFailure(int.MaxValue);
  76. dbOptions.CommandTimeout(int.MaxValue);
  77. });
  78. });
  79. services.AddSingleton<ProfileHandler>();
  80. services.AddScoped<OuterBusinessService>();
  81. services.AddScoped<LocalBusinessService>();
  82. services.AddScoped<CPOOuterResponse>();
  83. services.AddSingleton<IBusinessServiceFactory, BusinessServiceFactory>();
  84. //services.AddHostedService<ProtalServer>();
  85. services.AddSingleton<IMainDbService, MainDbService>();
  86. services.AddProtalServer();
  87. })
  88. .Build();
  89. host.Run();
  90. //ProtalServer s = new ProtalServer();
  91. //Console.WriteLine("Starting Server...");
  92. //s.Start();
  93. //Console.Read();
  94. }
  95. public static object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
  96. {
  97. DateTime? timevalue = null;
  98. if (reader.Value != null)
  99. {
  100. DateTime date = ((DateTime)reader.Value).ToLocalTime();
  101. timevalue = new DateTime(date.Year, date.Month, date.Day, date.TimeOfDay.Hours, date.TimeOfDay.Minutes, date.TimeOfDay.Seconds, 000);
  102. }
  103. return timevalue;
  104. }
  105. }
  106. }