Multiprocotol Terminalprogram (BAT)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
MultiTerm/MultiTerm.Core/ViewModel/ByteDataViewModel.cs

75 lines
2.2 KiB

using CommunityToolkit.Mvvm.ComponentModel;
using MultiTerm.Protocols.Model;
namespace MultiTerm.Core.ViewModel;
public partial class ByteDataViewModel : ObservableObject, IDataViewModel, IComparable<ByteDataViewModel>, ICloneable
{
/// <summary>
/// Object of data model.
/// </summary>
internal readonly ExtendedByte Data;
#region IDataViewModel Implementation
[ObservableProperty]
private int lineIdentifier;
[ObservableProperty]
private string timeAsString = String.Empty;
[ObservableProperty]
private string displayStringChar = String.Empty;
[ObservableProperty]
private string displayStringHex = String.Empty;
[ObservableProperty]
private string displayStringBin = String.Empty;
#endregion
/// <summary>
/// Instanciates new <see cref="ByteDataViewModel"/>.
/// Initializes internal variables with data according to <paramref name="extendedByte"/>.
/// </summary>
/// <param name="extendedByte">data</param>
/// <param name="lineIdentifier">identifies line in which this byte is located</param>
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.TimeAsString = extendedByte.Time.ToString("HH:mm:ss.ffff");
}
#region IComparable Implementation
/// <summary>
/// IComparable method. To allow sorting <see cref="ByteDataViewModel"/>
/// </summary>
/// <param name="other">compared element</param>
/// <returns></returns>
public int CompareTo(ByteDataViewModel? other)
{
if(other == null)
return 1;
if (other.Data.Time.Ticks > this.Data.Time.Ticks)
return -1;
else if(this.Data.Time.Ticks > other.Data.Time.Ticks)
return 1;
else // equal
return 0;
}
#endregion
#region ICloneable Implementation
public object Clone()
{
return this.MemberwiseClone();
}
#endregion
}