|
@@ -5,21 +5,16 @@ using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Linq;
|
|
|
using System.Net;
|
|
|
-using System.Net.Http;
|
|
|
using Newtonsoft.Json;
|
|
|
using System.Threading.Tasks;
|
|
|
using EVCB_OCPP.WEBAPI.Models.WebAPI.Dto;
|
|
|
-using System.Net.Http.Headers;
|
|
|
using EVCB_OCPP.Packet.Messages.SubTypes;
|
|
|
-using System.Security.Cryptography.X509Certificates;
|
|
|
-using OCPPPackage.Profiles;
|
|
|
-using EVCB_OCPP.Packet.Messages.Core;
|
|
|
-using EVCB_OCPP.Packet.Messages;
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
using Microsoft.AspNetCore.Http.Extensions;
|
|
|
using Microsoft.Extensions.Configuration;
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
+using Microsoft.Extensions.Logging;
|
|
|
|
|
|
namespace EVCB_OCPP.WEBAPI.Controllers.Version1
|
|
|
{
|
|
@@ -30,19 +25,20 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
|
|
|
[Route("api/v1/cpo")]
|
|
|
public class CPOController : ControllerBase
|
|
|
{
|
|
|
- private HttpClientService service = new HttpClientService();
|
|
|
private readonly IServiceProvider serviceProvider;
|
|
|
+ private readonly ILogger<CPOController> logger;
|
|
|
|
|
|
- public CPOController(IServiceProvider serviceProvider, IConfiguration configuration)
|
|
|
+ public CPOController(IServiceProvider serviceProvider, IConfiguration configuration, ILogger<CPOController> logger)
|
|
|
{
|
|
|
this.serviceProvider = serviceProvider;
|
|
|
+ this.logger = logger;
|
|
|
}
|
|
|
|
|
|
private bool ContainsChargePoint(string chargeBoxId, out string customerId)
|
|
|
{
|
|
|
customerId = string.Empty;
|
|
|
|
|
|
- if (!Request.Headers.Keys.Contains(EVCBConfiguration.Header_PartnerId)) return false;
|
|
|
+ if (!Request.Headers.ContainsKey(EVCBConfiguration.Header_PartnerId)) return false;
|
|
|
|
|
|
customerId = Request.Headers[EVCBConfiguration.Header_PartnerId].First();
|
|
|
|
|
@@ -60,7 +56,7 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
|
|
|
int statusCode = StatusCodes.Status500InternalServerError;
|
|
|
try
|
|
|
{
|
|
|
- if (Request.Headers.Keys.Contains(EVCBConfiguration.Header_PartnerId))
|
|
|
+ if (Request.Headers.ContainsKey(EVCBConfiguration.Header_PartnerId))
|
|
|
{
|
|
|
var _customerId = Request.Headers[EVCBConfiguration.Header_PartnerId].First();
|
|
|
ChargingStationService _service = serviceProvider.GetRequiredService<ChargingStationService>();
|
|
@@ -97,7 +93,7 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
|
|
|
{
|
|
|
ChargePointService _CPService = serviceProvider.GetRequiredService<ChargePointService>();// new ChargePointService();
|
|
|
var tt = _CPService.GetLastUpdatedTimebyMachineId("0da4f4a6-a952-46f0-b2f3-696385a9a56a");
|
|
|
- if (Request.Headers.Keys.Contains(EVCBConfiguration.Header_PartnerId))
|
|
|
+ if (Request.Headers.ContainsKey(EVCBConfiguration.Header_PartnerId))
|
|
|
{
|
|
|
var _customerId = Request.Headers[EVCBConfiguration.Header_PartnerId].First();
|
|
|
|
|
@@ -1262,7 +1258,7 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- List<ActiveSession> _innerData = new List<ActiveSession>();
|
|
|
+ List<ActiveSession> _innerData = new();
|
|
|
|
|
|
foreach (var transactionData in transactionDatas)
|
|
|
{
|
|
@@ -1292,9 +1288,9 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
|
|
|
Currency = currencyText
|
|
|
});
|
|
|
decimal energy = decimal.Parse(_innerData[_innerData.Count - 1].Energy);
|
|
|
- energy = _innerData[_innerData.Count - 1].Energy_Format == UnitOfMeasure.Wh.ToString() ? Decimal.Divide(energy, 1000) : energy;
|
|
|
- _innerData[_innerData.Count - 1].Energy = energy.ToString("0.000");
|
|
|
- _innerData[_innerData.Count - 1].Energy_Format = UnitOfMeasure.kWh.ToString();
|
|
|
+ energy = _innerData[^1].Energy_Format == UnitOfMeasure.Wh.ToString() ? Decimal.Divide(energy, 1000) : energy;
|
|
|
+ _innerData[^1].Energy = energy.ToString("0.000");
|
|
|
+ _innerData[^1].Energy_Format = UnitOfMeasure.kWh.ToString();
|
|
|
}
|
|
|
var _innerResponse = new { Sessions = _innerData };
|
|
|
result.Data = JsonConvert.SerializeObject(_innerResponse, EVCBConfiguration.JSONSERIALIZER_FORMAT);
|
|
@@ -1389,7 +1385,7 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
|
|
|
var result = new CPOOuterResponse();
|
|
|
//HttpStatusCode statusCode = HttpStatusCode.InternalServerError;
|
|
|
int statusCode = StatusCodes.Status500InternalServerError;
|
|
|
- var _innerData = new { Result = CommandResponseType.Rejected.ToString(), Timeout = 60 };
|
|
|
+ //var _innerData = new { Result = CommandResponseType.Rejected.ToString(), Timeout = 60 };
|
|
|
try
|
|
|
{
|
|
|
|
|
@@ -1424,6 +1420,8 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
+ logger.LogWarning(_innerresult.Exception, _innerresult.Response);
|
|
|
+
|
|
|
result.StatusCode = (int)CPO_StatusCode.CANT_FOUND_DATA;
|
|
|
result.StatusMessage = CPO_StatusMessage.ERROR_MSG_INNERSERVICE_ERROR;
|
|
|
//statusCode = HttpStatusCode.BadRequest;
|