|
@@ -0,0 +1,1116 @@
|
|
|
+using EVCB_OCPP.WEBAPI.Handlers;
|
|
|
+using EVCB_OCPP.WEBAPI.Models.WebAPI;
|
|
|
+using EVCB_OCPP.WEBAPI.Services;
|
|
|
+using System;
|
|
|
+using System.Collections.Generic;
|
|
|
+using System.Linq;
|
|
|
+using System.Net;
|
|
|
+using System.Net.Http;
|
|
|
+using System.Web.Http;
|
|
|
+using System.Web.Http.Description;
|
|
|
+using Newtonsoft.Json;
|
|
|
+using System.Threading.Tasks;
|
|
|
+using EVCB_OCPP.WEBAPI.Models.WebAPI.Dto;
|
|
|
+
|
|
|
+namespace EVCB_OCPP.WEBAPI.Controllers.Version1
|
|
|
+{
|
|
|
+ public class TT
|
|
|
+ {
|
|
|
+ public bool Result { get; set; }
|
|
|
+
|
|
|
+ public int Timeout { set; get; }
|
|
|
+
|
|
|
+ public string Msg { set; get; }
|
|
|
+ }
|
|
|
+
|
|
|
+ [RoutePrefix("api/v1/cpo")]
|
|
|
+ [CPOAuthentication]
|
|
|
+ public class CPOController : ApiController
|
|
|
+ {
|
|
|
+ private HttpClientService service = new HttpClientService();
|
|
|
+
|
|
|
+ private bool ContainsChargePoint(string chargeBoxId, out string customerId)
|
|
|
+ {
|
|
|
+
|
|
|
+ customerId = string.Empty;
|
|
|
+
|
|
|
+ if (!Request.Headers.Contains(EVCBConfiguration.Header_PartnerId)) return false;
|
|
|
+
|
|
|
+ customerId = Request.Headers.GetValues(EVCBConfiguration.Header_PartnerId).First();
|
|
|
+
|
|
|
+ ChargePointService _service = new ChargePointService();
|
|
|
+ return _service.ContainsChargePoint(chargeBoxId, customerId);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ [Route("station")]
|
|
|
+ [ResponseType(typeof(CPOOuterResponse))]
|
|
|
+ [HttpGet]
|
|
|
+ public HttpResponseMessage Station()
|
|
|
+ {
|
|
|
+ var result = new CPOOuterResponse();
|
|
|
+ HttpStatusCode statusCode = HttpStatusCode.InternalServerError;
|
|
|
+ try
|
|
|
+ {
|
|
|
+ if (Request.Headers.Contains(EVCBConfiguration.Header_PartnerId))
|
|
|
+ {
|
|
|
+ var _customerId = Request.Headers.GetValues(EVCBConfiguration.Header_PartnerId).First();
|
|
|
+ ChargingStationService _service = new ChargingStationService();
|
|
|
+ var _innerResponse = new { Stations = _service.GetStationsbyCustomerId(_customerId) };
|
|
|
+ result.Data = JsonConvert.SerializeObject(_innerResponse, EVCBConfiguration.JSONSERIALIZER_FORMAT);
|
|
|
+
|
|
|
+ }
|
|
|
+ return Request.CreateResponse(statusCode, result);
|
|
|
+ }
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ [Route("information")]
|
|
|
+ [ResponseType(typeof(CPOOuterResponse))]
|
|
|
+ [HttpGet]
|
|
|
+ public HttpResponseMessage BasicInformationofEVSEs(string StationId, DateTime? DateFrom = null, DateTime? DateTo = null, int? Offset = 0, int? Limit = 1)
|
|
|
+ {
|
|
|
+
|
|
|
+ var result = new CPOOuterResponse();
|
|
|
+ HttpStatusCode statusCode = HttpStatusCode.InternalServerError;
|
|
|
+ try
|
|
|
+ {
|
|
|
+ if (Request.Headers.Contains(EVCBConfiguration.Header_PartnerId))
|
|
|
+ {
|
|
|
+ var _customerId = Request.Headers.GetValues(EVCBConfiguration.Header_PartnerId).First();
|
|
|
+ EVSEService _service = new EVSEService();
|
|
|
+ var _innerResponse = new { Stations = _service.GetEVSEsbyCustomerIdAndStationId(_customerId, StationId) };
|
|
|
+ result.Data = JsonConvert.SerializeObject(_innerResponse);
|
|
|
+
|
|
|
+ }
|
|
|
+ return Request.CreateResponse(statusCode, result);
|
|
|
+ }
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ [Route("commands/start_session")]
|
|
|
+ [ResponseType(typeof(CPOOuterResponse))]
|
|
|
+ [HttpPost]
|
|
|
+ async public Task<HttpResponseMessage> StartSession([FromBody] StartSessionRequest 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(request.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 _CPService = new ChargePointService();
|
|
|
+
|
|
|
+ if (!string.IsNullOrEmpty(request.ChargeBoxId) && request.ChargeBoxId.Length <= 25
|
|
|
+ && _CPService.GetNumberofConnectors(request.ChargeBoxId) <= request.ConnectorId && request.ConnectorId > 0
|
|
|
+ && !string.IsNullOrEmpty(request.Token) && request.Token.Length <= 20)
|
|
|
+ {
|
|
|
+
|
|
|
+ InternalHttpClient _client = new InternalHttpClient();
|
|
|
+ CustomerService _customer = new CustomerService();
|
|
|
+
|
|
|
+ //trigger to charge
|
|
|
+ var _request = new StartTransactionRequest()
|
|
|
+ {
|
|
|
+ ConnectorId = request.ConnectorId,
|
|
|
+ IdTag = request.Token
|
|
|
+ };
|
|
|
+
|
|
|
+ string urlformat = "http://localhost:{0}/api/v1/ocpp16/transaction?ChargeBoxId={1}";
|
|
|
+
|
|
|
+ var _innerResult = await _client.Post(string.Format(urlformat, Request.RequestUri.Port, request.ChargeBoxId), new Dictionary<string, string>()
|
|
|
+ {
|
|
|
+ { "PartnerId",_CustomerId}
|
|
|
+
|
|
|
+ }, _request, _customer.GetAPIKey(new Guid(_CustomerId)));
|
|
|
+
|
|
|
+
|
|
|
+ _innerData = new { Result = string.IsNullOrEmpty(_innerResult.SerialNo) ? CommandResponseType.Rejected.ToString() : CommandResponseType.Accepted.ToString(), Timeout = 60 };
|
|
|
+ result = GetErrorDescription(_innerResult);
|
|
|
+ result.Data = JsonConvert.SerializeObject(_innerData, EVCBConfiguration.JSONSERIALIZER_FORMAT);
|
|
|
+
|
|
|
+ if (_innerResult.Success)
|
|
|
+ {
|
|
|
+ result.SerialNo = _innerResult.SerialNo;
|
|
|
+ result.StatusCode = (int)CPO_StatusCode.Success;
|
|
|
+ result.StatusMessage = CPO_StatusMessage.SUCCESS;
|
|
|
+ statusCode = HttpStatusCode.OK;
|
|
|
+
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+
|
|
|
+ result.StatusCode = _innerResult.ErrorCode;
|
|
|
+ result.StatusMessage = CPO_StatusMessage.ERROR_MSG_INNERSERVICE_ERROR;
|
|
|
+ statusCode = HttpStatusCode.BadRequest;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ // 參數不符合定義
|
|
|
+ result.StatusMessage = CPO_StatusMessage.ERROR_MSG_PARAMETER_OUTOFRANGE_INCORRECT;
|
|
|
+ result.StatusCode = (int)CPO_StatusCode.PARAMETER_OUTOFRANGE_INCORRECT;
|
|
|
+ result.Data = JsonConvert.SerializeObject(_innerData, EVCBConfiguration.JSONSERIALIZER_FORMAT);
|
|
|
+ statusCode = HttpStatusCode.BadRequest;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ return Request.CreateResponse(statusCode, result);
|
|
|
+ }
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ [Route("commands/stop_session")]
|
|
|
+ [ResponseType(typeof(CPOOuterResponse))]
|
|
|
+ [HttpPost]
|
|
|
+ async public Task<HttpResponseMessage> StopSession(string ChargeBoxId, int SessionId)
|
|
|
+ {
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ InternalHttpClient _client = new InternalHttpClient();
|
|
|
+ CustomerService _customer = new CustomerService();
|
|
|
+
|
|
|
+
|
|
|
+ string urlformat = "http://localhost:{0}/api/v1/ocpp16/transaction?ChargeBoxId={1}&TransactionId={2}";
|
|
|
+
|
|
|
+ var _innerResult = await _client.Put(string.Format(urlformat, Request.RequestUri.Port, ChargeBoxId, SessionId), new Dictionary<string, string>()
|
|
|
+ {
|
|
|
+ { "PartnerId",_CustomerId}
|
|
|
+
|
|
|
+ }, null, _customer.GetAPIKey(new Guid(_CustomerId)));
|
|
|
+
|
|
|
+
|
|
|
+ _innerData = new { Result = string.IsNullOrEmpty(_innerResult.SerialNo) ? CommandResponseType.Rejected.ToString() : CommandResponseType.Accepted.ToString(), Timeout = 60 };
|
|
|
+ result = GetErrorDescription(_innerResult);
|
|
|
+ result.Data = JsonConvert.SerializeObject(_innerData, EVCBConfiguration.JSONSERIALIZER_FORMAT);
|
|
|
+ if (_innerResult.Success)
|
|
|
+ {
|
|
|
+ result.SerialNo = _innerResult.SerialNo;
|
|
|
+ result.StatusCode = (int)CPO_StatusCode.Success;
|
|
|
+ result.StatusMessage = CPO_StatusMessage.SUCCESS;
|
|
|
+ statusCode = HttpStatusCode.OK;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+
|
|
|
+ result.StatusCode = _innerResult.ErrorCode;
|
|
|
+ result.StatusMessage = CPO_StatusMessage.ERROR_MSG_INNERSERVICE_ERROR;
|
|
|
+ statusCode = HttpStatusCode.BadRequest;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ 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("commands/reserve_now")]
|
|
|
+ [ResponseType(typeof(CPOOuterResponse))]
|
|
|
+ [HttpPost]
|
|
|
+ async public Task<HttpResponseMessage> ReserveNow([FromBody]ReserveNowRequest 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(request.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);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ InternalHttpClient _client = new InternalHttpClient();
|
|
|
+ CustomerService _customer = new CustomerService();
|
|
|
+
|
|
|
+ string urlformat = "http://localhost:{0}/api/v1/ocpp16/reservation?ChargeBoxId={1}";
|
|
|
+
|
|
|
+ var _innerRequest = new ReserveRequest()
|
|
|
+ {
|
|
|
+ ConnectorId = request.ConnectorId,
|
|
|
+ IdTag = request.Token,
|
|
|
+ ReservationId = request.ReservationId,
|
|
|
+ ExpiryDate = request.ExpiryDate.ToString(EVCBConfiguration.UTC_DATETIMEFORMAT)
|
|
|
+ };
|
|
|
+
|
|
|
+ var _innerResult = await _client.Post(string.Format(urlformat, Request.RequestUri.Port, request.ChargeBoxId), new Dictionary<string, string>()
|
|
|
+ {
|
|
|
+ { "PartnerId",_CustomerId}
|
|
|
+
|
|
|
+ }, _innerRequest, _customer.GetAPIKey(new Guid(_CustomerId)));
|
|
|
+
|
|
|
+
|
|
|
+ _innerData = new { Result = string.IsNullOrEmpty(_innerResult.SerialNo) ? CommandResponseType.Rejected.ToString() : CommandResponseType.Accepted.ToString(), Timeout = 60 };
|
|
|
+ result = GetErrorDescription(_innerResult);
|
|
|
+ result.Data = JsonConvert.SerializeObject(_innerData, EVCBConfiguration.JSONSERIALIZER_FORMAT);
|
|
|
+ if (_innerResult.Success)
|
|
|
+ {
|
|
|
+ result.SerialNo = _innerResult.SerialNo;
|
|
|
+ result.StatusCode = (int)CPO_StatusCode.Success;
|
|
|
+ result.StatusMessage = CPO_StatusMessage.SUCCESS;
|
|
|
+ statusCode = HttpStatusCode.OK;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+
|
|
|
+ result.StatusCode = _innerResult.ErrorCode;
|
|
|
+ result.StatusMessage = CPO_StatusMessage.ERROR_MSG_INNERSERVICE_ERROR;
|
|
|
+ statusCode = HttpStatusCode.BadRequest;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ 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("commands/cancel_reservation")]
|
|
|
+ [ResponseType(typeof(CPOOuterResponse))]
|
|
|
+ [HttpPost]
|
|
|
+ async public Task<HttpResponseMessage> CancelReservation(string ChargeBoxId, int ReservationId)
|
|
|
+ {
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ InternalHttpClient _client = new InternalHttpClient();
|
|
|
+ CustomerService _customer = new CustomerService();
|
|
|
+
|
|
|
+
|
|
|
+ string urlformat = "http://localhost:{0}/api/v1/ocpp16/reservation?ChargeBoxId={1}&ReservationId={2}";
|
|
|
+
|
|
|
+ var _innerResult = await _client.Delete(string.Format(urlformat, Request.RequestUri.Port, ChargeBoxId, ReservationId), new Dictionary<string, string>()
|
|
|
+ {
|
|
|
+ { "PartnerId",_CustomerId}
|
|
|
+
|
|
|
+ }, _customer.GetAPIKey(new Guid(_CustomerId)));
|
|
|
+
|
|
|
+
|
|
|
+ _innerData = new { Result = string.IsNullOrEmpty(_innerResult.SerialNo) ? CommandResponseType.Rejected.ToString() : CommandResponseType.Accepted.ToString(), Timeout = 60 };
|
|
|
+ result = GetErrorDescription(_innerResult);
|
|
|
+ result.Data = JsonConvert.SerializeObject(_innerData, EVCBConfiguration.JSONSERIALIZER_FORMAT);
|
|
|
+ if (_innerResult.Success)
|
|
|
+ {
|
|
|
+ result.SerialNo = _innerResult.SerialNo;
|
|
|
+ result.StatusCode = (int)CPO_StatusCode.Success;
|
|
|
+ result.StatusMessage = CPO_StatusMessage.SUCCESS;
|
|
|
+ statusCode = HttpStatusCode.OK;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+
|
|
|
+ result.StatusCode = _innerResult.ErrorCode;
|
|
|
+ result.StatusMessage = CPO_StatusMessage.ERROR_MSG_INNERSERVICE_ERROR;
|
|
|
+ statusCode = HttpStatusCode.BadRequest;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ 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("commands/chargingporfiles")]
|
|
|
+ [ResponseType(typeof(CPOOuterResponse))]
|
|
|
+ [HttpGet]
|
|
|
+ async public Task<HttpResponseMessage> GetActiveChargingPorfile(string ChargeBoxId, int ConnectorId, int Duration)
|
|
|
+ {
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ InternalHttpClient _client = new InternalHttpClient();
|
|
|
+ CustomerService _customer = new CustomerService();
|
|
|
+
|
|
|
+
|
|
|
+ string urlformat = "http://localhost:{0}/api/v1/ocpp16/compositeschedule?ChargeBoxId={1}&ConnectorId={2}&Duration={3}";
|
|
|
+
|
|
|
+ var _innerResult = await _client.Get(string.Format(urlformat, Request.RequestUri.Port, ChargeBoxId, ConnectorId, Duration), new Dictionary<string, string>()
|
|
|
+ {
|
|
|
+ { "PartnerId",_CustomerId}
|
|
|
+
|
|
|
+ }, _customer.GetAPIKey(new Guid(_CustomerId)));
|
|
|
+
|
|
|
+
|
|
|
+ _innerData = new { Result = string.IsNullOrEmpty(_innerResult.SerialNo) ? CommandResponseType.Rejected.ToString() : CommandResponseType.Accepted.ToString(), Timeout = 60 };
|
|
|
+ result = GetErrorDescription(_innerResult);
|
|
|
+ result.Data = JsonConvert.SerializeObject(_innerData, EVCBConfiguration.JSONSERIALIZER_FORMAT);
|
|
|
+ if (_innerResult.Success)
|
|
|
+ {
|
|
|
+ result.SerialNo = _innerResult.SerialNo;
|
|
|
+ result.StatusCode = (int)CPO_StatusCode.Success;
|
|
|
+ result.StatusMessage = CPO_StatusMessage.SUCCESS;
|
|
|
+ statusCode = HttpStatusCode.OK;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+
|
|
|
+ result.StatusCode = _innerResult.ErrorCode;
|
|
|
+ result.StatusMessage = CPO_StatusMessage.ERROR_MSG_INNERSERVICE_ERROR;
|
|
|
+ statusCode = HttpStatusCode.BadRequest;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ 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("commands/chargingporfiles")]
|
|
|
+ [ResponseType(typeof(CPOOuterResponse))]
|
|
|
+ [HttpPut]
|
|
|
+ async public Task<HttpResponseMessage> SetChargingProfile(string ChargeBoxId, [FromBody] ChargingProfileRequest 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);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ InternalHttpClient _client = new InternalHttpClient();
|
|
|
+ CustomerService _customer = new CustomerService();
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ string urlformat = "http://localhost:{0}/api/v1/ocpp16/chargingprofile?ChargeBoxId={1}";
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ var _innerResult = await _client.Post(string.Format(urlformat, Request.RequestUri.Port, ChargeBoxId), new Dictionary<string, string>()
|
|
|
+ {
|
|
|
+ { "PartnerId",_CustomerId}
|
|
|
+
|
|
|
+ }, request, _customer.GetAPIKey(new Guid(_CustomerId)));
|
|
|
+
|
|
|
+
|
|
|
+ _innerData = new { Result = string.IsNullOrEmpty(_innerResult.SerialNo) ? CommandResponseType.Rejected.ToString() : CommandResponseType.Accepted.ToString(), Timeout = 60 };
|
|
|
+ result = GetErrorDescription(_innerResult);
|
|
|
+ result.Data = JsonConvert.SerializeObject(_innerData, EVCBConfiguration.JSONSERIALIZER_FORMAT);
|
|
|
+ if (_innerResult.Success)
|
|
|
+ {
|
|
|
+ result.SerialNo = _innerResult.SerialNo;
|
|
|
+ result.StatusCode = (int)CPO_StatusCode.Success;
|
|
|
+ result.StatusMessage = CPO_StatusMessage.SUCCESS;
|
|
|
+ statusCode = HttpStatusCode.OK;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+
|
|
|
+ result.StatusCode = _innerResult.ErrorCode;
|
|
|
+ result.StatusMessage = CPO_StatusMessage.ERROR_MSG_INNERSERVICE_ERROR;
|
|
|
+ statusCode = HttpStatusCode.BadRequest;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ 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("commands/chargingporfiles")]
|
|
|
+ [ResponseType(typeof(CPOOuterResponse))]
|
|
|
+ [HttpDelete]
|
|
|
+ async public Task<HttpResponseMessage> ClearChargingPorfile(string ChargeBoxId, int ChargeProfileId = -1)
|
|
|
+ {
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ InternalHttpClient _client = new InternalHttpClient();
|
|
|
+ CustomerService _customer = new CustomerService();
|
|
|
+
|
|
|
+
|
|
|
+ string urlformat = "http://localhost:{0}/api/v1/ocpp16/chargeprofile?ChargeBoxId={1}{2}";
|
|
|
+
|
|
|
+ var _innerResult = await _client.Delete(string.Format(urlformat, Request.RequestUri.Port, ChargeBoxId, ChargeProfileId == -1 ? "" : "&Id=" + ChargeProfileId), new Dictionary<string, string>()
|
|
|
+ {
|
|
|
+ { "PartnerId",_CustomerId}
|
|
|
+
|
|
|
+ }, _customer.GetAPIKey(new Guid(_CustomerId)));
|
|
|
+
|
|
|
+
|
|
|
+ _innerData = new { Result = string.IsNullOrEmpty(_innerResult.SerialNo) ? CommandResponseType.Rejected.ToString() : CommandResponseType.Accepted.ToString(), Timeout = 60 };
|
|
|
+ result = GetErrorDescription(_innerResult);
|
|
|
+ result.Data = JsonConvert.SerializeObject(_innerData, EVCBConfiguration.JSONSERIALIZER_FORMAT);
|
|
|
+ if (_innerResult.Success)
|
|
|
+ {
|
|
|
+ result.SerialNo = _innerResult.SerialNo;
|
|
|
+ result.StatusCode = (int)CPO_StatusCode.Success;
|
|
|
+ result.StatusMessage = CPO_StatusMessage.SUCCESS;
|
|
|
+ statusCode = HttpStatusCode.OK;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+
|
|
|
+ result.StatusCode = _innerResult.ErrorCode;
|
|
|
+ result.StatusMessage = CPO_StatusMessage.ERROR_MSG_INNERSERVICE_ERROR;
|
|
|
+ statusCode = HttpStatusCode.BadRequest;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ 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("commands/set_locallist")]
|
|
|
+ [ResponseType(typeof(CPOOuterResponse))]
|
|
|
+ [HttpPost]
|
|
|
+ async public Task<HttpResponseMessage> SendLocalList(string ChargeBoxId, [FromBody]LocalListRequest 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);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ InternalHttpClient _client = new InternalHttpClient();
|
|
|
+ CustomerService _customer = new CustomerService();
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ string urlformat = "http://localhost:{0}/api/v1/ocpp16/locallist?ChargeBoxId={1}";
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ var _innerResult = await _client.Post(string.Format(urlformat, Request.RequestUri.Port, ChargeBoxId), new Dictionary<string, string>()
|
|
|
+ {
|
|
|
+ { "PartnerId",_CustomerId}
|
|
|
+
|
|
|
+ }, request, _customer.GetAPIKey(new Guid(_CustomerId)));
|
|
|
+
|
|
|
+
|
|
|
+ _innerData = new { Result = string.IsNullOrEmpty(_innerResult.SerialNo) ? CommandResponseType.Rejected.ToString() : CommandResponseType.Accepted.ToString(), Timeout = 60 };
|
|
|
+ result = GetErrorDescription(_innerResult);
|
|
|
+ result.Data = JsonConvert.SerializeObject(_innerData, EVCBConfiguration.JSONSERIALIZER_FORMAT);
|
|
|
+ if (_innerResult.Success)
|
|
|
+ {
|
|
|
+ result.SerialNo = _innerResult.SerialNo;
|
|
|
+ result.StatusCode = (int)CPO_StatusCode.Success;
|
|
|
+ result.StatusMessage = CPO_StatusMessage.SUCCESS;
|
|
|
+ statusCode = HttpStatusCode.OK;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+
|
|
|
+ result.StatusCode = _innerResult.ErrorCode;
|
|
|
+ result.StatusMessage = CPO_StatusMessage.ERROR_MSG_INNERSERVICE_ERROR;
|
|
|
+ statusCode = HttpStatusCode.BadRequest;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ 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("commands/locallistversion")]
|
|
|
+ [ResponseType(typeof(CPOOuterResponse))]
|
|
|
+ [HttpGet]
|
|
|
+ async public Task<HttpResponseMessage> GetLocalListVersion(string ChargeBoxId)
|
|
|
+ {
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ InternalHttpClient _client = new InternalHttpClient();
|
|
|
+ CustomerService _customer = new CustomerService();
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ string urlformat = "http://localhost:{0}/api/v1/ocpp16/locallistversion?ChargeBoxId={1}";
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ var _innerResult = await _client.Get(string.Format(urlformat, Request.RequestUri.Port, ChargeBoxId), new Dictionary<string, string>()
|
|
|
+ {
|
|
|
+ { "PartnerId",_CustomerId}
|
|
|
+
|
|
|
+ }, _customer.GetAPIKey(new Guid(_CustomerId)));
|
|
|
+
|
|
|
+
|
|
|
+ _innerData = new { Result = string.IsNullOrEmpty(_innerResult.SerialNo) ? CommandResponseType.Rejected.ToString() : CommandResponseType.Accepted.ToString(), Timeout = 60 };
|
|
|
+ result = GetErrorDescription(_innerResult);
|
|
|
+ result.Data = JsonConvert.SerializeObject(_innerData, EVCBConfiguration.JSONSERIALIZER_FORMAT);
|
|
|
+ if (_innerResult.Success)
|
|
|
+ {
|
|
|
+ result.SerialNo = _innerResult.SerialNo;
|
|
|
+ result.StatusCode = (int)CPO_StatusCode.Success;
|
|
|
+ result.StatusMessage = CPO_StatusMessage.SUCCESS;
|
|
|
+ statusCode = HttpStatusCode.OK;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+
|
|
|
+ result.StatusCode = _innerResult.ErrorCode;
|
|
|
+ result.StatusMessage = CPO_StatusMessage.ERROR_MSG_INNERSERVICE_ERROR;
|
|
|
+ statusCode = HttpStatusCode.BadRequest;
|
|
|
+ }
|
|
|
+
|
|
|
+ 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("commands/results")]
|
|
|
+ [ResponseType(typeof(CPOOuterResponse))]
|
|
|
+ [HttpGet]
|
|
|
+ async public Task<HttpResponseMessage> ExecutionofCmdSearch(string ChargeBoxId, CommandType? commandType, string SerialNo)
|
|
|
+ {
|
|
|
+ var result = new CPOOuterResponse();
|
|
|
+ HttpStatusCode statusCode = HttpStatusCode.InternalServerError;
|
|
|
+
|
|
|
+ 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;
|
|
|
+ statusCode = HttpStatusCode.BadRequest;
|
|
|
+ return Request.CreateResponse(statusCode, result);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ InternalHttpClient _client = new InternalHttpClient();
|
|
|
+ CustomerService _customer = new CustomerService();
|
|
|
+
|
|
|
+ int? orderNo = (int?)null;
|
|
|
+
|
|
|
+ switch (commandType.Value)
|
|
|
+ {
|
|
|
+ case CommandType.CancelReservation:
|
|
|
+ {
|
|
|
+ orderNo = 4;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case CommandType.ClearChargingProfile:
|
|
|
+ {
|
|
|
+ orderNo = 6;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case CommandType.GetAcitveChargingProfile:
|
|
|
+ {
|
|
|
+ orderNo = 7;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case CommandType.GetLocalListVersion:
|
|
|
+ {
|
|
|
+ orderNo = 9;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case CommandType.Start_Session:
|
|
|
+ {
|
|
|
+ orderNo = 10;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case CommandType.Stop_Session:
|
|
|
+ {
|
|
|
+ orderNo = 11;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case CommandType.Reserve_Now:
|
|
|
+ {
|
|
|
+ orderNo = 12;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case CommandType.SetLocalList:
|
|
|
+ {
|
|
|
+ orderNo = 14;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case CommandType.SetChargingProfile:
|
|
|
+ {
|
|
|
+ orderNo = 15;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ string urlformat = "http://localhost:{0}/api/v1/ocpp16/command?ChargeBoxId={1}{2}&SerialNo={3}";
|
|
|
+
|
|
|
+
|
|
|
+ var _innerResult = await _client.Get(string.Format(urlformat, Request.RequestUri.Port, ChargeBoxId, orderNo.HasValue ? "&OrderNo=" + orderNo.Value : "", SerialNo), new Dictionary<string, string>()
|
|
|
+ {
|
|
|
+ { "PartnerId",_CustomerId}
|
|
|
+
|
|
|
+ }, _customer.GetAPIKey(new Guid(_CustomerId)));
|
|
|
+
|
|
|
+
|
|
|
+ result = GetErrorDescription(_innerResult);
|
|
|
+
|
|
|
+ if (_innerResult.Success)
|
|
|
+ {
|
|
|
+ ComandExecution _execution = JsonConvert.DeserializeObject<ComandExecution>(_innerResult.Message);
|
|
|
+
|
|
|
+ CommandResultType? _cmdResult = (CommandResultType?)null;
|
|
|
+
|
|
|
+ switch (_execution.Code)
|
|
|
+ {
|
|
|
+ case 1:
|
|
|
+ {
|
|
|
+ _cmdResult = CommandResultType.Accepted;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case 9:
|
|
|
+ {
|
|
|
+ _cmdResult = CommandResultType.Notsupported;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case 10:
|
|
|
+ {
|
|
|
+ _cmdResult = CommandResultType.Unknown;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case 26:
|
|
|
+ {
|
|
|
+ _cmdResult = CommandResultType.Occupied;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case 31:
|
|
|
+ {
|
|
|
+ _cmdResult = CommandResultType.Rejected;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case 32:
|
|
|
+ {
|
|
|
+ _cmdResult = CommandResultType.Failed;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case 254:
|
|
|
+ {
|
|
|
+ _cmdResult = CommandResultType.EVSE_ERROR;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ {
|
|
|
+ if (_execution.IsTimeout.HasValue && _execution.IsTimeout.Value) _cmdResult = CommandResultType.Timeout;
|
|
|
+ if (_execution.IsWaited.HasValue && _execution.IsWaited.Value) _cmdResult = CommandResultType.Waited;
|
|
|
+
|
|
|
+ }
|
|
|
+ break;
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if (!_cmdResult.HasValue)
|
|
|
+ {
|
|
|
+ result.StatusCode = (int)CPO_StatusCode.CANT_FOUND_DATA;
|
|
|
+ result.StatusMessage = CPO_StatusMessage.ERROR_MSG_CANT_FIND_RESULT;
|
|
|
+ statusCode = HttpStatusCode.NotFound;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ var _innerData = new { Result = _cmdResult.Value.ToString(), Message = _execution.Detail };
|
|
|
+ result.Data = JsonConvert.SerializeObject(_innerData, EVCBConfiguration.JSONSERIALIZER_FORMAT);
|
|
|
+ result.SerialNo = _innerResult.SerialNo;
|
|
|
+ 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)
|
|
|
+ {
|
|
|
+ var result = new CPOOuterResponse();
|
|
|
+ HttpStatusCode statusCode = HttpStatusCode.InternalServerError;
|
|
|
+
|
|
|
+ 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;
|
|
|
+ statusCode = HttpStatusCode.BadRequest;
|
|
|
+ return Request.CreateResponse(statusCode, result);
|
|
|
+ }
|
|
|
+
|
|
|
+ // query meter value
|
|
|
+ ChargePointService _service = new ChargePointService();
|
|
|
+ var _meterValues = _service.GetActiveSessionInfo(ChargeBoxId, SessionId, new List<Packet.Messages.SubTypes.Measurand>()
|
|
|
+ { Packet.Messages.SubTypes.Measurand.Voltage,
|
|
|
+ Packet.Messages.SubTypes.Measurand.Current_Export,
|
|
|
+ Packet.Messages.SubTypes.Measurand.SoC,
|
|
|
+ Packet.Messages.SubTypes.Measurand.Power_Active_Export,
|
|
|
+ Packet.Messages.SubTypes.Measurand.Energy_Active_Export_Interval
|
|
|
+ });
|
|
|
+
|
|
|
+ if (_meterValues.Count == 0)
|
|
|
+ {
|
|
|
+ result.StatusCode = (int)CPO_StatusCode.CANT_FOUND_DATA;
|
|
|
+ result.StatusMessage = CPO_StatusMessage.ERROR_MSG_CANT_FIND_RESULT;
|
|
|
+ statusCode = HttpStatusCode.NotFound;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ 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(),
|
|
|
+ };
|
|
|
+
|
|
|
+ result.Data = JsonConvert.SerializeObject(_innerData, EVCBConfiguration.JSONSERIALIZER_FORMAT);
|
|
|
+ result.StatusCode = (int)CPO_StatusCode.Success;
|
|
|
+ result.StatusMessage = CPO_StatusMessage.SUCCESS;
|
|
|
+ statusCode = HttpStatusCode.OK;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ return Request.CreateResponse(statusCode, result);
|
|
|
+ }
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ [Route("completedsession")]
|
|
|
+ [ResponseType(typeof(CPOOuterResponse))]
|
|
|
+ [HttpGet]
|
|
|
+ public HttpResponseMessage CompletedSession(string ChargeBoxId, string SessionId)
|
|
|
+ {
|
|
|
+ var result = new CPOOuterResponse();
|
|
|
+ HttpStatusCode statusCode = HttpStatusCode.InternalServerError;
|
|
|
+
|
|
|
+ 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;
|
|
|
+ statusCode = HttpStatusCode.BadRequest;
|
|
|
+ return Request.CreateResponse(statusCode, result);
|
|
|
+ }
|
|
|
+
|
|
|
+ // query meter value
|
|
|
+ ChargePointService _service = new ChargePointService();
|
|
|
+ var _innerData = _service.GetSessionDetail(ChargeBoxId, SessionId);
|
|
|
+
|
|
|
+ if (_innerData == null)
|
|
|
+ {
|
|
|
+
|
|
|
+ result.StatusCode = (int)CPO_StatusCode.CANT_FOUND_DATA;
|
|
|
+ result.StatusMessage = CPO_StatusMessage.ERROR_MSG_CANT_FIND_SESSIONDETAIL;
|
|
|
+ statusCode = HttpStatusCode.NotFound;
|
|
|
+ return Request.CreateResponse(statusCode, result);
|
|
|
+ }
|
|
|
+
|
|
|
+ result.Data = JsonConvert.SerializeObject(_innerData, EVCBConfiguration.JSONSERIALIZER_FORMAT);
|
|
|
+ result.StatusCode = (int)CPO_StatusCode.Success;
|
|
|
+ result.StatusMessage = CPO_StatusMessage.SUCCESS;
|
|
|
+ statusCode = HttpStatusCode.OK;
|
|
|
+ return Request.CreateResponse(statusCode, result);
|
|
|
+ }
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private CPOOuterResponse GetErrorDescription(InternalHttpResult innerResponse)
|
|
|
+ {
|
|
|
+ CPOOuterResponse result = new CPOOuterResponse();
|
|
|
+
|
|
|
+ result.ErrorDetail = innerResponse.Exception == null ? string.Empty : innerResponse.Exception.ToString();
|
|
|
+
|
|
|
+ if (innerResponse.Status != HttpStatusCode.Accepted)
|
|
|
+ {
|
|
|
+ switch (innerResponse.ErrorCode)
|
|
|
+ {
|
|
|
+ #region Authorization
|
|
|
+ case 2000:
|
|
|
+ {
|
|
|
+ result.StatusCode = innerResponse.ErrorCode;
|
|
|
+ result.StatusMessage = string.Format("{0}-{1}", "InnerService", "Authorize Unexpected Error");
|
|
|
+ result.ErrorDetail = result.StatusMessage;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case 2001:
|
|
|
+ case 2002:
|
|
|
+ case 2003:
|
|
|
+ {
|
|
|
+ result.StatusCode = innerResponse.ErrorCode;
|
|
|
+ result.StatusMessage = string.Format("{0}-{1}", "InnerService", innerResponse.Message);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+
|
|
|
+ #endregion
|
|
|
+ case 2100:
|
|
|
+ case 2101:
|
|
|
+ case 2102:
|
|
|
+ case 2103:
|
|
|
+ case 2104:
|
|
|
+ case 2105:
|
|
|
+ {
|
|
|
+ result.StatusCode = innerResponse.ErrorCode;
|
|
|
+ result.StatusMessage = innerResponse.Message;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case 2999:
|
|
|
+ {
|
|
|
+ result.StatusCode = innerResponse.ErrorCode;
|
|
|
+ result.StatusMessage = string.Format("{0}-{1}", "InnerService", "Unexpected Error");
|
|
|
+ result.ErrorDetail = result.StatusMessage;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ {
|
|
|
+ result.StatusCode = 2998;
|
|
|
+ result.StatusMessage = CPO_StatusMessage.ERROR_MSG_CANT_FIND_ERRORCODE;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return result;
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+}
|