feat: 初始功能
This commit is contained in:
82
Models/Printer.cs
Normal file
82
Models/Printer.cs
Normal file
@@ -0,0 +1,82 @@
|
||||
using CloudPrint.Client.Infrastructure;
|
||||
|
||||
namespace CloudPrint.Client.Models;
|
||||
|
||||
public enum PrinterStatus
|
||||
{
|
||||
Idle = 0,
|
||||
Printing = 1,
|
||||
Offline = 2,
|
||||
Error = 3,
|
||||
Unknown = 99
|
||||
}
|
||||
|
||||
public sealed class PrinterInfo : ObservableObject
|
||||
{
|
||||
private PrinterStatus _status;
|
||||
private int _queueCount;
|
||||
private string _statusMessage = string.Empty;
|
||||
|
||||
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; }
|
||||
|
||||
public int QueueCount
|
||||
{
|
||||
get => _queueCount;
|
||||
set
|
||||
{
|
||||
if (SetProperty(ref _queueCount, Math.Max(0, value)))
|
||||
{
|
||||
OnPropertyChanged(nameof(DisplayText));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string StatusMessage
|
||||
{
|
||||
get => _statusMessage;
|
||||
set
|
||||
{
|
||||
if (SetProperty(ref _statusMessage, value))
|
||||
{
|
||||
OnPropertyChanged(nameof(DisplayText));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public PrinterStatus Status
|
||||
{
|
||||
get => _status;
|
||||
set
|
||||
{
|
||||
if (SetProperty(ref _status, value))
|
||||
{
|
||||
OnPropertyChanged(nameof(StatusText));
|
||||
OnPropertyChanged(nameof(DisplayText));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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})";
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user