Class CommandSenderViewModel

ViewModel for the CommandSender device card. Provides checkboxes for stream type selection, editable IP/port fields, device number, on/off toggle, and a send button.

Inheritance
CommandSenderViewModel
Namespace: MOSAIC.ViewModels.Devices
Assembly: MOSAIC.dll
Syntax
public class CommandSenderViewModel : ObservableObject, INotifyPropertyChanged, INotifyPropertyChanging

Constructors

CommandSenderViewModel(CommandSender?)

Initialises the ViewModel. If a block is provided (from JSON config), its host/port are used as defaults.

Declaration
public CommandSenderViewModel(CommandSender? block = null)
Parameters
Type Name Description
CommandSender block

Fields

_block

Declaration
private CommandSender? _block
Field Value
Type Description
CommandSender

_deviceSpec

Which ESP nodes to address, as a spec like "18", "1,2,5" or "1-8, 18".

Declaration
[ObservableProperty]
[NotifyPropertyChangedFor("CommandPreview")]
[NotifyPropertyChangedFor("DeviceCount")]
private string _deviceSpec
Field Value
Type Description
string
Remarks

A body rig carries many nodes at once, and their ids are not a dense 1..n range — a rig can have sensor 18 with nothing below it. A free-text spec addresses a whole set in one action instead of forcing one Apply per node.

_host

Target ESP host IP address (editable).

Declaration
[ObservableProperty]
private string _host
Field Value
Type Description
string

_isConnected

Whether the UDP client is currently connected.

Declaration
[ObservableProperty]
private bool _isConnected
Field Value
Type Description
bool

_isSending

Indicates a command is currently being sent.

Declaration
[ObservableProperty]
private bool _isSending
Field Value
Type Description
bool

_port

Target UDP port number (editable as text).

Declaration
[ObservableProperty]
private string _port
Field Value
Type Description
string

_statusMessage

Status or error message displayed in the UI.

Declaration
[ObservableProperty]
private string _statusMessage
Field Value
Type Description
string

applyCommand

The backing field for ApplyCommand.

Declaration
private AsyncRelayCommand? applyCommand
Field Value
Type Description
AsyncRelayCommand

clearAllStreamsCommand

The backing field for ClearAllStreamsCommand.

Declaration
private RelayCommand? clearAllStreamsCommand
Field Value
Type Description
RelayCommand

connectCommand

The backing field for ConnectCommand.

Declaration
private RelayCommand? connectCommand
Field Value
Type Description
RelayCommand

disconnectCommand

The backing field for DisconnectCommand.

Declaration
private RelayCommand? disconnectCommand
Field Value
Type Description
RelayCommand

selectAllStreamsCommand

The backing field for SelectAllStreamsCommand.

Declaration
private RelayCommand? selectAllStreamsCommand
Field Value
Type Description
RelayCommand

Properties

ApplyCommand

Gets an IAsyncRelayCommand instance wrapping ApplyAsync().

Declaration
[ExcludeFromCodeCoverage]
public IAsyncRelayCommand ApplyCommand { get; }
Property Value
Type Description
IAsyncRelayCommand

ClearAllStreamsCommand

Gets an IRelayCommand instance wrapping ClearAllStreams().

Declaration
[ExcludeFromCodeCoverage]
public IRelayCommand ClearAllStreamsCommand { get; }
Property Value
Type Description
IRelayCommand

CommandPreview

A summary of exactly what ApplyCommand will put on the wire. For a single node this is the literal command list (ROT18on ACC18off …); for several it is a device list plus the per-node stream states, since spelling out 72 commands helps nobody.

Declaration
public string CommandPreview { get; }
Property Value
Type Description
string

ConnectCommand

Gets an IRelayCommand instance wrapping Connect().

Declaration
[ExcludeFromCodeCoverage]
public IRelayCommand ConnectCommand { get; }
Property Value
Type Description
IRelayCommand

DeviceCount

How many nodes DeviceSpec resolves to.

Declaration
public int DeviceCount { get; }
Property Value
Type Description
int

