WsClientData.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. 
  2. using EVCB_OCPP.Packet.Messages.Basic;
  3. using EVCB_OCPP.WSServer.Dto;
  4. namespace EVCB_OCPP.WSServer.Service.WsService
  5. {
  6. public class WsClientData : WsSession
  7. { /// <summary>
  8. /// 根據unique id來儲存.取出OCPP Request
  9. /// </summary>
  10. public Queue queue = new Queue();
  11. public EVCB_OCPP20.Packet.Messages.Basic.Queue queue20 = new EVCB_OCPP20.Packet.Messages.Basic.Queue();
  12. public bool? IsPending { set; get; }
  13. public bool IsCheckIn { set; get; } = false;
  14. public string ChargeBoxId { set; get; }
  15. public Guid CustomerId { get; set; }
  16. public string MachineId { set; get; }
  17. public bool ISOCPP20 { set; get; }
  18. public bool ResetSecurityProfile { set; get; }
  19. public bool IsAC { set; get; } = true;
  20. #region Billing
  21. public Dictionary<string, string> UserPrices { set; get; } = new Dictionary<string, string>();
  22. public Dictionary<string, string> UserDisplayPrices { set; get; } = new Dictionary<string, string>();
  23. public List<ChargingPrice> ChargingPrices { set; get; }
  24. /// <summary>
  25. /// 電樁顯示費率
  26. /// </summary>
  27. public string DisplayPrice { set; get; }
  28. /// <summary>
  29. /// 充電費率 以小時計費
  30. /// </summary>
  31. public decimal ChargingFeebyHour { set; get; }
  32. /// <summary>
  33. /// 停車費率 以小時計費
  34. /// </summary>
  35. public decimal ParkingFee { set; get; }
  36. /// <summary>
  37. /// 電樁是否計費
  38. /// </summary>
  39. public bool IsBilling { set; get; }
  40. /// <summary>
  41. /// 收費方式 1: 以度計費 2:以小時計費
  42. /// </summary>
  43. public int BillingMethod { set; get; }
  44. /// <summary>
  45. /// 電樁適用幣別
  46. /// </summary>
  47. public string Currency { get; internal set; }
  48. #endregion
  49. public string CustomerName { get; set; }
  50. public string StationId { set; get; }
  51. public event EventHandler<string> m_ReceiveData;
  52. private string stringBuffer = string.Empty;
  53. public WsClientData()
  54. {
  55. ChargeBoxId = SessionID;
  56. MachineId = SessionID;
  57. }
  58. internal override void HandleReceivedData(string data)
  59. {
  60. stringBuffer += data;
  61. while (TryGetOCPPMsg(ref stringBuffer, out var msg))
  62. {
  63. m_ReceiveData?.Invoke(this, msg);
  64. }
  65. }
  66. private bool TryGetOCPPMsg(ref string buffer, out string msg)
  67. {
  68. msg = string.Empty;
  69. int? startIndex = null;
  70. int? stopIndex = null;
  71. uint cnt = 0;
  72. for (int index = 0; index < buffer.Length; index++)
  73. {
  74. if (buffer[index] == '[')
  75. {
  76. cnt++;
  77. if (startIndex == null)
  78. {
  79. startIndex = index;
  80. }
  81. }
  82. if (startIndex != null && buffer[index] == ']')
  83. {
  84. cnt--;
  85. }
  86. if (startIndex != null && cnt == 0)
  87. {
  88. stopIndex = index;
  89. break;
  90. }
  91. }
  92. if (startIndex is not null && stopIndex is not null)
  93. {
  94. msg = buffer.Substring(startIndex.Value, stopIndex.Value - startIndex.Value);
  95. buffer = buffer.Substring(stopIndex.Value);
  96. return true;
  97. }
  98. return false;
  99. }
  100. }
  101. }