Program.cs 4.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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);
  47. });
  48. services.AddDbContextFactory<MeterValueDBContext>((options) => {
  49. var cString = hostContext.Configuration.GetConnectionString("MeterValueDBContext");
  50. options.UseSqlServer(cString);
  51. });
  52. services.AddDbContextFactory<ConnectionLogDBContext>((options) => {
  53. var cString = hostContext.Configuration.GetConnectionString("ConnectionLogDBContext");
  54. options.UseSqlServer(cString);
  55. });
  56. services.AddScoped<ProfileHandler>();
  57. services.AddScoped<LocalBusinessService>();
  58. services.AddScoped<CPOOuterResponse>();
  59. services.AddSingleton<BusinessServiceFactory>();
  60. services.AddHostedService<ProtalServer>();
  61. })
  62. .Build();
  63. host.Run();
  64. //ProtalServer s = new ProtalServer();
  65. //Console.WriteLine("Starting Server...");
  66. //s.Start();
  67. //Console.Read();
  68. }
  69. public static object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
  70. {
  71. DateTime? timevalue = null;
  72. if (reader.Value != null)
  73. {
  74. DateTime date = ((DateTime)reader.Value).ToLocalTime();
  75. timevalue = new DateTime(date.Year, date.Month, date.Day, date.TimeOfDay.Hours, date.TimeOfDay.Minutes, date.TimeOfDay.Seconds, 000);
  76. }
  77. return timevalue;
  78. }
  79. }
  80. }