示例#1
0
        private void LoadButton_Click(object sender, EventArgs e)
        {
            treeView1.Nodes.Clear();
            nodeCatalogTypeXml = null;
            EnableDisable();

            String path = GetCatalogContentStoreLocation();

            if (path == "")
            {
                MessageBox.Show("Catalog path is invalid or does not contain a \"ContentStore\" folder.");
                return;
            }

            // First check for locks (ie. Catalog is in flux being rebuilt)

            ICatalogReadWriteLock RWLock = Globals.catalog.GetReadWriteLock(path);

            if (RWLock.IsCurrentlyNonBlockingWriteLocked || RWLock.IsCurrentlyWriteLocked)
            {
                MessageBox.Show("Catalog is busy. Try again soon.\nCatalog is currently write locked.");
                return;
            }

            // Load Catalog XML -- Locking as we go so others don't try a modify it while we read

            RWLock.StartNonBlockingWriteOperation(10000);   //10 second time out (usually reads all XML under 1 second on my laptop VM)
            Cursor.Current = Cursors.WaitCursor;
            try
            {
                _catalogXml             = new CatalogParser(path);
                _catalogPackageMetaData = _catalogXml.GetPackageMetaData();
                BuildToc();
                EnableDisable();

                if (_catalogXml.InstalledBooks == null)
                {
                    MessageBox.Show("No data found! Note that only VS 11 catalog folders contain HV2 XML data.");
                }
            }
            finally
            {
                Cursor.Current = Cursors.Default;
                RWLock.ExitNonBlockingWriteOperation();
            }
        }
示例#2
0
 public void Convert(CatalogParser parser, XmlReader reader, Date created,
                     Stream bookStream, Stream volumeStream)
 {
     // There are almost 42,000 books and 520,000 files in the project Gutenberg. We set
     // up 59 * 10,000 steps here to have the progress bar stretching quite good and still
     // having a little space to grow for the project content.
     var progress = Log.Action(59, "Converting catalog...");
     int bookCount = 0, skippedCount = 0, volumeCount = 0, totalCount = 0;
     var bookParser = new BookParser { Log = Log };
     var volumeParser = new VolumeParser { Log = Log };
     using (var bookWriter = bookParser.Create(bookStream, created))
     using (var volumeWriter = volumeParser.Create(volumeStream, created)) {
         foreach (var item in parser.GetItems(reader)) {
             var book = item as Book;
             if (book != null) {
                 // Book 9140 and a couple of others are invalid.
                 if (string.IsNullOrEmpty(book.Title)) {
                     Log.Verbose("Skipping book {0} with no title.", book.Number);
                     ++skippedCount;
                 } else {
                     bookParser.Write(bookWriter, book);
                 }
                 ++bookCount;
             } else {
                 volumeParser.Write(volumeWriter, (Volume) item);
                 ++volumeCount;
             }
             // One step after every 10,000 items run nicely on my laptop; less loaded the
             // CPU with constant reporting and more made the console wait for too long.
             if (++totalCount % 10000 == 0)
                 progress.Continue("{0} items processed...", totalCount);
         }
         bookParser.Finalize(bookWriter);
         volumeParser.Finalize(volumeWriter);
     }
     Log.Verbose("{0} books and {1} volumes were processed, {2} books skipped.",
         bookCount, volumeCount, skippedCount);
     progress.Finish();
 }
示例#3
0
 public CatalogPageViewModel(INavigationService navigationService)
 {
     _navigationService = navigationService;
     Tiles   = new ObservableCollection <ICatalogTile>();
     _parser = new CatalogParser <CatalogTile>();
 }
示例#4
0
 public LibraryLoader()
 {
     parser = new CatalogParser();
     writer = new CatalogEntityWriter();
 }
示例#5
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;
     }
 }