RemoteTriggerHandler.cs 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. using EVCB_OCPP.Domain;
  2. using EVCB_OCPP.Packet.Features;
  3. using EVCB_OCPP.Packet.Messages;
  4. using EVCB_OCPP.Packet.Messages.RemoteTrigger;
  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 ExecuteRemoteTriggerConfirm(Actions action, ClientData session, IConfirmation confirm, string requestId)
  16. {
  17. MessageResult result = new MessageResult() { Success = true };
  18. switch (action)
  19. {
  20. case Actions.TriggerMessage:
  21. {
  22. TriggerMessageConfirmation _confirm = confirm as TriggerMessageConfirmation;
  23. TriggerMessageRequest _request = _confirm.GetRequest() as TriggerMessageRequest;
  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 = (int)_confirm.status;//OK
  33. db.SaveChanges();
  34. }
  35. }
  36. }
  37. break;
  38. default:
  39. {
  40. Console.WriteLine(string.Format("Not Implement {0} Logic", confirm.GetType().ToString().Replace("OCPPPackage.Messages.RemoteTrigger.", "")));
  41. }
  42. break;
  43. }
  44. return result;
  45. }
  46. internal MessageResult ReceivedRemoteTriggerError(Actions action, string errorMsg, ClientData session, string requestId)
  47. {
  48. MessageResult result = new MessageResult() { Success = true };
  49. switch (action)
  50. {
  51. case Actions.TriggerMessage:
  52. {
  53. using (var db = new MainDBContext())
  54. {
  55. var operation = db.MachineOperateRecord.Where(x => x.SerialNo == requestId &&
  56. x.ChargeBoxId == session.ChargeBoxId && x.Status == 0).FirstOrDefault();
  57. if (operation != null)
  58. {
  59. operation.FinishedOn = DateTime.Now;
  60. operation.Status = 1;//電樁有回覆
  61. operation.EVSE_Status = (int)255;//錯誤
  62. operation.EVSE_Value = errorMsg;
  63. db.SaveChanges();
  64. }
  65. }
  66. }
  67. break;
  68. default:
  69. {
  70. Console.WriteLine(string.Format("Not Implement {0} Logic", action));
  71. }
  72. break;
  73. }
  74. return result;
  75. }
  76. }
  77. }