Files
annotations/Azaion.Common/DTO/AnnotationThumbnail.cs
T
2025-06-13 23:06:48 +03:00

45 lines
1.5 KiB
C#

using System.ComponentModel;
using System.IO;
using System.Runtime.CompilerServices;
using System.Windows.Media.Imaging;
using Azaion.Common.Database;
using Azaion.Common.Extensions;
namespace Azaion.Common.DTO;
public class AnnotationThumbnail(Annotation annotation, bool isValidator) : INotifyPropertyChanged
{
public Annotation Annotation { get; set; } = annotation;
public bool IsValidator { get; set; } = isValidator;
private BitmapImage? _thumbnail;
public BitmapImage? Thumbnail
{
get
{
if (_thumbnail == null)
Task.Run(async () => Thumbnail = await Annotation.ThumbPath.OpenImage());
return _thumbnail;
}
private set
{
_thumbnail = value;
OnPropertyChanged();
}
}
public string ImageName => Path.GetFileName(Annotation.ImagePath);
public string CreatedDate => $"{Annotation.CreatedDate:dd.MM.yyyy HH:mm:ss}";
public string CreatedEmail => Annotation.CreatedEmail;
public bool IsSeed => IsValidator &&
Annotation.AnnotationStatus.In(AnnotationStatus.Created, AnnotationStatus.Edited) &&
!Annotation.CreatedRole.IsValidator();
public event PropertyChangedEventHandler? PropertyChanged;
protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
public void UpdateUI() => OnPropertyChanged(nameof(IsSeed));
}