Click here to Skip to main content
13,050,358 members (140,336 online)
Click here to Skip to main content

Stats

79.8K views
120 bookmarked
Posted 30 Jun 2009

WPF Book Reader

, 10 May 2012
A WPF book reader for cbz/cbr files
BookReader.exe.manifest
ICSharpCode.SharpZipLib.dll
SevenZipSharp.dll
WPFToolkit.dll
Dependencies
7z.dll
BookReader.application
BookReader.exe
BookReader
ClassDiagram.cd
Dependencies
7-zip.dll
7z.dll
ICSharpCode.SharpZipLib.dll
SevenZipSharp.dll
WPFToolkit.dll
Properties
app.manifest
Reader
Catalog
Common
Images
RAR
ZIP
Resources
TheRedPushPin.png
XAML
BookReader.application
BookReader.exe
BookReader.exe.manifest
7z.dll
SevenZipSharp.dll
WPFToolkit.dll
Release
BookReader.application
BookReader.exe
BookReader.exe.manifest
Dependencies
7z.dll
pdftohtml.exe
SevenZipSharp.dll
WPFToolkit.dll
BookReader.csproj.user
BookReader.csproj.vspscc
7z.dll
pdftohtml.exe
SevenZipSharp.dll
WPFToolkit.dll
app.manifest
acroread.png
document.png
ecran.png
exit.png
FitHeight.png
FitWidth.png
info.png
open_folder.png
refresh.png
Search.png
Theme
TheRedPushPin.png
tools.png
BookReader.csproj.user
ClassDiagram.cd
7-zip.dll
7z.dll
ICSharpCode.SharpZipLib.dll
SevenZipSharp.dll
WPFToolkit.dll
app.manifest
TheRedPushPin.png
BookReader.application
BookReader.exe
BookReader.exe.manifest
BookReader.vshost.exe
7z.dll
pdftohtml.exe
SevenZipSharp.dll
WPFToolkit.dll
BookReader.csproj.user
BookReader.csproj.vspscc
7z.dll
pdftohtml.exe
SevenZipSharp.dll
WPFToolkit.dll
app.manifest
acroread.png
book.ico
document.png
ecran.png
exit.png
FitHeight.png
FitWidth.png
info.png
open_folder.png
refresh.png
Search.png
TheRedPushPin.png
tools.png
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Windows.Media.Imaging;

namespace BookReader
{
	internal class BaseBook : IBook
	{
		#region -----------------constructors-----------------

		public BaseBook()
		{
		}

		public BaseBook(string filePath)
		{
			_filePath = filePath;
			RaisePropetyChanged("FilePath");
			RaisePropetyChanged("FileName");
		}
		#endregion

		#region -----------------properties-----------------
		private ImageCache _Cache = new ImageCache();
		public ImageCache Cache
		{
			get { if (_Cache == null) _Cache = new ImageCache();  return _Cache; }
			set { _Cache = value; }
		}

		private string _filePath = string.Empty;
		public string FilePath
		{
			get { return _filePath; }
			set { _filePath = value; }
		}

		[NonSerialized()]
		private IBookItem _CurrentPage = null;
		public IBookItem CurrentPage
		{
			get { return _CurrentPage; }
			set { _CurrentPage = value; }
		}

		private List<IBookItem> _Pages = new List<IBookItem>();
		public List<IBookItem> Pages
		{
			get { if (_Pages == null) _Pages = new List<IBookItem>(); return _Pages; }
			set { _Pages = value; }
		}
		
		private string _Bookmark = string.Empty;
		public string Bookmark
		{
			get { return _Bookmark; }
			set { _Bookmark = value; RaisePropetyChanged("Bookmark"); }
		}

        private bool _IsRead= false;
        public bool IsRead
        {
            get { return _IsRead; }
            set { _IsRead = value; RaisePropetyChanged("IsRead"); }
        }


		private BitmapImage _Cover = null;
		public BitmapImage Cover
		{
			get { return _Cover; }
			set { _Cover = value; RaisePropetyChanged("Cover"); }
		}

		public string FileName
		{
			get
			{
				return Path.GetFileName(this._filePath);
			}
		}

		private int _NbPages;
		public int NbPages
		{
			get { return _NbPages; }
			set { _NbPages = value; }
		}

		private long _Size;
		public long Size
		{
			get { return _Size; }
			set { _Size = value; }
		}


		#endregion

		#region -----------------loading/unloading-----------------

		virtual public void Load()
		{
			_CurrentPage = Pages[0];
		}

		virtual public void UnLoad()
		{
			Pages.Clear();
			Cache.Clear();
		}
		#endregion

		#region -----------------virtual's-----------------

		virtual public BitmapImage GetCurrentPageImage()
		{
			throw new NotSupportedException();
		}

		#endregion

		#region -----------------bookmark-----------------

		public void SetMark()
		{
			Bookmark = _CurrentPage.FilePath;
		}

		public void GotoMark()
		{
			if (!string.IsNullOrEmpty(_Bookmark))
			{
				foreach (IBookItem pg in Pages)
				{
					if( pg.FilePath == _Bookmark )
						_CurrentPage = pg;
				}
			}
		}
		#endregion

		#region -----------------page navigation management-----------------

		public bool GotoPage( IBookItem page )
		{
			foreach (IBookItem pg in Pages)
			{
				if (pg == page)
				{
					_CurrentPage = pg;
					return true;
				}
			}
			return false;
		}

		public bool GotoNextPage()
		{
			int next = Pages.IndexOf(_CurrentPage);
			if (next >= Pages.Count-1)
				return false;
			else
			{
				next = next + 1;
				_CurrentPage = Pages[next];
				return true;
			}
		}

		public bool GotoPreviousPage()
		{
			int next = Pages.IndexOf(_CurrentPage);
			if (next == 0)
				return false;
			else
			{
				next = next - 1;
				_CurrentPage = Pages[next];
				return true;
			}
		}
		#endregion

		#region -----------------cache management-----------------

		internal IBookItem GetNextPage(IBookItem fromPage )
		{
			int next = Pages.IndexOf(fromPage);
			if (next >= Pages.Count-1)
				return null;
			else
			{
				next = next + 1;
				return Pages[next];
			}
		}

		virtual public void ManageCache()
		{
			Cache.ManageCache();
		}

		#endregion

		#region -----------------INotifyPropertyChanged-----------------

		private void RaisePropetyChanged(string propertyName)
		{
			if (PropertyChanged != null)
			{
				PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
			}
		}

		public event PropertyChangedEventHandler PropertyChanged;

		#endregion
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)

Share

About the Author

Guillaume Waser
Architect XEROX
France France
WPF and MVVM fan, I practice C # in all its forms from the beginning of the NET Framework without mentioning C ++ / MFC and other software packages such as databases, ASP, WCF, Web & Windows services, Application, and now Core and UWP.
In my wasted hours, I am guilty of having fathered C.B.R. and its cousins C.B.R. for WinRT and UWP on the Windows store.
But apart from that, I am a great handyman ... the house, a rocket stove to heat the jacuzzi and the last one: a wood oven for pizza, bread, and everything that goes inside

https://guillaumewaser.wordpress.com/
https://fouretcompagnie.wordpress.com/

You may also be interested in...

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170713.1 | Last Updated 10 May 2012
Article Copyright 2009 by Guillaume Waser
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid