Ejemplo n.º 1
0
 public DataContextTest()
 {
     // TODO: Should be in the TestIntialize MEthod but that doesn't seem to get called.
     FileSystem = new InMemoryFileSystem();
     Context = new DataContext(FileSystem);
 }
 /// <summary>
 /// This method is called when a book package has been constructed, we then tell
 /// the datacontext to complete loading the book contents (xml, ncx etc.)
 /// </summary>
 /// <param name="package">Book package to load the contents of.</param>
 private void SetCurrentBook(IPackage package)
 {
     DataContext store = new DataContext(base.MainState.BookFileSystem);
     store.BookCreated += store_BookCreated;
     store.GetBookAsync(package);
 }
Ejemplo n.º 3
0
 private void SetUp()
 {
     // Never fires!
     FileSystem = new InMemoryFileSystem();
     Context = new DataContext(FileSystem);
 }
        /// <summary>
        /// Initiates the processing of loading a book (from a zip stream) into the FileSystem, by loading and creating
        /// the book package and passing that off to the datacontext to load the rest of the book.
        /// </summary>
        /// <param name="zipStream">FileStream of the zip file to load the book from.</param>
        private void LoadBook(FileStream zipStream)
        {
            // The DataContext is instatiated with a IFileSystem implementation that will determine
            // where the books are stored to and retrieved from. For example, IsolatedStorage/ServerStorage
            DataContext store = new DataContext(base.MainState.BookFileSystem);

            // Listen to the progress the store DataContext makes
            store.ProgressChanged += store_ProgressChanged;

            IPackageInspector inspector;

            // To ensure the FileStream is property disposed wrap it in
            // a using statement.
            using (FileStream fileStream = zipStream)
            {
                inspector = new PackageInspector();

                // The inspector will pass on any progress updates to this event. We subscribe to
                // it from the View to be able to update the display.
                inspector.ProgressChanged += inspector_ProgressChanged;

                // Process the package - this will perform an initial parse over the zip file
                // to derive some basic information like its version, the bookId and Filecount.
                // This method will raise some ProgressChanged events for us to update the UI.
                inspector.ProcessPackage(fileStream);

                // Check the file was OK.
                if(!inspector.IsValid)
                {
                    // TODO: Could be enhanced to return all the errors.
                    // While there could actally be more than one error in ValidationErrors
                    // we are only going to notify of the first.
                    throw new InvalidPackageException(inspector.ValidationErrors[0]);
                }
                else
                {
                    // Save the book files to the store - don't bother replacing if the
                    // book is already there. Again this will take some time and will raise
                    // ProgressChanged events for us to update the UI with progress.
                    store.LoadZipPackage(inspector, false);
                }
            }

            // Set the CurrentBook on View
            SetCurrentBook(inspector.Package);
        }