Esempio n. 1
0
        private void ShowNoteCollections()
        {
            try
            {
                List <Page> pageList = new List <Page>();

                List <Note> noteList = BooksOnDeviceAccessor.GetNotes(book.ID);
                if (noteList != null)
                {
                    pageList = new List <Page>();

                    foreach (Note note in noteList)
                    {
                        Page page = BooksOnDeviceAccessor.GetPage(note.BookID, note.PageID);
                        pageList.Add(page);
                    }
                }

                ShowCollectionView(new NSString("NoteCell"), pageList);
            }
            catch (Exception ex)
            {
                Logger.WriteLineDebugging("PageViewController - ShowNoteCollections: {0}", ex.ToString());
            }
        }
Esempio n. 2
0
        public NoteDataSource(Book book, UICollectionView collectionView, String cellID)
        {
            this.cellID         = new NSString(cellID);
            this.bookID         = book.ID;
            this.collectionView = collectionView;

            // dictionary
            dictionary = new Dictionary <Chapter, List <Note> > ();

            List <Page> pageList = BooksOnDeviceAccessor.GetPages(bookID);

            if (pageList != null)
            {
                foreach (var page in pageList)
                {
                    List <Note> notesOnPage = BooksOnDeviceAccessor.GetNotes(bookID, page.ID);
                    if (notesOnPage != null && notesOnPage.Count > 0)
                    {
                        // chapter
                        Chapter chapter = BooksOnDeviceAccessor.GetChapter(bookID, page.ChapterID);
                        if (chapter != null)
                        {
                            if (!dictionary.ContainsKey(chapter))
                            {
                                dictionary.Add(chapter, new List <Note> ());
                            }
                        }
                    }
                }
            }
        }
Esempio n. 3
0
        public bool Generate()
        {
            try
            {
                dict1 = new Dictionary <Page, eBriefingMobile.Annotation>();
                dict2 = new Dictionary <Page, List <eBriefingMobile.Note> >();

                foreach (var page in pageList)
                {
                    // Add annotations to dictionary if necessary
                    if (Annotation == ANNOTATION.WITH)
                    {
                        Annotation ann = BooksOnDeviceAccessor.GetAnnotation(bookID, page.ID);
                        dict1.Add(page, ann);
                    }

                    // Add notes to dictionary if necessary
                    if (Note == NOTE.WITH)
                    {
                        List <Note> noteList = new List <eBriefingMobile.Note>();
                        Note        note     = null;
                        if (String.IsNullOrEmpty(URL.MultipleNoteURL))
                        {
                            note = BooksOnDeviceAccessor.GetNote(bookID, page.ID);
                            if (note != null)
                            {
                                noteList.Add(note);
                                dict2.Add(page, noteList);
                            }
                        }
                        else
                        {
                            noteList = BooksOnDeviceAccessor.GetNotes(bookID, page.ID);
                            if (noteList != null && noteList.Count > 0)
                            {
                                dict2.Add(page, noteList);
                            }
                        }
                    }
                }

                return(GenerateImage(dict1, dict2));
            }
            catch (Exception ex)
            {
                Logger.WriteLineDebugging("PrintHelper - Generate: {0}", ex.ToString());
                return(false);
            }
        }
Esempio n. 4
0
        void HandleExpandEvent(Chapter chapter, NSIndexPath indexPath)
        {
            try
            {
                List <Page> pageList = BooksOnDeviceAccessor.GetPages(bookID, chapter.ID);
                if (pageList != null)
                {
                    foreach (var page in pageList)
                    {
                        List <Note> notesOnPage = BooksOnDeviceAccessor.GetNotes(bookID, page.ID);
                        if (notesOnPage != null && notesOnPage.Count > 0)
                        {
                            // Sort by latest
                            notesOnPage.Sort((x, y) => x.ModifiedUtc.CompareTo(y.ModifiedUtc));

                            // headerNote
                            Note headerNote = new Note();
                            headerNote.Text   = "Header: " + page.ID;
                            headerNote.PageID = page.ID;
                            notesOnPage.Insert(0, headerNote);

                            // footerNote
                            Note footerNote = new Note();
                            footerNote.Text   = "Footer: " + page.ID;
                            footerNote.PageID = page.ID;
                            notesOnPage.Add(footerNote);

                            if (dictionary.ContainsKey(chapter))
                            {
                                List <Note> noteList = dictionary [chapter];
                                noteList.AddRange(notesOnPage);
                                dictionary [chapter] = noteList;
                            }
                        }
                    }

                    // Remove last separator
                    dictionary [chapter].RemoveAt(dictionary [chapter].Count - 1);
                }

                collectionView.ReloadSections(NSIndexSet.FromIndex(indexPath.Section));
            }
            catch (Exception ex)
            {
                Logger.WriteLineDebugging("NoteDataSource - HandleExpandEvent: {0}", ex.ToString());
            }
        }
        private void RetrieveData()
        {
            chapterList  = BooksOnDeviceAccessor.GetChapters(book.ID);
            bookmarkList = BooksOnDeviceAccessor.GetBookmarks(book.ID);
            noteList     = BooksOnDeviceAccessor.GetNotes(book.ID);
            annList      = BooksOnDeviceAccessor.GetAnnotations(book.ID);

            // Update chapter number for backward compatibililty
            if (chapterList != null && chapterList.Count > 0)
            {
                for (int i = 0; i < chapterList.Count; i++)
                {
                    chapterList[i].ChapterNumber = i + 1;
                }

                BooksOnDeviceAccessor.UpdateChapters(book.ID, chapterList);
            }
        }