DeviceSpec

Which ESP nodes to address, as a spec like "18", "1,2,5" or "1-8, 18".

Declaration
[ExcludeFromCodeCoverage]
public string DeviceSpec { get; set; }
Property Value
Type Description
string
Remarks

A body rig carries many nodes at once, and their ids are not a dense 1..n range — a rig can have sensor 18 with nothing below it. A free-text spec addresses a whole set in one action instead of forcing one Apply per node.

Devices

The node ids DeviceSpec currently resolves to; empty if malformed.

Declaration
public IReadOnlyList<int> Devices { get; }
Property Value
Type Description
IReadOnlyList<int>

DisconnectCommand

Gets an IRelayCommand instance wrapping Disconnect().

Declaration
[ExcludeFromCodeCoverage]
public IRelayCommand DisconnectCommand { get; }
Property Value
Type Description
IRelayCommand

Host

Target ESP host IP address (editable).

Declaration
[ExcludeFromCodeCoverage]
public string Host { get; set; }
Property Value
Type Description
string

Info

Observable info from the underlying block.

Declaration
public CommandSenderInfo? Info { get; }
Property Value
Type Description
CommandSenderInfo

IsConnected

Whether the UDP client is currently connected.

Declaration
[ExcludeFromCodeCoverage]
public bool IsConnected { get; set; }
Property Value
Type Description
bool

IsSending

Indicates a command is currently being sent.

Declaration
[ExcludeFromCodeCoverage]
public bool IsSending { get; set; }
Property Value
Type Description
bool

Port

Target UDP port number (editable as text).

Declaration
[ExcludeFromCodeCoverage]
public string Port { get; set; }
Property Value
Type Description
string

SelectAllStreamsCommand

Gets an IRelayCommand instance wrapping SelectAllStreams().

Declaration
[ExcludeFromCodeCoverage]
public IRelayCommand SelectAllStreamsCommand { get; }
Property Value
Type Description
IRelayCommand

StatusMessage

Status or error message displayed in the UI.

Declaration
[ExcludeFromCodeCoverage]
public string StatusMessage { get; set; }
Property Value
Type Description
string

StreamOptions

The four sensor streams, as checkboxes. A ticked box means "this stream should be ON".

Declaration
public ObservableCollection<StreamTypeOption> StreamOptions { get; }
Property Value
Type Description
ObservableCollection<StreamTypeOption>
Remarks

ALL is deliberately not offered here. It is a shorthand on the wire, but as a checkbox alongside the individual streams it is ambiguous — ticking ALL and un-ticking ROT describes no coherent state. Ticking all four boxes expresses the same thing unambiguously.

Methods

ApplyAsync()

Drives the device to exactly the state shown by the checkboxes: every ticked stream is switched on and every un-ticked one is switched off.

Declaration
[RelayCommand]
private Task ApplyAsync()
Returns
Type Description
Task
Remarks

Every stream receives an explicit desired state. Cleared checkboxes therefore send off rather than merely omitting a command.

ClearAllStreams()

Clears every stream. Only changes the checkboxes — press Apply to send.

Declaration
[RelayCommand]
private void ClearAllStreams()

Connect()

Connects (or reconnects) the UDP client with the current host and port.

Declaration
[RelayCommand]
private void Connect()

Disconnect()

Closes the UDP client, leaving the block reusable on a different host or port.

Declaration
[RelayCommand]
private void Disconnect()

EndpointMatchesCard()

Whether the block is bound to the endpoint the card is currently displaying.

Declaration
private bool EndpointMatchesCard()
Returns
Type Description
bool
Remarks

An unparsable port counts as a mismatch, so Apply routes through Connect() and gets "Invalid port number." instead of quietly using the last good endpoint.

OnDeviceSpecChanged(string)

Executes the logic for when DeviceSpec just changed.

Declaration
private void OnDeviceSpecChanged(string value)
Parameters
Type Name Description
string value

The new property value that was set.

Remarks

This method is invoked right after the value of DeviceSpec is changed.

