示例#1
0
        public string ExpandedContent(UploadFile file)
        {
            var             wikiTextFilename = file.FullPath + _fileExtension;
            VariableContent content;

            if (_helpers.FileExists(wikiTextFilename))
            {
                content = new VariableContent(_helpers.ReadAllText(wikiTextFilename));
            }
            else
            {
                if (!_wikiText.TryGetValue(file.Folder, out content))
                {
                    var folderWikiText = file.Folder + _fileName;
                    if (_helpers.FileExists(folderWikiText))
                    {
                        content = new VariableContent(_helpers.ReadAllText(folderWikiText));
                        _wikiText.Add(file.Folder, content);
                    }
                    else
                    {
                        _wikiText.Add(file.Folder, _defaultContent);
                        content = _defaultContent;
                    }
                }
            }
            return(content.ExpandedContent(file));
        }
示例#2
0
 public VariablePageContent(string fileExtension, string defaultContent, IHelpers helpers)
 {
     _defaultContent = new VariableContent(defaultContent);
     _helpers        = helpers;
     _fileExtension  = "." + fileExtension;
     _fileName       = "\\" + fileExtension + _fileExtension;
 }
示例#3
0
        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();
            }
        }