interactive console test runner for EpsonTest
Replace commented-out code blocks with arrow-key navigation menu. First menu selects receipt type (Kitchen/Final/Invoice/Bar/OrderItems), second selects printer target (HTML or Epson hardware). Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
@@ -1,212 +1,237 @@
|
||||
using EpsonTest;
|
||||
using Inspectron.Epson;
|
||||
using Inspectron.Epson.PrintServer.Printers.Utils.FinalRecipe;
|
||||
using Inspectron.Epson.PrintServer.Printers.Utils.BarReceipt;
|
||||
using Inspectron.Epson.PrintServer.Printers.Utils.FinalReceipt;
|
||||
using Inspectron.Epson.PrintServer.Printers.Utils.InvoiceReceipt;
|
||||
using Inspectron.Epson.PrintServer.Printers.Utils.KitchenReceipt;
|
||||
using Inspectron.Epson.PrintServer.Printers.Utils.OrderItems;
|
||||
using System.Text.Json;
|
||||
|
||||
// ============================================================================
|
||||
// FINAL RECEIPT - HTML PRINTER
|
||||
// ============================================================================
|
||||
//var receipt = TestHelpers.BuildSampleFinalReceipt(true);
|
||||
//var serializedReceipt = JsonSerializer.Serialize(receipt, new JsonSerializerOptions { WriteIndented = true });
|
||||
while (true)
|
||||
{
|
||||
Console.Clear();
|
||||
Console.WriteLine("=== Epson Print Test Runner ===\n");
|
||||
|
||||
//var converter = new FinalReceiptConverter(lineWidth: 48, bigFontLineWidth: 24);
|
||||
//var printCommands = converter.Convert(serializedReceipt);
|
||||
var receiptType = ShowMenu("Select receipt type:", new[]
|
||||
{
|
||||
"KitchenReceipt",
|
||||
"FinalReceipt",
|
||||
"InvoiceReceipt",
|
||||
"BarReceipt",
|
||||
"OrderItems",
|
||||
"Exit"
|
||||
});
|
||||
|
||||
//TestHelpers.PrintCommandsToConsole(printCommands);
|
||||
if (receiptType == 5) break;
|
||||
|
||||
//var printer = await TestHelpers.CreateHtmlPrinterAsync();
|
||||
//await TestHelpers.PrintCommandsToHtmlPrinterAsync(
|
||||
// printer,
|
||||
// printCommands,
|
||||
// logoPath: "ristorante-klinglers.ch-logo_white_bg.png");
|
||||
var printerTarget = ShowMenu("Select printer target:", new[]
|
||||
{
|
||||
"HTML Printer (local file)",
|
||||
"Epson Printer (real hardware)"
|
||||
});
|
||||
|
||||
Console.Clear();
|
||||
Console.WriteLine($"Running {GetReceiptTypeName(receiptType)} on {(printerTarget == 0 ? "HTML" : "Epson")} printer...\n");
|
||||
|
||||
// ============================================================================
|
||||
// FINAL RECEIPT - EPSON PRINTER
|
||||
// ============================================================================
|
||||
//var receipt = TestHelpers.BuildSampleFinalReceipt();
|
||||
//var serializedReceipt = JsonSerializer.Serialize(receipt, new JsonSerializerOptions { WriteIndented = true });
|
||||
try
|
||||
{
|
||||
await RunTest(receiptType, printerTarget);
|
||||
Console.WriteLine("\nDone! Press any key to return to menu...");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"\nError: {ex.Message}");
|
||||
Console.WriteLine("Press any key to return to menu...");
|
||||
}
|
||||
|
||||
//var converter = new FinalReceiptConverter(lineWidth: 48, bigFontLineWidth: 24);
|
||||
//var printCommands = converter.Convert(serializedReceipt);
|
||||
Console.ReadKey(true);
|
||||
}
|
||||
|
||||
//TestHelpers.PrintCommandsToConsole(printCommands);
|
||||
static int ShowMenu(string prompt, string[] options)
|
||||
{
|
||||
int selected = 0;
|
||||
|
||||
//var printer = await TestHelpers.CreateEpsonPrinterAsync();
|
||||
//await TestHelpers.PrintCommandsToEpsonPrinterAsync(printer, printCommands);
|
||||
while (true)
|
||||
{
|
||||
Console.Clear();
|
||||
Console.WriteLine("=== Epson Print Test Runner ===\n");
|
||||
Console.WriteLine(prompt);
|
||||
Console.WriteLine();
|
||||
|
||||
for (int i = 0; i < options.Length; i++)
|
||||
{
|
||||
if (i == selected)
|
||||
{
|
||||
Console.BackgroundColor = ConsoleColor.White;
|
||||
Console.ForegroundColor = ConsoleColor.Black;
|
||||
Console.WriteLine($" > {options[i]}");
|
||||
Console.ResetColor();
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine($" {options[i]}");
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// INVOICE RECEIPT - HTML PRINTER
|
||||
// ============================================================================
|
||||
//var receipt = TestHelpers.BuildSampleInvoiceReceipt();
|
||||
//var serializedReceipt = JsonSerializer.Serialize(receipt, new JsonSerializerOptions { WriteIndented = true });
|
||||
////var fileContent = File.ReadAllText("invoice.json");
|
||||
////var serializedReceipt = JsonSerializer.Deserialize<string>(fileContent);
|
||||
//var converter = new InvoiceReceiptConverter(lineWidth: 48, bigFontLineWidth: 24);
|
||||
//var printCommands = converter.Convert(serializedReceipt);
|
||||
Console.WriteLine("\n[Up/Down] Navigate [Enter] Select");
|
||||
|
||||
//TestHelpers.PrintCommandsToConsole(printCommands);
|
||||
var key = Console.ReadKey(true).Key;
|
||||
switch (key)
|
||||
{
|
||||
case ConsoleKey.UpArrow:
|
||||
selected = (selected - 1 + options.Length) % options.Length;
|
||||
break;
|
||||
case ConsoleKey.DownArrow:
|
||||
selected = (selected + 1) % options.Length;
|
||||
break;
|
||||
case ConsoleKey.Enter:
|
||||
return selected;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//var printer = await TestHelpers.CreateHtmlPrinterAsync();
|
||||
//await TestHelpers.PrintCommandsToHtmlPrinterAsync(
|
||||
// printer,
|
||||
// printCommands,
|
||||
// logoPath: "ristorante-klinglers.ch-logo_white_bg.png");
|
||||
static string GetReceiptTypeName(int index) => index switch
|
||||
{
|
||||
0 => "KitchenReceipt",
|
||||
1 => "FinalReceipt",
|
||||
2 => "InvoiceReceipt",
|
||||
3 => "BarReceipt",
|
||||
4 => "OrderItems",
|
||||
_ => "Unknown"
|
||||
};
|
||||
|
||||
static async Task RunTest(int receiptType, int printerTarget)
|
||||
{
|
||||
switch (receiptType)
|
||||
{
|
||||
case 0: await RunKitchenReceiptTest(printerTarget); break;
|
||||
case 1: await RunFinalReceiptTest(printerTarget); break;
|
||||
case 2: await RunInvoiceReceiptTest(printerTarget); break;
|
||||
case 3: await RunBarReceiptTest(printerTarget); break;
|
||||
case 4: await RunOrderItemsTest(printerTarget); break;
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// INVOICE RECEIPT - EPSON PRINTER
|
||||
// ============================================================================
|
||||
//var receipt = TestHelpers.BuildSampleInvoiceReceipt();
|
||||
//var serializedReceipt = JsonSerializer.Serialize(receipt, new JsonSerializerOptions { WriteIndented = true });
|
||||
static async Task RunKitchenReceiptTest(int printerTarget)
|
||||
{
|
||||
var receipt = TestHelpers.BuildSampleKitchenReceipt();
|
||||
var serializedReceipt = JsonSerializer.Serialize(receipt, new JsonSerializerOptions { WriteIndented = true });
|
||||
var deserializedReceipt = JsonSerializer.Deserialize<KitchenReceipt>(serializedReceipt);
|
||||
|
||||
//var converter = new InvoiceReceiptConverter(lineWidth: 48, bigFontLineWidth: 24);
|
||||
//var printCommands = converter.Convert(serializedReceipt);
|
||||
var converter = new KitchenReceiptConverterKlinglers(bigLineWidth: 20, lineWidth: 33);
|
||||
var printCommands = converter.ConvertToPrintCommands(deserializedReceipt);
|
||||
|
||||
//TestHelpers.PrintCommandsToConsole(printCommands);
|
||||
TestHelpers.PrintCommandsToConsole(printCommands);
|
||||
|
||||
//var printer = await TestHelpers.CreateEpsonPrinterAsync();
|
||||
//await TestHelpers.PrintCommandsToEpsonPrinterAsync(printer, printCommands);
|
||||
|
||||
|
||||
// ============================================================================
|
||||
// KITCHEN RECEIPT - HTML PRINTER
|
||||
// ============================================================================
|
||||
var receipt = TestHelpers.BuildSampleKitchenReceipt();
|
||||
var serializedReceipt = JsonSerializer.Serialize(receipt, new JsonSerializerOptions { WriteIndented = true });
|
||||
var deserializedReceipt = JsonSerializer.Deserialize<KitchenReceipt>(serializedReceipt);
|
||||
|
||||
var converter = new KitchenReceiptConverterKlinglers(bigLineWidth: 20, lineWidth: 33);
|
||||
var printCommands = converter.ConvertToPrintCommands(deserializedReceipt);
|
||||
|
||||
TestHelpers.PrintCommandsToConsole(printCommands);
|
||||
|
||||
var printer = await TestHelpers.CreateHtmlPrinterAsync(
|
||||
if (printerTarget == 0)
|
||||
{
|
||||
var printer = await TestHelpers.CreateHtmlPrinterAsync(
|
||||
path: @".\kitchen_test.html",
|
||||
paperWidth: TestHelpers.KitchenPaperWidth);
|
||||
await TestHelpers.PrintKitchenCommandsToHtmlPrinterAsync(printer, printCommands);
|
||||
await TestHelpers.PrintKitchenCommandsToHtmlPrinterAsync(printer, printCommands);
|
||||
Console.WriteLine("Output written to: kitchen_test.html");
|
||||
}
|
||||
else
|
||||
{
|
||||
var printer = await TestHelpers.CreateEpsonPrinterAsync(paperWidth: TestHelpers.KitchenPaperWidth);
|
||||
await TestHelpers.PrintCommandsToEpsonPrinterAsync(printer, printCommands, useDelay: true);
|
||||
}
|
||||
}
|
||||
|
||||
static async Task RunFinalReceiptTest(int printerTarget)
|
||||
{
|
||||
var receipt = TestHelpers.BuildSampleFinalReceipt();
|
||||
var serializedReceipt = JsonSerializer.Serialize(receipt, new JsonSerializerOptions { WriteIndented = true });
|
||||
|
||||
// ============================================================================
|
||||
// KITCHEN RECEIPT (NEXT DISH) - HTML PRINTER
|
||||
// ============================================================================
|
||||
//var receipt = TestHelpers.BuildSampleKitchenReceiptNextDish();
|
||||
//var serializedReceipt = JsonSerializer.Serialize(receipt, new JsonSerializerOptions { WriteIndented = true });
|
||||
//var deserializedReceipt = JsonSerializer.Deserialize<KitchenReceipt>(serializedReceipt);
|
||||
var converter = new FinalReceiptConverter(lineWidth: 48, bigFontLineWidth: 24);
|
||||
var printCommands = converter.Convert(serializedReceipt);
|
||||
|
||||
//var converter = new KitchenReceiptConverter(bigLineWidth: 18, lineWidth: 33);
|
||||
//var printCommands = converter.ConvertToPrintCommands(deserializedReceipt);
|
||||
TestHelpers.PrintCommandsToConsole(printCommands);
|
||||
|
||||
//TestHelpers.PrintCommandsToConsole(printCommands);
|
||||
if (printerTarget == 0)
|
||||
{
|
||||
var printer = await TestHelpers.CreateHtmlPrinterAsync();
|
||||
await TestHelpers.PrintCommandsToHtmlPrinterAsync(
|
||||
printer,
|
||||
printCommands,
|
||||
logoPath: "ristorante-klinglers.ch-logo_white_bg.png");
|
||||
Console.WriteLine("Output written to: test.html");
|
||||
}
|
||||
else
|
||||
{
|
||||
var printer = await TestHelpers.CreateEpsonPrinterAsync();
|
||||
await TestHelpers.PrintCommandsToEpsonPrinterAsync(printer, printCommands);
|
||||
}
|
||||
}
|
||||
|
||||
//var printer = await TestHelpers.CreateHtmlPrinterAsync(
|
||||
// path: @".\kitchen_next_dish.html",
|
||||
// paperWidth: TestHelpers.KitchenPaperWidth);
|
||||
//await TestHelpers.PrintKitchenCommandsToHtmlPrinterAsync(printer, printCommands);
|
||||
static async Task RunInvoiceReceiptTest(int printerTarget)
|
||||
{
|
||||
var receipt = TestHelpers.BuildSampleInvoiceReceipt();
|
||||
var serializedReceipt = JsonSerializer.Serialize(receipt, new JsonSerializerOptions { WriteIndented = true });
|
||||
|
||||
var converter = new InvoiceReceiptConverter(lineWidth: 48, bigFontLineWidth: 24);
|
||||
var printCommands = converter.Convert(serializedReceipt);
|
||||
|
||||
// ============================================================================
|
||||
// KITCHEN RECEIPT - EPSON PRINTER
|
||||
// ============================================================================
|
||||
//var receipt = TestHelpers.BuildSampleKitchenReceipt();
|
||||
//var serializedReceipt = JsonSerializer.Serialize(receipt, new JsonSerializerOptions { WriteIndented = true });
|
||||
//var deserializedReceipt = JsonSerializer.Deserialize<KitchenReceipt>(serializedReceipt);
|
||||
TestHelpers.PrintCommandsToConsole(printCommands);
|
||||
|
||||
//var converter = new KitchenReceiptConverter(bigLineWidth: 18, lineWidth: 33);
|
||||
//var printCommands = converter.ConvertToPrintCommands(deserializedReceipt);
|
||||
if (printerTarget == 0)
|
||||
{
|
||||
var printer = await TestHelpers.CreateHtmlPrinterAsync(path: @".\invoice_test.html");
|
||||
await TestHelpers.PrintCommandsToHtmlPrinterAsync(
|
||||
printer,
|
||||
printCommands,
|
||||
logoPath: "ristorante-klinglers.ch-logo_white_bg.png");
|
||||
Console.WriteLine("Output written to: invoice_test.html");
|
||||
}
|
||||
else
|
||||
{
|
||||
var printer = await TestHelpers.CreateEpsonPrinterAsync();
|
||||
await TestHelpers.PrintCommandsToEpsonPrinterAsync(printer, printCommands);
|
||||
}
|
||||
}
|
||||
|
||||
//TestHelpers.PrintCommandsToConsole(printCommands);
|
||||
static async Task RunBarReceiptTest(int printerTarget)
|
||||
{
|
||||
var receipt = TestHelpers.BuildSampleBarReceipt();
|
||||
|
||||
//var printer = await TestHelpers.CreateEpsonPrinterAsync(paperWidth: TestHelpers.KitchenPaperWidth);
|
||||
//await TestHelpers.PrintCommandsToEpsonPrinterAsync(printer, printCommands, useDelay: true);
|
||||
var converter = new BarReceiptConverter(lineWidth: 42, bigLineWidth: 22);
|
||||
var printCommands = converter.ConvertToPrintCommands(receipt);
|
||||
|
||||
TestHelpers.PrintCommandsToConsole(printCommands);
|
||||
|
||||
// ============================================================================
|
||||
// ORDER ITEMS RECEIPT - HTML PRINTER
|
||||
// ============================================================================
|
||||
//var receipt = TestHelpers.BuildSampleOrderItemsReceipt();
|
||||
//var serializedReceipt = JsonSerializer.Serialize(receipt, new JsonSerializerOptions { WriteIndented = true });
|
||||
//Console.WriteLine(serializedReceipt);
|
||||
//var deserializedReceipt = JsonSerializer.Deserialize<OrderItemsReceipt>(serializedReceipt);
|
||||
if (printerTarget == 0)
|
||||
{
|
||||
var printer = await TestHelpers.CreateHtmlPrinterAsync(
|
||||
path: @".\bar_test.html",
|
||||
paperWidth: TestHelpers.KitchenPaperWidth);
|
||||
await TestHelpers.PrintKitchenCommandsToHtmlPrinterAsync(printer, printCommands);
|
||||
Console.WriteLine("Output written to: bar_test.html");
|
||||
}
|
||||
else
|
||||
{
|
||||
var printer = await TestHelpers.CreateEpsonPrinterAsync(paperWidth: TestHelpers.KitchenPaperWidth);
|
||||
await TestHelpers.PrintCommandsToEpsonPrinterAsync(printer, printCommands, useDelay: true);
|
||||
}
|
||||
}
|
||||
|
||||
//var converter = new ReceiptConverter(lineWidth: 50, bigFontLineWidth: 21);
|
||||
//var printCommands = converter.ConvertToPrintCommands(deserializedReceipt);
|
||||
static async Task RunOrderItemsTest(int printerTarget)
|
||||
{
|
||||
var receipt = TestHelpers.BuildSampleOrderItemsReceipt();
|
||||
var serializedReceipt = JsonSerializer.Serialize(receipt, new JsonSerializerOptions { WriteIndented = true });
|
||||
|
||||
//TestHelpers.PrintCommandsToConsole(printCommands);
|
||||
var converter = new OrderItemsReceiptConverter(lineWidth: 50, bigFontLineWidth: 21);
|
||||
var printCommands = converter.Convert(serializedReceipt);
|
||||
|
||||
//var printer = await TestHelpers.CreateHtmlPrinterAsync(path: @".\order_items.html");
|
||||
//await TestHelpers.PrintCommandsToHtmlPrinterAsync(printer, printCommands);
|
||||
TestHelpers.PrintCommandsToConsole(printCommands);
|
||||
|
||||
|
||||
// ============================================================================
|
||||
// BASIC PRINTER STATUS CHECK
|
||||
// ============================================================================
|
||||
//var printer = await TestHelpers.CreateEpsonPrinterAsync();
|
||||
//var status = await printer.GetPrinterStatusAsync();
|
||||
//Console.WriteLine($"Printer Status: {status}");
|
||||
//var paperStatus = await printer.GetPaperSensorStatusAsync();
|
||||
//Console.WriteLine($"Paper Sensor Status: {paperStatus}");
|
||||
|
||||
|
||||
// ============================================================================
|
||||
// SIMPLE TEXT PRINT TEST
|
||||
// ============================================================================
|
||||
//var printer = await TestHelpers.CreateEpsonPrinterAsync();
|
||||
//await printer.InitAsync();
|
||||
//await printer.PrintTextAsync("Hello, World!\n");
|
||||
//await printer.FeedLinesAsync(5);
|
||||
//await printer.CutAsync();
|
||||
|
||||
|
||||
// ============================================================================
|
||||
// IMAGE PRINT TEST
|
||||
// ============================================================================
|
||||
//var printer = await TestHelpers.CreateEpsonPrinterAsync();
|
||||
//await printer.LoadImageAsync("test.png", 100);
|
||||
//await printer.PrintLoadedImage();
|
||||
//await printer.FeedLinesAsync(5);
|
||||
//await printer.CutAsync();
|
||||
|
||||
|
||||
// ============================================================================
|
||||
// FONT SIZE TEST
|
||||
// ============================================================================
|
||||
//var printer = await TestHelpers.CreateEpsonPrinterAsync();
|
||||
//await printer.InitAsync();
|
||||
|
||||
//// Double size (24 chars per line)
|
||||
//await printer.SetFontSizeAsync(2, 2);
|
||||
//await printer.SelectFont(EpsonCommands.PrinterFont.A);
|
||||
//await printer.PrintTextAsync("HHHH_HHHH_HHHH_HHHH_HHHH_HHHH_HHHH_\n");
|
||||
|
||||
//// Normal size (48 chars per line)
|
||||
//await printer.SetFontSizeAsync(1, 1);
|
||||
//await printer.SelectFont(EpsonCommands.PrinterFont.A);
|
||||
//await printer.PrintTextAsync("HHHH_HHHH_HHHH_HHHH_HHHH_HHHH_HHHH_HHHH_HHHH_HHHH_HHHH_HHHH_\n");
|
||||
|
||||
//await printer.FeedLinesAsync(5);
|
||||
//await printer.CutAsync();
|
||||
|
||||
|
||||
// ============================================================================
|
||||
// SOAP PRINTER TEST
|
||||
// ============================================================================
|
||||
//var printer = new SoapEpsonPrinter("localhost:8888");
|
||||
//var print = new SoapEpsonPrint();
|
||||
//print
|
||||
// .AddTextAlign(SoapEpsonPrint.ALIGN_CENTER)
|
||||
// .AddTextSize(2, 2)
|
||||
// .AddText("It works! Finally!!!")
|
||||
// .AddFeed()
|
||||
// .AddFeed()
|
||||
// .AddFeed()
|
||||
// .AddCut(SoapEpsonPrint.CUT_FEED);
|
||||
|
||||
//var task = await printer.Send(print);
|
||||
//var status = await printer.GetStatus(print);
|
||||
//Console.WriteLine($"Printer Status: {status}");
|
||||
if (printerTarget == 0)
|
||||
{
|
||||
var printer = await TestHelpers.CreateHtmlPrinterAsync(path: @".\order_items.html");
|
||||
await TestHelpers.PrintCommandsToHtmlPrinterAsync(printer, printCommands);
|
||||
Console.WriteLine("Output written to: order_items.html");
|
||||
}
|
||||
else
|
||||
{
|
||||
var printer = await TestHelpers.CreateEpsonPrinterAsync();
|
||||
await TestHelpers.PrintCommandsToEpsonPrinterAsync(printer, printCommands);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System.Diagnostics;
|
||||
using Inspectron.Epson;
|
||||
using Inspectron.Epson.PrintServer.Printers.Utils;
|
||||
using Inspectron.Epson.PrintServer.Printers.Utils.BarReceipt;
|
||||
using Inspectron.Epson.PrintServer.Printers.Utils.FinalRecipe;
|
||||
using Inspectron.Epson.PrintServer.Printers.Utils.InvoiceReceipt;
|
||||
using Inspectron.Epson.PrintServer.Printers.Utils.KitchenReceipt;
|
||||
@@ -399,6 +400,27 @@ public static class TestHelpers
|
||||
return receipt;
|
||||
}
|
||||
|
||||
public static BarReceipt BuildSampleBarReceipt()
|
||||
{
|
||||
var receipt = new BarReceipt
|
||||
{
|
||||
Title = "Bar",
|
||||
TransactionDateTime = new DateTime(2025, 10, 23, 12, 18, 0),
|
||||
ReceiptNumber = "132018166",
|
||||
WaiterName = "Mariano Amato",
|
||||
WaiterId = "32 (VK Restaurant)",
|
||||
TableNumber = "22"
|
||||
};
|
||||
|
||||
receipt.Gangs.Add(new Inspectron.Epson.PrintServer.Printers.Utils.BarReceipt.Gang(1, "Gang"));
|
||||
|
||||
receipt.Gangs[0].Dishes.Add(new Inspectron.Epson.PrintServer.Printers.Utils.BarReceipt.Dish(2, "Aperol Spritz") { GuestId = 1 });
|
||||
receipt.Gangs[0].Dishes.Add(new Inspectron.Epson.PrintServer.Printers.Utils.BarReceipt.Dish(1, "Prosecco") { GuestId = 2 });
|
||||
receipt.Gangs[0].Dishes.Add(new Inspectron.Epson.PrintServer.Printers.Utils.BarReceipt.Dish(1, "Mojito with extra mint and lime") { GuestId = 3 });
|
||||
|
||||
return receipt;
|
||||
}
|
||||
|
||||
public static OrderItemsReceipt BuildSampleOrderItemsReceipt()
|
||||
{
|
||||
return new OrderItemsReceipt
|
||||
|
||||
Reference in New Issue
Block a user