Overview
The IPrintService interface defines the core printing service contract for the Appsiel Print Manager. It orchestrates the complete printing workflow including parsing, rendering, ESC/POS command generation, and sending data to printers.
Namespace: AppsielPrintManager.Core.Interfaces
Methods
ProcessPrintJobAsync
Processes a print job request, including parsing, rendering, generating ESC/POS commands, and sending to the printer(s).
Task<PrintJobResult> ProcessPrintJobAsync(PrintJobRequest request)
The print job request object containing all details of the printing task
A PrintJobResult indicating the success or failure of the operation
Example:
var request = new PrintJobRequest
{
DocumentType = "invoice",
PrinterId = "thermal-printer-01",
Data = new Dictionary<string, object>
{
{ "invoiceNumber", "INV-001" },
{ "total", 150.00m },
{ "items", itemsList }
}
};
var result = await printService.ProcessPrintJobAsync(request);
if (result.Success)
{
Console.WriteLine($"Print job completed: {result.JobId}");
}
else
{
Console.WriteLine($"Print job failed: {result.ErrorMessage}");
}
Configures a specific printer by saving or updating its settings.
Task ConfigurePrinterAsync(PrinterSettings settings)
The printer configuration to save or update
A task representing the asynchronous operation
Example:
var printerSettings = new PrinterSettings
{
PrinterId = "thermal-printer-01",
PrinterType = "Térmica",
IpAddress = "192.168.1.100",
Port = 9100,
PaperWidthMm = 80,
ConnectionType = "TCP",
BeepOnPrint = false,
OpenCashDrawerAfterPrint = false
};
await printService.ConfigurePrinterAsync(printerSettings);
Console.WriteLine("Printer configured successfully");
GetPrinterSettingsAsync
Retrieves the configuration of a printer by its identifier.
Task<PrinterSettings> GetPrinterSettingsAsync(string printerId)
The unique identifier of the printer
The printer configuration if found, otherwise null
Example:
var settings = await printService.GetPrinterSettingsAsync("thermal-printer-01");
if (settings != null)
{
Console.WriteLine($"Printer ID: {settings.PrinterId}");
Console.WriteLine($"Type: {settings.PrinterType}");
Console.WriteLine($"Connection: {settings.ConnectionType}");
Console.WriteLine($"IP: {settings.IpAddress}:{settings.Port}");
}
else
{
Console.WriteLine("Printer not found");
}
GetAllPrinterSettingsAsync
Retrieves all saved printer configurations.
Task<List<PrinterSettings>> GetAllPrinterSettingsAsync()
return
Task<List<PrinterSettings>>
A list of all printer configurations
Example:
var allPrinters = await printService.GetAllPrinterSettingsAsync();
Console.WriteLine($"Total printers configured: {allPrinters.Count}");
foreach (var printer in allPrinters)
{
Console.WriteLine($"- {printer.PrinterId} ({printer.PrinterType}) - {printer.ConnectionType}");
}
DeletePrinterSettingsAsync
Deletes a printer configuration by its identifier.
Task DeletePrinterSettingsAsync(string printerId)
The unique identifier of the printer to delete
A task representing the asynchronous operation
Example:
await printService.DeletePrinterSettingsAsync("thermal-printer-01");
Console.WriteLine("Printer configuration deleted successfully");
Usage Example
Complete example showing typical IPrintService usage:
public class PrintController
{
private readonly IPrintService _printService;
public PrintController(IPrintService printService)
{
_printService = printService;
}
public async Task SetupAndPrintAsync()
{
// 1. Configure a printer
var settings = new PrinterSettings
{
PrinterId = "receipt-printer",
PrinterType = "Térmica",
IpAddress = "192.168.1.100",
Port = 9100,
PaperWidthMm = 80,
ConnectionType = "TCP",
BeepOnPrint = true,
OpenCashDrawerAfterPrint = false
};
await _printService.ConfigurePrinterAsync(settings);
// 2. Create and process a print job
var request = new PrintJobRequest
{
DocumentType = "receipt",
PrinterId = "receipt-printer",
Data = new Dictionary<string, object>
{
{ "orderNumber", "ORD-12345" },
{ "total", 85.50m }
}
};
var result = await _printService.ProcessPrintJobAsync(request);
if (result.Success)
{
Console.WriteLine("Receipt printed successfully");
}
else
{
Console.WriteLine($"Print failed: {result.ErrorMessage}");
}
}
}
See Also