예제 #1
0
 private static void Add(Note note)
 {
     BooksOnDeviceAccessor.AddNote(note);
 }
예제 #2
0
        private static void PullNotesWork(Book book)
        {
            List <Note> sNotes = null;

            if (String.IsNullOrEmpty(URL.MultipleNoteURL))
            {
                sNotes = SaveMyStuff.GetMyNotes(book.ID);
            }
            else
            {
                sNotes = SaveMyStuff.GetMyNotes(book.ID, book.LastSyncedDate);
            }

            if (sNotes != null && sNotes.Count > 0)
            {
                foreach (var sNote in sNotes)
                {
                    Note dNote = null;
                    if (String.IsNullOrEmpty(URL.MultipleNoteURL))
                    {
                        dNote = BooksOnDeviceAccessor.GetNote(book.ID, sNote.PageID);
                    }
                    else
                    {
                        dNote = BooksOnDeviceAccessor.GetNote(book.ID, sNote.NoteID);
                    }

                    if (dNote == null)
                    {
                        // This is a new note from the server
                        BooksOnDeviceAccessor.AddNote(sNote);
                    }
                    else
                    {
                        if (dNote.ModifiedUtc <= sNote.ModifiedUtc)
                        {
                            if (sNote.Removed)
                            {
                                // Remove note if the note on the cloud has 'Removed' checked
                                if (String.IsNullOrEmpty(URL.MultipleNoteURL))
                                {
                                    BooksOnDeviceAccessor.RemoveNote(dNote.BookID, dNote.PageID);
                                }
                                else
                                {
                                    BooksOnDeviceAccessor.RemoveNote(dNote.BookID, dNote.NoteID);
                                }
                            }
                            else
                            {
                                BooksOnDeviceAccessor.UpdateNote(sNote);
                            }
                        }
                    }
                }
            }

            // Update the last time synced for this book
            book.LastSyncedDate = DateTime.UtcNow;
            BooksOnDeviceAccessor.UpdateBook(book);
        }
예제 #3
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());
            }
        }