|
@@ -17,11 +17,11 @@ namespace EVCB_OCPP.WSServer.Service;
|
|
|
|
|
|
public interface IMainDbService
|
|
|
{
|
|
|
- Task<string> GetMachineAuthorizationKey(string ChargeBoxId);
|
|
|
- Task<string> GetMachineConfiguration(string ChargeBoxId, string configName);
|
|
|
+ Task<string> GetMachineAuthorizationKey(string ChargeBoxId, CancellationToken token = default);
|
|
|
+ Task<string> GetMachineConfiguration(string ChargeBoxId, string configName, CancellationToken token = default);
|
|
|
Task<string> GetMachineHeartbeatInterval(string ChargeBoxId);
|
|
|
- Task<MachineAndCustomerInfo> GetMachineIdAndCustomerInfo(string ChargeBoxId);
|
|
|
- Task<string> GetMachineSecurityProfile(string ChargeBoxId);
|
|
|
+ Task<MachineAndCustomerInfo> GetMachineIdAndCustomerInfo(string ChargeBoxId, CancellationToken token = default);
|
|
|
+ Task<string> GetMachineSecurityProfile(string ChargeBoxId, CancellationToken token = default);
|
|
|
Task UpdateMachineBasicInfo(string ChargeBoxId, Machine machine);
|
|
|
Task AddOCMF(Ocmf oCMF);
|
|
|
ValueTask<ConnectorStatus> GetConnectorStatus(string ChargeBoxId, int ConnectorId);
|
|
@@ -31,8 +31,8 @@ public interface IMainDbService
|
|
|
Task AddServerMessage(ServerMessage message);
|
|
|
Task AddServerMessage(string ChargeBoxId, string OutAction, object OutRequest, string CreatedBy = "", DateTime? CreatedOn = null, string SerialNo = "", string InMessage = "");
|
|
|
ValueTask AddMachineError(byte ConnectorId, DateTime CreatedOn, int Status, string ChargeBoxId, int ErrorCodeId, string ErrorInfo, int PreStatus, string VendorErrorCode, string VendorId);
|
|
|
- ValueTask<Customer> GetCustomer(string id);
|
|
|
- ValueTask<Customer> GetCustomer(Guid id);
|
|
|
+ ValueTask<Customer> GetCustomer(string id, CancellationToken token = default);
|
|
|
+ ValueTask<Customer> GetCustomer(Guid id, CancellationToken token = default);
|
|
|
Task<Guid> GetCustomerIdByChargeBoxId(string chargeboxId);
|
|
|
Task<int?> TryGetDuplicatedTransactionId(string chargeBoxId, Guid customerId, int connectorId, DateTime timestamp);
|
|
|
Task<int> AddNewTransactionRecord(TransactionRecord newTransaction);
|
|
@@ -88,39 +88,44 @@ public class MainDbService : IMainDbService
|
|
|
private GroupHandler<UpdateMachineBasicInfoParam> updateMachineBasicInfoHandler;
|
|
|
private GroupHandler<ServerMessage> addServerMessageHandler;
|
|
|
|
|
|
- public async Task<MachineAndCustomerInfo> GetMachineIdAndCustomerInfo(string ChargeBoxId)
|
|
|
+ public async Task<MachineAndCustomerInfo> GetMachineIdAndCustomerInfo(string ChargeBoxId, CancellationToken token = default)
|
|
|
{
|
|
|
using var semaphoreWrapper = await startupSemaphore.GetToken();
|
|
|
- using var db = await contextFactory.CreateDbContextAsync();
|
|
|
+ using var db = await contextFactory.CreateDbContextAsync(token);
|
|
|
|
|
|
- var machine = await db.Machines.Where(x => x.ChargeBoxId == ChargeBoxId && x.IsDelete == false).Select(x => new { x.CustomerId, x.Id }).AsNoTracking().FirstOrDefaultAsync();
|
|
|
+ var machine = await db.Machines
|
|
|
+ .Where(x => x.ChargeBoxId == ChargeBoxId && x.IsDelete == false)
|
|
|
+ .Select(x => new { x.CustomerId, x.Id })
|
|
|
+ .AsNoTracking()
|
|
|
+ .FirstOrDefaultAsync(token);
|
|
|
if (machine == null)
|
|
|
{
|
|
|
return new MachineAndCustomerInfo(string.Empty, Guid.Empty, "Unknown");
|
|
|
}
|
|
|
//var customerName = await db.Customer.Where(x => x.Id == machine.CustomerId).Select(x => x.Name).FirstOrDefaultAsync();
|
|
|
- var customer = await GetCustomer(machine.CustomerId);
|
|
|
+ var customer = await GetCustomer(machine.CustomerId, token);
|
|
|
var customerName = customer?.Name;
|
|
|
return new MachineAndCustomerInfo(machine.Id, machine.CustomerId, customerName);
|
|
|
}
|
|
|
|
|
|
- public async Task<string> GetMachineConfiguration(string ChargeBoxId, string configName)
|
|
|
+ public async Task<string> GetMachineConfiguration(string ChargeBoxId, string configName, CancellationToken token = default)
|
|
|
{
|
|
|
using var semaphoreWrapper = await startupSemaphore.GetToken();
|
|
|
- using var db = await contextFactory.CreateDbContextAsync();
|
|
|
+ using var db = await contextFactory.CreateDbContextAsync(token);
|
|
|
return await db.MachineConfigurations
|
|
|
.Where(x => x.ChargeBoxId == ChargeBoxId && x.ConfigureName == configName)
|
|
|
- .Select(x => x.ConfigureSetting).FirstOrDefaultAsync();
|
|
|
+ .Select(x => x.ConfigureSetting)
|
|
|
+ .FirstOrDefaultAsync(token);
|
|
|
}
|
|
|
|
|
|
- public Task<string> GetMachineSecurityProfile(string ChargeBoxId)
|
|
|
+ public Task<string> GetMachineSecurityProfile(string ChargeBoxId, CancellationToken token = default)
|
|
|
{
|
|
|
return GetMachineConfiguration(ChargeBoxId, StandardConfiguration.SecurityProfile);
|
|
|
}
|
|
|
|
|
|
- public Task<string> GetMachineAuthorizationKey(string ChargeBoxId)
|
|
|
+ public Task<string> GetMachineAuthorizationKey(string ChargeBoxId, CancellationToken token = default)
|
|
|
{
|
|
|
- return GetMachineConfiguration(ChargeBoxId, StandardConfiguration.AuthorizationKey);
|
|
|
+ return GetMachineConfiguration(ChargeBoxId, StandardConfiguration.AuthorizationKey, token);
|
|
|
}
|
|
|
|
|
|
public Task<string> GetMachineHeartbeatInterval(string ChargeBoxId)
|
|
@@ -261,10 +266,10 @@ public class MainDbService : IMainDbService
|
|
|
return AddServerMessageDapper(message);
|
|
|
}
|
|
|
|
|
|
- public ValueTask<Customer> GetCustomer(string id)
|
|
|
- => GetCustomer(new Guid(id));
|
|
|
+ public ValueTask<Customer> GetCustomer(string id, CancellationToken token = default)
|
|
|
+ => GetCustomer(new Guid(id), token);
|
|
|
|
|
|
- public async ValueTask<Customer> GetCustomer(Guid id)
|
|
|
+ public async ValueTask<Customer> GetCustomer(Guid id, CancellationToken token = default)
|
|
|
{
|
|
|
var key = string.Format(CustomerMemCacheKeyFromat, id);
|
|
|
if (memoryCache.TryGetValue<Customer>(key, out var customer))
|
|
@@ -273,9 +278,9 @@ public class MainDbService : IMainDbService
|
|
|
}
|
|
|
|
|
|
Customer toReturn = null;
|
|
|
- using (var db = await contextFactory.CreateDbContextAsync())
|
|
|
+ using (var db = await contextFactory.CreateDbContextAsync(token))
|
|
|
{
|
|
|
- toReturn = await db.Customers.FirstOrDefaultAsync(x => x.Id == id);
|
|
|
+ toReturn = await db.Customers.FirstOrDefaultAsync(x => x.Id == id, token);
|
|
|
}
|
|
|
|
|
|
if (toReturn is not null)
|