public override void ImportBook(BookBase book) { string template = Path.Combine(App.Config.DirectoryFormat, "{Title}"); string destinationFile = Path.Combine(App.Config.LibraryRoot, template.DictFormat(book.Props())) + ".mobi"; destinationFile = Utils.Files.MakeFilesystemSafe(destinationFile); Logger.Info("Importing {} from {} to {}", book.Title, book.FilePath, destinationFile); if (App.LocalLibrary.Database.BOOKS.Any(x => x.FilePath == destinationFile)) { throw new IOException("File already exists in libary"); } Directory.CreateDirectory(Directory.GetParent(destinationFile).FullName); if (!CompatibleFiletypes.Contains(Path.GetExtension(book.FilePath))) { int id = book.Id; book = Converters.ToMobi(book, destinationFile); book.Id = id; } else { File.Copy(book.FilePath, destinationFile); } book.FilePath = RelativeFilepath(destinationFile); App.LocalLibrary.Database.AddBook(book); }
public virtual void UpdateBookMetadata(BookBase donor) { Database.BookEntry entry = Database.BOOKS.FirstOrDefault(x => x.Id == donor.Id); if (entry == null) { return; } BookBase recip = BookBase.Auto(AbsoluteFilePath(entry)); recip.UpdateMetadata(donor); Database.UpdateBook(donor); string origPath = recip.FilePath; string targetPath = FormatFilePath(FilePathTemplate(), recip); if (origPath != targetPath) { try { Directory.CreateDirectory(Path.GetDirectoryName(targetPath)); File.Move(origPath, targetPath); donor.FilePath = targetPath; Database.UpdateBook(donor); } catch (Exception e) { throw new Exception($"Could not rename file in library directory. {e.Message}"); } } }
private async Task DoReceiveBook(BookBase bookBase) { if (_gdaxFile == null || DateTime.Today != _fileDate) { OpenFile(); } if (_productBook == null) { _productBook = await _gdaxClient.GetProductBook(_productType, BookLevel.Full); _gdaxFile.Serialize(_productBook, DateTime.UtcNow); Program.Log.Info("Product book loaded."); } if (_productBook.Update(bookBase)) { _gdaxFile.Serialize(bookBase); } else { _productBook = null; Program.Log.Error("Some event are missing, book order will be fully reloaded."); } }
public void create_new_book_from_factory_datepublished_defaults_to_min_date() { BookBase book = (BookBase)CollectableBaseFactory.CreateCollectableBase(CollectableBaseFactory.BookType); Assert.AreEqual(0, book.Year); Assert.AreEqual(0, book.Month); }
public void create_new_book_from_factory_getitems_defaults_to_zero_items_in_list() { BookBase book = (BookBase)CollectableBaseFactory.CreateCollectableBase(CollectableBaseFactory.BookType); IList <ICollectableItem> bookItems = book.ItemInstances; Assert.AreEqual(0, bookItems.Count); }
public static Book AddBook(IBookAdapter adapter, BookBase book) { var newBook = (Book)book; newBook.Id = Guid.NewGuid(); return(adapter.AddBook(newBook)); }
public void book_year_cannot_be_set_to_negative() { BookBase book = (BookBase)CollectableBaseFactory.CreateCollectableBase(CollectableBaseFactory.BookType); book.Year = -100; Assert.IsFalse(true, "Expected an exception to be thrown if a negative year is set"); }
public void book_year_can_be_set_to_zero_successfully() { BookBase book = (BookBase)CollectableBaseFactory.CreateCollectableBase(CollectableBaseFactory.BookType); book.Year = 0; Assert.AreEqual(0, book.Year); }
public void display_name_initialized_to_default_value() { string expectedValue = BookBase.DISPLAYNAME_DEFAULT; BookBase book = (BookBase)CollectableBaseFactory.CreateCollectableBase(CollectableBaseFactory.BookType); Assert.AreEqual(expectedValue, book.DisplayName); }
public void display_name_cannot_be_set_to_blank_string() { BookBase book = (BookBase)CollectableBaseFactory.CreateCollectableBase(CollectableBaseFactory.BookType); book.DisplayName = ""; Assert.IsFalse(true, "Expected an exception to be thrown if a blank display name is set"); }
public void create_new_book_from_factory_getitems_does_not_return_null_list() { BookBase book = (BookBase)CollectableBaseFactory.CreateCollectableBase(CollectableBaseFactory.BookType); IList <ICollectableItem> bookItems = book.ItemInstances; Assert.IsNotNull(bookItems); }
public void book_year_can_be_set_to_valid_year_successfully() { BookBase book = (BookBase)CollectableBaseFactory.CreateCollectableBase(CollectableBaseFactory.BookType); int testYear = 2015; book.Year = testYear; Assert.AreEqual(testYear, book.Year); }
public void display_name_set_to_nonblank_value_succeeds() { string expectedValue = "Display Name"; BookBase book = (BookBase)CollectableBaseFactory.CreateCollectableBase(CollectableBaseFactory.BookType); book.DisplayName = expectedValue; Assert.AreEqual(expectedValue, book.DisplayName); }
public void compare_book_base_instances_by_explicit_scottnumber_returns_false_when_null() { BookBase book = (BookBase)CollectableBaseFactory.CreateCollectableBase(CollectableBaseFactory.BookType); BookBase testbook = null; bool isEqual = book.IsSame(testbook, false); Assert.IsFalse(isEqual, "Expected test to throw exception when comparing a null base instance"); }
/// <summary> /// Scans for all books in library and recreates database and directory structure /// </summary> public virtual IEnumerable <BookBase> Rescan() { List <Exception> errs = new List <Exception>(); BookBase[] oldDB = Database.BOOKS.ToArray(); Database.Drop("BOOKS"); IEnumerable <string> bookPaths = Utils.Files.DirSearch(LibraryRoot).Where(x => CompatibleFiletypes.Contains(Path.GetExtension(x))); BookBase book; string dest; string destTemplate = FilePathTemplate(); foreach (string filePath in bookPaths) { try { book = BookBase.Auto(filePath); dest = FormatFilePath(destTemplate, book); Directory.CreateDirectory(Path.GetPathRoot(dest)); if (!File.Exists(dest)) { Directory.CreateDirectory(Path.GetDirectoryName(dest)); File.Move(filePath, dest); } book.FilePath = RelativeFilepath(dest); BookBase local = null; if (book.ISBN != 0) { local = oldDB.FirstOrDefault(x => x.ISBN == book.ISBN); } if (local != null) { book.Id = local.Id; book.Series = local.Series; book.SeriesNum = local.SeriesNum; } Database.AddBook(book); } catch (Exception e) { e.Data["item"] = filePath; errs.Add(e); continue; } yield return(book); } if (errs.Count > 0) { throw new AggregateException(errs.ToArray()); } }
/// <summary>Register service method with a service binder with or without implementation. Useful when customizing the service binding logic. /// Note: this method is part of an experimental API that can change or be removed without any prior notice.</summary> /// <param name="serviceBinder">Service methods will be bound by calling <c>AddMethod</c> on this object.</param> /// <param name="serviceImpl">An object implementing the server-side handling logic.</param> public static void BindService(grpc::ServiceBinderBase serviceBinder, BookBase serviceImpl) { serviceBinder.AddMethod(__Method_GetBooksById, serviceImpl == null ? null : new grpc::UnaryServerMethod<global::SzolgProg_vizsga.BookLookupModel, global::SzolgProg_vizsga.BookModel>(serviceImpl.GetBooksById)); serviceBinder.AddMethod(__Method_GetBooksByTitle, serviceImpl == null ? null : new grpc::ServerStreamingServerMethod<global::SzolgProg_vizsga.BookSearchModel, global::SzolgProg_vizsga.BookModel>(serviceImpl.GetBooksByTitle)); serviceBinder.AddMethod(__Method_DeleteBook, serviceImpl == null ? null : new grpc::UnaryServerMethod<global::SzolgProg_vizsga.BookLookupModel, global::SzolgProg_vizsga.AnswerModel>(serviceImpl.DeleteBook)); serviceBinder.AddMethod(__Method_EditBook, serviceImpl == null ? null : new grpc::UnaryServerMethod<global::SzolgProg_vizsga.BookModel, global::SzolgProg_vizsga.AnswerModel>(serviceImpl.EditBook)); serviceBinder.AddMethod(__Method_NewBook, serviceImpl == null ? null : new grpc::UnaryServerMethod<global::SzolgProg_vizsga.BookModel, global::SzolgProg_vizsga.AnswerModel>(serviceImpl.NewBook)); serviceBinder.AddMethod(__Method_BuyBook, serviceImpl == null ? null : new grpc::UnaryServerMethod<global::SzolgProg_vizsga.BookLookupModel, global::SzolgProg_vizsga.AnswerModel>(serviceImpl.BuyBook)); serviceBinder.AddMethod(__Method_ImportBook, serviceImpl == null ? null : new grpc::UnaryServerMethod<global::SzolgProg_vizsga.BookImportModel, global::SzolgProg_vizsga.AnswerModel>(serviceImpl.ImportBook)); serviceBinder.AddMethod(__Method_Login, serviceImpl == null ? null : new grpc::UnaryServerMethod<global::SzolgProg_vizsga.UserModel, global::SzolgProg_vizsga.AnswerModel>(serviceImpl.Login)); serviceBinder.AddMethod(__Method_Logout, serviceImpl == null ? null : new grpc::UnaryServerMethod<global::SzolgProg_vizsga.UserModel, global::SzolgProg_vizsga.AnswerModel>(serviceImpl.Logout)); }
private void AssertBase(BookBase saved, BookBase read) { Assert.IsNotNull(read); Assert.AreEqual(saved.Type, read.Type); Assert.AreEqual(saved.Time, read.Time); Assert.AreEqual(saved.Sequence, read.Sequence); Assert.AreEqual(saved.ProductType, read.ProductType); if (saved is BookOrder) { Assert.AreEqual(((BookOrder)saved).OrderId, ((BookOrder)read).OrderId); Assert.AreEqual(((BookOrder)saved).Side, ((BookOrder)read).Side); } }
public string FormatFilePath(string template, BookBase book) { string p = Utils.Files.MakeFilesystemSafe(template.DictFormat(book.Props()) + Path.GetExtension(book.FilePath)); string trimmable = RelativeFilepath(p); string o = LibraryRoot; foreach (string part in trimmable.Split(Path.DirectorySeparatorChar)) { o = Path.Combine(o, part.Trim()); } return(Path.GetFullPath(o)); }
/// <summary>Creates service definition that can be registered with a server</summary> /// <param name="serviceImpl">An object implementing the server-side handling logic.</param> public static grpc::ServerServiceDefinition BindService(BookBase serviceImpl) { return grpc::ServerServiceDefinition.CreateBuilder() .AddMethod(__Method_GetBooksById, serviceImpl.GetBooksById) .AddMethod(__Method_GetBooksByTitle, serviceImpl.GetBooksByTitle) .AddMethod(__Method_DeleteBook, serviceImpl.DeleteBook) .AddMethod(__Method_EditBook, serviceImpl.EditBook) .AddMethod(__Method_NewBook, serviceImpl.NewBook) .AddMethod(__Method_BuyBook, serviceImpl.BuyBook) .AddMethod(__Method_ImportBook, serviceImpl.ImportBook) .AddMethod(__Method_Login, serviceImpl.Login) .AddMethod(__Method_Logout, serviceImpl.Logout).Build(); }
public void compare_book_base_instances_by_isbn_are_equal() { BookBase book = (BookBase)CollectableBaseFactory.CreateCollectableBase(CollectableBaseFactory.BookType); book.ISBN = "978-0465002047"; BookBase testbook = new BookBase() { ISBN = book.ISBN }; bool isEqual = book.IsSame(testbook, false); Assert.IsTrue(isEqual); }
private void btnAdd_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { var uow = (gridView.GetRow(0) as BookBase).Session as UnitOfWork; var obj = new BookBase(uow); using (var dlg = new BaseBookEditForm(obj)) { if (dlg.ShowDialog() == DialogResult.OK) { dlg.Save(); uow.CommitChanges(); LoadData(); } } }
private void NotifyEvent(BookBase result, string json) { if (result != null && _eventsCallback != null) { try { _eventsCallback(result).Wait(); } catch (Exception ex) { Api.Log.Error(ex, $"Error sending message {json}, {ex.Message}"); } } }
public override object Import(string zipFilePath, UnitOfWork uow) { if (File.Exists(zipFilePath)) { var fileName = ExtractAndGetFirstArchiveItemFilePath(zipFilePath); try { using (var conn = new SqliteConnection($"DataSource=\"{fileName}\"")) { SQLitePCL.Batteries.Init(); conn.Open(); var command = conn.CreateCommand(); command.CommandText = @"SELECT book_number, short_name, long_name, book_color FROM books_all"; using (var reader = command.ExecuteReader()) { while (reader.Read()) { var number = reader.GetInt32(0); var shortcut = reader.GetString(1); var name = reader.GetString(2); var title = reader.GetString(3); var color = reader.GetString(4); var status = GetBookStatus(uow, GetPart(number), GetCanon(number)); var q = new XPQuery <BookBase>(uow).Where(x => x.NumberOfBook == number).FirstOrDefault(); if (q.IsNull()) { var book = new BookBase(uow) { NumberOfBook = number, BookName = name, BookShortcut = shortcut, BookTitle = title, Color = color, Status = status }; book.Save(); uow.CommitChanges(); uow.ReloadChangedObjects(); } } } conn.Close(); } } finally { try { File.Delete(fileName); } catch { } } } return(default);
public void compare_book_base_instances_by_title_and_author_are_not_equal_author() { BookBase book = (BookBase)CollectableBaseFactory.CreateCollectableBase(CollectableBaseFactory.BookType); book.Title = "Pebble in the Sky"; book.Author = "Asimov, Isaac"; BookBase testbook = new BookBase() { DisplayName = book.Title, Author = "Lee, Stan" }; bool isEqual = book.IsSame(testbook, true); Assert.IsFalse(isEqual); }
public async Task <ActionResult <Book> > UpdateAsync(string id, BookBase model, [FromQuery] string reason = null) { var result = await _books.UpdateAsync(id, model, new SnapshotArgs { Committer = User, Event = SnapshotEvent.AfterModification, Reason = reason, Source = SnapshotSource.User }); if (!result.TryPickT0(out var book, out _)) { return(ResultUtilities.NotFound(id)); } return(book.Convert(_services)); }
public async Task <DbBook> CreateAsync(BookBase book, BookContentBase content, int pages) { var client = Services.GetService <IElasticClient>(); var entry = client.Entry(new DbBook { Contents = new[] { new DbBookContent { PageCount = pages }.ApplyBase(content, Services) } }.ApplyBase(book, Services)); return(await entry.CreateAsync()); }
public void CopyFrom(BookBase b) { this.FilePath = b.FilePath; this.Title = b.Title; this.Language = b.Language; this.ISBN = b.ISBN; this.Author = b.Author; this.Contributor = b.Contributor; this.Publisher = b.Publisher; this.Subject = b.Subject; this.Description = b.Description; this.PubDate = b.PubDate; this.Rights = b.Rights; this.Id = b.Id; this.Series = b.Series; this.SeriesNum = b.SeriesNum; this.DateAdded = b.DateAdded; }
/// <summary> /// Updates BOOKS entry with matching Id /// Raises exception if filename not in colletion /// </summary> public void UpdateBook(BookBase update) { var col = db.GetCollection <BookEntry>("BOOKS"); BookEntry dbEntry = col.FindOne(x => x.Id == update.Id); if (dbEntry == null) { throw new IDNotFoundException($"{update.FilePath} not found in library"); } BookEntry tableRow = BOOKS.First(x => x.Id == update.Id); dbEntry = new BookEntry(update); tableRow.CopyFrom(update); col.Update(dbEntry); RefreshBook(tableRow); }
private BookBase GetTestBookBase(int i) { BookBase collectable = new BookBase() { Author = $"Author{i}", BookCode = $"ABC{i}", Month = (i + 1) % 12, Description = $"description{i}", DisplayName = $"display{i}", Edition = $"edition{i}", ISBN = $"123-4442111-{i}", Publisher = $"publisher{i}", Series = null, Title = $"title{i}", Year = 2000 + i }; return(collectable); }
public bool Update(BookBase book) { // Ignore oldest sequences if (book.Sequence <= Sequence) { return(true); } var result = book.Sequence == Sequence + 1; if (!result) { Api.Log.Warning($"Missing book sequence, expected {Sequence + 1} but receive {book.Sequence}"); } Sequence = book.Sequence; switch (book.Type) { case BookType.Received: ReceiveOrder(book as BookReceive); break; case BookType.Open: OpenOrder(book as BookOpen); break; case BookType.Done: RemoveOrder(book as BookDone); break; case BookType.Match: // TODO : Update order remaining size ??? break; case BookType.Change: UpdateOrder(book as BookChange); break; } return(result); }