LocalBusinessService.cs 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. using EVCB_OCPP.Packet.Messages.SubTypes;
  2. using EVCB_OCPP.WSServer.Dto;
  3. using Newtonsoft.Json.Linq;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Configuration;
  7. using System.Net;
  8. using System.Threading.Tasks;
  9. namespace EVCB_OCPP.WSServer.Service
  10. {
  11. public class LocalBusinessService : IBusinessService
  12. {
  13. string customerId = string.Empty;
  14. public LocalBusinessService(string customerId)
  15. {
  16. this.customerId = customerId;
  17. }
  18. async public Task<IdTokenInfo> Authorize(string chargeBoxId, string idTag, int? connectorId=-1)
  19. {
  20. await Task.Delay(10);
  21. IdTokenInfo info = new IdTokenInfo() { IdTagInfo = new IdTagInfo() { status = AuthorizationStatus.Invalid } };
  22. try
  23. {
  24. if (customerId.ToUpper() == "009E603C-79CD-4620-A2B8-D9349C0E8AD8")
  25. {
  26. info.IdTagInfo = new IdTagInfo() { status = AuthorizationStatus.Accepted };
  27. return info;
  28. }
  29. OuterHttpClient _client = new OuterHttpClient();
  30. string url = ConfigurationManager.AppSettings["LocalAuthAPI"];
  31. HttpClientService service = new HttpClientService();
  32. Dictionary<string, string> postData = new Dictionary<string, string>()
  33. {
  34. { "ChargeBoxId", chargeBoxId },
  35. { "IdTag", idTag },
  36. };
  37. var _innerresult = await service.PostFormDataAsync(url, postData, null);
  38. if (_innerresult.StatusCode == HttpStatusCode.OK)
  39. {
  40. JObject jo = JObject.Parse(_innerresult.Response);
  41. if (jo["code"].ToString() == "1")
  42. {
  43. try
  44. {
  45. info.IdTagInfo.status = (AuthorizationStatus)Enum.Parse(typeof(AuthorizationStatus), jo["message"].ToString());
  46. }
  47. catch (Exception)
  48. {
  49. ;
  50. }
  51. }
  52. }
  53. }
  54. catch (Exception ex)
  55. {
  56. ;
  57. }
  58. return info;
  59. }
  60. async public Task NotifyConnectorUnplugged(string chargeBoxId, string data)
  61. {
  62. await Task.Delay(10);
  63. }
  64. async public Task NotifyFaultStatus(ErrorDetails details)
  65. {
  66. await Task.Delay(10);
  67. }
  68. }
  69. }