Esempio n. 6
0
        public void LoadNoteViews()
        {
            List <Note> noteList = BooksOnDeviceAccessor.GetNotes(book.ID, pageID);

            // Remove everything first
            Reinitialize(noteList);

            // Then, start adding noteViews
            if (noteList != null && noteList.Count > 0)
            {
                // Sort by most recent
                noteList.Sort((x, y) => y.ModifiedUtc.CompareTo(x.ModifiedUtc));

                // Add noteView
                foreach (var note in noteList)
                {
                    AddNoteView(note);
                }
            }
        }
Esempio n. 7
0
        static void HandleGetMyNotesEvent(String bookID, List <Note> sNotes, bool lastItem)
        {
            try
            {
                List <Note> dNotes = BooksOnDeviceAccessor.GetNotes(bookID);
                if (dNotes != null && dNotes.Count > 0)
                {
                    foreach (Note dNote in dNotes)
                    {
                        if (sNotes != null && sNotes.Count > 0)
                        {
                            foreach (Note sNote in sNotes)
                            {
                                if (dNote.PageID == sNote.PageID)
                                {
                                    if (dNote.ModifiedUtc < sNote.ModifiedUtc)
                                    {
                                        if (sNote.Removed)
                                        {
                                            // Remove note if note on the cloud has 'Removed' checked
                                            BooksOnDeviceAccessor.RemoveNote(dNote.BookID, dNote.PageID);
                                        }
                                        else
                                        {
                                            // Update note if note on the cloud has the latest ModifiedUtc
                                            dNote.BookVersion = sNote.BookVersion;
                                            dNote.Text        = sNote.Text;
                                            dNote.ModifiedUtc = sNote.ModifiedUtc;

                                            BooksOnDeviceAccessor.UpdateNote(dNote);
                                        }
                                    }
                                    break;
                                }
                            }
                        }
                    }
                }

                // Add note if the note is not on the device
                if (sNotes != null && sNotes.Count > 0)
                {
                    foreach (Note sNote in sNotes)
                    {
                        if (!sNote.Removed)
                        {
                            if (BooksOnDeviceAccessor.GetNote(sNote.BookID, sNote.PageID) == null)
                            {
                                BooksOnDeviceAccessor.AddNote(sNote);
                            }
                        }
                    }
                }

                // Check if syncing is done
                if (cancelled)
                {
                    SetReceive(true);

                    CheckReceiveDone();
                }
                else
                {
                    if (lastItem)
                    {
                        SaveMyStuff.GetMyNotesEvent -= HandleGetMyNotesEvent;
                        receiveNotes = true;

                        CheckReceiveDone();
                    }
                }
            }
            catch (Exception ex)
            {
                SetReceive(true);

                CheckReceiveDone();

                Logger.WriteLineDebugging("CloudSync - HandleGetMyNotesEvent: {0}", ex.ToString());
            }
        }
Esempio n. 8
0
        private static void UpdateDatabase(Book book)
        {
            try
            {
                List <Chapter> chapterList = BooksOnServerAccessor.GetChapters(book.ID);
                List <Page>    pageList    = BooksOnServerAccessor.GetPages(book.ID);

                // Update notes
                if (BooksOnDeviceAccessor.GetNotes(book.ID) != null)
                {
                    // Remove orphans
                    BooksOnDeviceAccessor.RemoveOrphanNotes(book.ID, pageList);
                }

                // Update bookmarks
                if (BooksOnDeviceAccessor.GetBookmarks(book.ID) != null)
                {
                    // Remove orphans
                    BooksOnDeviceAccessor.RemoveOrphanBookmarks(book.ID, pageList);
                }

                // Update new chapters
                if (BooksOnDeviceAccessor.GetChapters(book.ID) == null)
                {
                    BooksOnDeviceAccessor.AddChapters(book.ID, chapterList);
                }
                else
                {
                    BooksOnDeviceAccessor.UpdateChapters(book.ID, chapterList);
                }

                BooksOnDeviceAccessor.MapPagesToChapter(chapterList, pageList); // ML: 4/9/2013 We need to map them after each update

                // Update new pages
                if (BooksOnDeviceAccessor.GetPages(book.ID) == null)
                {
                    BooksOnDeviceAccessor.AddPages(book.ID, pageList);
                }
                else
                {
                    BooksOnDeviceAccessor.UpdatePages(book.ID, pageList);
                }

                // Remove chapters and pages list from BooksOnServer because they now exist on the device
                BooksOnServerAccessor.RemoveChapters(book.ID);
                BooksOnServerAccessor.RemovePages(book.ID);

                // Update new book
                book.New           = true;
                book.Status        = Book.BookStatus.DOWNLOADED;
                book.UserAddedDate = DateTime.UtcNow;

                if (BooksOnDeviceAccessor.GetBook(book.ID) == null)
                {
                    BooksOnDeviceAccessor.AddBook(book);
                }
                else
                {
                    if (BooksDataAccessor.IsFavorite(book.ID))
                    {
                        book.IsFavorite = true;
                    }
                    BooksOnDeviceAccessor.UpdateBook(book);
                }
            }
            catch (Exception ex)
            {
                Logger.WriteLineDebugging("BookUpdater - UpdateDatabase: {0}", ex.ToString());
            }
        }