123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- 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);
- Task NotifyFaultStatus(ErrorDetails details);
- Task NotifyConnectorUnplugged(string chargeBoxId,string data);
- }
- public static class BusinessServiceFactoryRegistration
- {
- public static void AddBusinessServiceFactory(this IServiceCollection services)
- {
- services.AddSingleton<OuterBusinessService>();
- services.AddSingleton<LocalBusinessService>();
- services.AddSingleton<IBusinessServiceFactory, BusinessServiceFactory>();
- }
- }
- public class BusinessServiceFactory : IBusinessServiceFactory
- {
- public BusinessServiceFactory(
- IServiceProvider serviceProvider,
- IDbContextFactory<MainDBContext> mainDBContextFactory)
- {
- this.serviceProvider = serviceProvider;
- this.mainDBContextFactory = mainDBContextFactory;
- }
- private readonly IServiceProvider serviceProvider;
- private readonly IDbContextFactory<MainDBContext> mainDBContextFactory;
- public async Task<IBusinessService> CreateBusinessService(string customerId)
- {
- bool isCallOut = false;
- using (var db = this.mainDBContextFactory.CreateDbContext())
- {
- isCallOut = await db.Customer.Where(x => x.Id == new Guid(customerId)).Select(x => x.CallPartnerApiOnSchedule).FirstOrDefaultAsync();
- }
- //return isCallOut ? new OuterBusinessService(customerId) : new LocalBusinessService(customerId);
- if (isCallOut)
- {
- OuterBusinessService outerBusinessService = serviceProvider.GetService<OuterBusinessService>();
- outerBusinessService.CustomerId = customerId;
- return outerBusinessService;
- }
- LocalBusinessService toReturn = serviceProvider.GetService<LocalBusinessService>();
- toReturn.CustomerId = customerId;
- return toReturn;
- //return isCallOut ? new OuterBusinessService(customerId) :
- }
- }
|