Ejemplo n.º 1
0
        private async Task OpenSession()
        {
            ReportProgressAndCheckCacellation(new SyncProgress
            {
                Stage           = SyncStage.Connecting,
                PercentComplete = 0,
                Message         = "Opening Session"
            });

            var request = new JObject();
            var types   = new JArray();

            foreach (var type in _store.GetItemTypes())
            {
                types.Add(type);
            }
            request.Add("itemTypes", types);

            var response = await _transport.TransportAsync(SyncEndpoint.BeginSession, request);

            _remoteSessionId = (string)response["sessionID"];

            ReportProgressAndCheckCacellation(new SyncProgress
            {
                Stage           = SyncStage.Connecting,
                PercentComplete = 100,
                Message         = "Session Established"
            });
        }
Ejemplo n.º 2
0
        private static void UpdateItems(IDbConnection connection, ISyncableStore store)
        {
            // loop through types and apply updates or inserts
            foreach (var itemType in store.GetItemTypes())
            {
                System.Diagnostics.Debug.WriteLine("Updating itemType = " + itemType);

                IDbCommand getUpdatedItemsCommand = connection.CreateCommand();
                getUpdatedItemsCommand.CommandText =
                    String.Format(
                        "SELECT SyncStatus, GlobalCreatedReplica, CreatedTickCount, GlobalModifiedReplica, ModifiedTickCount, ItemData  FROM SyncItems WHERE SyncStatus IN ({0},{1}) AND ItemType=@ItemType",
                        (int)SyncStatus.Insert, (int)SyncStatus.Update);
                getUpdatedItemsCommand.AddParameter("@ItemType", itemType);

                using (var reader = getUpdatedItemsCommand.ExecuteReader())
                {
                    while (reader != null && reader.Read())
                    {
                        var createdReplicaInfo  = SessionDbHelper.ReplicaInfoFromDataReader(reader, "Created");
                        var modifiedReplicaInfo = SessionDbHelper.ReplicaInfoFromDataReader(reader, "Modified");
                        var itemData            = JObject.Parse((string)reader["ItemData"]);
                        var itemInfo            = new SyncableItemInfo
                        {
                            ItemType = itemType,
                            Created  = createdReplicaInfo,
                            Modified = modifiedReplicaInfo,
                            Deleted  = false
                        };
                        UpdateItem(connection, store, itemInfo, itemData);
                    }
                }
            }
        }
Ejemplo n.º 3
0
        private static void DeleteItems(IDbConnection connection, ISyncableStore store)
        {
            // loop backwards through types and apply deletions
            foreach (var itemType in store.GetItemTypes().Reverse())
            {
                IDbCommand getDeletedItemsCommand = connection.CreateCommand();
                getDeletedItemsCommand.CommandText =
                    String.Format("SELECT * FROM SyncItems WHERE SyncStatus IN ({0},{1}) AND ItemType=@ItemType",
                                  (int)SyncStatus.Delete, (int)SyncStatus.DeleteNonExisting);
                getDeletedItemsCommand.AddParameter("@ItemType", itemType);

                using (var reader = getDeletedItemsCommand.ExecuteReader())
                {
                    while (reader != null && reader.Read())
                    {
                        var createdReplicaInfo  = SessionDbHelper.ReplicaInfoFromDataReader(reader, "Created");
                        var modifiedReplicaInfo = SessionDbHelper.ReplicaInfoFromDataReader(reader, "Modified");
                        var itemInfo            = new SyncableItemInfo
                        {
                            ItemType = itemType,
                            Created  = createdReplicaInfo,
                            Modified = modifiedReplicaInfo,
                            Deleted  = true
                        };
                        store.DeleteItem(itemInfo);
                    }
                }
            }
        }
Ejemplo n.º 4
0
        public JObject BeginSession(JObject request)
        {
            var remoteItemTypes = request["itemTypes"].Select(itemType => (string)itemType).ToList();

            if (!remoteItemTypes.SequenceEqual(_store.GetItemTypes()))
            {
                throw new Exception("Mismatched item types");
            }

            SessionDbHelper.CreateSessionDbTables(_connection);

            var json = new JObject {
                { "maxBatchCount", 50 }, { "maxBatchSize", 1024 * 1024 }, { "useGzip", true }
            };

            return(json);
        }