private async Task SaveSyncData(IDbConnection connection, ISyncableItemInfo remoteSyncableItemInfo, SyncStatus status) { var data = JObject.Parse("{item:{itemRefs:[]}}"); if (!remoteSyncableItemInfo.Deleted) { var request = new JObject { { "sessionID", _remoteSessionId }, { "item", SyncUtil.SyncableItemInfoToJson(remoteSyncableItemInfo) } }; var response = await _transport.TransportAsync(SyncEndpoint.GetItemData, request); data = response; } SessionDbHelper.SaveItemData(connection, remoteSyncableItemInfo, status, data); var itemRefs = (JArray)data["item"]["itemRefs"]; foreach (var item in itemRefs) { ISyncableItemInfo itemRefInfo = SyncUtil.SyncableItemInfoFromJson(item); ISyncableItemInfo localItemRefInfo = _store.LocateCurrentItemInfo(itemRefInfo); if (localItemRefInfo != null && localItemRefInfo.Deleted) { await SaveSyncData(connection, itemRefInfo, SyncStatus.MayBeNeeded); } } }
private async Task <int> SaveChangesBatch(IDbConnection connection, IList <IReplicaInfo> localKnowledge, int startItem) { var request = new JObject { { "sessionID", _remoteSessionId }, { "startItem", startItem }, { "maxBatchCount", PullMaxBatchCount }, { "maxBatchSize", PullMaxBatchSize } }; JObject response = await _transport.TransportAsync(SyncEndpoint.GetItemDataBatch, request); var batch = (JArray)response["batch"]; foreach (var item in batch) { ISyncableItemInfo remoteSyncableItemInfo = SyncUtil.SyncableItemInfoFromJson(item["item"]); var itemData = new JObject { { "item", item["item"] } }; var status = SyncStatus.MayBeNeeded; if (!SyncUtil.KnowledgeContains(localKnowledge, remoteSyncableItemInfo.Modified)) { ISyncableItemInfo localSyncableItemInfo = _store.LocateCurrentItemInfo(remoteSyncableItemInfo); status = SyncUtil.CalculateSyncStatus(remoteSyncableItemInfo, localSyncableItemInfo, _remoteKnowledge); } SessionDbHelper.SaveItemData(connection, remoteSyncableItemInfo, status, itemData); var itemRefs = (JArray)itemData["item"]["itemRefs"]; foreach (var itemRef in itemRefs) { ISyncableItemInfo itemRefInfo = SyncUtil.SyncableItemInfoFromJson(itemRef); ISyncableItemInfo localItemRefInfo = _store.LocateCurrentItemInfo(itemRefInfo); if (localItemRefInfo != null && localItemRefInfo.Deleted) { await SaveSyncData(connection, itemRefInfo, SyncStatus.MayBeNeeded); } } } return(batch.Count); }