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();
}