feat(20-windows-client): aplikacja C# WinForms do zdalnego druku etykiet
- System tray app z NotifyIcon + ContextMenuStrip - Polling API orderPRO (GET /api/print/jobs/pending) - Pobieranie etykiet PDF i druk przez PdfiumViewer - Formularz ustawień: URL API, klucz, drukarka, interwał - Okno logów z historią (ciemny motyw, Consolas) - Self-contained .NET 8 publish (win-x64) - Milestone v0.7 Zdalne drukowanie etykiet — COMPLETE Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
61
clients/windows/OrderPROPrint/Services/PrintApiClient.cs
Normal file
61
clients/windows/OrderPROPrint/Services/PrintApiClient.cs
Normal file
@@ -0,0 +1,61 @@
|
||||
using System.Net.Http.Json;
|
||||
using System.Text.Json;
|
||||
using OrderPROPrint.Models;
|
||||
|
||||
namespace OrderPROPrint.Services;
|
||||
|
||||
public class PrintApiClient : IDisposable
|
||||
{
|
||||
private readonly HttpClient _httpClient;
|
||||
|
||||
public PrintApiClient(string apiUrl, string apiKey)
|
||||
{
|
||||
_httpClient = new HttpClient
|
||||
{
|
||||
BaseAddress = new Uri(apiUrl.TrimEnd('/') + "/"),
|
||||
Timeout = TimeSpan.FromSeconds(30)
|
||||
};
|
||||
_httpClient.DefaultRequestHeaders.Add("X-Api-Key", apiKey);
|
||||
}
|
||||
|
||||
public async Task<List<PrintJob>> GetPendingJobsAsync()
|
||||
{
|
||||
var response = await _httpClient.GetAsync("api/print/jobs/pending");
|
||||
response.EnsureSuccessStatusCode();
|
||||
|
||||
var json = await response.Content.ReadAsStringAsync();
|
||||
var result = JsonSerializer.Deserialize<PendingJobsResponse>(json);
|
||||
return result?.Jobs ?? new List<PrintJob>();
|
||||
}
|
||||
|
||||
public async Task<byte[]> DownloadLabelAsync(int jobId)
|
||||
{
|
||||
var response = await _httpClient.GetAsync($"api/print/jobs/{jobId}/download");
|
||||
response.EnsureSuccessStatusCode();
|
||||
return await response.Content.ReadAsByteArrayAsync();
|
||||
}
|
||||
|
||||
public async Task<bool> MarkCompleteAsync(int jobId)
|
||||
{
|
||||
var response = await _httpClient.PostAsync($"api/print/jobs/{jobId}/complete", null);
|
||||
return response.IsSuccessStatusCode;
|
||||
}
|
||||
|
||||
public async Task<bool> TestConnectionAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
var response = await _httpClient.GetAsync("api/print/jobs/pending");
|
||||
return response.IsSuccessStatusCode;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_httpClient.Dispose();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user