Пример #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);
        }
Пример #2
0
        private IEnumerable <SyncConflict> LoadConflicts(IDbConnection connection)
        {
            var        conflicts = new List <SyncConflict>();
            IDbCommand getInsertedItemsCommand = connection.CreateCommand();

            getInsertedItemsCommand.CommandText =
                String.Format(
                    "SELECT ItemID, SyncStatus, ItemType, GlobalCreatedReplica, CreatedTickCount, GlobalModifiedReplica, ModifiedTickCount, ItemData  FROM SyncItems WHERE SyncStatus NOT IN ({0},{1},{2},{3},{4},{5})",
                    (int)SyncStatus.Insert,
                    (int)SyncStatus.Update,
                    (int)SyncStatus.Delete,
                    (int)SyncStatus.DeleteNonExisting,
                    (int)SyncStatus.MayBeNeeded,
                    (int)SyncStatus.InsertConflict
                    );
            using (var reader = getInsertedItemsCommand.ExecuteReader())
            {
                while (reader != null && reader.Read())
                {
                    var createdReplicaInfo  = SessionDbHelper.ReplicaInfoFromDataReader(reader, "Created");
                    var modifiedReplicaInfo = SessionDbHelper.ReplicaInfoFromDataReader(reader, "Modified");
                    var itemType            = (string)reader["ItemType"];
                    var remoteItemInfo      = new SyncableItemInfo
                    {
                        ItemType = itemType,
                        Created  = createdReplicaInfo,
                        Modified = modifiedReplicaInfo,
                        Deleted  = false
                    };
                    var itemId = Convert.ToInt64(reader["ItemID"]);
                    var status = (SyncStatus)reader["SyncStatus"];

                    ISyncableItemInfo localItemInfo = _store.LocateCurrentItemInfo(remoteItemInfo);

                    if (status == SyncStatus.UpdateConflict)
                    {
                        // Check to see if the "conflict" is actually an exact same update
                        var builder = SyncUtil.JsonItemFromSyncableItemInfo(localItemInfo);
                        _store.BuildItemData(localItemInfo, builder);

                        var localItemData = new JObject {
                            { "item", builder }
                        };

                        var remoteItemData = JObject.Parse((string)reader["ItemData"]);
                        var dupStatus      = _store.GetDuplicateStatus(remoteItemInfo.ItemType, localItemData,
                                                                       remoteItemData);
                        if (dupStatus == DuplicateStatus.Exact)
                        {
                            var tickCount       = _store.IncrementLocalRepilcaTickCount();
                            var modifiedReplica = new ReplicaInfo
                            {
                                ReplicaId        = _store.GetLocalReplicaId(),
                                ReplicaTickCount = tickCount
                            };
                            SessionDbHelper.ResolveItemNoData(connection, remoteItemInfo, SyncStatus.Update,
                                                              modifiedReplica);
                            // TODO: Really should have an update status that just updates the modified repos without doing everything else, but this should work
                            continue;
                        }
                    }

                    conflicts.Add(new SyncConflict(itemId, status, localItemInfo, remoteItemInfo));
                }
            }

            return(conflicts);
        }