Program.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. using EVCB_OCPP.WSServer.Helper;
  18. using Quartz;
  19. using EVCB_OCPP.WSServer.Jobs;
  20. using Microsoft.AspNetCore.Builder;
  21. using EVCB_OCPP.WSServer.Service.WsService;
  22. using EVCB_OCPP.Service;
  23. using Microsoft.AspNetCore.Hosting;
  24. using System.Security.Cryptography.X509Certificates;
  25. using System.Net.Security;
  26. namespace EVCB_OCPP.WSServer
  27. {
  28. class Program
  29. {
  30. static void Main(string[] args)
  31. {
  32. AppContext.SetData("System.Net.Security.TlsCacheSize", 200);
  33. Console.WriteLine("====================================================================================================");
  34. Console.WriteLine("=================" +
  35. "===================================================================================");
  36. Console.WriteLine("== ==");
  37. Console.WriteLine("== ------------ ----------- ------------- ------------- ==");
  38. Console.WriteLine("== --- --- ---- ---------------- ---------------- ==");
  39. Console.WriteLine("== --- --- ---- ---- --- ---- --- ==");
  40. Console.WriteLine("== --- --- ---- ---- --- ---- --- ==");
  41. Console.WriteLine("== --- --- ---- ---- ------------- ---- ------------- ==");
  42. Console.WriteLine("== --- --- ---- ---- ----------- ---- ----------- ==");
  43. Console.WriteLine("== --- --- ---- ---- ---- ==");
  44. Console.WriteLine("== --- --- ---- ---- ---- ==");
  45. Console.WriteLine("== ----------- ----------- ---- ---- ==");
  46. Console.WriteLine("== ==");
  47. Console.WriteLine("====================================================================================================");
  48. Console.WriteLine("====================================================================================================");
  49. ThreadPool.GetMaxThreads(out var workerThreads, out var completionThreads);
  50. Console.WriteLine($"Max ThreadPool workerThreads:{workerThreads} completionThreads:{completionThreads}");
  51. ThreadPool.SetMinThreads((int)(10), (int)(0));
  52. var builder = WebApplication.CreateBuilder(args);
  53. //IHost host = Host.CreateDefaultBuilder(args)
  54. //.UseEnvironment("Development")
  55. //.ConfigureLogging((context, builder) => {
  56. // builder.ClearProviders();
  57. // builder.AddAzureWebAppDiagnostics();
  58. // NLog.LogManager.Configuration = new NLogLoggingConfiguration(context.Configuration.GetSection("NLog"));
  59. //})
  60. //.UseNLog()
  61. builder.Host
  62. .AddLogServcie()
  63. .ConfigureServices((hostContext, services) =>
  64. {
  65. //services.AddSingleton<MeterValueGroupSingleHandler>();
  66. //services.AddSingleton<IHostLifetime, DummyHostLifeTime>();
  67. services.AddProtalServer(hostContext.Configuration);
  68. //services.AddTransient<BlockingTreePrintService>();
  69. //services.AddTransient<GoogleGetTimePrintService>();
  70. });
  71. //.Build();
  72. builder.WebHost.ConfigureKestrel(opt =>
  73. {
  74. opt.ConfigureHttpsDefaults(opt =>
  75. {
  76. opt.ClientCertificateMode = Microsoft.AspNetCore.Server.Kestrel.Https.ClientCertificateMode.AllowCertificate;
  77. opt.ClientCertificateValidation = ValidateClientCertficatel;
  78. });
  79. });
  80. var app = builder.Build();
  81. app.UseHeaderRecordService();
  82. app.UseOcppWsService();
  83. app.MapApiServce();
  84. app.Urls.Add("http://*:80");
  85. app.Run();
  86. //host.Run();
  87. }
  88. public static object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
  89. {
  90. DateTime? timevalue = null;
  91. if (reader.Value != null)
  92. {
  93. DateTime date = ((DateTime)reader.Value).ToLocalTime();
  94. timevalue = new DateTime(date.Year, date.Month, date.Day, date.TimeOfDay.Hours, date.TimeOfDay.Minutes, date.TimeOfDay.Seconds, 000);
  95. }
  96. return timevalue;
  97. }
  98. private static bool ValidateClientCertficatel(X509Certificate2 clientCertificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
  99. {
  100. return true;
  101. }
  102. }
  103. }