This class represents an instance of a hyperlink which, when activated, causes a bloom book to be downloaded and opened. Such a link looks like bloom://localhost/order?orderFile={path}, where path is appropriate urlencoded. Optionally, it may be followed by &title={title}, where title is the book title (urlencoded). To allow Bloom to be automatically started when such a link is activated requires some registry entries: The key HKEY_CLASSES_ROOT\bloom\shell\open\command must contain as its default value a string which is the path to Bloom.exe in quotes, followed by " %1". For example, "C:\palaso\bloom-desktop\Output\Debug\Bloom.exe" "%1" In addition, the HKEY_CLASSES_ROOT\bloom key must have a default value of "URL:BLOOM Protocol" and another string value called "URL Protocol" (no value). (Don't ask me why...Alistair may know.) One way to set these up on a developer machine is to edit the file bloom link.reg in the project root directory so that it contains the correct path to your exe, then double-click it. When a properly-formed link is followed, a new instance of Bloom is started up and passed the URL as its one command-line argument. This is recognized and handled in Program.Main(). Todo: Make installer set up the registry entries. Todo Linux: probably something quite different needs to be done to make Bloom the handler for bloom:// URLs.
コード例 #1
0
        internal void HandleBloomBookOrder(string argument)
        {
            _downloadRequest = argument;
            using (_progressDialog = new ProgressDialog())
            {
                _progressDialog.CanCancel            = false;      // one day we may allow this...
                _progressDialog.Overview             = LocalizationManager.GetString("Download.DownloadingDialogTitle", "Downloading book");
                _progressDialog.ProgressRangeMaximum = 14;         // a somewhat minimal file count. We will fine-tune it when we know.
                if (IsUrlOrder(argument))
                {
                    var link = new BloomLinkArgs(argument);
                    _progressDialog.StatusText = link.Title;
                }
                else
                {
                    _progressDialog.StatusText = Path.GetFileNameWithoutExtension(argument);
                }

                // We must do the download in a background thread, even though the whole process is doing nothing else,
                // so we can invoke stuff on the main thread to (e.g.) update the progress bar.
                BackgroundWorker worker = new BackgroundWorker();
                worker.DoWork += OnDoDownload;
                _progressDialog.BackgroundWorker = worker;
                //dlg.CancelRequested += new EventHandler(OnCancelRequested);
                _progressDialog.ShowDialog();                 // hidden automatically when task completes
                if (_progressDialog.ProgressStateResult != null &&
                    _progressDialog.ProgressStateResult.ExceptionThatWasEncountered != null)
                {
                    Palaso.Reporting.ErrorReport.ReportFatalException(
                        _progressDialog.ProgressStateResult.ExceptionThatWasEncountered);
                }
            }
        }
コード例 #2
0
ファイル: BookDownload.cs プロジェクト: gmartin7/myBloomFork
        internal void HandleBloomBookOrder(string order)
        {
            _downloadRequest = order;
            using (var progressDialog = new ProgressDialog())
            {
                _progressDialog                     = new ProgressDialogWrapper(progressDialog);
                progressDialog.CanCancel            = true;
                progressDialog.Overview             = LocalizationManager.GetString("Download.DownloadingDialogTitle", "Downloading book");
                progressDialog.ProgressRangeMaximum = 14;                 // a somewhat minimal file count. We will fine-tune it when we know.
                if (IsUrlOrder(order))
                {
                    var link = new BloomLinkArgs(order);
                    progressDialog.StatusText = link.Title;
                }
                else
                {
                    progressDialog.StatusText = Path.GetFileNameWithoutExtension(order);
                }

                // We must do the download in a background thread, even though the whole process is doing nothing else,
                // so we can invoke stuff on the main thread to (e.g.) update the progress bar.
                BackgroundWorker worker = new BackgroundWorker();
                worker.DoWork += OnDoDownload;
                progressDialog.BackgroundWorker = worker;
                progressDialog.ShowDialog();                 // hidden automatically when task completes
                if (progressDialog.ProgressStateResult != null &&
                    progressDialog.ProgressStateResult.ExceptionThatWasEncountered != null)
                {
                    var exc = progressDialog.ProgressStateResult.ExceptionThatWasEncountered;
                    ProblemReportApi.ShowProblemDialog(null, exc, "", "fatal");
                }
            }
        }
