|
@@ -15,6 +15,8 @@ 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;
|
|
|
|
|
|
namespace EVCB_OCPP.WEBAPI.Controllers.Version1
|
|
|
{
|
|
@@ -175,7 +177,7 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
|
|
|
CustomerService _customer = new CustomerService();
|
|
|
|
|
|
//trigger to charge
|
|
|
- var _request = new StartTransactionRequest()
|
|
|
+ var _request = new Models.WebAPI.StartTransactionRequest()
|
|
|
{
|
|
|
ConnectorId = request.ConnectorId,
|
|
|
IdTag = request.Token
|
|
@@ -343,7 +345,7 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
|
|
|
ExpiryDate = request.ExpiryDate.ToString(EVCBConfiguration.UTC_DATETIMEFORMAT)
|
|
|
};
|
|
|
|
|
|
- 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.ChargeBoxId), new Dictionary<string, string>()
|
|
|
{
|
|
|
{ "PartnerId",_CustomerId}
|
|
|
|
|
@@ -411,7 +413,7 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
|
|
|
|
|
|
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>()
|
|
|
+ var _innerResult = await _client.Delete(string.Format(urlformat, parts[0], parts[2], ChargeBoxId, ReservationId), new Dictionary<string, string>()
|
|
|
{
|
|
|
{ "PartnerId",_CustomerId}
|
|
|
|
|
@@ -479,7 +481,7 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
|
|
|
|
|
|
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>()
|
|
|
+ var _innerResult = await _client.Get(string.Format(urlformat, parts[0], parts[2], ChargeBoxId, ConnectorId, Duration), new Dictionary<string, string>()
|
|
|
{
|
|
|
{ "PartnerId",_CustomerId}
|
|
|
|
|
@@ -538,18 +540,16 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
|
|
|
}
|
|
|
|
|
|
|
|
|
+
|
|
|
InternalHttpClient _client = new InternalHttpClient();
|
|
|
CustomerService _customer = new CustomerService();
|
|
|
|
|
|
|
|
|
-
|
|
|
string[] parts = Request.RequestUri.ToString().Split('/');
|
|
|
|
|
|
string urlformat = "{0}//{1}/api/v1/ocpp16/chargingprofile?ChargeBoxId={2}";
|
|
|
|
|
|
-
|
|
|
-
|
|
|
- var _innerResult = await _client.Post(string.Format(urlformat, Request.RequestUri.Port, ChargeBoxId), new Dictionary<string, string>()
|
|
|
+ var _innerResult = await _client.Post(string.Format(urlformat, parts[0], parts[2], ChargeBoxId), new Dictionary<string, string>()
|
|
|
{
|
|
|
{ "PartnerId",_CustomerId}
|
|
|
|
|
@@ -573,6 +573,14 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
|
|
|
result.StatusMessage = CPO_StatusMessage.ERROR_MSG_INNERSERVICE_ERROR;
|
|
|
statusCode = HttpStatusCode.BadRequest;
|
|
|
}
|
|
|
+ ChargePointService chargePointService = new ChargePointService();
|
|
|
+
|
|
|
+ if (!chargePointService.IsOnline(ChargeBoxId))
|
|
|
+ {
|
|
|
+ return Request.CreateResponse(HttpStatusCode.BadRequest, new ErrorResponse() { Code = 2101, Message = EVCBConfiguration.ERROR_MSG_CHARGEBOXID_ISNT_EXIST_OR_OFFLINE });
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
@@ -616,7 +624,7 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
|
|
|
|
|
|
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>()
|
|
|
+ var _innerResult = await _client.Delete(string.Format(urlformat, parts[0], parts[2], ChargeBoxId, ChargeProfileId == -1 ? "" : "&Id=" + ChargeProfileId), new Dictionary<string, string>()
|
|
|
{
|
|
|
{ "PartnerId",_CustomerId}
|
|
|
|
|
@@ -686,7 +694,7 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
|
|
|
|
|
|
|
|
|
|
|
|
- var _innerResult = await _client.Post(string.Format(urlformat, Request.RequestUri.Port, ChargeBoxId), new Dictionary<string, string>()
|
|
|
+ var _innerResult = await _client.Post(string.Format(urlformat, parts[0], parts[2], ChargeBoxId), new Dictionary<string, string>()
|
|
|
{
|
|
|
{ "PartnerId",_CustomerId}
|
|
|
|
|
@@ -757,7 +765,7 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
|
|
|
|
|
|
|
|
|
|
|
|
- var _innerResult = await _client.Get(string.Format(urlformat, Request.RequestUri.Port, ChargeBoxId), new Dictionary<string, string>()
|
|
|
+ var _innerResult = await _client.Get(string.Format(urlformat, parts[0], parts[2], ChargeBoxId), new Dictionary<string, string>()
|
|
|
{
|
|
|
{ "PartnerId",_CustomerId}
|
|
|
|
|
@@ -871,6 +879,9 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
|
|
|
}
|
|
|
break;
|
|
|
default:
|
|
|
+ {
|
|
|
+ orderNo = 18;
|
|
|
+ }
|
|
|
break;
|
|
|
|
|
|
|
|
@@ -882,7 +893,7 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
|
|
|
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>()
|
|
|
+ var _innerResult = await _client.Get(string.Format(urlformat, parts[0], parts[2], ChargeBoxId, orderNo.HasValue ? "&OrderNo=" + orderNo.Value : "", SerialNo), new Dictionary<string, string>()
|
|
|
{
|
|
|
{ "PartnerId",_CustomerId}
|
|
|
|
|
@@ -1049,7 +1060,7 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
|
|
|
else
|
|
|
{
|
|
|
List<ActiveSession> _innerData = new List<ActiveSession>();
|
|
|
-
|
|
|
+
|
|
|
foreach (var transactionData in transactionDatas)
|
|
|
{
|
|
|
|
|
@@ -1061,7 +1072,7 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
|
|
|
ElaspedTime = (int)DateTime.UtcNow.Subtract(transactionData.StartTime).TotalMinutes,
|
|
|
ConnectorId = transactionData.ConnectorId,
|
|
|
IdTag = transactionData.StartIdTag,
|
|
|
- Power = transactionData.MeterValues==null? "0":transactionData.MeterValues.Where(x => x.Measurand == Packet.Messages.SubTypes.Measurand.Power_Active_Import).Select(x => x.Value).FirstOrDefault(),
|
|
|
+ Power = transactionData.MeterValues == null ? "0" : transactionData.MeterValues.Where(x => x.Measurand == Packet.Messages.SubTypes.Measurand.Power_Active_Import).Select(x => x.Value).FirstOrDefault(),
|
|
|
Power_Format = transactionData.MeterValues == null ? UnitOfMeasure.W.ToString() : transactionData.MeterValues.Where(x => x.Measurand == Packet.Messages.SubTypes.Measurand.Power_Active_Import).Select(x => x.Unit.ToString()).FirstOrDefault(),
|
|
|
Current = transactionData.MeterValues == null ? "0" : transactionData.MeterValues.Where(x => x.Measurand == Packet.Messages.SubTypes.Measurand.Current_Import).Select(x => x.Value).FirstOrDefault(),
|
|
|
Current_Format = transactionData.MeterValues == null ? UnitOfMeasure.A.ToString() : transactionData.MeterValues.Where(x => x.Measurand == Packet.Messages.SubTypes.Measurand.Current_Import).Select(x => x.Unit.ToString()).FirstOrDefault(),
|
|
@@ -1092,12 +1103,12 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
|
|
|
}
|
|
|
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
|
|
|
[Route("completedsession")]
|
|
|
[ResponseType(typeof(CPOOuterResponse))]
|
|
|
[HttpGet]
|
|
|
- public HttpResponseMessage CompletedSession(string ChargeBoxId, string SessionId = "", string IdTag = "",string StartTime="", string StopTime = "")
|
|
|
+ public HttpResponseMessage CompletedSession(string ChargeBoxId, string SessionId = "", string IdTag = "", string StartTime = "", string StopTime = "")
|
|
|
{
|
|
|
var result = new CPOOuterResponse();
|
|
|
HttpStatusCode statusCode = HttpStatusCode.InternalServerError;
|
|
@@ -1115,7 +1126,7 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
|
|
|
return Request.CreateResponse(statusCode, result);
|
|
|
}
|
|
|
|
|
|
- DateTime startDt = string.IsNullOrEmpty(StartTime) ?new DateTime(1991,1,1):DateTime.Parse(StartTime);
|
|
|
+ DateTime startDt = string.IsNullOrEmpty(StartTime) ? new DateTime(1991, 1, 1) : DateTime.Parse(StartTime);
|
|
|
DateTime stopDt = string.IsNullOrEmpty(StopTime) ? new DateTime(1991, 1, 1) : DateTime.Parse(StopTime);
|
|
|
// query meter value
|
|
|
ChargePointService _service = new ChargePointService();
|
|
@@ -1488,6 +1499,212 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
|
|
|
return Request.CreateResponse(statusCode, result);
|
|
|
}
|
|
|
|
|
|
+ #region CDFA
|
|
|
+ [Route("commands/defaulprice")]
|
|
|
+ [ResponseType(typeof(CPOOuterResponse))]
|
|
|
+ [HttpPost]
|
|
|
+ async public Task<HttpResponseMessage> ChargePointDefaultPrice(string ChargeBoxId, [FromBody] ChargePointDefaultPriceRequest request)
|
|
|
+ {
|
|
|
+ var result = new CPOOuterResponse();
|
|
|
+ HttpStatusCode statusCode = HttpStatusCode.InternalServerError;
|
|
|
+ var _innerData = new { Result = CommandResponseType.Rejected.ToString(), Timeout = 60 };
|
|
|
+ try
|
|
|
+ {
|
|
|
+ string _CustomerId = string.Empty;
|
|
|
+
|
|
|
+ if (!ContainsChargePoint(ChargeBoxId, out _CustomerId))
|
|
|
+ {
|
|
|
+ // 沒槍~ 沒得充...
|
|
|
+ result.StatusMessage = CPO_StatusMessage.ERROR_MSG_CHARGEBOXID_DOESNT_EXIST;
|
|
|
+ result.StatusCode = (int)CPO_StatusCode.CHARGEBOXID_ISNT_EXIST_OR_OFFLINE;
|
|
|
+ result.Data = JsonConvert.SerializeObject(_innerData, EVCBConfiguration.JSONSERIALIZER_FORMAT);
|
|
|
+ statusCode = HttpStatusCode.BadRequest;
|
|
|
+ return Request.CreateResponse(statusCode, result);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ ChargePointService chargePointService = new ChargePointService();
|
|
|
+
|
|
|
+ if (!chargePointService.IsOnline(ChargeBoxId))
|
|
|
+ {
|
|
|
+
|
|
|
+ return Request.CreateResponse(HttpStatusCode.BadRequest, new ErrorResponse() { Code = 2101, Message = EVCBConfiguration.ERROR_MSG_CHARGEBOXID_ISNT_EXIST_OR_OFFLINE });
|
|
|
+ }
|
|
|
+ //create reqest
|
|
|
+ var _request = new DataTransferRequest()
|
|
|
+ {
|
|
|
+ messageId = "DefaultPrice",
|
|
|
+ vendorId = "Phihong Technology",
|
|
|
+ data = request.DefaultPrice
|
|
|
+ };
|
|
|
+
|
|
|
+ string uuid = Guid.NewGuid().ToString();
|
|
|
+ if (!AddCommandtoServer(ChargeBoxId, uuid, _request))
|
|
|
+ {
|
|
|
+ throw new Exception("Write Command Fail!!");
|
|
|
+ }
|
|
|
+
|
|
|
+ result.SerialNo = uuid;
|
|
|
+ result.Data = JsonConvert.SerializeObject(new { Result = CommandResponseType.Accepted.ToString(), Timeout = 60 });
|
|
|
+ await Task.Delay(10);
|
|
|
+
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ result.Data = JsonConvert.SerializeObject(_innerData);
|
|
|
+ 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("commands/userprice")]
|
|
|
+ [ResponseType(typeof(CPOOuterResponse))]
|
|
|
+ [HttpPost]
|
|
|
+ async public Task<HttpResponseMessage> UserPrice(string ChargeBoxId, [FromBody] UserPriceRequest request)
|
|
|
+ {
|
|
|
+ var result = new CPOOuterResponse();
|
|
|
+ HttpStatusCode statusCode = HttpStatusCode.InternalServerError;
|
|
|
+ var _innerData = new { Result = CommandResponseType.Rejected.ToString(), Timeout = 60 };
|
|
|
+ try
|
|
|
+ {
|
|
|
+ string _CustomerId = string.Empty;
|
|
|
+
|
|
|
+ if (!ContainsChargePoint(ChargeBoxId, out _CustomerId))
|
|
|
+ {
|
|
|
+ // 沒槍~ 沒得充...
|
|
|
+ result.StatusMessage = CPO_StatusMessage.ERROR_MSG_CHARGEBOXID_DOESNT_EXIST;
|
|
|
+ result.StatusCode = (int)CPO_StatusCode.CHARGEBOXID_ISNT_EXIST_OR_OFFLINE;
|
|
|
+ result.Data = JsonConvert.SerializeObject(_innerData, EVCBConfiguration.JSONSERIALIZER_FORMAT);
|
|
|
+ statusCode = HttpStatusCode.BadRequest;
|
|
|
+ return Request.CreateResponse(statusCode, result);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ ChargePointService chargePointService = new ChargePointService();
|
|
|
+
|
|
|
+ if (!chargePointService.IsOnline(ChargeBoxId))
|
|
|
+ {
|
|
|
+
|
|
|
+ return Request.CreateResponse(HttpStatusCode.BadRequest, new ErrorResponse() { Code = 2101, Message = EVCBConfiguration.ERROR_MSG_CHARGEBOXID_ISNT_EXIST_OR_OFFLINE });
|
|
|
+ }
|
|
|
+ //create reqest
|
|
|
+ var _request = new DataTransferRequest()
|
|
|
+ {
|
|
|
+ messageId = "SetUserPrice",
|
|
|
+ vendorId = "Phihong Technology",
|
|
|
+ data = JsonConvert.SerializeObject(request)
|
|
|
+ };
|
|
|
+
|
|
|
+ string uuid = Guid.NewGuid().ToString();
|
|
|
+ if (!AddCommandtoServer(ChargeBoxId, uuid, _request))
|
|
|
+ {
|
|
|
+ throw new Exception("Write Command Fail!!");
|
|
|
+ }
|
|
|
+
|
|
|
+ result.SerialNo = uuid;
|
|
|
+ result.Data = JsonConvert.SerializeObject(new { Result = CommandResponseType.Accepted.ToString(), Timeout = 60 });
|
|
|
+ await Task.Delay(10);
|
|
|
+
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ result.Data = JsonConvert.SerializeObject(_innerData);
|
|
|
+ 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("commands/finalcost")]
|
|
|
+ [ResponseType(typeof(CPOOuterResponse))]
|
|
|
+ [HttpPost]
|
|
|
+ async public Task<HttpResponseMessage> FinalCost(string ChargeBoxId, [FromBody] FinalCostRequest request)
|
|
|
+ {
|
|
|
+ var result = new CPOOuterResponse();
|
|
|
+ HttpStatusCode statusCode = HttpStatusCode.InternalServerError;
|
|
|
+ var _innerData = new { Result = CommandResponseType.Rejected.ToString(), Timeout = 60 };
|
|
|
+ try
|
|
|
+ {
|
|
|
+ string _CustomerId = string.Empty;
|
|
|
+
|
|
|
+ if (!ContainsChargePoint(ChargeBoxId, out _CustomerId))
|
|
|
+ {
|
|
|
+ // 沒槍~ 沒得充...
|
|
|
+ result.StatusMessage = CPO_StatusMessage.ERROR_MSG_CHARGEBOXID_DOESNT_EXIST;
|
|
|
+ result.StatusCode = (int)CPO_StatusCode.CHARGEBOXID_ISNT_EXIST_OR_OFFLINE;
|
|
|
+ result.Data = JsonConvert.SerializeObject(_innerData, EVCBConfiguration.JSONSERIALIZER_FORMAT);
|
|
|
+ statusCode = HttpStatusCode.BadRequest;
|
|
|
+ return Request.CreateResponse(statusCode, result);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ ChargePointService chargePointService = new ChargePointService();
|
|
|
+
|
|
|
+ if (!chargePointService.IsOnline(ChargeBoxId))
|
|
|
+ {
|
|
|
+
|
|
|
+ return Request.CreateResponse(HttpStatusCode.BadRequest, new ErrorResponse() { Code = 2101, Message = EVCBConfiguration.ERROR_MSG_CHARGEBOXID_ISNT_EXIST_OR_OFFLINE });
|
|
|
+ }
|
|
|
+
|
|
|
+ string text = JsonConvert.SerializeObject(request).Replace("SessionId", "txId");
|
|
|
+ //create reqest
|
|
|
+ var _request = new DataTransferRequest()
|
|
|
+ {
|
|
|
+ messageId = "DefaultPrice",
|
|
|
+ vendorId = "Phihong Technology",
|
|
|
+ data = text
|
|
|
+ };
|
|
|
+
|
|
|
+ string uuid = Guid.NewGuid().ToString();
|
|
|
+ if (!AddCommandtoServer(ChargeBoxId, uuid, _request))
|
|
|
+ {
|
|
|
+ throw new Exception("Write Command Fail!!");
|
|
|
+ }
|
|
|
+
|
|
|
+ result.SerialNo = uuid;
|
|
|
+ result.Data = JsonConvert.SerializeObject(new { Result = CommandResponseType.Accepted.ToString(), Timeout = 60 });
|
|
|
+ await Task.Delay(10);
|
|
|
+
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ result.Data = JsonConvert.SerializeObject(_innerData);
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+ #endregion
|
|
|
+
|
|
|
+
|
|
|
+ private bool AddCommandtoServer(string chargeBoxId, string uuid, IRequest request)
|
|
|
+ {
|
|
|
+ bool result = false;
|
|
|
+ try
|
|
|
+ {
|
|
|
+ ServerTriggerService service = new ServerTriggerService();
|
|
|
+ service.AddMessage(chargeBoxId, uuid, request);
|
|
|
+ result = true;
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ ;
|
|
|
+ }
|
|
|
+
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
private string GetStatisticChargeBoxIds(List<string> chargeBoxIds)
|
|
|
{
|
|
|
string result = JsonConvert.SerializeObject(chargeBoxIds, Formatting.None).Replace("\"", "'");
|