protected void SetValueFromObject(object value) { if (!IsDisabled) { Property.Setter(Entity, value); } EditContext.NotifyPropertyChanged(Property); }
protected virtual async Task OnFileSelectedAsync(ChangeEventArgs args) { EditContext.NotifyPropertyBusy(Property); UploadCompletion = 0.01; var files = await FileReaderService.CreateReference(_fileInput).EnumerateFilesAsync(); if (files.Count() > 1) { EditContext.AddValidationMessage(Property, "This editor only supports single files for now."); } var file = files.FirstOrDefault(); if (file == null) { return; } var fileInfo = await file.ReadFileInfoAsync(); var validationMessages = FileUploadHandler.ValidateFile(fileInfo); if (validationMessages.Any()) { foreach (var message in validationMessages) { EditContext.AddValidationMessage(Property, message); } EditContext.NotifyPropertyFinished(Property); StateHasChanged(); return; } using var uploadedFile = await UploadFileToTempFileAsync(file, 8192, fileInfo.Size, (completion) => { if (completion - UploadCompletion > 1) { UploadCompletion = completion; StateHasChanged(); } }); UploadCompletion = 0.0; StateHasChanged(); var value = await FileUploadHandler.SaveFileAsync(fileInfo, uploadedFile); SetValueFromObject(value); EditContext.NotifyPropertyFinished(Property); EditContext.NotifyPropertyChanged(Property); }