コード例 #3
0
 public void LinkArgs_WithoutTitle_GetsCorrectOrderAndTitle()
 {
     var order = HttpUtility.UrlEncode("somepath/whatever=.BookOrder");
     var input = BloomLinkArgs.kBloomUrlPrefix + BloomLinkArgs.kOrderFile + "=" + order;
     var args = new BloomLinkArgs(input);
     Assert.That(args.OrderUrl, Is.EqualTo("somepath/whatever=.BookOrder"));
     Assert.That(args.Title, Is.EqualTo("whatever="));
 }
コード例 #4
0
 public void LinkArgs_WithTitle_GetsCorrectOrderAndTitle()
 {
     var order = HttpUtility.UrlEncode("whatever=&?!<>'\".BookOrder");
     var title = HttpUtility.UrlEncode("title=&?!<>'\"");
     var input = BloomLinkArgs.kBloomUrlPrefix + BloomLinkArgs.kOrderFile + "=" + order + "&title=" + title;
     var args = new BloomLinkArgs(input);
     Assert.That(args.OrderUrl, Is.EqualTo("whatever=&?!<>'\".BookOrder"));
     Assert.That(args.Title, Is.EqualTo("title=&?!<>'\""));
 }
コード例 #5
0
 /// <summary>
 /// this runs in a worker thread
 /// </summary>
 private void OnDoDownload(object sender, DoWorkEventArgs args)
 {
     // If we are passed a bloom book order URL, download the corresponding book and open it.
     if (IsUrlOrder(_downloadRequest))
     {
         var link = new BloomLinkArgs(_downloadRequest);
         DownloadFromOrderUrl(link.OrderUrl, DownloadFolder);
     }
     // If we are passed a bloom book order, download the corresponding book and open it.
     else if (_downloadRequest.ToLower().EndsWith(BookTransfer.BookOrderExtension.ToLower()) &&
              File.Exists(_downloadRequest))
     {
         HandleBookOrder(_downloadRequest);
     }
 }
コード例 #6
0
 /// <summary>
 /// this runs in a worker thread
 /// </summary>
 private void OnDoDownload(object sender, DoWorkEventArgs args)
 {
     // If we are passed a bloom book order URL, download the corresponding book and open it.
     if (IsUrlOrder(_downloadRequest))
     {
         var link = new BloomLinkArgs(_downloadRequest);
         DownloadFromOrderUrl(_downloadRequest, DownloadFolder, link.Title);
     }
         // If we are passed a bloom book order, download the corresponding book and open it.
     else if (_downloadRequest.ToLowerInvariant().EndsWith(BookTransfer.BookOrderExtension.ToLowerInvariant()) &&
              RobustFile.Exists(_downloadRequest))
     {
         HandleBookOrder(_downloadRequest);
     }
 }
コード例 #7
0
        internal void HandleBloomBookOrder(string order)
        {
            _downloadRequest = order;
            using (var progressDialog = new ProgressDialog())
            {
                _progressDialog = new ProgressDialogWrapper(progressDialog);
                progressDialog.CanCancel = false; // one day we may allow this...
                progressDialog.Overview = LocalizationManager.GetString("Download.DownloadingDialogTitle", "Downloading book");
                progressDialog.ProgressRangeMaximum = 14; // a somewhat minimal file count. We will fine-tune it when we know.
                if (IsUrlOrder(order))
                {
                    var link = new BloomLinkArgs(order);
                    progressDialog.StatusText = link.Title;
                }
                else
                {
                    progressDialog.StatusText = Path.GetFileNameWithoutExtension(order);
                }

                // We must do the download in a background thread, even though the whole process is doing nothing else,
                // so we can invoke stuff on the main thread to (e.g.) update the progress bar.
                BackgroundWorker worker = new BackgroundWorker();
                worker.DoWork += OnDoDownload;
                progressDialog.BackgroundWorker = worker;
                //dlg.CancelRequested += new EventHandler(OnCancelRequested);
                progressDialog.ShowDialog(); // hidden automatically when task completes
                if (progressDialog.ProgressStateResult != null &&
                    progressDialog.ProgressStateResult.ExceptionThatWasEncountered != null)
                {
                    SIL.Reporting.ErrorReport.ReportFatalException(
                        progressDialog.ProgressStateResult.ExceptionThatWasEncountered);
                }
            }
        }