81 lines
2.8 KiB
C#
81 lines
2.8 KiB
C#
using System;
|
|
using System.Web;
|
|
|
|
namespace RecticelPrintService
|
|
{
|
|
class Program
|
|
{
|
|
static void Main(string[] args)
|
|
{
|
|
try
|
|
{
|
|
if (args.Length == 0)
|
|
{
|
|
Console.WriteLine("Recticel Print Service - No arguments provided");
|
|
Console.WriteLine("Usage: RecticelPrintService.exe \"recticel-print://printer/data\"");
|
|
Console.ReadKey();
|
|
return;
|
|
}
|
|
|
|
string url = args[0];
|
|
Console.WriteLine($"Received print request: {url}");
|
|
|
|
// Parse the custom protocol URL
|
|
// Format: recticel-print://printer_name/base64_encoded_json_data
|
|
if (!url.StartsWith("recticel-print://"))
|
|
{
|
|
Console.WriteLine("Invalid protocol. Expected: recticel-print://");
|
|
Console.ReadKey();
|
|
return;
|
|
}
|
|
|
|
// Remove protocol prefix
|
|
string data = url.Substring("recticel-print://".Length);
|
|
|
|
// Split printer name and data
|
|
string[] parts = data.Split('/');
|
|
if (parts.Length < 2)
|
|
{
|
|
Console.WriteLine("Invalid URL format. Expected: recticel-print://printer_name/data");
|
|
Console.ReadKey();
|
|
return;
|
|
}
|
|
|
|
string printerName = HttpUtility.UrlDecode(parts[0]);
|
|
string encodedData = HttpUtility.UrlDecode(parts[1]);
|
|
|
|
Console.WriteLine($"Target Printer: {printerName}");
|
|
Console.WriteLine($"Data Length: {encodedData.Length}");
|
|
|
|
// Decode base64 JSON data
|
|
byte[] dataBytes = Convert.FromBase64String(encodedData);
|
|
string jsonData = System.Text.Encoding.UTF8.GetString(dataBytes);
|
|
|
|
Console.WriteLine($"Decoded JSON: {jsonData}");
|
|
|
|
// Parse and print the label
|
|
var printer = new LabelPrinter();
|
|
bool success = printer.PrintLabel(printerName, jsonData);
|
|
|
|
if (success)
|
|
{
|
|
Console.WriteLine("✅ Label printed successfully!");
|
|
}
|
|
else
|
|
{
|
|
Console.WriteLine("❌ Failed to print label!");
|
|
}
|
|
|
|
// Keep console open for debugging (remove in production)
|
|
Console.WriteLine("Press any key to exit...");
|
|
Console.ReadKey();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Console.WriteLine($"Error: {ex.Message}");
|
|
Console.WriteLine(ex.StackTrace);
|
|
Console.ReadKey();
|
|
}
|
|
}
|
|
}
|
|
} |