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/SendReceiveViewModel.cs

79 lines
2.3 KiB

using Common;
using Common.AppSettings;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using CommunityToolkit.Mvvm.Messaging;
using MultiTerm.Core.Model;
using MultiTerm.Core.Types;
using MultiTerm.Protocols.Model;
namespace MultiTerm.Core.ViewModel;
public partial class SendReceiveViewModel : TerminalViewModel
{
public override TerminalViewType ViewType => TerminalViewType.SendReceive;
#region Observable Properties
/// <summary>
/// Holds communication data that was received via the communication protocol.
/// </summary>
[ObservableProperty]
private MultiFormatDataViewModel receivedData;
/// <summary>
/// Holds communication data that was sent via the communication protocol.
/// </summary>
[ObservableProperty]
private MultiFormatDataViewModel sentData;
/// <summary>
/// Model for sendable data.
/// </summary>
[ObservableProperty]
private MultiFormatString sendableData = new();
#endregion
/// <summary>
/// Constructor.
/// </summary>
/// <param name="appSettings"></param>
public SendReceiveViewModel(IAppSettingsProvider appSettings, IMessenger messenger, IContext context) : base(appSettings, messenger)
{
// create new Communication data containers
this.receivedData = new(context);
this.sentData = new(context);
}
/// <summary>
/// Send command.
/// </summary>
[RelayCommand]
private void Send()
{
// send data
bool successfullySent = this.SendToCommunicationProtocol(this.SendableData.GetBytes());
if (successfullySent)
{
// clear textbox
this.SendableData.Clear();
}
}
public override void DisplayNewReceivedData(IEnumerable<ExtendedByte> newData)
{
this.ReceivedData!.HandleNewData(newData);
}
public override void DisplayNewSentData(IEnumerable<ExtendedByte> newData)
{
this.SentData!.HandleNewData(newData);
}
protected override void ActOnDataDisplayNewlineSeparatorTypeChanged(NewlineSeparatorType newType)
{
// triggers rearranging the displayed data with the new NewlineSeparatorType
this.ReceivedData!.NewlineSeparator = newType;
this.SentData!.NewlineSeparator = newType;
}
}