private long TrySyncDown(SyncState.MergeModeOptions mergeMode)
        {
            // Ids clause
            String idsClause = "('" + String.Join("', '", _idToNames.Keys) + "')";

            // Create sync
            SyncDownTarget target =
                new SoqlSyncDownTarget("SELECT Id, Name, " + Constants.LastModifiedDate + " FROM Account WHERE Id IN " +
                                       idsClause);
            SyncOptions options = SyncOptions.OptionsForSyncDown(mergeMode);
            SyncState   sync    = SyncState.CreateSyncDown(_smartStore, target, AccountsSoup, options);
            long        syncId  = sync.Id;

            CheckStatus(sync, SyncState.SyncTypes.SyncDown, syncId, SyncState.SyncStatusTypes.New, 0, -1);
            // Run sync
            _syncCheck = 0;
            _syncManager.RunSync(sync, HandleSyncDownCheck);
            DateTime end = DateTime.Now.AddSeconds(60);

            while (_syncCheck < 3)
            {
                if (DateTime.Now > end)
                {
                    Assert.Fail("Sync timed out");
                }
            }
            return(syncId);
        }
 public void SyncDownContacts()
 {
     RegisterSoup();
     if (syncId == -1)
     {
         string soqlQuery =
             SOQLBuilder.GetInstanceWithFields(ContactObject.ContactFields)
             .From(Constants.Contact)
             .Limit(Limit)
             .Build();
         SyncOptions    options = SyncOptions.OptionsForSyncDown(SyncState.MergeModeOptions.LeaveIfChanged);
         SyncDownTarget target  = new SoqlSyncDownTarget(soqlQuery);
         try
         {
             SyncState sync = _syncManager.SyncDown(target, ContactSoup, HandleSyncUpdate);
             syncId = sync.Id;
         }
         catch (SmartStoreException)
         {
             // log here
         }
     }
     else
     {
         _syncManager.ReSync(syncId, HandleSyncUpdate);
     }
 }
Пример #3
0
        public virtual async Task <SyncState> SyncDownRecords(Action <string> callbackHandler, CancellationToken token = default(CancellationToken))
        {
            if (string.IsNullOrEmpty(SoqlQuery))
            {
                return(new SyncState {
                    Status = SyncState.SyncStatusTypes.Done
                });
            }

            CallBackHandler = callbackHandler;

            RegisterClearSoup();

            var options = SyncOptions.OptionsForSyncDown(SyncState.MergeModeOptions.Overwrite);
            var target  = new SoqlSyncDownTarget(SoqlQuery);

            if (target.Query == null) //there are no data to sync down, so we return success
            {
                return(new SyncState {
                    Status = SyncState.SyncStatusTypes.Done
                });
            }


            SyncState syncResult = new SyncState {
                Status = SyncState.SyncStatusTypes.Failed
            };

            try
            {
                var syncManager = SyncManager.GetInstance(AccountManager.GetAccount());
                syncResult = await syncManager.SyncDown(target, SoupName, HandleSyncUpdate, options, token);
            }
            catch (SmartStoreException sse)
            {
                CreateLogItem("SmartStoreException", sse);
            }
            catch (OperationCanceledException oce)
            {
                CreateLogItem("OperationCanceledException", oce);
                throw;
            }
            catch (ErrorResponseException errorRes)
            {
                CreateLogItem("ErrorResponseException", errorRes);
                throw;
            }
            catch (Exception e)
            {
                CreateLogItem("General exception", e);
            }

            return(syncResult);
        }
Пример #4
0
        public virtual async Task <SyncState> SyncDownRecordsToSoup(Action <string> callbackHandler, CancellationToken token = default(CancellationToken))
        {
            if (string.IsNullOrEmpty(SoqlQuery))
            {
                return(new SyncState {
                    Status = SyncState.SyncStatusTypes.Done
                });
            }

            CallBackHandler = callbackHandler;

            if (!string.IsNullOrWhiteSpace(TempSoupName) && !Store.HasSoup(TempSoupName))
            {
                RegisterClearSoupBySoupName(TempSoupName);
            }

            if (!Store.HasSoup(SoupName))
            {
                RegisterClearSoup();
            }

            var options = SyncOptions.OptionsForSyncDown(SyncState.MergeModeOptions.Overwrite);
            var target  = new SoqlSyncDownTarget(SoqlQuery);


            SyncState syncResult = new SyncState {
                Status = SyncState.SyncStatusTypes.Failed
            };

            try
            {
                var syncManager = SyncManager.GetInstance(AccountManager.GetAccount());
                if (!string.IsNullOrWhiteSpace(TempSoupName))
                {
                    syncResult = await syncManager.SyncDown(target, TempSoupName, HandleSyncUpdate, options, token);
                }
                else
                {
                    syncResult = await syncManager.SyncDown(target, SoupName, HandleSyncUpdate, options, token);
                }
            }
            catch (SmartStoreException sse)
            {
                CreateLogItem("SmartStoreException", sse);
            }
            catch (Exception e)
            {
                CreateLogItem("General exception", e);
            }

            return(syncResult);
        }
        public void SyncDownNotes()
        {
            RegisterSoup();
            string soqlQuery =
                SOQLBuilder.GetInstanceWithFields(NoteObject.NoteFields)
                .From(NoteObject.NoteSObjectType)
                .Limit(Limit)
                .Build();
            SyncOptions    options = SyncOptions.OptionsForSyncDown(SyncState.MergeModeOptions.LeaveIfChanged);
            SyncDownTarget target  = new SoqlSyncDownTarget(soqlQuery);

            try
            {
                SyncState sync = _syncManager.SyncDown(target, NotesSoup, HandleSyncUpdate, options);
                syncId = sync.Id;
            }
            catch (SmartStoreException)
            {
                // log here
            }
        }