12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- using EVCB_OCPP.Domain;
- using EVCB_OCPP.Domain.Models.Database;
- using EVCB_OCPP.Packet.Messages.SubTypes;
- using EVCB_OCPP.WSServer.Dto;
- using Microsoft.EntityFrameworkCore;
- using Microsoft.Extensions.DependencyInjection;
- using System;
- using System.Linq;
- using System.Threading.Tasks;
- namespace EVCB_OCPP.WSServer.Service;
- public interface IBusinessService
- {
- Task<IdTokenInfo> Authorize(string chargeBoxId, string idTag, int? connectorId = null);
- Task NotifyFaultStatus(ErrorDetails details);
- Task NotifyConnectorUnplugged(string chargeBoxId,string data);
- }
- public static class BusinessServiceFactoryRegistration
- {
- public static void AddBusinessServiceFactory(this IServiceCollection services)
- {
- services.AddSingleton<HttpClientService>();
- services.AddSingleton<OuterHttpClient>();
- services.AddTransient<OuterBusinessService>();
- services.AddTransient<LocalBusinessService>();
- services.AddSingleton<IBusinessServiceFactory, BusinessServiceFactory>();
- }
- }
- public class BusinessServiceFactory : IBusinessServiceFactory
- {
- public BusinessServiceFactory(
- IServiceProvider serviceProvider,
- IMainDbService mainDbService
- //IDbContextFactory<MainDBContext> mainDBContextFactory
- )
- {
- this.serviceProvider = serviceProvider;
- this.mainDbService = mainDbService;
-
- }
- private readonly IServiceProvider serviceProvider;
- private readonly IMainDbService mainDbService;
-
- public async Task<IBusinessService> CreateBusinessService(string customerId)
- {
- bool isCallOut = false;
-
-
-
-
- CustomerSignMaterial _customer = null;
-
-
-
-
- var _customerDb = await mainDbService.GetCustomer(customerId);
- if (_customerDb is not null)
- {
- _customer = new CustomerSignMaterial() {
- Id = _customerDb.Id.ToString(),
- APIUrl = _customerDb.ApiUrl,
- SaltKey = _customerDb.ApiKey,
- CallsThirdParty = _customerDb.CallPartnerApiOnSchedule
- };
- }
- isCallOut = _customer != null && _customer.CallsThirdParty;
-
- if (isCallOut)
- {
- OuterBusinessService outerBusinessService = serviceProvider.GetService<OuterBusinessService>();
-
- outerBusinessService.CustomerSignMaterial = _customer;
- return outerBusinessService;
- }
- LocalBusinessService toReturn = serviceProvider.GetService<LocalBusinessService>();
- toReturn.CustomerId = customerId;
- return toReturn;
-
- }
- }
|