public BookInfo(string folderPath,bool isEditable) { IsSuitableForVernacularLibrary = true; // default FolderPath = folderPath; Id = Guid.NewGuid().ToString(); CoverColor = NextBookColor(); var jsonPath = MetaDataPath; if (File.Exists(jsonPath)) { _metadata = BookMetaData.FromString(File.ReadAllText(jsonPath)); // Enhance: error handling? } else { // Look for old tags files not yet migrated var oldTagsPath = Path.Combine(folderPath, "tags.txt"); if (File.Exists(oldTagsPath)) { Book.ConvertTagsToMetaData(oldTagsPath, this); } } //TODO Type = Book.BookType.Publication; IsEditable = isEditable; }
public BookInfo(string folderPath, bool isEditable) { FolderPath = folderPath; //NB: This was coded in an unfortunate way such that touching almost any property causes a new metadata to be quietly created. //So It's vital that we not touch properties that could create a blank metadata, before attempting to load the existing one. var jsonPath = MetaDataPath; if (RobustFile.Exists(jsonPath)) { _metadata = BookMetaData.FromString(RobustFile.ReadAllText(jsonPath)); // Enhance: error handling? } else { // Look for old tags files not yet migrated var oldTagsPath = Path.Combine(folderPath, "tags.txt"); if (RobustFile.Exists(oldTagsPath)) { Book.ConvertTagsToMetaData(oldTagsPath, this); } } //TODO Type = Book.BookType.Publication; IsEditable = isEditable; FixDefaultsIfAppropriate(); }
private static string GetMetaJsonModfiedForTemplate(string path) { var meta = BookMetaData.FromString(RobustFile.ReadAllText(path)); meta.IsSuitableForMakingShells = true; return(meta.Json); }
private static bool TryReadMetaData(string path, out BookMetaData result) { result = null; if (!RobustFile.Exists(path)) { return(false); } try { result = FromString(RobustFile.ReadAllText(path)); return(true); } catch (Exception e) { return(false); } }
public BookInfo(string folderPath, bool isEditable) { IsSuitableForVernacularLibrary = true; // default FolderPath = folderPath; Id = Guid.NewGuid().ToString(); CoverColor = NextBookColor(); var jsonPath = MetaDataPath; if (File.Exists(jsonPath)) { _metadata = BookMetaData.FromString(File.ReadAllText(jsonPath)); // Enhance: error handling? } else { // Look for old tags files not yet migrated var oldTagsPath = Path.Combine(folderPath, "tags.txt"); if (File.Exists(oldTagsPath)) { Book.ConvertTagsToMetaData(oldTagsPath, this); } } // should the accordion be enabled? if ((_metadata != null) && (_metadata.Tools != null)) { if (!_metadata.ReaderToolsAvailable) { if (_metadata.Tools.Any(t => t.Enabled)) { _metadata.ReaderToolsAvailable = true; } } } //TODO Type = Book.BookType.Publication; IsEditable = isEditable; FixDefaultsIfAppropriate(); }
public BookInfo(string folderPath, bool isEditable) { FolderPath = folderPath; //NB: This was coded in an unfortunate way such that touching almost any property causes a new metadata to be quietly created. //So It's vital that we not touch properties that could create a blank metadata, before attempting to load the existing one. _metadata = BookMetaData.FromFolder(FolderPath); if (_metadata == null) { // Look for old tags files not yet migrated var oldTagsPath = Path.Combine(folderPath, "tags.txt"); if (RobustFile.Exists(oldTagsPath)) { Book.ConvertTagsToMetaData(oldTagsPath, this); } // otherwise leave it null, first attempt to use will create a default one } IsEditable = isEditable; FixDefaultsIfAppropriate(); }
static PublishSettings MigrateSettings(string bookFolderPath) { // See if we can migrate data from an old metaData. var metaDataPath = BookMetaData.MetaDataPath(bookFolderPath); var settings = new PublishSettings(); try { if (!RobustFile.Exists(metaDataPath)) { return(settings); } var metaDataString = RobustFile.ReadAllText(metaDataPath, Encoding.UTF8); // I chose to do this using DynamicJson, rather than just BloomMetaData.FromString() and // reading the obsolete properties, in hopes that we can eventually retire the obsolete // properties. However, that may not be possible without breaking things when we attempt // to load an old meta.json with JsonConvert. Still, at least this approach makes for // fewer warnings about use of obsolete methods. var metaDataJson = DynamicJson.Parse(metaDataString) as DynamicJson; if (metaDataJson.IsDefined("features")) { if (metaDataJson.TryGet("features", out string[] features))
private string S3BookId(BookMetaData metadata) { // It's tempting to use '/' so that S3 tools will treat all the books with the same ID as a folder. // But this complicates things because that character is taken as a path separator (even in Windows), // which gives us an extra level of folder in our temp folder...too much trouble for now, anyway. // So use a different separator. var s3BookId = _parseClient.Account + "/" + metadata.Id; return s3BookId; }
public void WebDataJson_IncludesCorrectFields() { var meta = new BookMetaData() { Id = "myId", IsSuitableForMakingShells = true, IsSuitableForVernacularLibrary = false, IsExperimental = true, Title = "myTitle", AllTitles = "abc,\"def", BaseUrl = "http://some/unlikely/url", Isbn = "123-456-78-9", DownloadSource = "http://some/amazon/url", License = "ccby", FormatVersion = "1.0", Credits = "JohnT", Summary = "A very nice book\\ in a very nice nook", Tags= new []{"Animals"}, CurrentTool = "mytool", BookletMakingIsAppropriate = false, PageCount=7, LanguageTableReferences = new [] {new ParseDotComObjectPointer() { ClassName = "Language", ObjectId = "23456" }}, Uploader = new ParseDotComObjectPointer() { ClassName="User", ObjectId = "12345"}, Tools = new List<ToolboxTool>(new [] {new DecodableReaderTool()}), AllowUploadingToBloomLibrary = false }; var result = meta.WebDataJson; var meta2 = BookMetaData.FromString(result); Assert.That(meta2.Id, Is.EqualTo("myId")); Assert.That(meta2.IsSuitableForMakingShells, Is.True); Assert.That(meta2.IsSuitableForVernacularLibrary, Is.False); Assert.That(meta2.IsExperimental, Is.True); Assert.That(meta2.Title, Is.EqualTo("myTitle")); Assert.That(meta2.AllTitles, Is.EqualTo("abc,\"def")); Assert.That(meta2.BaseUrl, Is.EqualTo("http://some/unlikely/url")); Assert.That(meta2.Isbn, Is.EqualTo("123-456-78-9")); Assert.That(meta2.License, Is.EqualTo("ccby")); Assert.That(meta2.FormatVersion, Is.EqualTo("1.0")); Assert.That(meta2.Credits, Is.EqualTo("JohnT")); Assert.That(meta2.Tags, Has.Length.EqualTo(1)); Assert.That(meta2.Summary, Is.EqualTo("A very nice book\\ in a very nice nook")); Assert.That(meta2.PageCount, Is.EqualTo(7)); Assert.That(meta2.LanguageTableReferences, Has.Length.EqualTo(1)); Assert.That(meta2.LanguageTableReferences[0].ObjectId, Is.EqualTo("23456")); Assert.That(meta2.Uploader, Is.Not.Null); Assert.That(meta2.Uploader.ObjectId, Is.EqualTo("12345")); // These properties (and various others) should not be in the serialization data. // Since AllowUploadingToBloomLibrary defaults true, that should be its value if not set by json Assert.That(meta2.AllowUploadingToBloomLibrary, Is.True, "AllowUploadingtoBloomLibrary was unexpectedly serialized"); Assert.That(meta2.DownloadSource, Is.Null); Assert.That(meta2.CurrentTool, Is.Null); Assert.That(meta2.Tools, Is.Null); Assert.That(meta2.BookletMakingIsAppropriate, Is.True); // default value }