FDCPOSManager.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Collections.Generic;
  5. using System.Threading;
  6. using System.Reflection;
  7. using System.Runtime.InteropServices;
  8. using System.Net;
  9. using System.Net.Sockets;
  10. using System.Diagnostics;
  11. using Wayne.FDCPOSInterface.Configuration;
  12. using Wayne.FDCPOSLibrary;
  13. using Microsoft.Extensions.Logging;
  14. using Microsoft.Extensions.DependencyInjection;
  15. namespace Wayne.FDCPOSInterface
  16. {
  17. public abstract class FDCPOSManager
  18. {
  19. //[ComVisible(false)]
  20. //public static SINPFileTrace tracer = null;
  21. public Dictionary<string, FDCPOSClient> fdcClientList;
  22. [ComVisible(false)]
  23. public static long messageIdCounter = 1;
  24. [ComVisible(false)]
  25. public bool encryptedHeader;
  26. [ComVisible(false)]
  27. public string forecourtConfiguration;
  28. [ComVisible(false)]
  29. public bool useExtensions;
  30. [ComVisible(false)]
  31. public string certificate;
  32. public FDCPOSManager()
  33. {
  34. encryptedHeader = false;
  35. fdcClientList = new Dictionary<string, FDCPOSClient>();
  36. forecourtConfiguration = "";
  37. FDCGlobal.ProtocolVersion = FDCVersion.V0003;
  38. useExtensions = true;
  39. certificate = certificateType.NONE;
  40. }
  41. public abstract void DisconnectClient(FDCPOSClient fdcposClient);
  42. }
  43. public class FDCPOSInterfaceServerManager : FDCPOSManager
  44. {
  45. //protected static NLog.Logger fdcSocketLogger = NLog.LogManager.LoadConfiguration("nlog.config").GetLogger("FdcServerSocket");
  46. protected ILogger fdcSocketLogger;
  47. //= ServiceBuilder.Provider
  48. //.GetRequiredService<ILoggerFactory>().CreateLogger("FdcServerSocket");
  49. public static string FDCPOSServerApplication = "FDCPOSServer@@@";
  50. public static FDCPOSManager fdcPosManager;
  51. public FDCPOSInterfaceServer fdcPosInterface;
  52. private TcpListener _socketChannelA = null;
  53. [ComVisible(false)]
  54. public TcpListener socketChannelA
  55. {
  56. get { return _socketChannelA; }
  57. set { _socketChannelA = value; }
  58. }
  59. [ComVisible(false)]
  60. public FdcServerTcpHandler FdcServerTcpHandler;
  61. public FDCPOSInterfaceServerManager(IServiceProvider services)
  62. : base()
  63. {
  64. var loggerFactory = services.GetRequiredService<ILoggerFactory>();
  65. this.fdcSocketLogger = loggerFactory.CreateLogger("DynamicPrivate_FdcServerSocket");
  66. }
  67. public override void DisconnectClient(FDCPOSClient fdcPosClient)
  68. {
  69. string fdcClientId = FDCPOSClient.getClientID(fdcPosClient.workstationID, fdcPosClient.applicationSender);
  70. try
  71. {
  72. fdcSocketLogger.LogDebug(" Removing Client: " + fdcClientId + " from client list");
  73. try
  74. {
  75. fdcPosInterface.messages.RemovePendingMessages(fdcClientId);
  76. }
  77. finally
  78. {
  79. fdcPosClient.heartbeat?.Dispose();
  80. fdcClientList.Remove(fdcClientId);
  81. fdcPosManager.fdcClientList.Remove(fdcClientId);
  82. fdcPosInterface.Disconnect(fdcPosClient.workstationID, fdcPosClient.applicationSender);
  83. fdcSocketLogger.LogDebug(" removed Client: " + fdcClientId);
  84. }
  85. }
  86. catch (Exception e)
  87. {
  88. fdcSocketLogger.LogError(" Removing Client: " + fdcClientId + " exceptioned: " + e);
  89. }
  90. }
  91. }
  92. public class FDCPOSConfigurationManager : FDCPOSManager
  93. {
  94. public static FDCPOSConfigurationManager fdcposManager = null;
  95. public ConfigurationInterface configurationInterface;
  96. private TcpListener _socketChannelConfig = null;
  97. [ComVisible(false)]
  98. public TcpListener socketChannelConfig
  99. {
  100. get { return _socketChannelConfig; }
  101. set { _socketChannelConfig = value; }
  102. }
  103. [ComVisible(false)]
  104. public FdcServerTcpHandler respChannelConfigThreadObj;
  105. public FDCPOSConfigurationManager()
  106. : base()
  107. {
  108. }
  109. public override void DisconnectClient(FDCPOSClient fdcposClient)
  110. {
  111. }
  112. }
  113. }