check point
This commit is contained in:
60
VisionBuilder.UI.Common/ViewModel/ErrorsVM.cs
Normal file
60
VisionBuilder.UI.Common/ViewModel/ErrorsVM.cs
Normal file
@@ -0,0 +1,60 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using VisionBuilder.UI.Common.Commands;
|
||||
using VisionBuilder.UI.Common.Commands.Interfaces;
|
||||
using VisionBuilder.UI.Common.ViewModel.Classes;
|
||||
using VisionBuilder.UI.Common.ViewModel.Interfaces.UI;
|
||||
|
||||
namespace VisionBuilder.UI.Common.ViewModel;
|
||||
|
||||
public class ErrorsVM:IEventHandler<ImageProcessedEvent>, IEventHandler<SessionStartedEvent>
|
||||
{
|
||||
private readonly UIConfiguration _uiConfiguration;
|
||||
private readonly IImagePreviewService _imagePreviewService;
|
||||
private readonly ILearningTool _learningTool;
|
||||
|
||||
public ErrorsVM(UIConfiguration uiConfiguration, IImagePreviewService imagePreviewService, ILearningTool learningTool)
|
||||
{
|
||||
_uiConfiguration = uiConfiguration;
|
||||
_imagePreviewService = imagePreviewService;
|
||||
_learningTool = learningTool;
|
||||
}
|
||||
|
||||
|
||||
public ObservableCollection<ErrorData> Errors { get; set; } = new ObservableCollection<ErrorData>();
|
||||
|
||||
public void ShowImage(ErrorData errorData)
|
||||
{
|
||||
if (errorData == null) return;
|
||||
|
||||
var vm = new ErrorPreviewVM(this, errorData, errorData.RecipeName, _uiConfiguration, _learningTool);
|
||||
_imagePreviewService.ShowImagePreview(vm);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void Handle(ImageProcessedEvent @event)
|
||||
{
|
||||
if(!@event.HasError)return;
|
||||
|
||||
ErrorData errorData = new ErrorData
|
||||
{
|
||||
RecipeName = @event.RecipeName,
|
||||
ImageOriginal = @event.ImageOriginal,
|
||||
ImageAnalysis = @event.ImageAnalysis,
|
||||
Title = @event.ErrorNames +" "+ DateTime.Now.ToString("T")
|
||||
};
|
||||
|
||||
if (Errors.Count >= _uiConfiguration.MaxErrorCount)
|
||||
{
|
||||
Errors.RemoveAt(0);
|
||||
}
|
||||
|
||||
Errors.Add(errorData);
|
||||
}
|
||||
|
||||
public void Handle(SessionStartedEvent @event)
|
||||
{
|
||||
Errors.Clear();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user