|
@@ -72,7 +72,7 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
|
|
|
[Route("information")]
|
|
|
[ResponseType(typeof(CPOOuterResponse))]
|
|
|
[HttpGet]
|
|
|
- public HttpResponseMessage BasicInformationofEVSEs(int StationId, DateTime? DateFrom = null, DateTime? DateTo = null, int? Offset = 0, int? Limit = 1)
|
|
|
+ public HttpResponseMessage BasicInformationofEVSEs(int StationId = -1, string ChargeBoxId = "", DateTime? DateFrom = null, DateTime? DateTo = null, int? Offset = 0, int? Limit = 1)
|
|
|
{
|
|
|
|
|
|
var result = new CPOOuterResponse();
|
|
@@ -88,23 +88,34 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
|
|
|
var _innerResponse = new { EVSEs = new List<EVSE>() };
|
|
|
ChargingStationService _stationService = new ChargingStationService();
|
|
|
|
|
|
- if (_stationService.ContainsStation(_customerId, StationId))
|
|
|
+ if (StationId > -1)
|
|
|
{
|
|
|
- if (DateTo.HasValue)
|
|
|
+ if (_stationService.ContainsStation(_customerId, StationId))
|
|
|
{
|
|
|
- if (!DateFrom.HasValue)
|
|
|
+ if (DateTo.HasValue)
|
|
|
{
|
|
|
-
|
|
|
- result.StatusMessage = CPO_StatusMessage.ERROR_MSG_PARAMETER_OUTOFRANGE_INCORRECT;
|
|
|
- result.StatusCode = (int)CPO_StatusCode.PARAMETER_OUTOFRANGE_INCORRECT;
|
|
|
- statusCode = HttpStatusCode.BadRequest;
|
|
|
- return Request.CreateResponse(statusCode, result);
|
|
|
+ if (!DateFrom.HasValue)
|
|
|
+ {
|
|
|
+
|
|
|
+ result.StatusMessage = CPO_StatusMessage.ERROR_MSG_PARAMETER_OUTOFRANGE_INCORRECT;
|
|
|
+ result.StatusCode = (int)CPO_StatusCode.PARAMETER_OUTOFRANGE_INCORRECT;
|
|
|
+ statusCode = HttpStatusCode.BadRequest;
|
|
|
+ return Request.CreateResponse(statusCode, result);
|
|
|
+ }
|
|
|
}
|
|
|
+ _innerResponse = new { EVSEs = _stationService.GetEVSEsbyStationId(StationId, DateFrom, DateTo, Offset.Value, Limit.Value) };
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
- _innerResponse = new { EVSEs = _stationService.GetEVSEsbyStationId(StationId, DateFrom, DateTo, Offset.Value, Limit.Value) };
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ _innerResponse = new { EVSEs = new List<EVSE>() };
|
|
|
+ _innerResponse.EVSEs.Add(_CPService.GetEVSEsbyChargeBoxId(ChargeBoxId, DateFrom, DateTo));
|
|
|
|
|
|
|
|
|
}
|
|
|
+
|
|
|
result.Data = JsonConvert.SerializeObject(_innerResponse, EVCBConfiguration.JSONSERIALIZER_FORMAT);
|
|
|
result.StatusCode = (int)CPO_StatusCode.Success;
|
|
|
result.StatusMessage = CPO_StatusMessage.Success;
|
|
@@ -166,9 +177,10 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
|
|
|
IdTag = request.Token
|
|
|
};
|
|
|
|
|
|
- string urlformat = "http://localhost:{0}/api/v1/ocpp16/transaction?ChargeBoxId={1}";
|
|
|
+ string[] parts = Request.RequestUri.ToString().Split('/');
|
|
|
+ string urlformat = "{0}//{1}/api/v1/ocpp16/transaction?ChargeBoxId={3}";
|
|
|
|
|
|
- var _innerResult = await _client.Post(string.Format(urlformat, Request.RequestUri.Port, request.ChargeBoxId), new Dictionary<string, string>()
|
|
|
+ var _innerResult = await _client.Post(string.Format(urlformat, parts[0], parts[2], Request.RequestUri.Port, request.ChargeBoxId), new Dictionary<string, string>()
|
|
|
{
|
|
|
{ "PartnerId",_CustomerId}
|
|
|
|
|
@@ -179,23 +191,24 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
|
|
|
result = GetErrorDescription(_innerResult);
|
|
|
result.Data = JsonConvert.SerializeObject(_innerData, EVCBConfiguration.JSONSERIALIZER_FORMAT);
|
|
|
|
|
|
- if (_innerResult.Success)
|
|
|
+ if (_innerResult.Status == HttpStatusCode.InternalServerError)
|
|
|
{
|
|
|
- result.SerialNo = _innerResult.SerialNo;
|
|
|
- result.StatusCode = (int)CPO_StatusCode.Success;
|
|
|
- result.StatusMessage = CPO_StatusMessage.Success;
|
|
|
- statusCode = HttpStatusCode.OK;
|
|
|
|
|
|
+ result.StatusCode = _innerResult.ErrorCode;
|
|
|
+ result.StatusMessage = CPO_StatusMessage.ERROR_MSG_INNERSERVICE_ERROR;
|
|
|
+ statusCode = HttpStatusCode.InternalServerError;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
-
|
|
|
+ result.SerialNo = _innerResult.SerialNo;
|
|
|
result.StatusCode = _innerResult.ErrorCode;
|
|
|
- result.StatusMessage = CPO_StatusMessage.ERROR_MSG_INNERSERVICE_ERROR;
|
|
|
- statusCode = HttpStatusCode.BadRequest;
|
|
|
+ result.StatusMessage = _innerResult.Message;
|
|
|
+ statusCode = HttpStatusCode.OK;
|
|
|
+
|
|
|
}
|
|
|
|
|
|
|
|
|
+
|
|
|
}
|
|
|
else
|
|
|
{
|
|
@@ -247,10 +260,11 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
|
|
|
InternalHttpClient _client = new InternalHttpClient();
|
|
|
CustomerService _customer = new CustomerService();
|
|
|
|
|
|
+ string[] parts = Request.RequestUri.ToString().Split('/');
|
|
|
|
|
|
- string urlformat = "http://localhost:{0}/api/v1/ocpp16/transaction?ChargeBoxId={1}&TransactionId={2}";
|
|
|
+ string urlformat = "{0}//{1}/api/v1/ocpp16/transaction?ChargeBoxId={2}&TransactionId={3}";
|
|
|
|
|
|
- var _innerResult = await _client.Put(string.Format(urlformat, Request.RequestUri.Port, ChargeBoxId, SessionId), new Dictionary<string, string>()
|
|
|
+ var _innerResult = await _client.Put(string.Format(urlformat, parts[0], parts[2], ChargeBoxId, SessionId), new Dictionary<string, string>()
|
|
|
{
|
|
|
{ "PartnerId",_CustomerId}
|
|
|
|
|
@@ -314,7 +328,8 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
|
|
|
InternalHttpClient _client = new InternalHttpClient();
|
|
|
CustomerService _customer = new CustomerService();
|
|
|
|
|
|
- string urlformat = "http://localhost:{0}/api/v1/ocpp16/reservation?ChargeBoxId={1}";
|
|
|
+ string[] parts = Request.RequestUri.ToString().Split('/');
|
|
|
+ string urlformat = "{0}//{1}/api/v1/ocpp16/reservation?ChargeBoxId={2}";
|
|
|
|
|
|
var _innerRequest = new ReserveRequest()
|
|
|
{
|
|
@@ -388,7 +403,9 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
|
|
|
CustomerService _customer = new CustomerService();
|
|
|
|
|
|
|
|
|
- string urlformat = "http://localhost:{0}/api/v1/ocpp16/reservation?ChargeBoxId={1}&ReservationId={2}";
|
|
|
+ string[] parts = Request.RequestUri.ToString().Split('/');
|
|
|
+
|
|
|
+ string urlformat = "{0}//{1}/api/v1/ocpp16/reservation?ChargeBoxId={2}&ReservationId={3}";
|
|
|
|
|
|
var _innerResult = await _client.Delete(string.Format(urlformat, Request.RequestUri.Port, ChargeBoxId, ReservationId), new Dictionary<string, string>()
|
|
|
{
|
|
@@ -454,7 +471,9 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
|
|
|
CustomerService _customer = new CustomerService();
|
|
|
|
|
|
|
|
|
- string urlformat = "http://localhost:{0}/api/v1/ocpp16/compositeschedule?ChargeBoxId={1}&ConnectorId={2}&Duration={3}";
|
|
|
+ string[] parts = Request.RequestUri.ToString().Split('/');
|
|
|
+
|
|
|
+ string urlformat = "{0}//{1}/api/v1/ocpp16/compositeschedule?ChargeBoxId={2}&ConnectorId={3}&Duration={4}";
|
|
|
|
|
|
var _innerResult = await _client.Get(string.Format(urlformat, Request.RequestUri.Port, ChargeBoxId, ConnectorId, Duration), new Dictionary<string, string>()
|
|
|
{
|
|
@@ -520,7 +539,9 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
|
|
|
|
|
|
|
|
|
|
|
|
- string urlformat = "http://localhost:{0}/api/v1/ocpp16/chargingprofile?ChargeBoxId={1}";
|
|
|
+ string[] parts = Request.RequestUri.ToString().Split('/');
|
|
|
+
|
|
|
+ string urlformat = "{0}//{1}/api/v1/ocpp16/chargingprofile?ChargeBoxId={2}";
|
|
|
|
|
|
|
|
|
|
|
@@ -587,7 +608,9 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
|
|
|
CustomerService _customer = new CustomerService();
|
|
|
|
|
|
|
|
|
- string urlformat = "http://localhost:{0}/api/v1/ocpp16/chargingprofile?ChargeBoxId={1}{2}";
|
|
|
+ string[] parts = Request.RequestUri.ToString().Split('/');
|
|
|
+
|
|
|
+ string urlformat = "{0}//{1}/api/v1/ocpp16/chargingprofile?ChargeBoxId={2}{3}";
|
|
|
|
|
|
var _innerResult = await _client.Delete(string.Format(urlformat, Request.RequestUri.Port, ChargeBoxId, ChargeProfileId == -1 ? "" : "&Id=" + ChargeProfileId), new Dictionary<string, string>()
|
|
|
{
|
|
@@ -653,7 +676,9 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
|
|
|
|
|
|
|
|
|
|
|
|
- string urlformat = "http://localhost:{0}/api/v1/ocpp16/locallist?ChargeBoxId={1}";
|
|
|
+ string[] parts = Request.RequestUri.ToString().Split('/');
|
|
|
+
|
|
|
+ string urlformat = "{0}//{1}/api/v1/ocpp16/locallist?ChargeBoxId={2}";
|
|
|
|
|
|
|
|
|
|
|
@@ -722,7 +747,9 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
|
|
|
|
|
|
|
|
|
|
|
|
- string urlformat = "http://localhost:{0}/api/v1/ocpp16/locallistversion?ChargeBoxId={1}";
|
|
|
+ string[] parts = Request.RequestUri.ToString().Split('/');
|
|
|
+
|
|
|
+ string urlformat = "{0}//{1}/api/v1/ocpp16/locallistversion?ChargeBoxId={2}";
|
|
|
|
|
|
|
|
|
|
|
@@ -846,7 +873,9 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
|
|
|
}
|
|
|
|
|
|
|
|
|
- string urlformat = "http://localhost:{0}/api/v1/ocpp16/command?ChargeBoxId={1}{2}&SerialNo={3}";
|
|
|
+ string[] parts = Request.RequestUri.ToString().Split('/');
|
|
|
+
|
|
|
+ string urlformat = "{0}//{1}/api/v1/ocpp16/command?ChargeBoxId={2}{3}&SerialNo={4}";
|
|
|
|
|
|
|
|
|
var _innerResult = await _client.Get(string.Format(urlformat, Request.RequestUri.Port, ChargeBoxId, orderNo.HasValue ? "&OrderNo=" + orderNo.Value : "", SerialNo), new Dictionary<string, string>()
|
|
@@ -945,10 +974,41 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
|
|
|
}
|
|
|
|
|
|
|
|
|
+ [Route("version")]
|
|
|
+ [ResponseType(typeof(CPOOuterResponse))]
|
|
|
+ [HttpGet]
|
|
|
+ public HttpResponseMessage Version(string ChargeBoxId)
|
|
|
+ {
|
|
|
+ var result = new CPOOuterResponse();
|
|
|
+ HttpStatusCode statusCode = HttpStatusCode.InternalServerError;
|
|
|
+
|
|
|
+ try
|
|
|
+ {
|
|
|
+ ChargePointService _service = new ChargePointService();
|
|
|
+ string version = _service.GetVersionbyChargeBoxId(ChargeBoxId);
|
|
|
+
|
|
|
+ result.Data = version;
|
|
|
+ result.StatusCode = (int)CPO_StatusCode.Success;
|
|
|
+ result.StatusMessage = CPO_StatusMessage.Success;
|
|
|
+ statusCode = HttpStatusCode.OK;
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ result.ErrorDetail = ex.ToString();
|
|
|
+ result.StatusMessage = CPO_StatusMessage.ERROR_MSG_UNEXPECTEDERROR;
|
|
|
+ result.StatusCode = (int)CPO_StatusCode.UnexpectedError;
|
|
|
+ return Request.CreateResponse(statusCode, result);
|
|
|
+ }
|
|
|
+
|
|
|
+ return Request.CreateResponse(statusCode, result);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
[Route("activesession")]
|
|
|
[ResponseType(typeof(CPOOuterResponse))]
|
|
|
[HttpGet]
|
|
|
- public HttpResponseMessage ActiveSession(string ChargeBoxId, string SessionId)
|
|
|
+ public HttpResponseMessage ActiveSession(string ChargeBoxId, string SessionId = "", string IdTag = "")
|
|
|
{
|
|
|
var result = new CPOOuterResponse();
|
|
|
HttpStatusCode statusCode = HttpStatusCode.InternalServerError;
|
|
@@ -968,15 +1028,15 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
|
|
|
|
|
|
// query meter value
|
|
|
ChargePointService _service = new ChargePointService();
|
|
|
- var _meterValues = _service.GetActiveSessionInfo(ChargeBoxId, SessionId, new List<Packet.Messages.SubTypes.Measurand>()
|
|
|
+ var transactionData = _service.GetActiveSessionInfo(ChargeBoxId, new List<Packet.Messages.SubTypes.Measurand>()
|
|
|
{ Packet.Messages.SubTypes.Measurand.Voltage,
|
|
|
- Packet.Messages.SubTypes.Measurand.Current_Export,
|
|
|
+ Packet.Messages.SubTypes.Measurand.Current_Import,
|
|
|
Packet.Messages.SubTypes.Measurand.SoC,
|
|
|
- Packet.Messages.SubTypes.Measurand.Power_Active_Export,
|
|
|
- Packet.Messages.SubTypes.Measurand.Energy_Active_Export_Interval
|
|
|
- });
|
|
|
+ Packet.Messages.SubTypes.Measurand.Power_Active_Import,
|
|
|
+ Packet.Messages.SubTypes.Measurand.Energy_Active_Import_Interval
|
|
|
+ }, SessionId, IdTag);
|
|
|
|
|
|
- if (_meterValues.Count == 0)
|
|
|
+ if (transactionData == null)
|
|
|
{
|
|
|
result.StatusCode = (int)CPO_StatusCode.CANT_FOUND_DATA;
|
|
|
result.StatusMessage = CPO_StatusMessage.ERROR_MSG_CANT_FIND_RESULT;
|
|
@@ -986,16 +1046,21 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
|
|
|
{
|
|
|
var _innerData = new
|
|
|
{
|
|
|
- Power = _meterValues.Where(x => x.Measurand == Packet.Messages.SubTypes.Measurand.Power_Active_Export).Select(x => x.Value).FirstOrDefault(),
|
|
|
- Power_Format = _meterValues.Where(x => x.Measurand == Packet.Messages.SubTypes.Measurand.Power_Active_Export).Select(x => x.Unit.ToString()).FirstOrDefault(),
|
|
|
- Current = _meterValues.Where(x => x.Measurand == Packet.Messages.SubTypes.Measurand.Current_Export).Select(x => x.Value).FirstOrDefault(),
|
|
|
- Current_Format = _meterValues.Where(x => x.Measurand == Packet.Messages.SubTypes.Measurand.Current_Export).Select(x => x.Unit.ToString()).FirstOrDefault(),
|
|
|
- Energy = _meterValues.Where(x => x.Measurand == Packet.Messages.SubTypes.Measurand.Energy_Active_Export_Interval).Select(x => x.Value).FirstOrDefault(),
|
|
|
- Energy_Format = _meterValues.Where(x => x.Measurand == Packet.Messages.SubTypes.Measurand.Energy_Active_Export_Interval).Select(x => x.Unit.ToString()).FirstOrDefault(),
|
|
|
- Voltage = _meterValues.Where(x => x.Measurand == Packet.Messages.SubTypes.Measurand.Voltage).Select(x => x.Value).FirstOrDefault(),
|
|
|
- Voltage_Format = _meterValues.Where(x => x.Measurand == Packet.Messages.SubTypes.Measurand.Voltage).Select(x => x.Unit.ToString()).FirstOrDefault(),
|
|
|
- SOC = _meterValues.Where(x => x.Measurand == Packet.Messages.SubTypes.Measurand.SoC).Select(x => x.Value).FirstOrDefault(),
|
|
|
- SOC_Format = _meterValues.Where(x => x.Measurand == Packet.Messages.SubTypes.Measurand.SoC).Select(x => x.Unit.ToString()).FirstOrDefault(),
|
|
|
+ ChargeBoxId= ChargeBoxId,
|
|
|
+ SessionId = transactionData.Id,
|
|
|
+ ElaspedTime = (int)DateTime.UtcNow.Subtract(transactionData.StartTime).TotalMinutes,
|
|
|
+ ConnectorId = transactionData.ConnectorId,
|
|
|
+ IdTag = transactionData.StartIdTag,
|
|
|
+ Power = transactionData.MeterValues.Where(x => x.Measurand == Packet.Messages.SubTypes.Measurand.Power_Active_Import).Select(x => x.Value).FirstOrDefault(),
|
|
|
+ Power_Format = transactionData.MeterValues.Where(x => x.Measurand == Packet.Messages.SubTypes.Measurand.Power_Active_Import).Select(x => x.Unit.ToString()).FirstOrDefault(),
|
|
|
+ Current = transactionData.MeterValues.Where(x => x.Measurand == Packet.Messages.SubTypes.Measurand.Current_Import).Select(x => x.Value).FirstOrDefault(),
|
|
|
+ Current_Format = transactionData.MeterValues.Where(x => x.Measurand == Packet.Messages.SubTypes.Measurand.Current_Import).Select(x => x.Unit.ToString()).FirstOrDefault(),
|
|
|
+ Energy = transactionData.MeterValues.Where(x => x.Measurand == Packet.Messages.SubTypes.Measurand.Energy_Active_Import_Interval).Select(x => x.Value).FirstOrDefault(),
|
|
|
+ Energy_Format = transactionData.MeterValues.Where(x => x.Measurand == Packet.Messages.SubTypes.Measurand.Energy_Active_Import_Interval).Select(x => x.Unit.ToString()).FirstOrDefault(),
|
|
|
+ Voltage = transactionData.MeterValues.Where(x => x.Measurand == Packet.Messages.SubTypes.Measurand.Voltage).Select(x => x.Value).FirstOrDefault(),
|
|
|
+ Voltage_Format = transactionData.MeterValues.Where(x => x.Measurand == Packet.Messages.SubTypes.Measurand.Voltage).Select(x => x.Unit.ToString()).FirstOrDefault(),
|
|
|
+ SOC = transactionData.MeterValues.Where(x => x.Measurand == Packet.Messages.SubTypes.Measurand.SoC).Select(x => x.Unit.ToString()).FirstOrDefault()==null?null: transactionData.MeterValues.Where(x => x.Measurand == Packet.Messages.SubTypes.Measurand.SoC).Select(x => x.Value).FirstOrDefault(),
|
|
|
+ SOC_Format = transactionData.MeterValues.Where(x => x.Measurand == Packet.Messages.SubTypes.Measurand.SoC).Select(x => x.Unit.ToString()).FirstOrDefault(),
|
|
|
};
|
|
|
|
|
|
result.Data = JsonConvert.SerializeObject(_innerData, EVCBConfiguration.JSONSERIALIZER_FORMAT);
|
|
@@ -1020,7 +1085,7 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
|
|
|
[Route("completedsession")]
|
|
|
[ResponseType(typeof(CPOOuterResponse))]
|
|
|
[HttpGet]
|
|
|
- public HttpResponseMessage CompletedSession(string ChargeBoxId, string SessionId)
|
|
|
+ public HttpResponseMessage CompletedSession(string ChargeBoxId, string SessionId = "", string IdTag = "", DateTime SearchTime = new DateTime())
|
|
|
{
|
|
|
var result = new CPOOuterResponse();
|
|
|
HttpStatusCode statusCode = HttpStatusCode.InternalServerError;
|
|
@@ -1040,11 +1105,10 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
|
|
|
|
|
|
// query meter value
|
|
|
ChargePointService _service = new ChargePointService();
|
|
|
- var _innerData = _service.GetSessionDetail(ChargeBoxId, SessionId);
|
|
|
+ var _innerData = _service.GetSessionDetail(ChargeBoxId, SessionId, IdTag, SearchTime);
|
|
|
|
|
|
if (_innerData == null)
|
|
|
{
|
|
|
-
|
|
|
result.StatusCode = (int)CPO_StatusCode.CANT_FOUND_DATA;
|
|
|
result.StatusMessage = CPO_StatusMessage.ERROR_MSG_CANT_FIND_SESSIONDETAIL;
|
|
|
statusCode = HttpStatusCode.NotFound;
|
|
@@ -1327,9 +1391,9 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
|
|
|
if (_innerresult.StatusCode == HttpStatusCode.OK)
|
|
|
{
|
|
|
string titles = "\"Title\":[\"ChargeBox Id\",\"Connector Id\",\"Session Id\",\"DateFrom\",\"DateTo\",\"Duration(sec)\",\"Energy(kWh)\",\"Stop Reason\"],";
|
|
|
-
|
|
|
+
|
|
|
_innerresult.Response = _innerresult.Response.Replace("data", "Session");
|
|
|
- _innerresult.Response= _innerresult.Response.Insert(1, titles);
|
|
|
+ _innerresult.Response = _innerresult.Response.Insert(1, titles);
|
|
|
result.Data = _innerresult.Response;
|
|
|
result.StatusCode = (int)CPO_StatusCode.Success;
|
|
|
result.StatusMessage = CPO_StatusMessage.Success;
|