123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- using EVCB_OCPP.Domain;
- 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;
-
- }
- }
|