-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathLogEntry.cs
More file actions
63 lines (57 loc) · 2.43 KB
/
Copy pathLogEntry.cs
File metadata and controls
63 lines (57 loc) · 2.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
using System;
using System.ComponentModel;
namespace PostCodeSerialMonitor.Models;
// Simple model to hold log entry data
public class LogEntry : INotifyPropertyChanged
{
public event PropertyChangedEventHandler? PropertyChanged;
private bool isSelected;
public bool IsSelected
{
get => isSelected;
set
{
if (isSelected == value) return;
isSelected = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(IsSelected)));
}
}
public string RawText { get; set; } = string.Empty;
public DateTime Timestamp { get; set; } = DateTime.Now;
public string TimestampText => Timestamp.ToString("HH:mm:ss.fff");
public required DecodedCode DecodedCode { get; set; }
public string FormattedWithTs => $"{TimestampText} {FormattedText}";
// CodeText + Description
public string FormattedText => FormatText();
// Flavor, index and code (hex)
public string CodeText => FormatCodeText();
// Individual fields, for column-aligned display
public string FlavorText => DecodedCode.Flavor.ToString();
public string CodeHexText => $"{DecodedCode.Code:X4}";
public string NameText => string.IsNullOrEmpty(DecodedCode?.Name) ? string.Empty : $"[{DecodedCode.Name}]";
// Name + description on one line, for the truncated inline preview
public string InlinePreviewText => string.IsNullOrEmpty(Description)
? NameText
: string.IsNullOrEmpty(NameText) ? Description : $"{NameText} {Description}";
// Description or null
public string? Description => string.IsNullOrEmpty(DecodedCode.Description) ? null : DecodedCode?.Description;
public bool HasDescription => !string.IsNullOrEmpty(Description);
public bool IsWarning => SeverityLevel == CodeSeverity.Warning;
public bool IsError => SeverityLevel == CodeSeverity.Error;
public CodeSeverity SeverityLevel => DecodedCode.SeverityLevel;
private string FormatCodeText()
{
// Format flavor, index, and code with fixed spacing
var formatted = $"{DecodedCode?.Flavor,-4}: {DecodedCode?.Code,4:X8}";
if (!string.IsNullOrEmpty(DecodedCode?.Name))
formatted += $" [{DecodedCode?.Name}]";
return formatted;
}
private string FormatText()
{
var formatted = $"{CodeText}";
if (!string.IsNullOrEmpty(Description))
formatted += $"\n- {Description}";
return formatted;
}
}