System.Data.DataTable.RestoreIndexEvents C# (CSharp) Method

RestoreIndexEvents() private method

private RestoreIndexEvents ( bool forceReset ) : void
forceReset bool
return void
        internal void RestoreIndexEvents(bool forceReset)
        {
            DataCommonEventSource.Log.Trace("<ds.DataTable.RestoreIndexEvents|Info> {0}, {1}", ObjectID, _suspendIndexEvents);
            if (0 < _suspendIndexEvents)
            {
                _suspendIndexEvents--;
                if (0 == _suspendIndexEvents)
                {
                    Exception first = null;
                    SetShadowIndexes();
                    try
                    {
                        // the length of shadowIndexes will not change
                        // but the array instance may change during
                        // events during Index.Reset
                        int numIndexes = _shadowIndexes.Count;
                        for (int i = 0; i < numIndexes; i++)
                        {
                            Index ndx = _shadowIndexes[i];// shadowindexes may change, see ShadowIndexCopy()
                            try
                            {
                                if (forceReset || ndx.HasRemoteAggregate)
                                {
                                    ndx.Reset(); // resets & fires
                                }
                                else
                                {
                                    ndx.FireResetEvent(); // fire the Reset event we were firing
                                }
                            }
                            catch (Exception e) when (ADP.IsCatchableExceptionType(e))
                            {
                                ExceptionBuilder.TraceExceptionWithoutRethrow(e);
                                if (null == first)
                                {
                                    first = e;
                                }
                            }
                        }
                        if (null != first)
                        {
                            throw first;
                        }
                    }
                    finally
                    {
                        RestoreShadowIndexes();
                    }
                }
            }
        }

Usage Example

Example #1
0
        private void MergeTable(DataTable src, DataTable dst)
        {
            int  rowsCount = src.Rows.Count;
            bool wasEmpty  = dst.Rows.Count == 0;

            if (0 < rowsCount)
            {
                Index?  ndxSearch = null;
                DataKey key       = default(DataKey);
                dst.SuspendIndexEvents();
                try
                {
                    if (!wasEmpty && dst._primaryKey != null)
                    {
                        key = GetSrcKey(src, dst);
                        if (key.HasValue)
                        {
                            ndxSearch = dst._primaryKey.Key.GetSortIndex(DataViewRowState.OriginalRows | DataViewRowState.Added);
                        }
                    }

                    // this improves performance by iterating over the rows instead of computing their position
                    foreach (DataRow sourceRow in src.Rows)
                    {
                        DataRow?targetRow = null;
                        if (ndxSearch != null)
                        {
                            targetRow = dst.FindMergeTarget(sourceRow, key, ndxSearch);
                        }
                        dst.MergeRow(sourceRow, targetRow, _preserveChanges, ndxSearch);
                    }
                }
                finally
                {
                    dst.RestoreIndexEvents(true);
                }
            }
            MergeExtendedProperties(src.ExtendedProperties, dst.ExtendedProperties);
        }
All Usage Examples Of System.Data.DataTable::RestoreIndexEvents
DataTable