Exemplo n.º 1
0
 private void SetupProviders(SyncClass[] localModified, SyncClass[] remoteModified, int[] localDeletedIds, int[] remoteDeletedIds)
 {
     _remoteProvider.GetModifiedEntries(Arg.Any <DateTime?>()).Returns(remoteModified ?? new SyncClass[0]);
     _localProvider.GetModifiedEntries(Arg.Any <DateTime?>()).Returns(localModified ?? new SyncClass[0]);
     _remoteProvider.GetDeletedEntries(Arg.Any <DateTime?>()).Returns(remoteDeletedIds ?? new int[0]);
     _localProvider.GetDeletedEntries(Arg.Any <DateTime?>()).Returns(localDeletedIds ?? new int[0]);
 }
        private SynchronisationResults TwoWaySync()
        {
            List <TType> saveLocal;
            List <TType> saveRemote;
            var          remoteDeleted = _remoteProvider.GetDeletedEntries(_settings.LastSync).ToList();
            var          localDeleted  = _localProvider.GetDeletedEntries(_settings.LastSync).ToList();

            var results = PopulateItemsToSave(
                _remoteProvider.GetModifiedEntries(_settings.LastSync),
                _localProvider.GetModifiedEntries(_settings.LastSync),
                out saveLocal, out saveRemote);

            try
            {
                _remoteProvider.SaveEntries(saveRemote);
                _localProvider.SaveEntries(saveLocal);
                _localProvider.DeleteEntries(remoteDeleted);
                _remoteProvider.DeleteEntries(localDeleted);
            }
            catch (Exception ex)
            {
                results.Success = false;
                results.Message = ex.Message;
                return(results);
            }

            results.NumberDeletedRemote = localDeleted.Count;
            results.NumberDeletedLocal  = remoteDeleted.Count;
            results.NumberUpdatedLocal  = saveLocal.Count;
            results.NumberUpdatedRemote = saveRemote.Count;

            _settings.LastSync = DateTime.Now;
            _settings.Save();
            results.Success = true;
            return(results);
        }