LocalBusinessService.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. OuterHttpClient _client = new OuterHttpClient();
  25. string url = ConfigurationManager.AppSettings["LocalAuthAPI"];
  26. HttpClientService service = new HttpClientService();
  27. Dictionary<string, string> postData = new Dictionary<string, string>()
  28. {
  29. { "ChargeBoxId", chargeBoxId },
  30. { "IdTag", idTag },
  31. };
  32. var _innerresult = await service.PostFormDataAsync(url, postData, null);
  33. if (_innerresult.StatusCode == HttpStatusCode.OK)
  34. {
  35. JObject jo = JObject.Parse(_innerresult.Response);
  36. if (jo["code"].ToString() == "1")
  37. {
  38. try
  39. {
  40. info.status = (AuthorizationStatus)Enum.Parse(typeof(AuthorizationStatus), jo["message"].ToString());
  41. }
  42. catch (Exception)
  43. {
  44. ;
  45. }
  46. }
  47. }
  48. }
  49. catch (Exception ex)
  50. {
  51. ;
  52. }
  53. return info;
  54. }
  55. async public Task NotifyConnectorUnplugged(string chargeBoxId, string data)
  56. {
  57. await Task.Delay(10);
  58. }
  59. async public Task NotifyFaultStatus(ErrorDetails details)
  60. {
  61. await Task.Delay(10);
  62. }
  63. }
  64. }