Exemple #1
0
        public JObject GetItemData(JObject request)
        {
            ISyncableItemInfo requestedItemInfo = SyncUtil.SyncableItemInfoFromJson(request["item"]);

            var json = new JObject();

            JObject builder = SyncUtil.JsonItemFromSyncableItemInfo(requestedItemInfo);

            _store.BuildItemData(requestedItemInfo, builder);
            json.Add(new JProperty("item", builder));

            return(json);
        }
Exemple #2
0
        public JObject GetItemDataBatch(JObject request)
        {
            var startItem     = (int)request["startItem"];
            var maxBatchCount = (int)request["maxBatchCount"];
            var maxBatchSize  = (int)request["maxBatchSize"];

            var batchArray = new JArray();

            var getChangedItemsCommand = _connection.CreateCommand();

            getChangedItemsCommand.CommandText = String.Format("SELECT ItemID, SyncStatus, ItemType, GlobalCreatedReplica, CreatedTickCount, GlobalModifiedReplica, ModifiedTickCount FROM SyncItems WHERE ItemID >= {0} ORDER BY ItemID", startItem);
            using (var reader = getChangedItemsCommand.ExecuteReader())
            {
                var batchSize = 0;
                while (reader != null && reader.Read())
                {
                    ISyncableItemInfo requestedItemInfo = SessionDbHelper.SyncableItemInfoFromDataReader(reader);

                    var     singleItem = new JObject();
                    JObject builder    = SyncUtil.JsonItemFromSyncableItemInfo(requestedItemInfo);
                    if (!requestedItemInfo.Deleted)
                    {
                        _store.BuildItemData(requestedItemInfo, builder);
                    }
                    singleItem.Add(new JProperty("item", builder));

                    batchSize += singleItem.ToString().Length;
                    batchArray.Add(singleItem);

                    if (batchArray.Count >= maxBatchCount || batchSize >= maxBatchSize)
                    {
                        break;
                    }
                }
            }

            var json = new JObject {
                { "batch", batchArray }
            };

            return(json);
        }