Exemplo n.º 1
0
        /// <summary>
        /// Instantiates an instance based on an XElement parsed from XML
        /// </summary>
        /// <param name="xml">The XElement corresponding to the Collection. One of its elements should be named "BulkPublishBloomPubSettings" in order for it to be loaded</param>
        /// <returns>Parses the XML elements and returns an instantiated BulkBloomPubPublishSettings object.
        /// Returns null if element not found.
        /// </returns>
        public static BulkBloomPubPublishSettings LoadFromXElement(XElement xml)
        {
            var settingsElement = xml.Elements().Where(e => e.Name == kXmlAttrName).FirstOrDefault();

            if (settingsElement == null)
            {
                return(null);
            }

            var publishSettings = new BulkBloomPubPublishSettings();

            publishSettings.makeBookshelfFile = CollectionSettings.ReadBoolean(settingsElement, "MakeBookshelfFile", true);
            publishSettings.makeBloomBundle   = CollectionSettings.ReadBoolean(settingsElement, "MakeBloomBundle", true);
            publishSettings.bookshelfColor    = CollectionSettings.ReadString(settingsElement, "BookshelfColor", Palette.kBloomLightBlueHex);
            // patch a problem we introduced with the first version of the code. (BL-10573)
            if (publishSettings.bookshelfColor == "lightblue")
            {
                publishSettings.bookshelfColor = Palette.kBloomLightBlueHex;
            }
            publishSettings.distributionTag = CollectionSettings.ReadString(settingsElement, "DistributionTag", "");
            publishSettings.bookshelfLabel  = CollectionSettings.ReadString(settingsElement, "BookshelfLabel", "");
            return(publishSettings);
        }
Exemplo n.º 2
0
        // Precondition: bulkSaveSettings must be non-null
        public void PublishAllBooks(BulkBloomPubPublishSettings bulkSaveSettings)
        {
            BrowserProgressDialog.DoWorkWithProgressDialog(_webSocketServer, "Bulk Save BloomPubs",
                                                           (progress, worker) =>
            {
                var dest = new TemporaryFolder("BloomPubs");
                progress.MessageWithoutLocalizing($"Creating files in {dest.FolderPath}...");

                var filenameWithoutExtension = _collectionModel.CollectionSettings.DefaultBookshelf.SanitizeFilename(' ', true);
                ;
                if (bulkSaveSettings.makeBookshelfFile)
                {
                    // see https://docs.google.com/document/d/1UUvwxJ32W2X5CRgq-TS-1HmPj7gCKH9Y9bxZKbmpdAI

                    progress.MessageWithoutLocalizing($"Creating bloomshelf file...");
                    System.Diagnostics.Debug.Assert(!bulkSaveSettings.bookshelfColor.Contains("\n") && !bulkSaveSettings.bookshelfColor.Contains("\r"), "(BL-10190 Repro) Invalid bookshelfColor setting (contains newline). Please investigate!");
                    var colorString = getBloomReaderColorString(bulkSaveSettings.bookshelfColor);
                    System.Diagnostics.Debug.Assert(!colorString.Contains("\n") && !colorString.Contains("\r"), "(BL-10190 Repro) Invalid computed colorString value (contains newline). Please investigate!");

                    // OK I know this looks lame but trust me, using jsconvert to make that trivial label array is way too verbose.
                    var template =
                        "{ 'label': [{ 'en': 'bookshelf-name'}], 'id': 'id-of-the-bookshelf', 'color': 'hex-color-value'}";
                    var json = template.Replace('\'', '"')
                               .Replace("bookshelf-name", bulkSaveSettings.bookshelfLabel.Replace('"', '\''))
                               .Replace("id-of-the-bookshelf", _collectionModel.CollectionSettings.DefaultBookshelf)
                               .Replace("hex-color-value", colorString);
                    var filename       = $"{filenameWithoutExtension}.bloomshelf";
                    var bloomShelfPath = Path.Combine(dest.FolderPath, filename);
                    RobustFile.WriteAllText(bloomShelfPath, json, Encoding.UTF8);
                }

                foreach (var bookInfo in _collectionModel.TheOneEditableCollection.GetBookInfos())
                {
                    if (worker.CancellationPending)
                    {
                        progress.MessageWithoutLocalizing("Cancelled.");
                        return(true);
                    }
                    progress.MessageWithoutLocalizing($"Making BloomPUB for {bookInfo.QuickTitleUserDisplay}...",
                                                      ProgressKind.Heading);

                    var settings             = AndroidPublishSettings.GetPublishSettingsForBook(_bookServer, bookInfo);
                    settings.DistributionTag = bulkSaveSettings.distributionTag;
                    if (bulkSaveSettings.makeBookshelfFile)
                    {
                        settings.BookshelfTag = _collectionModel.CollectionSettings.DefaultBookshelf;
                    }
                    BloomPubMaker.CreateBloomPub(bookInfo, settings, dest.FolderPath, _bookServer, progress);
                }

                if (bulkSaveSettings.makeBloomBundle)
                {
                    var bloomBundlePath = Path.Combine(dest.FolderPath, $"{filenameWithoutExtension}.bloombundle");

                    var bloomBundleFile = new BloomTarArchive(bloomBundlePath);
                    bloomBundleFile.AddDirectoryContents(dest.FolderPath, new string[] { ".bloombundle" });
                    bloomBundleFile.Save();
                }

                progress.MessageWithoutLocalizing("Done.", ProgressKind.Heading);
                Process.SafeStart(dest.FolderPath);
                // true means wait for the user, don't close automatically
                return(true);
            });
        }