hot reload

This commit is contained in:
EugeneTes
2026-02-18 11:01:35 +01:00
parent 2bac7140a4
commit 14fe822962
9 changed files with 345 additions and 47 deletions

View File

@@ -142,6 +142,7 @@ public abstract class BaseRecognitionControl: IRecognitionControl
_cts?.Dispose();
_cts = null;
_loopTask = null;
Cleanup();
}
SessionEnded?.Invoke(new SessionEndedEvent
@@ -241,4 +242,9 @@ public abstract class BaseRecognitionControl: IRecognitionControl
public event Action<SessionStartedEvent> SessionStarted = delegate { };
public event Action<SessionEndedEvent> SessionEnded = delegate { };
public event Action<ErrorsInSequenceEvent> ErrorsInSequenceAlarm = delegate { };
public event Action RecipeFileChanged = delegate { };
public virtual void HotReload() { }
protected void RaiseRecipeFileChanged() => RecipeFileChanged?.Invoke();
protected virtual void Cleanup() { }
}

View File

@@ -17,4 +17,6 @@ public interface IRecognitionControl
event Action<SessionEndedEvent> SessionEnded;
event Action<ErrorsInSequenceEvent> ErrorsInSequenceAlarm;
void HotReload();
event Action RecipeFileChanged;
}

View File

@@ -32,9 +32,11 @@ namespace VisionBuilder.UI.Common
[NotifyPropertyChangedFor(nameof(CanStop))]
[NotifyPropertyChangedFor(nameof(CanPause))]
[NotifyPropertyChangedFor(nameof(CanResume))]
[NotifyPropertyChangedFor(nameof(CanHotReload))]
[NotifyCanExecuteChangedFor(nameof(SelectRecipeCommand))]
[NotifyCanExecuteChangedFor(nameof(StartCommand))]
[NotifyCanExecuteChangedFor(nameof(StopCommand))]
[NotifyCanExecuteChangedFor(nameof(HotReloadCommand))]
private bool _isRunning;
[ObservableProperty]
@@ -55,6 +57,13 @@ namespace VisionBuilder.UI.Common
public bool IsResumed => !IsPaused;
[ObservableProperty]
[NotifyPropertyChangedFor(nameof(CanHotReload))]
[NotifyCanExecuteChangedFor(nameof(HotReloadCommand))]
private bool _isHotReloadAvailable;
public bool CanHotReload => IsRunning && IsHotReloadAvailable;
public bool CanStop => IsRunning;
public bool CanStart => !IsRunning && SelectedRecipe!=null;
public bool CanPause => (IsRunning && !IsPaused)&&_uiConfiguration.ShowPauseButton;
@@ -100,6 +109,9 @@ namespace VisionBuilder.UI.Common
recognitionControl.SessionStarted += StatisticsVm.Handle;
recognitionControl.SessionStarted += ErrorsVm.Handle;
recognitionControl.RecipeFileChanged += () =>
SynchronizationContext?.Post(_ => IsHotReloadAvailable = true, null);
}
@@ -153,7 +165,14 @@ namespace VisionBuilder.UI.Common
});
IsPaused = false;
IsRunning = false;
IsHotReloadAvailable = false;
}
[RelayCommand(CanExecute = nameof(CanHotReload))]
public void HotReload()
{
_recognitionControl.HotReload();
IsHotReloadAvailable = false;
}
[RelayCommand]