public static void AddEvent(Book book, BookHistoryEventType eventType, string message = "") { if (SIL.PlatformUtilities.Platform.IsLinux) { return; // SQLiteConnection never works on Linux. } try { using (var db = GetConnection(book.FolderPath)) { GetOrMakeBookRecord(book, db); var evt = new BookHistoryEvent() { BookId = book.ID, Message = message, UserId = TeamCollectionManager.CurrentUser, UserName = TeamCollectionManager.CurrentUserFirstName, Type = eventType, // Be sure to use UTC, otherwise, order will not be preserved properly. When = DateTime.UtcNow }; db.Insert(evt); db.Close(); } } catch (Exception e) { NonFatalProblem.Report(ModalIf.None, PassiveIf.All, "Problem writing book history", $"folder={book.FolderPath}", e); // swallow... we don't want to prevent whatever was about to happen. } BloomWebSocketServer.Instance.SendEvent("bookHistory", "eventAdded"); }
public static void AddEvent(Book book, BookHistoryEventType eventType, string message = "") { try { using (var db = GetConnection(book.FolderPath)) { var bookRecord = db.Table <BookHistoryBook>().FirstOrDefault(b => b.Id == book.ID); if (bookRecord == null) { bookRecord = new BookHistoryBook { Id = book.ID, // TODO: update Name every time because it can change? Add an event if we notice that it changed? Name = book.TitleBestForUserDisplay }; db.Insert(bookRecord); } var evt = new BookHistoryEvent() { BookId = book.ID, Message = message, UserId = TeamCollectionManager.CurrentUser, UserName = TeamCollectionManager.CurrentUserFirstName, Type = eventType, When = DateTime.Now }; db.Insert(evt); db.Close(); } } catch (Exception e) { NonFatalProblem.Report(ModalIf.None, PassiveIf.All, "Problem writing book history", $"folder={book.FolderPath}", e); // swallow... we don't want to prevent whatever was about to happen. } }