OnDeviceSpecChanged(string?, string)

Executes the logic for when DeviceSpec just changed.

Declaration
private void OnDeviceSpecChanged(string? oldValue, string newValue)
Parameters
Type Name Description
string oldValue

The previous property value that was replaced.

string newValue

The new property value that was set.

Remarks

This method is invoked right after the value of DeviceSpec is changed.

OnDeviceSpecChanging(string)

Executes the logic for when DeviceSpec is changing.

Declaration
private void OnDeviceSpecChanging(string value)
Parameters
Type Name Description
string value

The new property value being set.

Remarks

This method is invoked right before the value of DeviceSpec is changed.

OnDeviceSpecChanging(string?, string)

Executes the logic for when DeviceSpec is changing.

Declaration
private void OnDeviceSpecChanging(string? oldValue, string newValue)
Parameters
Type Name Description
string oldValue

The previous property value that is being replaced.

string newValue

The new property value being set.

Remarks

This method is invoked right before the value of DeviceSpec is changed.

OnHostChanged(string)

Executes the logic for when Host just changed.

Declaration
private void OnHostChanged(string value)
Parameters
Type Name Description
string value

The new property value that was set.

Remarks

This method is invoked right after the value of Host is changed.

OnHostChanged(string?, string)

Executes the logic for when Host just changed.

Declaration
private void OnHostChanged(string? oldValue, string newValue)
Parameters
Type Name Description
string oldValue

The previous property value that was replaced.

string newValue

The new property value that was set.

Remarks

This method is invoked right after the value of Host is changed.

OnHostChanging(string)

Executes the logic for when Host is changing.

Declaration
private void OnHostChanging(string value)
Parameters
Type Name Description
string value

The new property value being set.

Remarks

This method is invoked right before the value of Host is changed.

OnHostChanging(string?, string)

Executes the logic for when Host is changing.

Declaration
private void OnHostChanging(string? oldValue, string newValue)
Parameters
Type Name Description
string oldValue

The previous property value that is being replaced.

string newValue

The new property value being set.

Remarks

This method is invoked right before the value of Host is changed.

OnIsConnectedChanged(bool)

Executes the logic for when IsConnected just changed.

Declaration
private void OnIsConnectedChanged(bool value)
Parameters
Type Name Description
bool value

The new property value that was set.

Remarks

This method is invoked right after the value of IsConnected is changed.

OnIsConnectedChanged(bool, bool)

Executes the logic for when IsConnected just changed.

Declaration
private void OnIsConnectedChanged(bool oldValue, bool newValue)
Parameters
Type Name Description
bool oldValue

The previous property value that was replaced.

bool newValue

The new property value that was set.

Remarks

This method is invoked right after the value of IsConnected is changed.

OnIsConnectedChanging(bool)

Executes the logic for when IsConnected is changing.

Declaration
private void OnIsConnectedChanging(bool value)
Parameters
Type Name Description
bool value

The new property value being set.

Remarks

This method is invoked right before the value of IsConnected is changed.

OnIsConnectedChanging(bool, bool)

Executes the logic for when IsConnected is changing.

Declaration
private void OnIsConnectedChanging(bool oldValue, bool newValue)
Parameters
Type Name Description
bool oldValue

The previous property value that is being replaced.

bool newValue

The new property value being set.

Remarks

This method is invoked right before the value of IsConnected is changed.

OnIsSendingChanged(bool)

Executes the logic for when IsSending just changed.

Declaration
private void OnIsSendingChanged(bool value)
Parameters
Type Name Description
bool value

The new property value that was set.

Remarks

This method is invoked right after the value of IsSending is changed.

OnIsSendingChanged(bool, bool)

Executes the logic for when IsSending just changed.

Declaration
private void OnIsSendingChanged(bool oldValue, bool newValue)
Parameters
Type Name Description
bool oldValue

The previous property value that was replaced.

bool newValue

The new property value that was set.

Remarks

This method is invoked right after the value of IsSending is changed.

OnIsSendingChanging(bool)

Executes the logic for when IsSending is changing.

