Esempio n. 1
0
 void CheckOrUpdateCatalog()
 {
     var progress = Log.Action(2, "Checking and/or updating catalog...");
     var books = new BookSource { Log = Log };
     var volumes = new VolumeSource { Log = Log };
     if (!string.IsNullOrEmpty(ActualDirectory)) {
         books.SetDirectory(ActualDirectory);
         volumes.SetDirectory(ActualDirectory);
     }
     var updater = new CatalogUpdater { Log = Log };
     Date localDate = Date.MinValue;
     if (Always || updater.ShouldUpdate(books, volumes, out localDate)) {
         progress.Continue("Downloading remote catalog...");
         var catalog = new Catalog { Log = Log };
         if (!string.IsNullOrEmpty(URL))
             catalog.SetUrl(URL);
         using (var stream = catalog.Open())
             updater.TryUpdate(stream, books, volumes,
                 remoteDate => localDate == Date.MinValue || localDate < remoteDate,
                 () => ShouldProcess("Catalog", "Update") && (Force ||
                 ShouldContinue("Do you really want to update the local catalog?",
                                "Catalog Update")));
     }
     progress.Finish();
 }
Esempio n. 2
0
 public bool ShouldUpdate(BookSource books, VolumeSource volumes, out Date date)
 {
     var progress = Log.Action(3, "Checking local catalog...");
     progress.Continue("Opening local catalog...");
     if (books.Exists && volumes.Exists) {
         progress.Continue("Getting local creation date...");
         date = Date.Min(books.GetCreated(), volumes.GetCreated());
         Log.Verbose("Local creation date: {0}.", date);
         if (new Date(DateTime.Now) == date) {
             Log.Warning("Local catalog up-to-date.");
             progress.Finish();
             return false;
         }
     } else {
         date = Date.MinValue;
     }
     progress.Finish();
     return true;
 }
Esempio n. 3
0
 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;
     }
 }