public bool TryUpdate(Stream catalogStream, BookSource books, VolumeSource volumes, Func<Date, bool> update, Func<bool> confirm) { var progress = Log.Action(5, "Trying catalog update..."); progress.Continue("Opening remote catalog..."); var parser = new CatalogParser { Log = Log }; using (var reader = parser.Open(catalogStream)) { progress.Continue("Checking remote creation date..."); var date = parser.GetCreated(reader); Log.Verbose("Remote creation date: {0}.", date); if (update(date)) { progress.Continue("Updating local catalog..."); string bookPath = null, volumePath = null; try { using (var bookStream = books.Create(out bookPath)) using (var volumeStream = volumes.Create(out volumePath)) Convert(parser, reader, date, bookStream, volumeStream); progress.Continue("Copying converted catalog..."); if (confirm()) { books.Update(bookPath); volumes.Update(volumePath); Log.Verbose("Local catalog updated."); progress.Finish(); return true; } } finally { if (bookPath != null) IOUtility.DeleteTempFile(bookPath); if (volumePath != null) IOUtility.DeleteTempFile(volumePath); } Log.Warning("Local catalog left intact."); progress.Finish(); return false; } Log.Warning("Local catalog up-to-date."); progress.Finish(); return false; } }