Program.cs 5.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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.AddScoped<ProfileHandler>();
  63. services.AddScoped<OuterBusinessService>();
  64. services.AddScoped<LocalBusinessService>();
  65. services.AddScoped<CPOOuterResponse>();
  66. services.AddSingleton<BusinessServiceFactory>();
  67. services.AddHostedService<ProtalServer>();
  68. })
  69. .Build();
  70. host.Run();
  71. //ProtalServer s = new ProtalServer();
  72. //Console.WriteLine("Starting Server...");
  73. //s.Start();
  74. //Console.Read();
  75. }
  76. public static object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
  77. {
  78. DateTime? timevalue = null;
  79. if (reader.Value != null)
  80. {
  81. DateTime date = ((DateTime)reader.Value).ToLocalTime();
  82. timevalue = new DateTime(date.Year, date.Month, date.Day, date.TimeOfDay.Hours, date.TimeOfDay.Minutes, date.TimeOfDay.Seconds, 000);
  83. }
  84. return timevalue;
  85. }
  86. }
  87. }