Bloom.Publish.PublishModel.Save C# (CSharp) Method

Save() public method

public Save ( ) : void
return void
        public void Save()
        {
            if (EpubMode)
            {
                try
                {
                    SaveAsEpub();
                }
                catch (Exception err)
                {
                    SIL.Reporting.ErrorReport.NotifyUserOfProblem("Bloom was not able to save the ePUB.  {0}", err.Message);
                }
                return;
            }
            try
            {
                // Give a slight preference to USB keys, though if they used a different directory last time, we favor that.

                if (string.IsNullOrEmpty(_lastDirectory) || !Directory.Exists(_lastDirectory))
                {
                    var drives = SIL.UsbDrive.UsbDriveInfo.GetDrives();
                    if (drives != null && drives.Count > 0)
                    {
                        _lastDirectory = drives[0].RootDirectory.FullName;
                    }
                }

                using (var dlg = new SaveFileDialog())
                {
                    if (!string.IsNullOrEmpty(_lastDirectory) && Directory.Exists(_lastDirectory))
                        dlg.InitialDirectory = _lastDirectory;
                    var portion = "";
                    switch (BookletPortion)
                    {
                        case BookletPortions.None:
                            Debug.Fail("Save should not be enabled");
                            return;
                        case BookletPortions.AllPagesNoBooklet:
                            portion = "Pages";
                            break;
                        case BookletPortions.BookletCover:
                            portion = "Cover";
                            break;
                        case BookletPortions.BookletPages:
                            portion = "Inside";
                            break;
                        default:
                            throw new ArgumentOutOfRangeException();
                    }
                    string suggestedName = string.Format("{0}-{1}-{2}.pdf", Path.GetFileName(_currentlyLoadedBook.FolderPath),
                                                         _collectionSettings.GetLanguage1Name("en"), portion);
                    dlg.FileName = suggestedName;
                    dlg.Filter = "PDF|*.pdf";
                    if (DialogResult.OK == dlg.ShowDialog())
                    {
                        _lastDirectory = Path.GetDirectoryName(dlg.FileName);
                        RobustFile.Copy(PdfFilePath, dlg.FileName, true);
                        Analytics.Track("Save PDF", new Dictionary<string, string>()
                            {
                                {"Portion",  Enum.GetName(typeof(BookletPortions), BookletPortion)},
                                {"Layout", PageLayout.ToString()},
                                {"BookId", BookSelection.CurrentSelection.ID },
                                {"Country", _collectionSettings.Country}
                            });
                    }
                }
            }
            catch (Exception err)
            {
                SIL.Reporting.ErrorReport.NotifyUserOfProblem("Bloom was not able to save the PDF.  {0}", err.Message);
            }
        }

Usage Example

Example #1
0
 private void OnSave_Click(object sender, EventArgs e)
 {
     _model.Save();
 }