LocalAuthListManagementProfileHandler.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. using EVCB_OCPP.Domain;
  2. using EVCB_OCPP.Packet.Features;
  3. using EVCB_OCPP.Packet.Messages;
  4. using EVCB_OCPP.Packet.Messages.LocalAuthListManagement;
  5. using EVCB_OCPP.WSServer.Service.WsService;
  6. using Microsoft.EntityFrameworkCore;
  7. using Microsoft.Extensions.Logging;
  8. using OCPPServer.Protocol;
  9. using System;
  10. using System.Linq;
  11. using System.Threading.Tasks;
  12. namespace EVCB_OCPP.WSServer.Message
  13. {
  14. internal partial class ProfileHandler
  15. {
  16. internal async Task<MessageResult> ExecuteLocalAuthListManagementConfirm(Actions action, WsClientData session, IConfirmation confirm, string requestId)
  17. {
  18. MessageResult result = new MessageResult() { Success = true };
  19. switch (action)
  20. {
  21. case Actions.GetLocalListVersion:
  22. {
  23. GetLocalListVersionConfirmation _confirm = confirm as GetLocalListVersionConfirmation;
  24. GetLocalListVersionRequest _request = _confirm.GetRequest() as GetLocalListVersionRequest;
  25. using (var db = await maindbContextFactory.CreateDbContextAsync())
  26. {
  27. var operation = await db.MachineOperateRecord.Where(x => x.SerialNo == requestId &&
  28. x.ChargeBoxId == session.ChargeBoxId && x.Status == 0).FirstOrDefaultAsync();
  29. if (operation != null)
  30. {
  31. operation.FinishedOn = DateTime.UtcNow;
  32. operation.Status = 1;//電樁有回覆
  33. operation.EVSE_Status = 1;//OK
  34. operation.EVSE_Value = _confirm.listVersion.ToString();
  35. await db.SaveChangesAsync();
  36. }
  37. }
  38. }
  39. break;
  40. case Actions.SendLocalList:
  41. {
  42. SendLocalListConfirmation _confirm = confirm as SendLocalListConfirmation;
  43. SendLocalListRequest _request = _confirm.GetRequest() as SendLocalListRequest;
  44. using (var db = await maindbContextFactory.CreateDbContextAsync())
  45. {
  46. var operation = await db.MachineOperateRecord.Where(x => x.SerialNo == requestId &&
  47. x.ChargeBoxId == session.ChargeBoxId && x.Status == 0).FirstOrDefaultAsync();
  48. if (operation != null)
  49. {
  50. operation.FinishedOn = DateTime.UtcNow;
  51. operation.Status = 1;//電樁有回覆
  52. operation.EVSE_Status = (int)_confirm.status;//OK
  53. operation.EVSE_Value = _confirm.status.ToString();
  54. await db.SaveChangesAsync();
  55. }
  56. }
  57. }
  58. break;
  59. default:
  60. {
  61. logger.LogWarning(string.Format("Not Implement {0} Logic", confirm.GetType().ToString().Replace("OCPPPackage.Messages.RemoteTrigger.", "")));
  62. }
  63. break;
  64. }
  65. return result;
  66. }
  67. internal async Task<MessageResult> ReceivedLocalAuthListManagementError(Actions action, string errorMsg, WsClientData session, string requestId)
  68. {
  69. MessageResult result = new MessageResult() { Success = true };
  70. switch (action)
  71. {
  72. case Actions.SendLocalList:
  73. case Actions.GetLocalListVersion:
  74. {
  75. using (var db = await maindbContextFactory.CreateDbContextAsync())
  76. {
  77. var operation = await db.MachineOperateRecord.Where(x => x.SerialNo == requestId &&
  78. x.ChargeBoxId == session.ChargeBoxId && x.Status == 0).FirstOrDefaultAsync();
  79. if (operation != null)
  80. {
  81. operation.FinishedOn = DateTime.UtcNow;
  82. operation.Status = 1;//電樁有回覆
  83. operation.EVSE_Status = (int)255;//錯誤
  84. operation.EVSE_Value = errorMsg;
  85. await db.SaveChangesAsync();
  86. }
  87. }
  88. }
  89. break;
  90. default:
  91. {
  92. logger.LogWarning(string.Format("Not Implement {0} Logic", action));
  93. }
  94. break;
  95. }
  96. return result;
  97. }
  98. }
  99. }