コード例 #1
0
        private async Task CommitEditsInternal(DbConnection connection, Func <Task> successHandler, Func <Exception, Task> errorHandler)
        {
            try
            {
                // @TODO: Add support for transactional commits

                // Trust the RowEdit to sort itself appropriately
                var editOperations = EditCache.Values.ToList();
                editOperations.Sort();
                foreach (var editOperation in editOperations)
                {
                    // Get the command from the edit operation and execute it
                    using (DbCommand editCommand = editOperation.GetCommand(connection))
                        using (DbDataReader reader = await editCommand.ExecuteReaderAsync())
                        {
                            // Apply the changes of the command to the result set
                            await editOperation.ApplyChanges(reader);
                        }

                    // If we succeeded in applying the changes, then remove this from the cache
                    // @TODO: Prevent edit sessions from being modified while a commit is in progress
                    RowEditBase re;
                    EditCache.TryRemove(editOperation.RowId, out re);
                }
                await successHandler();
            }
            catch (Exception e)
            {
                await errorHandler(e);
            }
        }
コード例 #2
0
        /// <summary>
        /// Removes a pending row update from the update cache.
        /// </summary>
        /// <exception cref="ArgumentOutOfRangeException">
        /// If a pending row update with the given row ID does not exist.
        /// </exception>
        /// <param name="rowId">The internal ID of the row to reset</param>
        public void RevertRow(long rowId)
        {
            ThrowIfNotInitialized();

            // Attempt to remove the row with the given ID
            RowEditBase removedEdit;

            if (!EditCache.TryRemove(rowId, out removedEdit))
            {
                throw new ArgumentOutOfRangeException(nameof(rowId), SR.EditDataUpdateNotPending);
            }
        }
コード例 #3
0
        /// <summary>
        /// Removes the edit from the edit cache if the row is no longer dirty
        /// </summary>
        /// <param name="rowId">ID of the update to cleanup</param>
        /// <param name="editCellResult">Result with row dirty flag</param>
        private void CleanupEditIfRowClean(long rowId, EditCellResult editCellResult)
        {
            // If the row is still dirty, don't do anything
            if (editCellResult.IsRowDirty)
            {
                return;
            }

            // Make an attempt to remove the clean row edit. If this fails, it'll be handled on commit attempt.
            RowEditBase removedRow;

            EditCache.TryRemove(rowId, out removedRow);
        }