Declaration
private void OnIsSendingChanging(bool value)
Parameters
Type Name Description
bool value

The new property value being set.

Remarks

This method is invoked right before the value of IsSending is changed.

OnIsSendingChanging(bool, bool)

Executes the logic for when IsSending is changing.

Declaration
private void OnIsSendingChanging(bool oldValue, bool newValue)
Parameters
Type Name Description
bool oldValue

The previous property value that is being replaced.

bool newValue

The new property value being set.

Remarks

This method is invoked right before the value of IsSending is changed.

OnPortChanged(string)

Executes the logic for when Port just changed.

Declaration
private void OnPortChanged(string value)
Parameters
Type Name Description
string value

The new property value that was set.

Remarks

This method is invoked right after the value of Port is changed.

OnPortChanged(string?, string)

Executes the logic for when Port just changed.

Declaration
private void OnPortChanged(string? oldValue, string newValue)
Parameters
Type Name Description
string oldValue

The previous property value that was replaced.

string newValue

The new property value that was set.

Remarks

This method is invoked right after the value of Port is changed.

OnPortChanging(string)

Executes the logic for when Port is changing.

Declaration
private void OnPortChanging(string value)
Parameters
Type Name Description
string value

The new property value being set.

Remarks

This method is invoked right before the value of Port is changed.

OnPortChanging(string?, string)

Executes the logic for when Port is changing.

Declaration
private void OnPortChanging(string? oldValue, string newValue)
Parameters
Type Name Description
string oldValue

The previous property value that is being replaced.

string newValue

The new property value being set.

Remarks

This method is invoked right before the value of Port is changed.

OnStatusMessageChanged(string)

Executes the logic for when StatusMessage just changed.

Declaration
private void OnStatusMessageChanged(string value)
Parameters
Type Name Description
string value

The new property value that was set.

Remarks

This method is invoked right after the value of StatusMessage is changed.

OnStatusMessageChanged(string?, string)

Executes the logic for when StatusMessage just changed.

Declaration
private void OnStatusMessageChanged(string? oldValue, string newValue)
Parameters
Type Name Description
string oldValue

The previous property value that was replaced.

string newValue

The new property value that was set.

Remarks

This method is invoked right after the value of StatusMessage is changed.

OnStatusMessageChanging(string)

Executes the logic for when StatusMessage is changing.

Declaration
private void OnStatusMessageChanging(string value)
Parameters
Type Name Description
string value

The new property value being set.

Remarks

This method is invoked right before the value of StatusMessage is changed.

OnStatusMessageChanging(string?, string)

Executes the logic for when StatusMessage is changing.

Declaration
private void OnStatusMessageChanging(string? oldValue, string newValue)
Parameters
Type Name Description
string oldValue

The previous property value that is being replaced.

string newValue

The new property value being set.

Remarks

This method is invoked right before the value of StatusMessage is changed.

SelectAllStreams()

Ticks every stream. Only changes the checkboxes — press Apply to send.

Declaration
[RelayCommand]
private void SelectAllStreams()

Summarise(IReadOnlyList<int>)

Renders a sorted id list compactly, collapsing runs (1,2,3,7 → "1-3,7").

Declaration
private static string Summarise(IReadOnlyList<int> ids)
Parameters
Type Name Description
IReadOnlyList<int> ids
Returns
Type Description
string

TryParseDevices(string?, out IReadOnlyList<int>, out string?)

Parses a device spec — comma/space separated ids and inclusive ranges, e.g. "1-8, 18" — into a sorted, de-duplicated list of node ids.

Declaration
public static bool TryParseDevices(string? spec, out IReadOnlyList<int> devices, out string? error)
Parameters
Type Name Description
string spec

The text to parse.

IReadOnlyList<int> devices

The resolved ids, or empty when parsing fails.

string error

A message naming the offending token, or null.

Returns
Type Description
bool

true if the whole spec parsed.

Implements

INotifyPropertyChanged
INotifyPropertyChanging

Search documentation

Start typing to search the documentation.