public void TestImport1() { const int numRecords = 100; var file1 = CreateMockBackup(numRecords); var notes = CreateMockBibleNotes().ToArray(); var mockImportOptions = new ImportBibleNotesParams(); const int mepsLanguageId = 0; var importer = new NotesImporter( file1.Database, "nwtsty", mepsLanguageId, mockImportOptions); var result = importer.Import(notes); file1.Database.CheckValidity(); Assert.AreEqual(notes.Length, result.BibleNotesAdded); Assert.IsTrue(result.BibleNotesUnchanged == 0); Assert.IsTrue(result.BibleNotesUpdated == 0); result = importer.Import(notes); Assert.AreEqual(notes.Length, result.BibleNotesUnchanged); Assert.IsTrue(result.BibleNotesAdded == 0); Assert.IsTrue(result.BibleNotesUpdated == 0); }
/// <inheritdoc /> public BackupFile ImportBibleNotes( BackupFile originalBackupFile, IEnumerable <BibleNote> notes, string bibleKeySymbol, int mepsLanguageId, ImportBibleNotesParams options) { if (originalBackupFile == null) { throw new ArgumentNullException(nameof(originalBackupFile)); } if (notes == null) { throw new ArgumentNullException(nameof(notes)); } ProgressMessage("Importing Bible notes"); var newManifest = UpdateManifest(originalBackupFile.Manifest); var notesImporter = new NotesImporter( originalBackupFile.Database, bibleKeySymbol, mepsLanguageId, options); notesImporter.Import(notes); return(new BackupFile { Manifest = newManifest, Database = originalBackupFile.Database }); }
public NotesImporter( Database targetDatabase, string bibleKeySymbol, int mepsLanguageId, ImportBibleNotesParams options) { _targetDatabase = targetDatabase; _bibleKeySymbol = bibleKeySymbol; _mepsLanguageId = mepsLanguageId; _options = options; _maxNoteId = !_targetDatabase.Notes.Any() ? 0 : _targetDatabase.Notes.Max(x => x.NoteId); _maxTagMapId = !_targetDatabase.TagMaps.Any() ? 0 : _targetDatabase.TagMaps.Max(x => x.TagMapId); _maxLocationId = !_targetDatabase.Locations.Any() ? 0 : _targetDatabase.Locations.Max(x => x.LocationId); _maxUserMarkId = !_targetDatabase.UserMarks.Any() ? 0 : _targetDatabase.UserMarks.Max(x => x.UserMarkId); _maxBlockRangeId = !_targetDatabase.BlockRanges.Any() ? 0 : _targetDatabase.BlockRanges.Max(x => x.BlockRangeId); }
public static async Task ExecuteAsync( BackupFile backupFile, IBackupFileService backupFileService, string backupFilePath, string importFilePath, ImportBibleNotesParams options) { await Task.Run(() => { var file = new BibleNotesFile(importFilePath); backupFileService.ImportBibleNotes( backupFile, file.GetNotes(), file.GetBibleKeySymbol(), file.GetMepsLanguageId(), options); backupFileService.WriteNewDatabase(backupFile, backupFilePath, backupFilePath); }); }
public NotesImporter( Database targetDatabase, string bibleKeySymbol, int mepsLanguageId, ImportBibleNotesParams options) { _targetDatabase = targetDatabase; _bibleKeySymbol = bibleKeySymbol; _mepsLanguageId = mepsLanguageId; _options = options; _maxNoteId = !_targetDatabase.Notes.Any() ? 0 : _targetDatabase.Notes.Max(x => x.NoteId); _maxTagMapId = !_targetDatabase.TagMaps.Any() ? 0 : _targetDatabase.TagMaps.Max(x => x.TagMapId); _maxLocationId = !_targetDatabase.Locations.Any() ? 0 : _targetDatabase.Locations.Max(x => x.LocationId); _maxUserMarkId = !_targetDatabase.UserMarks.Any() ? 0 : _targetDatabase.UserMarks.Max(x => x.UserMarkId); _maxBlockRangeId = !_targetDatabase.BlockRanges.Any() ? 0 : _targetDatabase.BlockRanges.Max(x => x.BlockRangeId); if (_options.TagId > 0) { var tagEntries = _targetDatabase.TagMaps.Where(x => x.TagId == _options.TagId).ToArray(); if (tagEntries.Any()) { _tagMapPositionToUse = tagEntries.Max(x => x.Position) + 1; } } }