BusinessServiceFactory.cs 996 B

123456789101112131415161718192021222324252627282930313233343536
  1. using EVCB_OCPP.Domain;
  2. using EVCB_OCPP.Packet.Messages.SubTypes;
  3. using EVCB_OCPP.WSServer.Dto;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. namespace EVCB_OCPP.WSServer.Service
  10. {
  11. public interface IBusinessService
  12. {
  13. Task<IdTagInfo> Authorize(string chargeBoxId, string idTag);
  14. Task NotifyFaultStatus(ErrorDetails details);
  15. }
  16. static public class BusinessServiceFactory
  17. {
  18. static public IBusinessService CreateBusinessService(string customerId)
  19. {
  20. bool isCallOut = false;
  21. using (var db = new MainDBContext())
  22. {
  23. isCallOut = db.Customer.Where(x => x.Id == new Guid(customerId)).Select(x => x.CallPartnerApiOnSchedule).SingleOrDefault();
  24. }
  25. return isCallOut ? new OuterBusinessService(customerId) : (IBusinessService)new LocalBusinessService(customerId);
  26. }
  27. }
  28. }