public BookViewer(Canvas c, MainWindow h, Book b) { designerCanvas = c; host = h; currentbook = b; viewIndex = 0; }
/// <summary> /// Opens a new book /// </summary> /// <param name="filelocation">location of the new book</param> public void OpenBook(string filelocation) { BookReader br = new BookReader(filelocation); Book openedBook = br.ReadBook(); currentbook = openedBook; SetNewViewIndex(0); }
/// <summary> /// Book saver constructor /// </summary> /// <param name="c">Canvas all the controls being saved from are loaded on</param> /// <param name="b">the book being saved</param> public BookSaver(Canvas c, Book b) : base(c) { book = b; }
/// <summary> /// Reads out the offsets and the lengths in the file for the pages in question /// </summary> /// <param name="fileLocation">string of the file location</param> public Book ReadBook() { //adds in a new blank book newBook = new Book(); int Offset = 0 ; //opens the file at the location provided using (FileStream fs = File.Open(fileLoc, FileMode.Open)) { string headerLog = ""; LineReader lr = new LineReader(fs); Page p = new Page(); int index = 0; //reads untill the end of the file while (fs.Position != fs.Length) { //reads in the inital line string buffer = lr.ReadLine(); //adds the buffer and the end line demimiter to the log headerLog += buffer + "\r\n"; bool indexRead = false; //gets the action from the buffer string action = GetParam(buffer); switch (action) { case "bookname": newBook.BookName = GetString(buffer); break; case "created": newBook.Created = GetDate(buffer); break; case "lastmodified": newBook.LastModified = GetDate(buffer); break; case "pagenumber": p.PageNumber = Getint(buffer); break; case "page": //if not the first page add the page to the book if (index != 0) { newBook.Pages.Add(p); } p = new Page(); index++; break; case "offset": p.Offset = Getint(buffer); break; case "length": p.Length = Getint(buffer); break; case "pagetype": //parses the enum value p.PageType = (PageType)Enum.Parse(typeof(PageType), GetString(buffer)); break; case "indexend": //adds the last page to the book newBook.Pages.Add(p); //sets the number of bytes in the header Offset = UnicodeEncoding.Unicode.GetByteCount(headerLog); indexRead = true; break; //probally unreachible code now case "node": indexRead = true; break; default: break; } //if we read the end of the header end the loop if (indexRead) { break; } } } //loop through the number of pages found //assigns a page number // and gets the page contents for (int i = 0; i < newBook.Pages.Count; i++) { newBook.Pages[i].PageNumber = i; newBook.Pages[i].Children.AddRange(ReadPage(fileLoc, newBook.Pages[i].Length, newBook.Pages[i].Offset+Offset)); } return newBook; }
/// <summary> /// After the actual form has initilized run this event, mainly here for debuging purposes as the main form /// constructor wont show exceptions in visual studio /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Window_Initialized_1(object sender, EventArgs e) { //initilizes the book viewer for a new book and sets up the page navigation Book b = new Book(); b.SetAsStarterBook(); current = new BookViewer(DesignerCanvas, this, b); lblTotalPages.Content = "/ " + current.CurrentBook.Pages.Count.ToString(); tbxPageIndex.Text = (current.ViewIndex + 1).ToString(); }