LocalAuthListManagementProfileHandler.cs 4.7 KB

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