Files
client/Models/Printer.cs

63 lines
1.7 KiB
C#
Raw Permalink Normal View History

2026-05-28 23:26:37 +08:00
using CommunityToolkit.Mvvm.ComponentModel;
2026-05-23 18:16:50 +08:00
namespace CloudPrint.Client.Models;
public enum PrinterStatus
{
Idle = 0,
Printing = 1,
Offline = 2,
Error = 3,
Unknown = 99
}
2026-05-28 23:26:37 +08:00
public sealed partial class PrinterInfo : ObservableObject
2026-05-23 18:16:50 +08:00
{
2026-05-28 23:26:37 +08:00
[ObservableProperty]
[NotifyPropertyChangedFor(nameof(DisplayText))]
private int queueCount;
[ObservableProperty]
[NotifyPropertyChangedFor(nameof(DisplayText))]
private string statusMessage = string.Empty;
[ObservableProperty]
[NotifyPropertyChangedFor(nameof(StatusText))]
[NotifyPropertyChangedFor(nameof(DisplayText))]
private PrinterStatus status;
2026-05-23 18:16:50 +08:00
public int Id { get; init; }
public string Name { get; init; } = string.Empty;
public string DisplayName { get; init; } = string.Empty;
public bool IsActive { get; init; } = true;
public string ApiKey { get; init; } = string.Empty;
public DateTime? LastHeartbeat { get; set; }
2026-05-28 23:26:37 +08:00
partial void OnQueueCountChanged(int value)
2026-05-23 18:16:50 +08:00
{
2026-05-28 23:26:37 +08:00
if (value < 0)
2026-05-23 18:16:50 +08:00
{
2026-05-28 23:26:37 +08:00
QueueCount = 0;
2026-05-23 18:16:50 +08:00
}
}
public string StatusText => Status switch
{
PrinterStatus.Idle => "空闲",
PrinterStatus.Printing => "打印中",
PrinterStatus.Offline => "离线",
PrinterStatus.Error => "异常",
_ => "未知"
};
public string DisplayText
{
get
{
var queueText = QueueCount > 0 ? $",队列 {QueueCount}" : string.Empty;
var messageText = string.IsNullOrWhiteSpace(StatusMessage) ? string.Empty : $"{StatusMessage}";
return $"{DisplayName}{StatusText}{queueText}{messageText}";
}
}
2026-05-28 23:26:37 +08:00
}