SmartDeviceProject1.SqlCeStorageHandler.SaveDownloadedChanges C# (CSharp) Method

SaveDownloadedChanges() public method

Save changes retrieved from the sync service. This method is called to save changes from a download response.
public SaveDownloadedChanges ( byte serverBlob, IEnumerable entities ) : void
serverBlob byte New blob received from the service.
entities IEnumerable List of entities received from the service.
return void
        public void SaveDownloadedChanges(byte[] serverBlob, IEnumerable<SqlCeOfflineEntity> entities)
        {
            using (GetSqlCeConnection())
            {
                SqlCeTransaction transaction = _connection.BeginTransaction();

                try
                {
                    foreach (var entity in entities)
                    {
                        if (entity.ServiceMetadata.IsTombstone)
                        {
                            // Call delete command
                            var deleteMethod = _deleteCommands[entity.GetType()];
                            deleteMethod(entity);
                        }
                        else
                        {
                            // Call insert/update command
                            var getMethod = _getCommands[entity.GetType()];

                            if (getMethod(entity))
                            {
                                var updateMethod = _updateCommands[entity.GetType()];
                                updateMethod(entity);
                            }
                            else
                            {
                                var insertMethod = _insertCommands[entity.GetType()];
                                insertMethod(entity);
                            }
                        }
                    }

                    SaveAnchor(serverBlob);

                    transaction.Commit();
                }
                catch
                {
                    transaction.Rollback();
                    throw;
                }

            }
        }