Пример #1
0
        private void postProgress()
        {
            Console.WriteLine("Progress report");
            double progressPercentage = ((double)curPage / (double)totPage) * 100;

            Console.WriteLine(progressPercentage);

            Booker bkr = new Booker();

            bkr.postProgress(progressPercentage, this.current_book_id);
        }
Пример #2
0
        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                // reset every variable
                currentLine = 0;
                curPage     = 0;
                totPage     = 0;


                OpenFileDialog openEbook = new OpenFileDialog();
                openEbook.Filter      = "Ebook Files (.epub)| *.epub";
                openEbook.FilterIndex = 1;
                openEbook.Multiselect = false;

                if (openEbook.ShowDialog() == DialogResult.OK)
                {
                    // MessageBox.Show(openEbook.FileName);
                    Epub myEbook = new Epub(openEbook.FileName);

                    string title  = myEbook.Title[0];
                    string author = myEbook.Creator[0];

                    bookInfoLabel.Text = title + " - " + author;

                    String bookContent = myEbook.GetContentAsPlainText();

                    // each line in a each array elements
                    bookContentArray = bookContent.Split('\n');

                    progressBar1.Visible     = true;
                    progressBarLabel.Visible = true;

                    string pageSaveLocation = System.IO.Path.ChangeExtension(openEbook.FileName, "page");

                    if (System.IO.File.Exists(pageSaveLocation))
                    {
                        this.pageSave = Newtonsoft.Json.JsonConvert.DeserializeObject <List <BookPage> >(System.IO.File.ReadAllText(pageSaveLocation));
                        this.totPage  = pageSave.Count;
                    }
                    else
                    {
                        countThePage();
                        String pageSaveJson = Newtonsoft.Json.JsonConvert.SerializeObject(pageSave);
                        System.IO.File.WriteAllText(pageSaveLocation, pageSaveJson);
                    }



                    progressBar1.Visible     = false;
                    progressBarLabel.Visible = false;

                    totalPage.Text = totPage.ToString();
                    label2.Text    = "/";

                    curPage = 0;



                    // check if the book info is saved or not
                    // get joson file name
                    string bookInfoFile = System.IO.Path.ChangeExtension(openEbook.FileName, "booker");

                    // if file exits
                    Booker bkr = new Booker();
                    if (System.IO.File.Exists(bookInfoFile))
                    {
                        // read file info
                        var book = JsonParser.Deserialize(System.IO.File.ReadAllText(bookInfoFile));

                        this.current_book_id = book.book._id;

                        bookInfoLabel.Text = book.book.title + " : " + book.book.author_name;
                    }
                    else
                    {
                        bkr.searchBook(title, openEbook.FileName, author);

                        var book = JsonParser.Deserialize(System.IO.File.ReadAllText(bookInfoFile));
                        this.current_book_id = book.book._id;
                        bookInfoLabel.Text   = book.book.title + " : " + book.book.author_name;
                    }

                    double progressPercentage = bkr.getProgress(current_book_id);



                    // if not not saved then save it
                    // default show page 1 contents
                    if (progressPercentage == 0)
                    {
                        showPageContent(1);
                    }
                    else
                    {
                        Console.WriteLine(progressPercentage);
                        int pageToShow = (int)(((progressPercentage * totPage) / 100) + .5);
                        showPageContent(pageToShow);
                    }

                    // save pagesave as json
                }
            } catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }