123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- using EVCB_OCPP.Domain.Models.MainDb;
- using EVCB_OCPP.Packet.Messages.SubTypes;
- using EVCB_OCPP.WSServer.Dto;
- using Microsoft.Extensions.Configuration;
- using Newtonsoft.Json.Linq;
- using System;
- using System.Collections.Generic;
- using System.Configuration;
- using System.Net;
- using System.Threading.Tasks;
- namespace EVCB_OCPP.WSServer.Service.BusinessService
- {
- public class LocalBusinessService : IBusinessService
- {
- public string CustomerId { get; set; }
- private readonly IConfiguration configuration;
- private readonly HttpClientService service;
- private readonly OuterHttpClient _client;
- public LocalBusinessService(IConfiguration configuration, HttpClientService service, OuterHttpClient client)
- {
- this.configuration = configuration;
- this.service = service;
- _client = client;
- }
- async public Task<IdTokenInfo> Authorize(string chargeBoxId, string idTag, int? connectorId = null, string source = null)
- {
- await Task.Delay(10);
- IdTokenInfo info = new IdTokenInfo() { IdTagInfo = new IdTagInfo() { status = AuthorizationStatus.Invalid } };
- try
- {
- if (CustomerId.ToUpper() == "009E603C-79CD-4620-A2B8-D9349C0E8AD8")
- {
- info.IdTagInfo = new IdTagInfo() { status = AuthorizationStatus.Accepted };
- return info;
- }
- //OuterHttpClient _client = new OuterHttpClient();
- string url = configuration["LocalAuthAPI"];
- //HttpClientService service = new HttpClientService();
- Dictionary<string, string> postData = new Dictionary<string, string>()
- {
- { "ChargeBoxId", chargeBoxId },
- { "IdTag", idTag },
- };
- var _innerresult = await service.PostFormDataAsync(url, postData, null);
- if (_innerresult.StatusCode == HttpStatusCode.OK)
- {
- JObject jo = JObject.Parse(_innerresult.Response);
- if (jo["code"].ToString() == "1")
- {
- try
- {
- info.IdTagInfo.status = (AuthorizationStatus)Enum.Parse(typeof(AuthorizationStatus), jo["message"].ToString());
- }
- catch (Exception)
- {
- ;
- }
- }
- }
- }
- catch (Exception ex)
- {
- ;
- }
- return info;
- }
- async public Task NotifyConnectorUnplugged(string chargeBoxId, string data)
- {
- await Task.Delay(10);
- }
- async public Task NotifyFaultStatus(ErrorDetails details)
- {
- await Task.Delay(10);
- }
- public ValueTask<NotifyTransactionCompletedResult> NotifyTransactionCompleted(TransactionRecord tx, Dictionary<string, decimal> roundedPeriodEnergy = null)
- {
- return ValueTask.FromResult<NotifyTransactionCompletedResult>(null);
- }
- }
- }
|