|
@@ -88,11 +88,11 @@ internal partial class ProfileHandler
|
|
|
//private readonly IDbContextFactory<MeterValueDBContext> metervaluedbContextFactory;
|
|
|
private readonly IBusinessServiceFactory businessServiceFactory;
|
|
|
private readonly IMainDbService mainDbService;
|
|
|
- private OuterHttpClient httpClient = new OuterHttpClient();
|
|
|
+ private OuterHttpClient httpClient;
|
|
|
|
|
|
public ProfileHandler(
|
|
|
IConfiguration configuration,
|
|
|
- IDbContextFactory<MainDBContext> maindbContextFactory,
|
|
|
+ IDbContextFactory<MainDBContext> maindbContextFactory,
|
|
|
SqlConnectionFactory<WebDBConetext> webDbConnectionFactory,
|
|
|
//IDbContextFactory<MeterValueDBContext> metervaluedbContextFactory,
|
|
|
MeterValueDbService meterValueDbService,
|
|
@@ -100,7 +100,8 @@ internal partial class ProfileHandler
|
|
|
IMainDbService mainDbService,
|
|
|
ILogger<ProfileHandler> logger,
|
|
|
BlockingTreePrintService blockingTreePrintService,
|
|
|
- GoogleGetTimePrintService googleGetTimePrintService)
|
|
|
+ GoogleGetTimePrintService googleGetTimePrintService,
|
|
|
+ OuterHttpClient httpClient)
|
|
|
{
|
|
|
//webConnectionString = configuration.GetConnectionString("WebDBContext");
|
|
|
|
|
@@ -113,6 +114,7 @@ internal partial class ProfileHandler
|
|
|
this.mainDbService = mainDbService;
|
|
|
//this.metervaluedbContextFactory = metervaluedbContextFactory;
|
|
|
this.businessServiceFactory = businessServiceFactory;
|
|
|
+ this.httpClient = httpClient;
|
|
|
}
|
|
|
|
|
|
async internal Task<MessageResult> ExecuteCoreRequest(Actions action, ClientData session, IRequest request)
|
|
@@ -381,7 +383,7 @@ internal partial class ProfileHandler
|
|
|
energyRegister = energy_Register.unit.Value == UnitOfMeasure.kWh ? decimal.Multiply(energyRegister, 1000) : energyRegister;
|
|
|
|
|
|
|
|
|
- using (var maindb = maindbContextFactory.CreateDbContext())
|
|
|
+ using (var maindb = await maindbContextFactory.CreateDbContextAsync())
|
|
|
{
|
|
|
meterStart = await maindb.TransactionRecord
|
|
|
.Where(x => x.Id == _request.transactionId.Value).Select(x => x.MeterStart)
|
|
@@ -536,7 +538,7 @@ internal partial class ProfileHandler
|
|
|
}
|
|
|
|
|
|
|
|
|
- using (var db = maindbContextFactory.CreateDbContext())
|
|
|
+ using (var db = await maindbContextFactory.CreateDbContextAsync())
|
|
|
{
|
|
|
var _CustomerId = await db.Machine.Where(x => x.ChargeBoxId == session.ChargeBoxId).Include(x => x.Customer).
|
|
|
Select(x => x.CustomerId).FirstOrDefaultAsync();
|
|
@@ -642,7 +644,7 @@ internal partial class ProfileHandler
|
|
|
}
|
|
|
try
|
|
|
{
|
|
|
- using (var db = maindbContextFactory.CreateDbContext())
|
|
|
+ using (var db = await maindbContextFactory.CreateDbContextAsync())
|
|
|
{
|
|
|
var transaction = db.TransactionRecord.Where(x => x.Id == _request.transactionId
|
|
|
&& x.ChargeBoxId == session.ChargeBoxId).FirstOrDefault();
|
|
@@ -776,6 +778,8 @@ internal partial class ProfileHandler
|
|
|
result.Exception = new Exception("TransactionId " + _request.transactionId + " " + ex.Message);
|
|
|
result.CallErrorMsg = "Reject Response Message";
|
|
|
result.Success = false;
|
|
|
+
|
|
|
+ logger.LogCritical("StopTransaction {msg} trace:{trace}", ex.Message, ex.StackTrace);
|
|
|
// return result;
|
|
|
}
|
|
|
|
|
@@ -871,11 +875,11 @@ internal partial class ProfileHandler
|
|
|
|
|
|
if (watch.ElapsedMilliseconds > 5_000)
|
|
|
{
|
|
|
- ThreadPool.GetAvailableThreads(out int workerThreads,out int completionThreads);
|
|
|
- logger.LogInformation($"ThreadPool workerThreads:{workerThreads} completionThreads:{completionThreads}");
|
|
|
+ //ThreadPool.GetAvailableThreads(out int workerThreads,out int completionThreads);
|
|
|
+ //logger.LogInformation($"ThreadPool workerThreads:{workerThreads} completionThreads:{completionThreads}");
|
|
|
|
|
|
- await blockingTreePrintService.PrintDbBlockingTree();
|
|
|
- await googleGetTimePrintService.Print();
|
|
|
+ //await blockingTreePrintService.PrintDbBlockingTree();
|
|
|
+ //await googleGetTimePrintService.Print();
|
|
|
}
|
|
|
|
|
|
return result;
|
|
@@ -893,7 +897,7 @@ internal partial class ProfileHandler
|
|
|
{
|
|
|
DataTransferConfirmation _confirm = confirm as DataTransferConfirmation;
|
|
|
DataTransferRequest _request = _confirm.GetRequest() as DataTransferRequest;
|
|
|
- using (var db = maindbContextFactory.CreateDbContext())
|
|
|
+ using (var db = await maindbContextFactory.CreateDbContextAsync())
|
|
|
{
|
|
|
var operation = await db.MachineOperateRecord.Where(x => x.SerialNo == requestId &&
|
|
|
x.ChargeBoxId == session.ChargeBoxId && x.Status == 0).FirstOrDefaultAsync();
|
|
@@ -1204,7 +1208,7 @@ internal partial class ProfileHandler
|
|
|
#region 提供給PHA 過CDFA認證 使用
|
|
|
if (tx.CustomerId == Guid.Parse("10C7F5BD-C89A-4E2A-8611-B617E0B41A73"))
|
|
|
{
|
|
|
- var mail_response = new OuterHttpClient().PostFormDataAsync("http://ocpp.phihong.com.tw/CDFA/" + tx.Id, new Dictionary<string, string>()
|
|
|
+ var mail_response = httpClient.PostFormDataAsync("http://ocpp.phihong.com.tw/CDFA/" + tx.Id, new Dictionary<string, string>()
|
|
|
{
|
|
|
{ "email","2"},
|
|
|
{ "to","wonderj@phihongusa.com;jessica_tseng@phihong.com.tw"}
|
|
@@ -1298,7 +1302,7 @@ internal partial class ProfileHandler
|
|
|
ChangeAvailabilityConfirmation _confirm = confirm as ChangeAvailabilityConfirmation;
|
|
|
ChangeAvailabilityRequest _request = _confirm.GetRequest() as ChangeAvailabilityRequest;
|
|
|
|
|
|
- using (var db = maindbContextFactory.CreateDbContext())
|
|
|
+ using (var db = await maindbContextFactory.CreateDbContextAsync())
|
|
|
{
|
|
|
var operation = await db.MachineOperateRecord.Where(x => x.SerialNo == requestId &&
|
|
|
x.ChargeBoxId == session.ChargeBoxId && x.Status == 0).FirstOrDefaultAsync();
|
|
@@ -1319,7 +1323,7 @@ internal partial class ProfileHandler
|
|
|
ClearCacheConfirmation _confirm = confirm as ClearCacheConfirmation;
|
|
|
ClearCacheRequest _request = _confirm.GetRequest() as ClearCacheRequest;
|
|
|
|
|
|
- using (var db = maindbContextFactory.CreateDbContext())
|
|
|
+ using (var db = await maindbContextFactory.CreateDbContextAsync())
|
|
|
{
|
|
|
var operation = await db.MachineOperateRecord.Where(x => x.SerialNo == requestId &&
|
|
|
x.ChargeBoxId == session.ChargeBoxId && x.Status == 0).FirstOrDefaultAsync();
|
|
@@ -1340,7 +1344,7 @@ internal partial class ProfileHandler
|
|
|
RemoteStartTransactionConfirmation _confirm = confirm as RemoteStartTransactionConfirmation;
|
|
|
RemoteStartTransactionRequest _request = _confirm.GetRequest() as RemoteStartTransactionRequest;
|
|
|
|
|
|
- using (var db = maindbContextFactory.CreateDbContext())
|
|
|
+ using (var db = await maindbContextFactory.CreateDbContextAsync())
|
|
|
{
|
|
|
var operation = await db.MachineOperateRecord.Where(x => x.SerialNo == requestId &&
|
|
|
x.ChargeBoxId == session.ChargeBoxId && x.Status == 0).FirstOrDefaultAsync();
|
|
@@ -1361,7 +1365,7 @@ internal partial class ProfileHandler
|
|
|
RemoteStopTransactionConfirmation _confirm = confirm as RemoteStopTransactionConfirmation;
|
|
|
RemoteStopTransactionRequest _request = _confirm.GetRequest() as RemoteStopTransactionRequest;
|
|
|
|
|
|
- using (var db = maindbContextFactory.CreateDbContext())
|
|
|
+ using (var db = await maindbContextFactory.CreateDbContextAsync())
|
|
|
{
|
|
|
var operation = await db.MachineOperateRecord.Where(x => x.SerialNo == requestId &&
|
|
|
x.ChargeBoxId == session.ChargeBoxId && x.Status == 0).FirstOrDefaultAsync();
|
|
@@ -1382,7 +1386,7 @@ internal partial class ProfileHandler
|
|
|
ResetConfirmation _confirm = confirm as ResetConfirmation;
|
|
|
ResetRequest _request = _confirm.GetRequest() as ResetRequest;
|
|
|
|
|
|
- using (var db = maindbContextFactory.CreateDbContext())
|
|
|
+ using (var db = await maindbContextFactory.CreateDbContextAsync())
|
|
|
{
|
|
|
var operation = await db.MachineOperateRecord.Where(x => x.SerialNo == requestId &&
|
|
|
x.ChargeBoxId == session.ChargeBoxId && x.Status == 0).FirstOrDefaultAsync();
|
|
@@ -1403,7 +1407,7 @@ internal partial class ProfileHandler
|
|
|
ChangeConfigurationConfirmation _confirm = confirm as ChangeConfigurationConfirmation;
|
|
|
ChangeConfigurationRequest _request = _confirm.GetRequest() as ChangeConfigurationRequest;
|
|
|
|
|
|
- using (var db = maindbContextFactory.CreateDbContext())
|
|
|
+ using (var db = await maindbContextFactory.CreateDbContextAsync())
|
|
|
{
|
|
|
var operation = await db.MachineOperateRecord.Where(x => x.SerialNo == requestId &&
|
|
|
x.ChargeBoxId == session.ChargeBoxId && x.Status == 0).FirstOrDefaultAsync();
|
|
@@ -1451,9 +1455,9 @@ internal partial class ProfileHandler
|
|
|
GetConfigurationConfirmation _confirm = confirm as GetConfigurationConfirmation;
|
|
|
// GetConfigurationRequest _request = _confirm.GetRequest() as GetConfigurationRequest;
|
|
|
|
|
|
- using (var db = maindbContextFactory.CreateDbContext())
|
|
|
+ using (var db = await maindbContextFactory.CreateDbContextAsync())
|
|
|
{
|
|
|
- var configure = db.MachineConfigurations.Where(x => x.ChargeBoxId == session.ChargeBoxId).ToList();
|
|
|
+ var configure = await db.MachineConfigurations.Where(x => x.ChargeBoxId == session.ChargeBoxId).ToListAsync();
|
|
|
|
|
|
if (_confirm.configurationKey != null)
|
|
|
{
|
|
@@ -1548,7 +1552,7 @@ internal partial class ProfileHandler
|
|
|
UnlockConnectorConfirmation _confirm = confirm as UnlockConnectorConfirmation;
|
|
|
UnlockConnectorRequest _request = _confirm.GetRequest() as UnlockConnectorRequest;
|
|
|
|
|
|
- using (var db = maindbContextFactory.CreateDbContext())
|
|
|
+ using (var db = await maindbContextFactory.CreateDbContextAsync())
|
|
|
{
|
|
|
var operation = await db.MachineOperateRecord.Where(x => x.SerialNo == requestId &&
|
|
|
x.ChargeBoxId == session.ChargeBoxId && x.Status == 0).FirstOrDefaultAsync();
|
|
@@ -1603,7 +1607,7 @@ internal partial class ProfileHandler
|
|
|
logger.LogDebug(string.Format("DataTransfer Error {0}: {1}", session.ChargeBoxId, requestId));
|
|
|
}
|
|
|
|
|
|
- using (var db = maindbContextFactory.CreateDbContext())
|
|
|
+ using (var db = await maindbContextFactory.CreateDbContextAsync())
|
|
|
{
|
|
|
var operation = await db.MachineOperateRecord.Where(x => x.SerialNo == requestId &&
|
|
|
x.ChargeBoxId == session.ChargeBoxId && x.Status == 0).FirstOrDefaultAsync();
|