test run works
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Reflection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Inspectron.Epson.PrintServer.Printers;
|
||||
using Inspectron.Epson.PrintServer.Printers.Utils;
|
||||
|
||||
namespace Inspectron.Epson.PrintServer.PrintServices;
|
||||
|
||||
@@ -10,13 +10,15 @@ public class EpsonPrintService: IPrintService
|
||||
private readonly IPrinterFactory _printerFactory;
|
||||
private readonly IWrapperPrinterFactory _wrapperPrinterFactory;
|
||||
private readonly IPrinterConfigurationSource _printerConfigurationSource;
|
||||
private readonly IReceiptConverterFactory _receiptConverterFactory;
|
||||
|
||||
public EpsonPrintService(ILogger logger, IPrinterFactory printerFactory, IWrapperPrinterFactory wrapperPrinterFactory, IPrinterConfigurationSource printerConfigurationSource)
|
||||
public EpsonPrintService(ILogger logger, IPrinterFactory printerFactory, IWrapperPrinterFactory wrapperPrinterFactory, IPrinterConfigurationSource printerConfigurationSource, IReceiptConverterFactory receiptConverterFactory)
|
||||
{
|
||||
_logger = logger;
|
||||
_printerFactory = printerFactory;
|
||||
_wrapperPrinterFactory = wrapperPrinterFactory;
|
||||
_printerConfigurationSource = printerConfigurationSource;
|
||||
_receiptConverterFactory = receiptConverterFactory;
|
||||
}
|
||||
|
||||
public async Task<bool> PrintAsync(string printerIp, PrintJob job)
|
||||
@@ -25,19 +27,8 @@ public class EpsonPrintService: IPrintService
|
||||
{
|
||||
var configuration = _printerConfigurationSource.GetConfiguration(printerIp);
|
||||
await using var epsonPrinter = _printerFactory.CreatePrinter();
|
||||
string address;
|
||||
string address = printerIp;
|
||||
int port = 9100;
|
||||
var printerAddress = configuration.Address;
|
||||
if (printerAddress.Contains(":"))
|
||||
{
|
||||
var parts = printerAddress.Split(':');
|
||||
address = parts[0];
|
||||
port = int.Parse(parts[1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
address = printerAddress;
|
||||
}
|
||||
|
||||
await epsonPrinter.ConnectAsync(address, port);
|
||||
|
||||
@@ -90,7 +81,10 @@ public class EpsonPrintService: IPrintService
|
||||
|
||||
await printerAdapter.SetFontSizeAsync(configuration.FontSize);
|
||||
|
||||
await printerAdapter.PrintTextAsync(job.Document.Content);
|
||||
// Convert receipt content to print commands using the factory
|
||||
var converter = _receiptConverterFactory.Create(job.Document.ReceiptType, lineWidth: 48, bigFontLineWidth: 24);
|
||||
var commands = converter.Convert(job.Document.Content);
|
||||
await printerAdapter.PrintAsync(commands);
|
||||
await Task.Delay(200);
|
||||
status = await epsonPrinter.GetPrinterStatusAsync();
|
||||
if (!status.IsOnline)
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
namespace Inspectron.Epson.PrintServer.PrintServices;
|
||||
using Inspectron.Epson.PrintServer.Printers.Utils;
|
||||
|
||||
namespace Inspectron.Epson.PrintServer.PrintServices;
|
||||
|
||||
public interface IPrinter
|
||||
{
|
||||
public Task InitAsync();
|
||||
public Task PrintImageAsync(string path);
|
||||
public Task SetFontSizeAsync(int fontSize);
|
||||
public Task PrintTextAsync(string text);
|
||||
public Task PrintAsync(List<PrintCommand> commands);
|
||||
public Task Cut();
|
||||
}
|
||||
Reference in New Issue
Block a user