Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / whidbey / netfxsp / ndp / fx / src / Data / System / Data / DataViewListener.cs / 5 / DataViewListener.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //[....] //[....] //----------------------------------------------------------------------------- namespace System.Data { using System; using System.ComponentModel; using System.Collections.Generic; using System.Diagnostics; internal sealed class DataViewListener { private readonly WeakReference _dvWeak; private DataTable _table; private Index _index; ///internal readonly int ObjectID; internal DataViewListener(DataView dv) { this.ObjectID = dv.ObjectID; _dvWeak = new WeakReference(dv); } private void ChildRelationCollectionChanged(object sender, CollectionChangeEventArgs e) { DataView dv = (DataView)_dvWeak.Target; if (dv != null) { dv.ChildRelationCollectionChanged(sender, e); } else { CleanUp(true); } } private void ParentRelationCollectionChanged(object sender, CollectionChangeEventArgs e) { DataView dv = (DataView)_dvWeak.Target; if (dv != null) { dv.ParentRelationCollectionChanged(sender, e); } else { CleanUp(true); } } private void ColumnCollectionChanged(object sender, CollectionChangeEventArgs e) { DataView dv = (DataView)_dvWeak.Target; if (dv != null) { dv.ColumnCollectionChangedInternal(sender, e); } else { CleanUp(true); } } /// /// Maintain the DataView before internal void MaintainDataView(ListChangedType changedType, DataRow row, bool trackAddRemove) { DataView dv = (DataView)_dvWeak.Target; if (dv != null) { dv.MaintainDataView(changedType, row, trackAddRemove); } else { CleanUp(true); } } internal void IndexListChanged(ListChangedEventArgs e) { DataView dv = (DataView)_dvWeak.Target; if (dv != null) { dv.IndexListChangedInternal(e); } else { CleanUp(true); } } internal void RegisterMetaDataEvents(DataTable table) { Debug.Assert(null == _table, "DataViewListener already registered table"); _table = table; if (table != null) { // actively remove listeners without a target RegisterListener(table); // start listening to events CollectionChangeEventHandler handlerCollection = new CollectionChangeEventHandler(ColumnCollectionChanged); table.Columns.ColumnPropertyChanged += handlerCollection; table.Columns.CollectionChanged += handlerCollection; CollectionChangeEventHandler handlerChildRelation = new CollectionChangeEventHandler(ChildRelationCollectionChanged); ((DataRelationCollection.DataTableRelationCollection)(table.ChildRelations)).RelationPropertyChanged += handlerChildRelation; table.ChildRelations.CollectionChanged += handlerChildRelation; CollectionChangeEventHandler handlerParentRelation = new CollectionChangeEventHandler(ParentRelationCollectionChanged); ((DataRelationCollection.DataTableRelationCollection)(table.ParentRelations)).RelationPropertyChanged += handlerParentRelation; table.ParentRelations.CollectionChanged += handlerParentRelation; } } internal void UnregisterMetaDataEvents() { UnregisterMetaDataEvents(true); } private void UnregisterMetaDataEvents(bool updateListeners) { DataTable table = _table; _table = null; if (table != null) { CollectionChangeEventHandler handlerCollection = new CollectionChangeEventHandler(ColumnCollectionChanged); table.Columns.ColumnPropertyChanged -= handlerCollection; table.Columns.CollectionChanged -= handlerCollection; CollectionChangeEventHandler handlerChildRelation = new CollectionChangeEventHandler(ChildRelationCollectionChanged); ((DataRelationCollection.DataTableRelationCollection)(table.ChildRelations)).RelationPropertyChanged -= handlerChildRelation; table.ChildRelations.CollectionChanged -= handlerChildRelation; CollectionChangeEventHandler handlerParentRelation = new CollectionChangeEventHandler(ParentRelationCollectionChanged); ((DataRelationCollection.DataTableRelationCollection)(table.ParentRelations)).RelationPropertyChanged -= handlerParentRelation; table.ParentRelations.CollectionChanged -= handlerParentRelation; if (updateListeners) { Listis raised. /// listeners = table.GetListeners(); lock (listeners) { listeners.Remove(this); } } } } internal void RegisterListChangedEvent(Index index) { Debug.Assert(null == _index, "DataviewListener already registered index"); _index = index; if (null != index) { lock (index) { index.AddRef(); index.ListChangedAdd(this); } } } internal void UnregisterListChangedEvent() { Index index = _index; _index = null; if (index != null) { lock (index) { index.ListChangedRemove(this); if (index.RemoveRef() <= 1) { index.RemoveRef(); } } } } private void CleanUp(bool updateListeners) { UnregisterMetaDataEvents(updateListeners); UnregisterListChangedEvent(); } private void RegisterListener(DataTable table) { List listeners = table.GetListeners(); lock (listeners) { for (int i = listeners.Count - 1; 0 <= i; --i) { DataViewListener listener = listeners[i]; if (!listener._dvWeak.IsAlive) { listeners.RemoveAt(i); listener.CleanUp(false); } } listeners.Add(this); } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------------------ // // Copyright (c) Microsoft Corporation. All rights reserved. // //[....] //[....] //----------------------------------------------------------------------------- namespace System.Data { using System; using System.ComponentModel; using System.Collections.Generic; using System.Diagnostics; internal sealed class DataViewListener { private readonly WeakReference _dvWeak; private DataTable _table; private Index _index; ///internal readonly int ObjectID; internal DataViewListener(DataView dv) { this.ObjectID = dv.ObjectID; _dvWeak = new WeakReference(dv); } private void ChildRelationCollectionChanged(object sender, CollectionChangeEventArgs e) { DataView dv = (DataView)_dvWeak.Target; if (dv != null) { dv.ChildRelationCollectionChanged(sender, e); } else { CleanUp(true); } } private void ParentRelationCollectionChanged(object sender, CollectionChangeEventArgs e) { DataView dv = (DataView)_dvWeak.Target; if (dv != null) { dv.ParentRelationCollectionChanged(sender, e); } else { CleanUp(true); } } private void ColumnCollectionChanged(object sender, CollectionChangeEventArgs e) { DataView dv = (DataView)_dvWeak.Target; if (dv != null) { dv.ColumnCollectionChangedInternal(sender, e); } else { CleanUp(true); } } /// /// Maintain the DataView before internal void MaintainDataView(ListChangedType changedType, DataRow row, bool trackAddRemove) { DataView dv = (DataView)_dvWeak.Target; if (dv != null) { dv.MaintainDataView(changedType, row, trackAddRemove); } else { CleanUp(true); } } internal void IndexListChanged(ListChangedEventArgs e) { DataView dv = (DataView)_dvWeak.Target; if (dv != null) { dv.IndexListChangedInternal(e); } else { CleanUp(true); } } internal void RegisterMetaDataEvents(DataTable table) { Debug.Assert(null == _table, "DataViewListener already registered table"); _table = table; if (table != null) { // actively remove listeners without a target RegisterListener(table); // start listening to events CollectionChangeEventHandler handlerCollection = new CollectionChangeEventHandler(ColumnCollectionChanged); table.Columns.ColumnPropertyChanged += handlerCollection; table.Columns.CollectionChanged += handlerCollection; CollectionChangeEventHandler handlerChildRelation = new CollectionChangeEventHandler(ChildRelationCollectionChanged); ((DataRelationCollection.DataTableRelationCollection)(table.ChildRelations)).RelationPropertyChanged += handlerChildRelation; table.ChildRelations.CollectionChanged += handlerChildRelation; CollectionChangeEventHandler handlerParentRelation = new CollectionChangeEventHandler(ParentRelationCollectionChanged); ((DataRelationCollection.DataTableRelationCollection)(table.ParentRelations)).RelationPropertyChanged += handlerParentRelation; table.ParentRelations.CollectionChanged += handlerParentRelation; } } internal void UnregisterMetaDataEvents() { UnregisterMetaDataEvents(true); } private void UnregisterMetaDataEvents(bool updateListeners) { DataTable table = _table; _table = null; if (table != null) { CollectionChangeEventHandler handlerCollection = new CollectionChangeEventHandler(ColumnCollectionChanged); table.Columns.ColumnPropertyChanged -= handlerCollection; table.Columns.CollectionChanged -= handlerCollection; CollectionChangeEventHandler handlerChildRelation = new CollectionChangeEventHandler(ChildRelationCollectionChanged); ((DataRelationCollection.DataTableRelationCollection)(table.ChildRelations)).RelationPropertyChanged -= handlerChildRelation; table.ChildRelations.CollectionChanged -= handlerChildRelation; CollectionChangeEventHandler handlerParentRelation = new CollectionChangeEventHandler(ParentRelationCollectionChanged); ((DataRelationCollection.DataTableRelationCollection)(table.ParentRelations)).RelationPropertyChanged -= handlerParentRelation; table.ParentRelations.CollectionChanged -= handlerParentRelation; if (updateListeners) { Listis raised. /// listeners = table.GetListeners(); lock (listeners) { listeners.Remove(this); } } } } internal void RegisterListChangedEvent(Index index) { Debug.Assert(null == _index, "DataviewListener already registered index"); _index = index; if (null != index) { lock (index) { index.AddRef(); index.ListChangedAdd(this); } } } internal void UnregisterListChangedEvent() { Index index = _index; _index = null; if (index != null) { lock (index) { index.ListChangedRemove(this); if (index.RemoveRef() <= 1) { index.RemoveRef(); } } } } private void CleanUp(bool updateListeners) { UnregisterMetaDataEvents(updateListeners); UnregisterListChangedEvent(); } private void RegisterListener(DataTable table) { List listeners = table.GetListeners(); lock (listeners) { for (int i = listeners.Count - 1; 0 <= i; --i) { DataViewListener listener = listeners[i]; if (!listener._dvWeak.IsAlive) { listeners.RemoveAt(i); listener.CleanUp(false); } } listeners.Add(this); } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- DataConnectionHelper.cs
- CodeTypeReferenceCollection.cs
- MouseActionValueSerializer.cs
- ComplexTypeEmitter.cs
- GridViewAutomationPeer.cs
- OleDbErrorCollection.cs
- PriorityQueue.cs
- PersistChildrenAttribute.cs
- AttachedPropertiesService.cs
- CodeEntryPointMethod.cs
- GetWinFXPath.cs
- TypeLibConverter.cs
- DataGridToolTip.cs
- BasicKeyConstraint.cs
- ItemsPanelTemplate.cs
- _emptywebproxy.cs
- DataContractSerializerFaultFormatter.cs
- XmlNodeComparer.cs
- SmtpSpecifiedPickupDirectoryElement.cs
- ConstNode.cs
- PasswordPropertyTextAttribute.cs
- FillBehavior.cs
- XmlILOptimizerVisitor.cs
- GeometryCollection.cs
- CompilerInfo.cs
- TraceHandlerErrorFormatter.cs
- HtmlButton.cs
- DataColumnChangeEvent.cs
- DataGridTextBox.cs
- Matrix.cs
- BaseCodeDomTreeGenerator.cs
- TranslateTransform3D.cs
- EntityDataSourceConfigureObjectContext.cs
- LookupBindingPropertiesAttribute.cs
- SizeLimitedCache.cs
- ChameleonKey.cs
- TextLine.cs
- AdRotator.cs
- StreamInfo.cs
- GuidelineCollection.cs
- ColorPalette.cs
- TextStore.cs
- ViewLoader.cs
- XmlComment.cs
- BamlStream.cs
- MasterPage.cs
- DispatcherExceptionEventArgs.cs
- StronglyTypedResourceBuilder.cs
- CssClassPropertyAttribute.cs
- ColorAnimationUsingKeyFrames.cs
- MouseOverProperty.cs
- ToolBarOverflowPanel.cs
- LabelAutomationPeer.cs
- NavigationExpr.cs
- CopyAttributesAction.cs
- XmlWriterSettings.cs
- WebPartManagerInternals.cs
- GridViewSortEventArgs.cs
- CodeAttachEventStatement.cs
- HttpWebRequest.cs
- RegexParser.cs
- DispatcherTimer.cs
- FolderLevelBuildProviderCollection.cs
- WorkflowQueuingService.cs
- StatusBarPanel.cs
- GeneratedCodeAttribute.cs
- GlyphTypeface.cs
- CompressionTransform.cs
- TypeCodeDomSerializer.cs
- PinnedBufferMemoryStream.cs
- CommentEmitter.cs
- QilVisitor.cs
- InplaceBitmapMetadataWriter.cs
- WebScriptClientGenerator.cs
- XamlPoint3DCollectionSerializer.cs
- EntityType.cs
- CuspData.cs
- BitmapCodecInfo.cs
- ListParagraph.cs
- ThemeableAttribute.cs
- HelpEvent.cs
- FieldNameLookup.cs
- ServiceNameCollection.cs
- DesignTimeTemplateParser.cs
- PaintEvent.cs
- HwndKeyboardInputProvider.cs
- _NegotiateClient.cs
- DesignColumn.cs
- SerialReceived.cs
- ConnectionStringSettings.cs
- Path.cs
- StorageRoot.cs
- SqlReorderer.cs
- HtmlContainerControl.cs
- DataGridRowHeader.cs
- Document.cs
- StateMachineSubscription.cs
- Psha1DerivedKeyGenerator.cs
- RegexWorker.cs
- WmlLabelAdapter.cs