@page "/albums/{AlbumId}" @using ImageRecognition.BlazorWebAssembly.Models @using System.Collections.ObjectModel @using System.Threading @implements IDisposable @inject IServiceClientFactory ServiceClientFactory @inject ICommunicationClientFactory CommunicationClientFactory @inject NavigationManager NavigationManager @inject IFileUploader FileUploader
@if (!string.IsNullOrEmpty(Message)) {

@Message

} else {

@AlbumWrapper?.Album.Name


@ProgressMessage

@**@
@foreach (var photo in AlbumPhotos) { if (photo.Photo.ProcessingStatus != ProcessingStatus.Succeeded) {
@photo.Status
} else {
Uploaded: @photo.Photo.UploadTime

Detected labels:

@if (photo.Photo?.ObjectDetected != null) { @foreach (var label in photo.Photo.ObjectDetected) {
@label
} }

Image size: @photo.Photo.FullSize.Height x @photo.Photo.FullSize.Width

@if (photo.Photo?.GeoLocation != null) {

Geolocation: @photo.Photo.GeoLocation.ToString()

} @if (photo.Photo?.ExifModel != null) {

Device: @photo.Photo.ExifMake @photo.Photo.ExifModel

}
} }
}
@if (!Loaded) {

Loading photos...

} @code { bool Loaded { get; set; } readonly ObservableCollection AlbumPhotos = new(); private readonly List loadedFiles = new(); PhotoClient _photoClient; CancellationTokenSource _cancelSource; ICommunicationClient _communicationClient; string Name { get; set; } string SelectedGallery { get; set; } readonly bool DisableInput = false; long ProgressNow { get; set; } long ProgressMax { get; } = 100; string ProgressStyle { get; set; } = "width: 0%;"; string ProgressMessage { get; set; } [Parameter] public string AlbumId { get; set; } public AlbumWrapper AlbumWrapper { get; set; } public string Message { get; set; } private readonly int maxAllowedFiles = 3; protected override async Task OnInitializedAsync() { _cancelSource = new CancellationTokenSource(); _communicationClient = await CommunicationClientFactory.CreateCommunicationClient(_cancelSource.Token); } protected override async Task OnParametersSetAsync() { if (string.IsNullOrEmpty(AlbumId)) { Message = "Album Id is required."; } else { var albumClient = await ServiceClientFactory.CreateAlbumClient(); AlbumWrapper = new AlbumWrapper(await albumClient.GetAlbumByIdAsync(AlbumId)); _photoClient = await ServiceClientFactory.CreatePhotoClient(); await ReloadPhotos(); _ = ReadCommunicationEvents(); } } async Task ReloadPhotos() { try { var photos = await _photoClient.GetPhotosByAlbumAsync(AlbumId); AlbumPhotos.Clear(); foreach (var photo in photos) { AlbumPhotos.Add(new PhotoWrapper(photo)); } Loaded = true; } catch (Exception ex) { Console.WriteLine(ex.Message); NavigationManager.NavigateTo("authentication/login-callback", true); } } async Task ReadCommunicationEvents() { while (!_cancelSource.IsCancellationRequested) { var evnt = await _communicationClient.ReadEventAsync(_cancelSource.Token); if (evnt == null) continue; foreach (var photoWrapper in AlbumPhotos) { if (string.Equals(photoWrapper.Photo.PhotoId, evnt.ResourceId, StringComparison.Ordinal)) { photoWrapper.Update(evnt); StateHasChanged(); } } } } private async Task SubmitForm() { long maxFileSize = 1024 * 1024 * 15; foreach (var file in loadedFiles) { using (var stream = file.OpenReadStream(maxFileSize)) { var uploadUrl = await FileUploader.UploadFileAsync(stream, AlbumId, file.Name); } } loadedFiles.Clear(); await ReloadPhotos(); } private void OnInputFileChange(InputFileChangeEventArgs e) { foreach (var file in e.GetMultipleFiles(maxAllowedFiles)) { loadedFiles.Add(file); } } public void Dispose() { if (_communicationClient != null) { _cancelSource.Cancel(); _communicationClient.Dispose(); _communicationClient = null; } } }