LocalAuthListManagementProfileHandler.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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.Collections.Generic;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. namespace EVCB_OCPP.WSServer.Message
  12. {
  13. internal partial class ProfileHandler
  14. {
  15. internal MessageResult ExecuteLocalAuthListManagementConfirm(Actions action, ClientData session, IConfirmation confirm, string requestId)
  16. {
  17. MessageResult result = new MessageResult() { Success = true };
  18. switch (action)
  19. {
  20. case Actions.GetLocalListVersion:
  21. {
  22. GetLocalListVersionConfirmation _confirm = confirm as GetLocalListVersionConfirmation;
  23. GetLocalListVersionRequest _request = _confirm.GetRequest() as GetLocalListVersionRequest;
  24. using (var db = new MainDBContext())
  25. {
  26. var operation = db.MachineOperateRecord.Where(x => x.SerialNo == requestId &&
  27. x.ChargeBoxId == session.ChargeBoxId && x.Status == 0).FirstOrDefault();
  28. if (operation != null)
  29. {
  30. operation.FinishedOn = DateTime.Now;
  31. operation.Status = 1;//電樁有回覆
  32. operation.EVSE_Status = 1;//OK
  33. operation.EVSE_Value = _confirm.listVersion.ToString();
  34. db.SaveChanges();
  35. }
  36. }
  37. }
  38. break;
  39. case Actions.SendLocalList:
  40. {
  41. SendLocalListConfirmation _confirm = confirm as SendLocalListConfirmation;
  42. SendLocalListRequest _request = _confirm.GetRequest() as SendLocalListRequest;
  43. using (var db = new MainDBContext())
  44. {
  45. var operation = db.MachineOperateRecord.Where(x => x.SerialNo == requestId &&
  46. x.ChargeBoxId == session.ChargeBoxId && x.Status == 0).FirstOrDefault();
  47. if (operation != null)
  48. {
  49. operation.FinishedOn = DateTime.Now;
  50. operation.Status = 1;//電樁有回覆
  51. operation.EVSE_Status = (int)_confirm.updateStatus;//OK
  52. db.SaveChanges();
  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 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 = new MainDBContext())
  74. {
  75. var operation = db.MachineOperateRecord.Where(x => x.SerialNo == requestId &&
  76. x.ChargeBoxId == session.ChargeBoxId && x.Status == 0).FirstOrDefault();
  77. if (operation != null)
  78. {
  79. operation.FinishedOn = DateTime.Now;
  80. operation.Status = 1;//電樁有回覆
  81. operation.EVSE_Status = (int)255;//錯誤
  82. operation.EVSE_Value = errorMsg;
  83. db.SaveChanges();
  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. }