コード例 #1
0
        /// <summary>
        /// Delete a match
        /// </summary>
        /// <returns>True for sucess</returns>
        public override ErrorCode Delete(Records.Match record)
        {
            if (record.RowId == null || DataModel.Match.MatchKey.Find(record.RowId) == null)
            {
                return(ErrorCode.RecordNotFound);
            }

            DataModel            dataModel            = new DataModel();
            MatchRow             matchRow             = DataModel.Match.MatchKey.Find(record.RowId);
            DataModelTransaction dataModelTransaction = DataModelTransaction.Current;

            matchRow.AcquireReaderLock(dataModelTransaction);
            if (!TradingSupport.HasAccess(dataModelTransaction, matchRow.BlotterId, AccessRight.FullControl))
            {
                return(ErrorCode.AccessDenied);
            }
            MatchRow contraMatchRow = DataModel.Match.MatchKey.Find(matchRow.ContraMatchId);

            matchRow.ReleaseReaderLock(dataModelTransaction.TransactionId);

            dataModel.DestroyMatch(
                new object[] { record.RowId },
                record.RowVersion);
            matchRow.ReleaseWriterLock(dataModelTransaction.TransactionId);

            // Delete the contra second, in case the record.RowVersion is off.
            if (contraMatchRow != null)
            {
                contraMatchRow.AcquireWriterLock(dataModelTransaction);
                dataModel.DestroyMatch(
                    new object[] { contraMatchRow.MatchId },
                    contraMatchRow.RowVersion);
                contraMatchRow.ReleaseWriterLock(dataModelTransaction.TransactionId);
            }

            return(ErrorCode.Success);
        }