private async Task Upload() { if (AddingFiles) { return; } var needsLogin = false; await RunCommand(() => UploadIsRunning, async() => { using (_cancelSource = new CancellationTokenSource()) { var cancelToken = _cancelSource.Token; var filesToUpload = new List <UploadFile>(UploadFiles); var variableSummary = new VariableContent(AddAppName(UploadSummary)); var variablePageContent = new VariablePageContent(_appSettings.ContentFileExtension, PageContent, _helpers); _fileUploader.IncludeInWatchList = IncludeInWatchlist; _fileUploader.IgnoreWarnings = ForceUpload; _editTokenRefreshed = false; foreach (var file in filesToUpload) { if (!file.IsVideo && !_fileUploader.PermittedFiles.IsPermitted(file.FileName)) { file.SetError(UploadMessages.FileTypeNotPermitted(Path.GetExtension(file.FileName))); } else { SetViewdFile(file); try { if (file.IsVideo) { await UploadVideo(file, cancelToken); } else { await UploadFile( file, variableSummary.ExpandedContent(file), variablePageContent.ExpandedContent(file), cancelToken); } } catch (HttpRequestException ex) { if (ex.InnerException is IOException) { file.SetError(UploadMessages.ReadFail); } else { file.SetError(UploadMessages.NetworkError); } } catch (XmlException) { file.SetError(UploadMessages.InvalidXml); } catch (JsonException) { file.SetError(UploadMessages.InvalidJson); } catch (FileNotFoundException) { file.SetError(UploadMessages.FileNotFound); } catch (IOException) { file.SetError(UploadMessages.ReadFail); } catch (TaskCanceledException) { if (_helpers.IsCancellationRequested(cancelToken)) { file.SetError(UploadMessages.Cancelled); break; // foreach } else { file.SetError(UploadMessages.TimedOut); } } catch (OperationCanceledException) { file.SetError(UploadMessages.Cancelled); break; // foreach } catch (ServerIsBusyException) { file.SetError(UploadMessages.ServerBusy); break; // foreach } catch (NoEditTokenException) { file.SetError(UploadMessages.NoEditToken); break; // foreach } catch (MustBeLoggedInException) { needsLogin = true; break; } } } } }); if (needsLogin) { LoginAgain(); } }