public void Run(ITaskArgs args_) { var args = (ImportTaskArgs)args_; var id = Settings.Instance.Libraries.FirstOrDefault(lib => args.Library.Equals(lib.Value.Path, StringComparison.InvariantCultureIgnoreCase)).Key; if (id == Guid.Empty) { libId = Guid.NewGuid(); } else { libId = id; } var startedAt = DateTime.UtcNow; args.Plugin.Run(args.Library, args.Args, OnImportBook, OnImportFinished); importer.Open(Settings.Instance.DatabaseIndex); for (var i = 0; i < Environment.ProcessorCount; i++) { Task.Factory.StartNew(ImportWorker); } while (EntriesProcessed < EntriesTotal || !finished) { Thread.Sleep(100); } running = false; EntriesDeleted = importer.CleanupLibrary(libId.ToString(), startedAt); Settings.Instance.Libraries[libId] = new SettingsLibrary { Path = args.Library }; Settings.Save(); Finished = true; }
public void Update(Book book) { if (book.UpdatedFromFile) { return; } logger.Debug("Book being updated, id:{0}", book.Id); var parser = PluginProvider.Instance.GetFileFormatReader(book.Ext); if (parser == null) { return; } bool replace = false; try { using (var stream = FileUtils.GetBookFile(book)) { replace = parser.Read(book, stream); } logger.Debug("Book updated successfully, id:{0}", book.Id); } catch (Exception e) { logger.Debug("Book update failed, id:{0}. {1}", book.Id, e.Message); } if (importer == null) { importer = new LuceneIndexStorage(); importer.Open(Settings.Instance.DatabaseIndex); } if (replace) { book.UpdatedFromFile = true; importer.Replace(book); } }