Resume an interrupted synchronization where partial data has been downloaded to the device.
SMP101DB.ResumePendingSynchronization();
SMP101DB.CancelPendingSynchronization();
... ... ... //turn on the resume synchronization option SMP101DB.GetSynchronizationProfile().ResumeSynchronization = true; MyCallbackHandlerForResumeSync callback = new MyCallbackHandlerForResumeSync(); SMP101DBRegisterCallbackHandler(callback); MyResumeSyncStatusListener listener = new MyResumeSyncStatusListener(); GenericList<ISynchronizationGroup> groups = new GenericList<ISynchronizationGroup>(); groups.Add(SynchronizationGroup.GetInstance("default")); //submit a non-blocking sync request SMP101DB.BeginSynchronize(groups, null, false, listener);
//in the implementation of SUPDefaultCallbackHandler class ... ... ... SynchronizationAction OnSynchronize(GenericList<ISynchronizationGroup> groups, SynchronizationContext context) { switch (context.Status) { ... case SynchronizationStatus.INTERRUPTED_WITH_PARTIAL_DATA: _isInterruptedWithPartialData = true; // By returning continue, the system waits for a request to resume or cancel the pending synchronization and the synchronization queue is locked. // If returning SynchronizationAction.CANCEL instead, the system automatically cancels the pending synchronization. // Application cannot resume the synchronization and the synchronization queue is not locked. return SynchronizationAction.CONTINUE; ... } }
void HandleInterruptedWithPartialData() { if (MAX_INTERRUPTED_STATUS == _interruptedStatusCount) { CancelPendingSync(); Console.WriteLine("Resume sync is canceled."); Console.WriteLine("Interrupted status count reached the max: {0}.", MAX_INTERRUPTED_STATUS); } else { _isInterruptedWithPartialData = true; _interruptedStatusCount++; int waitCount = 0; while(!_isDeviceConnectedToInternet) { System.Threading.Thread.Sleep(1000); waitCount++; if (waitCount > MAX_WAIT) { Console.WriteLine("There is no network connection {0} seconds.", MAX_WAIT); break; } } if (_isDeviceConnectedToInternet) { ResumeSync(); } else { CancelPendingSync(); Console.WriteLine("Resume sync is canceled."); Console.WriteLine("there's no network connectivity for too long."); } } } void CancelPendingSync() { Console.WriteLine("going to cancel pending sync..."); if (SMP101DB.CancelPendingSynchronization()) { Console.WriteLine("failed to cancel pending sync."); } else { Console.WriteLine("pending sync has been cancelled."); } } void ResumeSync() { if (!_isInterruptedWithPartialData) { Console.WriteLine("no resume as there is no interrupted with partiald data."); return; } Console.WriteLine("going to resume sync..."); bool resumed = SMP101DB.ResumePendingSynchronization(); _isInterruptedWithPartialData = false; if (!resumed) { Console.WriteLine("failed to resume pending syn."); } else { _resumeSyncCount++; Console.WriteLine("resume sync count: {0}.", _resumeSyncCount); } }