ClientData.cs 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. 
  2. using EVCB_OCPP.Packet.Messages.Basic;
  3. using EVCB_OCPP.WSServer.Dto;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Collections.ObjectModel;
  7. using System.Threading.Tasks;
  8. using SuperWebSocket;
  9. using SuperSocket.SocketBase;
  10. using EVCB_OCPP.WSServer.Service;
  11. using System.Net.WebSockets;
  12. namespace OCPPServer.Protocol
  13. {
  14. public class WsClientData : WsSession
  15. { /// <summary>
  16. /// 根據unique id來儲存.取出OCPP Request
  17. /// </summary>
  18. public Queue queue = new Queue();
  19. public EVCB_OCPP20.Packet.Messages.Basic.Queue queue20 = new EVCB_OCPP20.Packet.Messages.Basic.Queue();
  20. public bool? IsPending { set; get; }
  21. public bool IsCheckIn { set; get; } = false;
  22. public string ChargeBoxId { set; get; }
  23. public Guid CustomerId { get; set; }
  24. public string MachineId { set; get; }
  25. public bool ISOCPP20 { set; get; }
  26. public bool ResetSecurityProfile { set; get; }
  27. public bool IsAC { set; get; } = true;
  28. #region Billing
  29. public Dictionary<string, string> UserPrices { set; get; } = new Dictionary<string, string>();
  30. public Dictionary<string, string> UserDisplayPrices { set; get; } = new Dictionary<string, string>();
  31. public List<ChargingPrice> ChargingPrices { set; get; }
  32. /// <summary>
  33. /// 電樁顯示費率
  34. /// </summary>
  35. public string DisplayPrice { set; get; }
  36. /// <summary>
  37. /// 充電費率 以小時計費
  38. /// </summary>
  39. public decimal ChargingFeebyHour { set; get; }
  40. /// <summary>
  41. /// 停車費率 以小時計費
  42. /// </summary>
  43. public decimal ParkingFee { set; get; }
  44. /// <summary>
  45. /// 電樁是否計費
  46. /// </summary>
  47. public bool IsBilling { set; get; }
  48. /// <summary>
  49. /// 收費方式 1: 以度計費 2:以小時計費
  50. /// </summary>
  51. public int BillingMethod { set; get; }
  52. /// <summary>
  53. /// 電樁適用幣別
  54. /// </summary>
  55. public string Currency { get; internal set; }
  56. #endregion
  57. public string CustomerName { get; set; }
  58. public string StationId { set; get; }
  59. public event ClientData.OCPPClientDataEventHandler<WsClientData, string> m_ReceiveData;
  60. public WsClientData()
  61. {
  62. ChargeBoxId = SessionID;
  63. MachineId = SessionID;
  64. }
  65. /// <summary>
  66. /// Sends the raw binary data to client.
  67. /// </summary>
  68. /// <param name="data">The data.</param>
  69. /// <param name="offset">The offset.</param>
  70. /// <param name="length">The length.</param>
  71. public void SendRawData(byte[] data, int offset, int length)
  72. {
  73. base.Send(data, offset, length);
  74. }
  75. internal override void HandleReceivedData(string msg)
  76. {
  77. m_ReceiveData?.Invoke(this, msg);
  78. }
  79. }
  80. public class ClientData : WebSocketSession<ClientData>
  81. { /// <summary>
  82. /// 根據unique id來儲存.取出OCPP Request
  83. /// </summary>
  84. public Queue queue = new Queue();
  85. public EVCB_OCPP20.Packet.Messages.Basic.Queue queue20 = new EVCB_OCPP20.Packet.Messages.Basic.Queue();
  86. public bool? IsPending { set; get; }
  87. public bool IsCheckIn { set; get; }
  88. public string ChargeBoxId { set; get; }
  89. public Guid CustomerId { get; set; }
  90. public string MachineId { set; get; }
  91. public bool ISOCPP20 { set; get; }
  92. public bool ResetSecurityProfile { set; get; }
  93. public bool IsAC { set; get; }
  94. #region Billing
  95. public Dictionary<string,string> UserPrices { set; get; }
  96. public Dictionary<string, string> UserDisplayPrices { set; get; }
  97. public List<ChargingPrice> ChargingPrices { set; get; }
  98. /// <summary>
  99. /// 電樁顯示費率
  100. /// </summary>
  101. public string DisplayPrice { set; get; }
  102. /// <summary>
  103. /// 充電費率 以小時計費
  104. /// </summary>
  105. public decimal ChargingFeebyHour { set; get; }
  106. /// <summary>
  107. /// 停車費率 以小時計費
  108. /// </summary>
  109. public decimal ParkingFee { set; get; }
  110. /// <summary>
  111. /// 電樁是否計費
  112. /// </summary>
  113. public bool IsBilling { set; get; }
  114. /// <summary>
  115. /// 收費方式 1: 以度計費 2:以小時計費
  116. /// </summary>
  117. public int BillingMethod { set; get; }
  118. /// <summary>
  119. /// 電樁適用幣別
  120. /// </summary>
  121. public string Currency { get; internal set; }
  122. #endregion
  123. public string CustomerName { get; set; }
  124. public string StationId { set; get; }
  125. public delegate void OCPPClientDataEventHandler<ClientData, String>(ClientData clientdata, String msg);
  126. public event OCPPClientDataEventHandler<ClientData, String> m_ReceiveData;
  127. public ClientData()
  128. {
  129. IsAC = true;
  130. IsCheckIn = false;
  131. ChargeBoxId = SessionID;
  132. MachineId = SessionID;
  133. UserPrices = new Dictionary<string, string>();
  134. UserDisplayPrices = new Dictionary<string, string>();
  135. }
  136. /// <summary>
  137. /// Sends the raw binary data to client.
  138. /// </summary>
  139. /// <param name="data">The data.</param>
  140. /// <param name="offset">The offset.</param>
  141. /// <param name="length">The length.</param>
  142. public void SendRawData(byte[] data, int offset, int length)
  143. {
  144. base.Send(data, offset, length);
  145. }
  146. //receive data event trigger
  147. public void ReceiveData(ClientData clientdata, string msg)
  148. {
  149. if (m_ReceiveData != null)
  150. m_ReceiveData(clientdata, msg);
  151. }
  152. /// <summary>
  153. /// Called when [session closed].
  154. /// </summary>
  155. /// <param name="reason">The reason.</param>
  156. protected override void OnSessionClosed(CloseReason reason)
  157. {
  158. }
  159. }
  160. }