|
@@ -94,7 +94,8 @@ internal partial class ProfileHandler
|
|
|
async internal Task<MessageResult> ExecuteCoreRequest(Actions action, ClientData session, IRequest request)
|
|
|
{
|
|
|
Stopwatch watch = new Stopwatch();
|
|
|
- if (action == Actions.Heartbeat)
|
|
|
+ long getDateTimeTime, getServiceTime, getTagInfoTime, dbOpTime = 0;
|
|
|
+ if (action == Actions.Heartbeat || action == Actions.StopTransaction)
|
|
|
{
|
|
|
watch.Start();
|
|
|
}
|
|
@@ -173,7 +174,7 @@ internal partial class ProfileHandler
|
|
|
|
|
|
logger.LogDebug("{0}\r\n{1}\r\n{2}", jo["txId"].Value<int>(), jo["dataString"].Value<string>(), jo["publicKey"].Value<string>());
|
|
|
|
|
|
- using (var db = await maindbContextFactory.CreateDbContextAsync())
|
|
|
+ using (var db = maindbContextFactory.CreateDbContext())
|
|
|
{
|
|
|
db.OCMF.Add(new OCMF()
|
|
|
{
|
|
@@ -197,7 +198,7 @@ internal partial class ProfileHandler
|
|
|
{
|
|
|
BootNotificationRequest _request = request as BootNotificationRequest;
|
|
|
int heartbeat_interval = GlobalConfig.GetHEARTBEAT_INTERVAL();
|
|
|
- using (var db = await maindbContextFactory.CreateDbContextAsync())
|
|
|
+ using (var db = maindbContextFactory.CreateDbContext())
|
|
|
{
|
|
|
var _machine = await db.Machine.Where(x => x.ChargeBoxId == session.ChargeBoxId).FirstOrDefaultAsync();
|
|
|
_machine.ChargeBoxSerialNumber = string.IsNullOrEmpty(_request.chargeBoxSerialNumber) ? string.Empty : _request.chargeBoxSerialNumber;
|
|
@@ -215,7 +216,7 @@ internal partial class ProfileHandler
|
|
|
}
|
|
|
|
|
|
|
|
|
- using (var db = await maindbContextFactory.CreateDbContextAsync())
|
|
|
+ using (var db = maindbContextFactory.CreateDbContext())
|
|
|
{
|
|
|
var configVaule = await db.MachineConfigurations
|
|
|
.Where(x => x.ChargeBoxId == session.ChargeBoxId && x.ConfigureName == StandardConfiguration.HeartbeatInterval)
|
|
@@ -240,7 +241,7 @@ internal partial class ProfileHandler
|
|
|
StatusNotificationRequest _request = request as StatusNotificationRequest;
|
|
|
int preStatus = 0;
|
|
|
ConnectorStatus _oldStatus;
|
|
|
- using (var db = await maindbContextFactory.CreateDbContextAsync())
|
|
|
+ using (var db = maindbContextFactory.CreateDbContext())
|
|
|
{
|
|
|
_oldStatus = await db.ConnectorStatus.Where(x => x.ChargeBoxId == session.ChargeBoxId
|
|
|
&& x.ConnectorId == _request.connectorId).AsNoTracking().FirstOrDefaultAsync();
|
|
@@ -249,7 +250,7 @@ internal partial class ProfileHandler
|
|
|
|
|
|
if (_oldStatus != null && (_request.status != (ChargePointStatus)_oldStatus.Status || _request.status == ChargePointStatus.Faulted))
|
|
|
{
|
|
|
- using (var db = await maindbContextFactory.CreateDbContextAsync())
|
|
|
+ using (var db = maindbContextFactory.CreateDbContext())
|
|
|
{
|
|
|
preStatus = _oldStatus.Status;
|
|
|
|
|
@@ -278,7 +279,7 @@ internal partial class ProfileHandler
|
|
|
|
|
|
if (_oldStatus == null)
|
|
|
{
|
|
|
- using (var db = await maindbContextFactory.CreateDbContextAsync())
|
|
|
+ using (var db = maindbContextFactory.CreateDbContext())
|
|
|
{
|
|
|
var _currentStatus = new Domain.Models.Database.ConnectorStatus()
|
|
|
{
|
|
@@ -299,7 +300,7 @@ internal partial class ProfileHandler
|
|
|
|
|
|
if (_request.status == Packet.Messages.SubTypes.ChargePointStatus.Faulted)
|
|
|
{
|
|
|
- using (var db = await maindbContextFactory.CreateDbContextAsync())
|
|
|
+ using (var db = maindbContextFactory.CreateDbContext())
|
|
|
{
|
|
|
db.MachineError.Add(new MachineError()
|
|
|
{
|
|
@@ -370,7 +371,7 @@ internal partial class ProfileHandler
|
|
|
energyRegister = energy_Register.unit.Value == UnitOfMeasure.kWh ? decimal.Multiply(energyRegister, 1000) : energyRegister;
|
|
|
|
|
|
|
|
|
- using (var maindb = await maindbContextFactory.CreateDbContextAsync())
|
|
|
+ using (var maindb = maindbContextFactory.CreateDbContext())
|
|
|
{
|
|
|
meterStart = await maindb.TransactionRecord
|
|
|
.Where(x => x.Id == _request.transactionId.Value).Select(x => x.MeterStart)
|
|
@@ -427,7 +428,7 @@ internal partial class ProfileHandler
|
|
|
if (session.IsBilling)
|
|
|
if (session.IsBilling)
|
|
|
{
|
|
|
- using (var db = await maindbContextFactory.CreateDbContextAsync())
|
|
|
+ using (var db = maindbContextFactory.CreateDbContext())
|
|
|
{
|
|
|
db.ServerMessage.Add(new ServerMessage()
|
|
|
{
|
|
@@ -525,7 +526,7 @@ internal partial class ProfileHandler
|
|
|
}
|
|
|
|
|
|
|
|
|
- using (var db = await maindbContextFactory.CreateDbContextAsync())
|
|
|
+ using (var db = maindbContextFactory.CreateDbContext())
|
|
|
{
|
|
|
var _CustomerId = await db.Machine.Where(x => x.ChargeBoxId == session.ChargeBoxId).Include(x => x.Customer).
|
|
|
Select(x => x.CustomerId).FirstOrDefaultAsync();
|
|
@@ -594,19 +595,23 @@ internal partial class ProfileHandler
|
|
|
|
|
|
int _ConnectorId = 0;
|
|
|
|
|
|
+ var utcNow = DateTime.UtcNow;
|
|
|
+ getDateTimeTime = watch.ElapsedMilliseconds;
|
|
|
var businessService = await serviceProvider.GetService<BusinessServiceFactory>().CreateBusinessService(session.CustomerId.ToString());
|
|
|
+ getServiceTime = watch.ElapsedMilliseconds;
|
|
|
|
|
|
var _idTagInfo = string.IsNullOrEmpty(_request.idTag) ? null : (_request.idTag == "Backend" ?
|
|
|
- new IdTagInfo() { expiryDate = DateTime.UtcNow.AddDays(1), status = AuthorizationStatus.Accepted } : (await businessService.Authorize(session.ChargeBoxId, _request.idTag)).IdTagInfo);
|
|
|
+ new IdTagInfo() { expiryDate = utcNow.AddDays(1), status = AuthorizationStatus.Accepted } : (await businessService.Authorize(session.ChargeBoxId, _request.idTag)).IdTagInfo);
|
|
|
+ getTagInfoTime = watch.ElapsedMilliseconds;
|
|
|
|
|
|
//特例****飛宏客戶旗下的電樁,若遇到Portal沒回應的狀況 ~允許充電
|
|
|
if (session.CustomerId.ToString().ToUpper() == "8456AED9-6DD9-4BF3-A94C-9F5DCB9506F7" && _idTagInfo != null && _idTagInfo.status == AuthorizationStatus.ConcurrentTx)
|
|
|
{
|
|
|
- _idTagInfo = new IdTagInfo() { expiryDate = DateTime.UtcNow.AddDays(1), status = AuthorizationStatus.Accepted };
|
|
|
+ _idTagInfo = new IdTagInfo() { expiryDate = utcNow.AddDays(1), status = AuthorizationStatus.Accepted };
|
|
|
}
|
|
|
try
|
|
|
{
|
|
|
- using (var db = await maindbContextFactory.CreateDbContextAsync())
|
|
|
+ using (var db = maindbContextFactory.CreateDbContext())
|
|
|
{
|
|
|
var transaction = await db.TransactionRecord.Where(x => x.Id == _request.transactionId
|
|
|
&& x.ChargeBoxId == session.ChargeBoxId).FirstOrDefaultAsync();
|
|
@@ -680,7 +685,7 @@ internal partial class ProfileHandler
|
|
|
{
|
|
|
ChargeBoxId = session.ChargeBoxId,
|
|
|
CreatedBy = "Server",
|
|
|
- CreatedOn = DateTime.UtcNow,
|
|
|
+ CreatedOn = utcNow,
|
|
|
OutAction = Actions.DataTransfer.ToString(),
|
|
|
OutRequest = JsonConvert.SerializeObject(
|
|
|
new DataTransferRequest()
|
|
@@ -708,7 +713,7 @@ internal partial class ProfileHandler
|
|
|
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+ dbOpTime = watch.ElapsedMilliseconds;
|
|
|
#region Save MeterValue
|
|
|
|
|
|
if (_request.transactionData != null &&
|
|
@@ -757,6 +762,13 @@ internal partial class ProfileHandler
|
|
|
result.Success = false;
|
|
|
// return result;
|
|
|
}
|
|
|
+
|
|
|
+ watch.Stop();
|
|
|
+ if (watch.ElapsedMilliseconds > 1000)
|
|
|
+ {
|
|
|
+ logger.Log( LogLevel.Critical, "ExecuteCoreRequest {action} {sessisonId} too long {time} sec", action.ToString(), session.SessionID , watch.ElapsedMilliseconds / 1000);
|
|
|
+ logger.Log(LogLevel.Critical, "{action} {sessisonId} time {getDateTime}/{serviceTime}/{tagInfoTime}/{dbOpTime}", action.ToString(), session.SessionID, getDateTimeTime/1000 , getServiceTime/1000, getTagInfoTime/1000, dbOpTime/1000);
|
|
|
+ }
|
|
|
}
|
|
|
break;
|
|
|
case Actions.Authorize:
|
|
@@ -854,7 +866,7 @@ internal partial class ProfileHandler
|
|
|
{
|
|
|
DataTransferConfirmation _confirm = confirm as DataTransferConfirmation;
|
|
|
DataTransferRequest _request = _confirm.GetRequest() as DataTransferRequest;
|
|
|
- using (var db = await maindbContextFactory.CreateDbContextAsync())
|
|
|
+ using (var db = maindbContextFactory.CreateDbContext())
|
|
|
{
|
|
|
var operation = await db.MachineOperateRecord.Where(x => x.SerialNo == requestId &&
|
|
|
x.ChargeBoxId == session.ChargeBoxId && x.Status == 0).FirstOrDefaultAsync();
|
|
@@ -1307,7 +1319,7 @@ internal partial class ProfileHandler
|
|
|
ChangeAvailabilityConfirmation _confirm = confirm as ChangeAvailabilityConfirmation;
|
|
|
ChangeAvailabilityRequest _request = _confirm.GetRequest() as ChangeAvailabilityRequest;
|
|
|
|
|
|
- using (var db = await maindbContextFactory.CreateDbContextAsync())
|
|
|
+ using (var db = maindbContextFactory.CreateDbContext())
|
|
|
{
|
|
|
var operation = await db.MachineOperateRecord.Where(x => x.SerialNo == requestId &&
|
|
|
x.ChargeBoxId == session.ChargeBoxId && x.Status == 0).FirstOrDefaultAsync();
|
|
@@ -1329,7 +1341,7 @@ internal partial class ProfileHandler
|
|
|
ClearCacheConfirmation _confirm = confirm as ClearCacheConfirmation;
|
|
|
ClearCacheRequest _request = _confirm.GetRequest() as ClearCacheRequest;
|
|
|
|
|
|
- using (var db = await maindbContextFactory.CreateDbContextAsync())
|
|
|
+ using (var db = maindbContextFactory.CreateDbContext())
|
|
|
{
|
|
|
var operation = await db.MachineOperateRecord.Where(x => x.SerialNo == requestId &&
|
|
|
x.ChargeBoxId == session.ChargeBoxId && x.Status == 0).FirstOrDefaultAsync();
|
|
@@ -1350,7 +1362,7 @@ internal partial class ProfileHandler
|
|
|
RemoteStartTransactionConfirmation _confirm = confirm as RemoteStartTransactionConfirmation;
|
|
|
RemoteStartTransactionRequest _request = _confirm.GetRequest() as RemoteStartTransactionRequest;
|
|
|
|
|
|
- using (var db = await maindbContextFactory.CreateDbContextAsync())
|
|
|
+ using (var db = maindbContextFactory.CreateDbContext())
|
|
|
{
|
|
|
var operation = await db.MachineOperateRecord.Where(x => x.SerialNo == requestId &&
|
|
|
x.ChargeBoxId == session.ChargeBoxId && x.Status == 0).FirstOrDefaultAsync();
|
|
@@ -1371,7 +1383,7 @@ internal partial class ProfileHandler
|
|
|
RemoteStopTransactionConfirmation _confirm = confirm as RemoteStopTransactionConfirmation;
|
|
|
RemoteStopTransactionRequest _request = _confirm.GetRequest() as RemoteStopTransactionRequest;
|
|
|
|
|
|
- using (var db = await maindbContextFactory.CreateDbContextAsync())
|
|
|
+ using (var db = maindbContextFactory.CreateDbContext())
|
|
|
{
|
|
|
var operation = await db.MachineOperateRecord.Where(x => x.SerialNo == requestId &&
|
|
|
x.ChargeBoxId == session.ChargeBoxId && x.Status == 0).FirstOrDefaultAsync();
|
|
@@ -1392,7 +1404,7 @@ internal partial class ProfileHandler
|
|
|
ResetConfirmation _confirm = confirm as ResetConfirmation;
|
|
|
ResetRequest _request = _confirm.GetRequest() as ResetRequest;
|
|
|
|
|
|
- using (var db = await maindbContextFactory.CreateDbContextAsync())
|
|
|
+ using (var db = maindbContextFactory.CreateDbContext())
|
|
|
{
|
|
|
var operation = await db.MachineOperateRecord.Where(x => x.SerialNo == requestId &&
|
|
|
x.ChargeBoxId == session.ChargeBoxId && x.Status == 0).FirstOrDefaultAsync();
|
|
@@ -1413,7 +1425,7 @@ internal partial class ProfileHandler
|
|
|
ChangeConfigurationConfirmation _confirm = confirm as ChangeConfigurationConfirmation;
|
|
|
ChangeConfigurationRequest _request = _confirm.GetRequest() as ChangeConfigurationRequest;
|
|
|
|
|
|
- using (var db = await maindbContextFactory.CreateDbContextAsync())
|
|
|
+ using (var db = maindbContextFactory.CreateDbContext())
|
|
|
{
|
|
|
var operation = await db.MachineOperateRecord.Where(x => x.SerialNo == requestId &&
|
|
|
x.ChargeBoxId == session.ChargeBoxId && x.Status == 0).FirstOrDefaultAsync();
|
|
@@ -1461,7 +1473,7 @@ internal partial class ProfileHandler
|
|
|
GetConfigurationConfirmation _confirm = confirm as GetConfigurationConfirmation;
|
|
|
// GetConfigurationRequest _request = _confirm.GetRequest() as GetConfigurationRequest;
|
|
|
|
|
|
- using (var db = await maindbContextFactory.CreateDbContextAsync())
|
|
|
+ using (var db = maindbContextFactory.CreateDbContext())
|
|
|
{
|
|
|
var configure = db.MachineConfigurations.Where(x => x.ChargeBoxId == session.ChargeBoxId).ToList();
|
|
|
|
|
@@ -1558,7 +1570,7 @@ internal partial class ProfileHandler
|
|
|
UnlockConnectorConfirmation _confirm = confirm as UnlockConnectorConfirmation;
|
|
|
UnlockConnectorRequest _request = _confirm.GetRequest() as UnlockConnectorRequest;
|
|
|
|
|
|
- using (var db = await maindbContextFactory.CreateDbContextAsync())
|
|
|
+ using (var db = maindbContextFactory.CreateDbContext())
|
|
|
{
|
|
|
var operation = await db.MachineOperateRecord.Where(x => x.SerialNo == requestId &&
|
|
|
x.ChargeBoxId == session.ChargeBoxId && x.Status == 0).FirstOrDefaultAsync();
|
|
@@ -1613,7 +1625,7 @@ internal partial class ProfileHandler
|
|
|
logger.LogDebug(string.Format("DataTransfer Error {0}: {1}", session.ChargeBoxId, requestId));
|
|
|
}
|
|
|
|
|
|
- using (var db = await maindbContextFactory.CreateDbContextAsync())
|
|
|
+ using (var db = maindbContextFactory.CreateDbContext())
|
|
|
{
|
|
|
var operation = await db.MachineOperateRecord.Where(x => x.SerialNo == requestId &&
|
|
|
x.ChargeBoxId == session.ChargeBoxId && x.Status == 0).FirstOrDefaultAsync();
|