Program.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. using Apache.NMS;
  2. using Apache.NMS.ActiveMQ;
  3. using Apache.NMS.Util;
  4. using Serilog;
  5. using System.Runtime.InteropServices;
  6. using wms.console;
  7. Console.WriteLine("主程序开始执行");
  8. // See https://aka.ms/new-console-template for more information
  9. Log.Logger = new LoggerConfiguration()
  10. .MinimumLevel.Information()
  11. //.WriteTo.Console()
  12. .WriteTo.File($"logs\\log.txt",
  13. rollingInterval: RollingInterval.Day,
  14. rollOnFileSizeLimit:true,
  15. shared:true,
  16. fileSizeLimitBytes: 102400000,
  17. outputTemplate: "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} {SourceContext} {ThreadId} [{Level:u3}] {Message:lj}{NewLine}{Exception}"
  18. )
  19. .CreateLogger();
  20. string fjqueuesName = "ESB.OUT.163LFJ.Q";//分拣队列
  21. string sxqueuesName = "ESB.OUT.163KSX.Q";//时效队列
  22. string cpqueuesName = "ESB.OUT.163JCP.Q";//成品队列
  23. string ptqueuesName = "ESB.OUT.163IPT.Q";//盘条队列
  24. string hjqueuesName = "ESB.OUT.163DHJ.Q";//盘条队列
  25. var fjcon = new HouseConsumer(fjqueuesName);
  26. var sxcon = new HouseConsumer(sxqueuesName);
  27. var cpcon = new HouseConsumer(cpqueuesName);
  28. var ptcon = new HouseConsumer(ptqueuesName);
  29. var hjcon = new HouseConsumer(hjqueuesName);
  30. fjcon.CreateConsumer();
  31. sxcon.CreateConsumer();
  32. cpcon.CreateConsumer();
  33. ptcon.CreateConsumer();
  34. hjcon.CreateConsumer();
  35. Console.WriteLine("主程序启动完成");
  36. Timer timer = new Timer(RestartProgram, null, TimeSpan.FromSeconds(0), TimeSpan.FromSeconds(1));
  37. AppDomain.CurrentDomain.ProcessExit += (object? sender, EventArgs e) => {
  38. Log.Information("控制台关闭");
  39. fjcon?.Stop();
  40. sxcon?.Stop();
  41. cpcon?.Stop();
  42. ptcon?.Stop();
  43. hjcon?.Stop();
  44. };
  45. while (!Console.ReadLine().ToUpper().Contains("CLOSE")) continue;
  46. Environment.Exit(0);
  47. static void RestartProgram(object state)
  48. {
  49. var curtime = DateTime.Now;
  50. if (curtime.DayOfWeek == DayOfWeek.Wednesday && curtime.Hour == 10 && curtime.Minute == 0 && curtime.Second == 0)
  51. {
  52. Console.WriteLine("消息接收程序自动停止");
  53. Environment.Exit(0);
  54. }
  55. }