Package com.evernote.edam.notestore

Examples of com.evernote.edam.notestore.SyncChunk


        }
    }

    private LinkedList<SyncChunk> getSyncChunks(final NoteStoreClient noteStore, final int lastUpdateCount, final boolean fullSync) throws EDAMUserException, EDAMSystemException, TException {
        LinkedList<SyncChunk> chunks = new LinkedList<SyncChunk>();
        SyncChunk chunk = noteStore.getSyncChunk(lastUpdateCount, MAX_ENTRIES, fullSync);
        if (chunk!=null) {
            chunks.add(chunk);
            while (chunk.getChunkHighUSN()<chunk.getUpdateCount()) {
                chunk = noteStore.getSyncChunk(chunk.getChunkHighUSN(), MAX_ENTRIES, fullSync);
                if (chunk!=null)
                    chunks.add(chunk);
            }
        }
        return chunks;
View Full Code Here


    for (int i=0; i<dirtyNotes.size() && keepRunning; i++) {
      dirtyNoteGuids.add(dirtyNotes.get(i).getGuid());
    }
   
    int chunkSize = 10;
    SyncChunk chunk = null;
    boolean fullSync = false;
    boolean more = true;
   
    if (updateSequenceNumber == 0)
      fullSync = true;
   
    status.message.emit(tr("Downloading 0% complete."));
   
    while(more &&  keepRunning) {
     
//      if (authRefreshNeeded)
//        if (!refreshConnection())
//          return;
     
      int sequence = updateSequenceNumber;
      try {
//        conn.beginTransaction();
        logger.log(logger.EXTREME, "Getting chunk from Evernote");
        chunk = noteStore.getSyncChunk(authToken, sequence, chunkSize, fullSync);
        logger.log(logger.LOW, "Chunk High Sequence: " +chunk.getChunkHighUSN());
      } catch (EDAMUserException e) {
        error = true;
        e.printStackTrace();
        status.message.emit(e.getMessage());
      } catch (EDAMSystemException e) {
        error = true;
        e.printStackTrace();
        status.message.emit(e.getMessage());
      } catch (TException e) {
        error = true;
        e.printStackTrace();
        status.message.emit(e.getMessage());
      }
      if (error || chunk == null)
        return;
       
   
     
      syncRemoteTags(chunk.getTags());
      syncRemoteSavedSearches(chunk.getSearches());
      syncRemoteNotebooks(chunk.getNotebooks());
      syncRemoteNotes(noteStore, chunk.getNotes(), fullSync, authToken);
      syncRemoteResources(noteStore, chunk.getResources());
      syncRemoteLinkedNotebooks(chunk.getLinkedNotebooks());
     
      // Signal about any updated notes to invalidate the cache
      for (int i=0; i<chunk.getNotesSize(); i++)
        noteSignal.noteChanged.emit(chunk.getNotes().get(i).getGuid(), null);
      syncExpungedNotes(chunk);
     
     
      // Check for more notes
      if (chunk.getChunkHighUSN() <= updateSequenceNumber)
        more = false;
      if (error)
        more = false;
      logger.log(logger.EXTREME, "More notes? " +more);

     
      // Save the chunk sequence number
      if (!error && chunk.getChunkHighUSN() > 0 && keepRunning) {
        logger.log(logger.EXTREME, "emitting sequence number to main thread");
        updateSequenceNumber = chunk.getChunkHighUSN();
        conn.getSyncTable().setLastSequenceDate(chunk.getCurrentTime());
        conn.getSyncTable().setUpdateSequenceNumber(updateSequenceNumber);
//        conn.commitTransaction();
      }
     
     
      if (more) {
        long pct = chunk.getChunkHighUSN() * 100;
        conn.getSyncTable().setLastSequenceDate(chunk.getCurrentTime());
        pct = pct/evernoteUpdateCount;
        status.message.emit(tr("Downloading ") +new Long(pct).toString()+tr("% complete."));
      }
//      conn.commitTransaction();
    }
View Full Code Here

      fullSync = true;
    boolean syncError = false;
    while (usn < highSequence && !syncError) {
      refreshNeeded = true;
      try {
        SyncChunk chunk =
          linkedNoteStore.getLinkedNotebookSyncChunk(token, book, usn, 10, fullSync);
       
        // Expunge notes
        syncExpungedNotes(chunk);

        logger.log(logger.EXTREME, "Syncing remote notes: " +chunk.getNotesSize());
        syncRemoteNotes(linkedNoteStore, chunk.getNotes(), fullSync, linkedAuthResult.getAuthenticationToken());
        logger.log(logger.EXTREME, "Finding new linked tags");
        findNewLinkedTags(linkedNoteStore, chunk.getNotes(), linkedAuthResult.getAuthenticationToken());
        // Sync resources
        logger.log(logger.EXTREME, "Synchronizing tags: " +chunk.getTagsSize());
        for (int i=0; i<chunk.getResourcesSize(); i++) {
          syncRemoteResource(linkedNoteStore, chunk.getResources().get(i), linkedAuthResult.getAuthenticationToken());
        }
        logger.log(logger.EXTREME, "Synchronizing linked notebooks: " +chunk.getNotebooksSize());
        syncRemoteLinkedNotebooks(linkedNoteStore, chunk.getNotebooks(), false, book);
        syncLinkedTags(chunk.getTags(), book.getGuid());
       
        // Go through & signal any notes that have changed so we can refresh the user's view
        for (int i=0; i<chunk.getNotesSize(); i++)
          noteSignal.noteChanged.emit(chunk.getNotes().get(i).getGuid(), null);

        // Expunge Notebook records
        logger.log(logger.EXTREME, "Expunging linked notebooks: " +chunk.getExpungedLinkedNotebooksSize());
        for (int i=0; i<chunk.getExpungedLinkedNotebooksSize(); i++) {
          conn.getLinkedNotebookTable().expungeNotebook(chunk.getExpungedLinkedNotebooks().get(i), false);
        }
        usn = chunk.getChunkHighUSN();
        conn.getLinkedNotebookTable().setLastSequenceDate(book.getGuid(),chunk.getCurrentTime());
        conn.getLinkedNotebookTable().setLastSequenceNumber(book.getGuid(),chunk.getChunkHighUSN());
      } catch (EDAMUserException e) {
        syncError = true;
        status.message.emit(tr("EDAM UserException synchronizing linked notbook.  See the log for datails."));
        e.printStackTrace();
        logger.log(logger.LOW, tr("EDAM UserException synchronizing linked notbook ")+ e.getMessage());
View Full Code Here

TOP

Related Classes of com.evernote.edam.notestore.SyncChunk

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.