using CommunityToolkit.Mvvm.ComponentModel; using MultiTerm.Protocols.Model; using System.Text; namespace MultiTerm.Core.ViewModel; public partial class ByteDataViewModel : ObservableObject, IDataViewModel, IComparable { /// /// Object of data model. /// private readonly ExtendedByte data; #region IDataViewModel Implementation [ObservableProperty] private int lineIdentifier; [ObservableProperty] private TimeOnly time; [ObservableProperty] private string displayStringChar = String.Empty; [ObservableProperty] private string displayStringHex = String.Empty; [ObservableProperty] private string displayStringBin = String.Empty; #endregion /// /// Allows access to the low level data byte. /// public byte Byte => this.data.Byte; /// /// Instanciates new . /// Initializes internal variables with data according to . /// /// data /// identifies line in which this byte is located public ByteDataViewModel(ExtendedByte extendedByte, int lineIdentifier) { this.data = extendedByte; this.lineIdentifier = lineIdentifier; this.DisplayStringChar = extendedByte.ToCharacterString(); this.DisplayStringHex = extendedByte.ToHexString(); this.DisplayStringBin = extendedByte.ToBinaryString(); this.Time = extendedByte.Time; } #region IComparable Implementation /// /// IComparable method. To allow sorting /// /// compared element /// public int CompareTo(ByteDataViewModel? other) { if(other == null) return 1; if (other.Time.Ticks > this.Time.Ticks) return -1; else if(this.Time.Ticks > other.Time.Ticks) return 1; else // equal return 0; } #endregion }