63 lines
2.0 KiB
C#
63 lines
2.0 KiB
C#
using AutoForge.Application.ExecutionTargets;
|
|
using AutoForge.Components;
|
|
using AutoForge.Core.ExecutionTargets;
|
|
|
|
namespace AutoForge.UI.Features.ExecutionTargets.SelectExecutionTarget;
|
|
|
|
public sealed class ExecutionTargetSelectionViewModel(IExecutionTargetResolver resolver)
|
|
{
|
|
public string ProviderIdentifier { get; set; } = string.Empty;
|
|
|
|
public ExecutionTargetKind? SelectedKind { get; set; }
|
|
|
|
public ExecutionTargetDescriptor? SelectedDescriptor { get; private set; }
|
|
|
|
public bool HasAttemptedSelection { get; private set; }
|
|
|
|
public StatusNoticeTone StatusTone { get; private set; } = StatusNoticeTone.Warning;
|
|
|
|
public string StatusMessage { get; private set; } =
|
|
"No provider metadata is registered. Choose an explicit provider identifier and target kind; selection will fail until a provider is configured. No connection is attempted.";
|
|
|
|
public void Select()
|
|
{
|
|
SelectedDescriptor = null;
|
|
HasAttemptedSelection = true;
|
|
|
|
if (string.IsNullOrWhiteSpace(ProviderIdentifier))
|
|
{
|
|
SetFailure("Enter an explicit provider identifier.");
|
|
return;
|
|
}
|
|
|
|
if (SelectedKind is null)
|
|
{
|
|
SetFailure("Choose an explicit execution-target kind.");
|
|
return;
|
|
}
|
|
|
|
try
|
|
{
|
|
var selection = new ExecutionTargetDescriptor(ProviderIdentifier, SelectedKind.Value);
|
|
SelectedDescriptor = resolver.Resolve(selection);
|
|
StatusTone = StatusNoticeTone.Success;
|
|
StatusMessage =
|
|
$"Metadata selected: {SelectedDescriptor.ProviderIdentifier} ({SelectedDescriptor.Kind}). This does not connect to a vehicle or authorize an operation.";
|
|
}
|
|
catch (TargetSelectionException exception)
|
|
{
|
|
SetFailure(exception.Message);
|
|
}
|
|
catch (ArgumentException exception)
|
|
{
|
|
SetFailure(exception.Message);
|
|
}
|
|
}
|
|
|
|
private void SetFailure(string message)
|
|
{
|
|
StatusTone = StatusNoticeTone.Error;
|
|
StatusMessage = message;
|
|
}
|
|
}
|