Untitled
unknown
csharp
2 years ago
2.3 kB
4
Indexable
Never
using System.Threading; using System.Threading.Tasks; using Autofac; using Data.Base; using Domain; using Domain.CustomerParcels; using Utilities.Services.Printing; namespace Facade.CustomerParcels; public interface ICustomerParcelPrintService { Task<PrintStatus> PrintTransformationLabels(long customerParcelId, long activityId, string printerName, CancellationToken cancellationToken); Task<PrintStatus> PrintLabels(long customerParcelId, long activityId, string printerName, CancellationToken cancellationToken); } public class CustomerParcelPrintService : ICustomerParcelPrintService { private readonly ILifetimeScope _lifetimeScope; private readonly IPrinterService _printerService; private readonly SessionInformation _sessionInformation; public CustomerParcelPrintService(ILifetimeScope lifetimeScope, IPrinterService printerService, SessionInformation sessionInformation) { _lifetimeScope = lifetimeScope; _printerService = printerService; _sessionInformation = sessionInformation; } public async Task<PrintStatus> PrintTransformationLabels(long customerParcelId, long activityId, string printerName, CancellationToken cancellationToken) { var transformationRepository = _lifetimeScope.ResolveKeyed<ICustomerParcelTransformationRepository>((ActivityEnum)activityId); var messagesTransformation = await transformationRepository.GetParcelLabelAsync(customerParcelId, cancellationToken); return await _printerService.SendToPrinter(messagesTransformation, printerName, cancellationToken, _sessionInformation.CorrelationId); } public async Task<PrintStatus> PrintLabels(long customerParcelId, long activityId, string printerName, CancellationToken cancellationToken) { var parcelRepository = _lifetimeScope.ResolveKeyed<ICustomerParcelRepository>((ActivityEnum)activityId); var message = await parcelRepository.GetParcelLabelAsync(customerParcelId, cancellationToken); return await _printerService.SendToPrinter(message, printerName, cancellationToken, _sessionInformation.CorrelationId); } }