LocalBusinessService.cs 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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<IdTagInfo> Authorize(string chargeBoxId, string idTag)
  19. {
  20. await Task.Delay(10);
  21. IdTagInfo info = new IdTagInfo() { status = AuthorizationStatus.Invalid };
  22. try
  23. {
  24. if (customerId.ToUpper() == "009E603C-79CD-4620-A2B8-D9349C0E8AD8")
  25. {
  26. info = 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.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 transactionId, string timestamp)
  61. {
  62. await Task.Delay(10);
  63. }
  64. async public Task NotifyFaultStatus(ErrorDetails details)
  65. {
  66. await Task.Delay(10);
  67. }
  68. }
  69. }