Files
client/Models/Printer.cs
2026-05-28 23:26:37 +08:00

63 lines
1.7 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using CommunityToolkit.Mvvm.ComponentModel;
namespace CloudPrint.Client.Models;
public enum PrinterStatus
{
Idle = 0,
Printing = 1,
Offline = 2,
Error = 3,
Unknown = 99
}
public sealed partial class PrinterInfo : ObservableObject
{
[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;
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; }
partial void OnQueueCountChanged(int value)
{
if (value < 0)
{
QueueCount = 0;
}
}
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}";
}
}
}