public void BookExists_ExistingBook_ReturnsTrue()
        {
            var someBookPath = MakeBook("local", Guid.NewGuid().ToString(), "someone", "test");

            Login();
            _transfer.UploadBook(someBookPath, new NullProgress());
            Assert.That(_transfer.IsBookOnServer(someBookPath), Is.True);
        }
Beispiel #2
0
        private void _uploadButton_Click(object sender, EventArgs e)
        {
            _uploadButton.Enabled = false;             // can't start another until done.
            ScrollControlIntoView(_progressBox);
            _progressBox.Clear();
            var info = _book.BookInfo;

            if (string.IsNullOrEmpty(info.Id))
            {
                info.Id = Guid.NewGuid().ToString();
            }
            info.Uploader = _bookTransferrer.UserId;

            _progressBox.WriteMessage("Checking bloom version eligibility...");
            if (!_bookTransferrer.IsThisVersionAllowedToUpload())
            {
                MessageBox.Show(this,
                                LocalizationManager.GetString("PublishTab.Upload.OldVersion",
                                                              "Sorry, this version of Bloom Desktop is not compatible with the current version of BloomLibrary.org. Please upgrade to a newer version."),
                                LocalizationManager.GetString("PublishTab.Upload.UploadNotAllowed", "Upload Not Allowed"),
                                MessageBoxButtons.OK, MessageBoxIcon.Stop);
                _progressBox.WriteMessage("Canceled.");
                return;
            }

            // Todo: try to make sure it has a thumbnail.

            _progressBox.WriteMessage("Checking for existing copy on server...");
            if (_bookTransferrer.IsBookOnServer(_book.FolderPath))
            {
                using (var dlg = new OverwriteWarningDialog())
                {
                    if (dlg.ShowDialog() == DialogResult.Cancel)
                    {
                        _progressBox.WriteMessage("Canceled.");
                        return;
                    }
                }
            }
            _progressBox.WriteMessage("Starting...");
            var worker = new BackgroundWorker();

            worker.DoWork += BackgroundUpload;
            worker.WorkerReportsProgress = true;
            worker.RunWorkerCompleted   += (theWorker, completedEvent) =>
            {
                if (completedEvent.Error != null)
                {
                    string errorMessage = LocalizationManager.GetString("PublishTab.Upload.ErrorUploading", "Sorry, there was a problem uploading {0}. Some details follow. You may need technical help.");
                    _progressBox.WriteError(errorMessage, _book.Title);
                    _progressBox.WriteException(completedEvent.Error);
                }
                else if (string.IsNullOrEmpty((string)completedEvent.Result))
                {
                    // Something went wrong, typically already reported.
                    string sorryMessage = LocalizationManager.GetString("PublishTab.Upload.FinalUploadFailureNotice", "Sorry, \"{0}\" was not successfully uploaded");
                    _progressBox.WriteError(sorryMessage, _book.Title);
                }
                else
                {
                    var    url             = BloomLibraryUrlPrefix + "/browse/detail/" + _parseId;
                    string congratsMessage = LocalizationManager.GetString("PublishTab.Upload.UploadCompleteNotice", "Congratulations, \"{0}\" is now available on BloomLibrary.org ({1})");
                    _progressBox.WriteMessageWithColor(Color.Blue, congratsMessage, _book.Title, url);
                }
                _uploadButton.Enabled = true;                 // Don't call UpdateDisplay, it will wipe out the progress messages.
            };
            worker.RunWorkerAsync(_book);
            //_bookTransferrer.UploadBook(_book.FolderPath, AddNotification);
        }
        private void _uploadButton_Click(object sender, EventArgs e)
        {
            if (_uploadWorker != null)
            {
                // We're already doing an upload, this is now the Cancel button.
                _progressBox.CancelRequested = true;
                return;
            }
            _progressBox.CancelRequested = false;
            ScrollControlIntoView(_progressBox);
            _progressBox.Clear();
            var info = _book.BookInfo;

            if (string.IsNullOrEmpty(info.Id))
            {
                info.Id = Guid.NewGuid().ToString();
            }
            info.Uploader = _bookTransferrer.UserId;

            if (_book.BookInfo.IsSuitableForMakingShells)
            {
                var msg = LocalizationManager.GetString("PublishTab.Upload.Template",
                                                        "This book seems to be a template, that is, it contains blank pages for authoring a new book "
                                                        + "rather than content to translate into other languages. "
                                                        + "If that is not what you intended, you should get expert help before uploading this book."
                                                        + "\n\n"
                                                        + "Do you want to go ahead?");
                var warning = LocalizationManager.GetString("Warning", "Warning");
                if (MessageBox.Show(Form.ActiveForm, msg,
                                    warning, MessageBoxButtons.YesNo, MessageBoxIcon.Warning) != DialogResult.Yes)
                {
                    return;
                }
            }

            try
            {
                _progressBox.WriteMessage("Checking bloom version eligibility...");
                if (!_bookTransferrer.IsThisVersionAllowedToUpload())
                {
                    MessageBox.Show(this,
                                    LocalizationManager.GetString("PublishTab.Upload.OldVersion",
                                                                  "Sorry, this version of Bloom Desktop is not compatible with the current version of BloomLibrary.org. Please upgrade to a newer version."),
                                    LocalizationManager.GetString("PublishTab.Upload.UploadNotAllowed", "Upload Not Allowed"),
                                    MessageBoxButtons.OK, MessageBoxIcon.Stop);
                    _progressBox.WriteMessage("Canceled.");
                    return;
                }

                // Todo: try to make sure it has a thumbnail.

                _progressBox.WriteMessage("Checking for existing copy on server...");
                if (_bookTransferrer.IsBookOnServer(_book.FolderPath))
                {
                    using (var dlg = new OverwriteWarningDialog())
                    {
                        if (dlg.ShowDialog() == DialogResult.Cancel)
                        {
                            _progressBox.WriteMessage("Canceled.");
                            return;
                        }
                    }
                }
            }
            catch (Exception)
            {
                ReportTryAgainDuringUpload();
                _uploadButton.Enabled = true;
                return;
            }
            _progressBox.WriteMessage("Starting...");
            _uploadWorker         = new BackgroundWorker();
            _uploadWorker.DoWork += BackgroundUpload;
            _uploadWorker.WorkerReportsProgress = true;
            _uploadWorker.RunWorkerCompleted   += (theWorker, completedEvent) =>
            {
                // Return all controls to normal state. (Do this first, just in case we get some further exception somehow.)
                // I believe the event is guaranteed to be raised, even if something in the worker thread throws,
                // so there should be no way to get stuck in the state where the tabs etc. are disabled.
                SetStateOfNonUploadControls(true);
                // Don't call UpdateDisplay, it will wipe out the progress messages.
                if (_progressBox.CancelRequested)
                {
                    _progressBox.WriteMessageWithColor(Color.Red, LocalizationManager.GetString("PublishTab.Upload.Cancelled", "Upload was cancelled"));
                }
                else
                {
                    if (completedEvent.Error != null)
                    {
                        string errorMessage = LocalizationManager.GetString("PublishTab.Upload.ErrorUploading",
                                                                            "Sorry, there was a problem uploading {0}. Some details follow. You may need technical help.");
                        _progressBox.WriteError(errorMessage, _book.Title);
                        _progressBox.WriteException(completedEvent.Error);
                    }
                    else if (string.IsNullOrEmpty((string)completedEvent.Result))
                    {
                        // Something went wrong, typically already reported.
                        ReportTryAgainDuringUpload();
                    }
                    else
                    {
                        var    url             = BloomLibraryUrlPrefix + "/browse/detail/" + _parseId;
                        string congratsMessage = LocalizationManager.GetString("PublishTab.Upload.UploadCompleteNotice",
                                                                               "Congratulations, \"{0}\" is now available on BloomLibrary.org ({1})");
                        _progressBox.WriteMessageWithColor(Color.Blue, congratsMessage, _book.Title, url);
                    }
                }
                _uploadWorker = null;
            };
            SetStateOfNonUploadControls(false);             // Last thing we do before launching the worker, so we can't get stuck in this state.
            _uploadWorker.RunWorkerAsync(_book);
            //_bookTransferrer.UploadBook(_book.FolderPath, AddNotification);
        }