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