refactor(net): converge live session state reset

This commit is contained in:
Erik 2026-07-21 12:00:48 +02:00
parent 78a9223b65
commit 4f31a5085f
35 changed files with 1460 additions and 83 deletions

View file

@ -78,20 +78,25 @@ public sealed class SelectionState : ISelectionService
public bool Reset(SelectionChangeSource source = SelectionChangeSource.System)
{
uint? old = SelectedObjectId;
bool changed = old is not null
|| PreviousObjectId is not null
|| PreviousValidObjectId is not null;
SelectedObjectId = null;
PreviousObjectId = null;
PreviousValidObjectId = null;
if (old is null)
return false;
var transition = new SelectionTransition(
old,
null,
source,
SelectionChangeReason.SessionReset);
Changed?.Invoke(transition);
List<Exception>? failures = DispatchChanged(transition);
DispatchPluginChanged(new SelectionChangedEvent(old, null));
return true;
if (failures is not null)
throw new AggregateException(
"One or more selection reset observers failed.",
failures);
return changed;
}
bool ISelectionService.Select(uint objectId)
@ -120,6 +125,21 @@ public sealed class SelectionState : ISelectionService
return true;
}
private List<Exception>? DispatchChanged(SelectionTransition transition)
{
Action<SelectionTransition>? listeners = Changed;
if (listeners is null)
return null;
List<Exception>? failures = null;
foreach (Action<SelectionTransition> listener in listeners.GetInvocationList())
{
try { listener(transition); }
catch (Exception error) { (failures ??= []).Add(error); }
}
return failures;
}
private void DispatchPluginChanged(SelectionChangedEvent change)
{
Action<SelectionChangedEvent>? listeners = PluginChanged;