Program.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. namespace EVCB_OCPP.WSServer
  16. {
  17. class Program
  18. {
  19. static void Main(string[] args)
  20. {
  21. Console.WriteLine("====================================================================================================");
  22. Console.WriteLine("====================================================================================================");
  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. IHost host = Host.CreateDefaultBuilder(args)
  37. .ConfigureLogging((context, builder) => {
  38. builder.ClearProviders();
  39. NLog.LogManager.Configuration = new NLogLoggingConfiguration(context.Configuration.GetSection("NLog"));
  40. })
  41. .UseNLog()
  42. .ConfigureServices((hostContext, services) =>
  43. {
  44. services.AddDbContextFactory<MainDBContext>((options) => {
  45. var cString = hostContext.Configuration.GetConnectionString("MainDBContext");
  46. options.UseSqlServer(cString, dbOptions => {
  47. dbOptions.CommandTimeout(180);
  48. });
  49. });
  50. services.AddDbContextFactory<MeterValueDBContext>((options) => {
  51. var cString = hostContext.Configuration.GetConnectionString("MeterValueDBContext");
  52. options.UseSqlServer(cString, dbOptions => {
  53. dbOptions.CommandTimeout(180);
  54. });
  55. });
  56. services.AddDbContextFactory<ConnectionLogDBContext>((options) => {
  57. var cString = hostContext.Configuration.GetConnectionString("ConnectionLogDBContext");
  58. options.UseSqlServer(cString, dbOptions => {
  59. dbOptions.CommandTimeout(180);
  60. });
  61. });
  62. services.AddSingleton<ProfileHandler>();
  63. services.AddScoped<OuterBusinessService>();
  64. services.AddScoped<LocalBusinessService>();
  65. services.AddScoped<CPOOuterResponse>();
  66. services.AddSingleton<BusinessServiceFactory>();
  67. //services.AddHostedService<ProtalServer>();
  68. services.AddProtalServer();
  69. })
  70. .Build();
  71. host.Run();
  72. //ProtalServer s = new ProtalServer();
  73. //Console.WriteLine("Starting Server...");
  74. //s.Start();
  75. //Console.Read();
  76. }
  77. public static object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
  78. {
  79. DateTime? timevalue = null;
  80. if (reader.Value != null)
  81. {
  82. DateTime date = ((DateTime)reader.Value).ToLocalTime();
  83. timevalue = new DateTime(date.Year, date.Month, date.Day, date.TimeOfDay.Hours, date.TimeOfDay.Minutes, date.TimeOfDay.Seconds, 000);
  84. }
  85. return timevalue;
  86. }
  87. }
  88. }