Files
amkovkov 72ae26eee7 comprehensive update
1) remove unused components: camera view (due it causes segmentation faults), compute resources and all related, illuminator controller (due in useless without camera view), image storage service, temperature and humidity service
2) database schema - reduce tables references, features storing in records themselves in compressed form, add records creation and editing date and time, add separator comment column
3) analysis - rework of pipeline and ui, now database storing only raw data and all display values calculated from it
4) lights service - add reconnection if disconnected
5) add width and height command line arguments
6) fix some typos and other issues
2026-06-29 15:13:29 +03:00

63 lines
1.7 KiB
C#

using Avalonia.Media;
using Avalonia.Media.Imaging;
using Avalonia.Threading;
using CommunityToolkit.Mvvm.ComponentModel;
using Microsoft.IdentityModel.Tokens;
namespace GSS2.UI.Core.ViewModels;
public partial class AsyncImageRecordViewModel : ViewModelBase
{
private static readonly SemaphoreSlim _semaphore = new(1, 1);
[ObservableProperty] public partial string Data { get; set; }
[ObservableProperty] public partial IImage? Image { get; set; }
[ObservableProperty] public partial bool IsLoading { get; set; } = false;
public AsyncImageRecordViewModel(string data = "")
{
Data = data;
}
partial void OnDataChanged(string value) => _ = LoadAsync();
private async Task LoadAsync()
{
await _semaphore.WaitAsync();
try
{
if (!string.IsNullOrEmpty(Data))
{
IsLoading = true;
byte[] imageBytes = Convert.FromBase64String(Data);
Bitmap bitmap;
using (var stream = new MemoryStream(imageBytes))
{
bitmap = await Task.Run(() => new Bitmap(stream));
}
await Dispatcher.UIThread.InvokeAsync(() =>
{
Image = bitmap;
IsLoading = false;
});
}
else
{
Image = new WriteableBitmap(new Avalonia.PixelSize(1, 1), new Avalonia.Vector(96, 96), Avalonia.Platform.PixelFormat.Bgra8888, Avalonia.Platform.AlphaFormat.Premul);
}
}
catch
{
await Dispatcher.UIThread.InvokeAsync(() => IsLoading = false);
}
finally
{
_semaphore.Release();
}
}
}