|
@@ -16,6 +16,8 @@ using EVCB_OCPP.WSServer.Dto;
|
|
|
using Newtonsoft.Json;
|
|
|
using OCPPPackage.Profiles;
|
|
|
using OCPPServer.Protocol;
|
|
|
+using System.Configuration;
|
|
|
+using System.Transactions;
|
|
|
|
|
|
namespace EVCB_OCPP.WSServer.Message
|
|
|
{
|
|
@@ -23,8 +25,8 @@ namespace EVCB_OCPP.WSServer.Message
|
|
|
internal partial class ProfileHandler
|
|
|
{
|
|
|
|
|
|
- int counnter = 0;
|
|
|
- internal MessageResult ExecuteCoreRequest(Actions action, ClientData session, IRequest request)
|
|
|
+
|
|
|
+ async internal Task<MessageResult> ExecuteCoreRequest(Actions action, ClientData session, IRequest request)
|
|
|
{
|
|
|
MessageResult result = new MessageResult() { Success = false };
|
|
|
|
|
@@ -117,23 +119,22 @@ namespace EVCB_OCPP.WSServer.Message
|
|
|
Id = Guid.NewGuid().ToString()
|
|
|
};
|
|
|
db.ConnectorStatus.Add(_currentStatus);
|
|
|
-
|
|
|
-
|
|
|
- if (_request.status == Packet.Messages.SubTypes.ChargePointStatus.Faulted)
|
|
|
+
|
|
|
+ }
|
|
|
+ if (_request.status == Packet.Messages.SubTypes.ChargePointStatus.Faulted)
|
|
|
+ {
|
|
|
+ db.MachineError.Add(new MachineError()
|
|
|
{
|
|
|
- db.MachineError.Add(new MachineError()
|
|
|
- {
|
|
|
- ConnectorId = (byte)_request.connectorId,
|
|
|
- CreatedOn = _request.timestamp.HasValue ? _request.timestamp.Value : DateTime.Now,
|
|
|
- Status = (int)_request.status,
|
|
|
- ChargeBoxId = session.ChargeBoxId,
|
|
|
- ErrorCodeId = (int)_request.errorCode,
|
|
|
- ErrorInfo = string.IsNullOrEmpty(_request.info) ? string.Empty : _request.info,
|
|
|
- PreStatus = _oldStatus == null ? -1 : preStatus,
|
|
|
- VendorErrorCode = string.IsNullOrEmpty(_request.vendorErrorCode) ? string.Empty : _request.vendorErrorCode,
|
|
|
- VendorId = string.IsNullOrEmpty(_request.vendorId) ? string.Empty : _request.vendorId
|
|
|
- });
|
|
|
- }
|
|
|
+ ConnectorId = (byte)_request.connectorId,
|
|
|
+ CreatedOn = _request.timestamp.HasValue ? _request.timestamp.Value : DateTime.Now,
|
|
|
+ Status = (int)_request.status,
|
|
|
+ ChargeBoxId = session.ChargeBoxId,
|
|
|
+ ErrorCodeId = (int)_request.errorCode,
|
|
|
+ ErrorInfo = string.IsNullOrEmpty(_request.info) ? string.Empty : _request.info,
|
|
|
+ PreStatus = _oldStatus == null ? -1 : preStatus,
|
|
|
+ VendorErrorCode = string.IsNullOrEmpty(_request.vendorErrorCode) ? string.Empty : _request.vendorErrorCode,
|
|
|
+ VendorId = string.IsNullOrEmpty(_request.vendorId) ? string.Empty : _request.vendorId
|
|
|
+ });
|
|
|
}
|
|
|
db.SaveChanges();
|
|
|
}
|
|
@@ -142,7 +143,7 @@ namespace EVCB_OCPP.WSServer.Message
|
|
|
if (_request.status == Packet.Messages.SubTypes.ChargePointStatus.Faulted)
|
|
|
{
|
|
|
var businessService = BusinessServiceFactory.CreateBusinessService(session.CustomerId.ToString());
|
|
|
- businessService.NotifyFaultStatus(new ErrorDetails()
|
|
|
+ await businessService.NotifyFaultStatus(new ErrorDetails()
|
|
|
{
|
|
|
ChargeBoxId = session.ChargeBoxId,
|
|
|
ConnectorId = _request.connectorId,
|
|
@@ -173,7 +174,7 @@ namespace EVCB_OCPP.WSServer.Message
|
|
|
machine.ConnectionType = session.UriScheme.Equals("wss") ? 2 : 1;
|
|
|
db.Entry(machine).Property(x => x.HeartbeatUpdatedOn).IsModified = true;
|
|
|
db.Entry(machine).Property(x => x.ConnectionType).IsModified = true;
|
|
|
- db.SaveChanges();
|
|
|
+ await db.SaveChangesAsync();
|
|
|
}
|
|
|
var confirm = new HeartbeatConfirmation() { currentTime = DateTime.Now };
|
|
|
result.Message = confirm;
|
|
@@ -193,12 +194,13 @@ namespace EVCB_OCPP.WSServer.Message
|
|
|
{
|
|
|
foreach (var sampleVaule in item.sampledValue)
|
|
|
{
|
|
|
- decimal value = Convert.ToDecimal(sampleVaule.value);
|
|
|
+
|
|
|
+ decimal value = Convert.ToDecimal(sampleVaule.value);
|
|
|
|
|
|
- string sp = "[dbo].[uspInsertMeterValueRecord] @ChargeBoxId," +
|
|
|
- "@ConnectorId,@Value,@CreatedOn,@ContextId,@FormatId,@MeasurandId,@PhaseId,@LocationId,@UnitId,@TransactionId";
|
|
|
+ string sp = "[dbo].[uspInsertMeterValueRecord] @ChargeBoxId," +
|
|
|
+ "@ConnectorId,@Value,@CreatedOn,@ContextId,@FormatId,@MeasurandId,@PhaseId,@LocationId,@UnitId,@TransactionId";
|
|
|
|
|
|
- List<SqlParameter> parameter = new List<SqlParameter>
|
|
|
+ List<SqlParameter> parameter = new List<SqlParameter>
|
|
|
{
|
|
|
new SqlParameter("ChargeBoxId",session.ChargeBoxId),
|
|
|
new SqlParameter("ConnectorId", (byte)_request.connectorId),
|
|
@@ -214,8 +216,13 @@ namespace EVCB_OCPP.WSServer.Message
|
|
|
};
|
|
|
|
|
|
|
|
|
- db.Database.ExecuteSqlCommand(sp, parameter.ToArray());
|
|
|
+ db.Database.ExecuteSqlCommand(sp, parameter.ToArray());
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -228,13 +235,19 @@ namespace EVCB_OCPP.WSServer.Message
|
|
|
case Actions.StartTransaction:
|
|
|
{
|
|
|
StartTransactionRequest _request = request as StartTransactionRequest;
|
|
|
- IdTagInfo _idTagInfo = new IdTagInfo() { status = AuthorizationStatus.Accepted };
|
|
|
+ IdTagInfo _idTagInfo = new IdTagInfo()
|
|
|
+ {
|
|
|
+ expiryDate = DateTime.UtcNow.AddDays(1),
|
|
|
+ parentIdTag = "Supervisor",
|
|
|
+ status = AuthorizationStatus.Accepted
|
|
|
+
|
|
|
+ };
|
|
|
|
|
|
int _transactionId = -1;
|
|
|
if (DateTime.Compare(DateTime.UtcNow.AddSeconds(-10), _request.timestamp.ToUniversalTime()) >= 0)
|
|
|
{
|
|
|
var businessService = BusinessServiceFactory.CreateBusinessService(session.CustomerId.ToString());
|
|
|
- _idTagInfo = businessService.Authorize(session.ChargeBoxId, _request.idTag);
|
|
|
+ _idTagInfo = await businessService.Authorize(session.ChargeBoxId, _request.idTag);
|
|
|
|
|
|
}
|
|
|
|
|
@@ -298,8 +311,16 @@ namespace EVCB_OCPP.WSServer.Message
|
|
|
List<TransactionDataRecord> _TransactionDatas = new List<TransactionDataRecord>();
|
|
|
int _ConnectorId = 0;
|
|
|
|
|
|
- var businessService = BusinessServiceFactory.CreateBusinessService(session.CustomerId.ToString());
|
|
|
- var _idTagInfo = businessService.Authorize(session.ChargeBoxId, _request.idTag);
|
|
|
+ // var businessService = BusinessServiceFactory.CreateBusinessService(session.CustomerId.ToString());
|
|
|
+ // var _idTagInfo = businessService.Authorize(session.ChargeBoxId, _request.idTag);
|
|
|
+
|
|
|
+ var _idTagInfo = new IdTagInfo()
|
|
|
+ {
|
|
|
+ expiryDate = DateTime.UtcNow.AddDays(1),
|
|
|
+ parentIdTag = "Supervisor",
|
|
|
+ status = AuthorizationStatus.Accepted
|
|
|
+
|
|
|
+ };
|
|
|
|
|
|
using (var db = new MainDBContext())
|
|
|
{
|
|
@@ -319,7 +340,7 @@ namespace EVCB_OCPP.WSServer.Message
|
|
|
_TransactionDatas.ForEach(x => x.ConnectorId = (byte)transaction.ConnectorId);
|
|
|
}
|
|
|
|
|
|
- db.SaveChanges();
|
|
|
+ await db.SaveChangesAsync();
|
|
|
var confirm = new StopTransactionConfirmation()
|
|
|
{
|
|
|
idTagInfo = _idTagInfo
|
|
@@ -384,7 +405,7 @@ namespace EVCB_OCPP.WSServer.Message
|
|
|
var businessService = BusinessServiceFactory.CreateBusinessService(session.CustomerId.ToString());
|
|
|
var confirm = new AuthorizeConfirmation()
|
|
|
{
|
|
|
- idTagInfo = businessService.Authorize(session.ChargeBoxId, _request.idTag)
|
|
|
+ idTagInfo = await businessService.Authorize(session.ChargeBoxId, _request.idTag)
|
|
|
};
|
|
|
result.Message = confirm;
|
|
|
result.Success = true;
|
|
@@ -630,6 +651,27 @@ namespace EVCB_OCPP.WSServer.Message
|
|
|
}
|
|
|
}
|
|
|
break;
|
|
|
+ case Actions.UnlockConnector:
|
|
|
+ {
|
|
|
+ UnlockConnectorConfirmation _confirm = confirm as UnlockConnectorConfirmation;
|
|
|
+ UnlockConnectorRequest _request = _confirm.GetRequest() as UnlockConnectorRequest;
|
|
|
+
|
|
|
+ using (var db = new MainDBContext())
|
|
|
+ {
|
|
|
+ var operation = db.MachineOperateRecord.Where(x => x.SerialNo == requestId &&
|
|
|
+ x.ChargeBoxId == session.ChargeBoxId && x.Status == 0).FirstOrDefault();
|
|
|
+ if (operation != null)
|
|
|
+ {
|
|
|
+ operation.FinishedOn = DateTime.Now;
|
|
|
+ operation.Status = 1;//電樁有回覆
|
|
|
+ operation.EVSE_Status = (int)_confirm.status;
|
|
|
+ operation.EVSE_Value = _confirm.status.ToString();
|
|
|
+ db.SaveChanges();
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ break;
|
|
|
default:
|
|
|
{
|
|
|
Console.WriteLine(string.Format("Not Implement {0} Logic", confirm.GetType().ToString().Replace("OCPPPackage.Messages.Core.", "")));
|
|
@@ -653,6 +695,7 @@ namespace EVCB_OCPP.WSServer.Message
|
|
|
case Actions.RemoteStopTransaction:
|
|
|
case Actions.Reset:
|
|
|
case Actions.GetConfiguration:
|
|
|
+ case Actions.UnlockConnector:
|
|
|
{
|
|
|
using (var db = new MainDBContext())
|
|
|
{
|