Exemplo n.º 1
0
        protected async Task OnUploadProgressAsync(IReadOnlyCollection <FileUploadProgress> progresses)
        {
            Console.WriteLine("OnUploadProgressAsync: " + Json.Serialize(progresses));

            UploadProgress.Clear();
            if (progresses.All(p => p.Status == "done" || p.Status == "error"))
            {
                UploadErrors.Clear();
                UploadErrors.AddRange(progresses.Where(p => p.Status == "error").Select(p => new UploadErrorModel(p)));
                if (UploadErrors.Count > 0)
                {
                    if (UploadErrors.All(e => e.Progress.StatusCode == 402))
                    {
                        FreeLimitsNotifier.Show();
                    }
                    else
                    {
                        UploadError.Show();
                    }
                }

                await LoadImagesAsync();
            }
            else
            {
                foreach (var progress in progresses)
                {
                    ImageModel image = null;
                    if (progress.Status == "done" && progress.ResponseText != null)
                    {
                        image = Json.Deserialize <ImageModel>(progress.ResponseText);
                    }

                    UploadProgress.Add(new UploadImageModel(progress, image));
                }
            }

            StateHasChanged();
        }