Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / Orcas / SP / wpf / src / Framework / MS / Internal / Data / XmlDataCollection.cs / 1 / XmlDataCollection.cs
//----------------------------------------------------------------------------
//
//
// Copyright (C) 2003 by Microsoft Corporation. All rights reserved.
//
//
//
// Description: Data collection produced by an XmlDataProvider
//
// Specs: http://avalon/connecteddata/M5%20Specs/IDataCollection.mht
//
//---------------------------------------------------------------------------
using System.Xml;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.Windows.Data;
using System.Windows.Markup;
namespace MS.Internal.Data
{
///
/// Implementation of a data collection based on ArrayList,
/// implementing INotifyCollectionChanged to notify listeners
/// when items get added, removed or the whole list is refreshed.
///
internal class XmlDataCollection : ReadOnlyObservableCollection
{
//-----------------------------------------------------
//
// Constructors
//
//-----------------------------------------------------
///
/// Initializes a new instance of XmlDataCollection that is empty and has the specified initial capacity.
///
/// Parent Xml Data Source
internal XmlDataCollection(XmlDataProvider xmlDataProvider) : base(new ObservableCollection())
{
_xds = xmlDataProvider;
}
//------------------------------------------------------
//
// Internal Properties
//
//-----------------------------------------------------
///
/// XmlNamespaceManager property, XmlNamespaceManager used for executing XPath queries.
///
internal XmlNamespaceManager XmlNamespaceManager
{
get
{
if (_nsMgr == null && _xds != null)
_nsMgr = _xds.XmlNamespaceManager;
return _nsMgr;
}
set { _nsMgr = value; }
}
internal XmlDataProvider ParentXmlDataProvider
{
get { return _xds; }
}
//------------------------------------------------------
//
// Internal Methods
//
//------------------------------------------------------
// return true if the counts are different or the identity of the nodes have changed
internal bool CollectionHasChanged(XmlNodeList nodes)
{
int count = this.Count;
if (count != nodes.Count)
return true;
for (int i = 0; i < count; ++i)
{
if (this[i] != nodes[i])
return true;
}
return false;
}
// Update the collection using new query results
internal void SynchronizeCollection(XmlNodeList nodes)
{
if (nodes == null)
{
Items.Clear();
return;
}
int i = 0, j;
while (i < this.Count && i < nodes.Count)
{
if (this[i] != nodes[i])
{
// starting after current node, see if the old node is still in the new list.
for (j = i + 1; j < nodes.Count; ++j)
{
if (this[i] == nodes[j])
{
break;
}
}
if (j < nodes.Count)
{
// the node from existing collection is found at [j] in the new collection;
// this means the node(s) [i ~ j-1] in new collection should be inserted.
while (i < j)
{
Items.Insert(i, nodes[i]);
++i;
}
++i; // advance to next node
}
else
{
// the node from existing collection is no longer in
// the new collection, delete it.
Items.RemoveAt(i);
// do not advance to the next node
}
}
else
{
// nodes are the same; advance to the next node.
++i;
}
}
// Remove any extra nodes left over in the old collection
while (i < this.Count)
{
Items.RemoveAt(i);
}
// Add any extra new nodes from the new collection
while (i < nodes.Count)
{
Items.Insert(i, nodes[i]);
++i;
}
}
private XmlDataProvider _xds;
private XmlNamespaceManager _nsMgr;
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
//----------------------------------------------------------------------------
//
//
// Copyright (C) 2003 by Microsoft Corporation. All rights reserved.
//
//
//
// Description: Data collection produced by an XmlDataProvider
//
// Specs: http://avalon/connecteddata/M5%20Specs/IDataCollection.mht
//
//---------------------------------------------------------------------------
using System.Xml;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.Windows.Data;
using System.Windows.Markup;
namespace MS.Internal.Data
{
///
/// Implementation of a data collection based on ArrayList,
/// implementing INotifyCollectionChanged to notify listeners
/// when items get added, removed or the whole list is refreshed.
///
internal class XmlDataCollection : ReadOnlyObservableCollection
{
//-----------------------------------------------------
//
// Constructors
//
//-----------------------------------------------------
///
/// Initializes a new instance of XmlDataCollection that is empty and has the specified initial capacity.
///
/// Parent Xml Data Source
internal XmlDataCollection(XmlDataProvider xmlDataProvider) : base(new ObservableCollection())
{
_xds = xmlDataProvider;
}
//------------------------------------------------------
//
// Internal Properties
//
//-----------------------------------------------------
///
/// XmlNamespaceManager property, XmlNamespaceManager used for executing XPath queries.
///
internal XmlNamespaceManager XmlNamespaceManager
{
get
{
if (_nsMgr == null && _xds != null)
_nsMgr = _xds.XmlNamespaceManager;
return _nsMgr;
}
set { _nsMgr = value; }
}
internal XmlDataProvider ParentXmlDataProvider
{
get { return _xds; }
}
//------------------------------------------------------
//
// Internal Methods
//
//------------------------------------------------------
// return true if the counts are different or the identity of the nodes have changed
internal bool CollectionHasChanged(XmlNodeList nodes)
{
int count = this.Count;
if (count != nodes.Count)
return true;
for (int i = 0; i < count; ++i)
{
if (this[i] != nodes[i])
return true;
}
return false;
}
// Update the collection using new query results
internal void SynchronizeCollection(XmlNodeList nodes)
{
if (nodes == null)
{
Items.Clear();
return;
}
int i = 0, j;
while (i < this.Count && i < nodes.Count)
{
if (this[i] != nodes[i])
{
// starting after current node, see if the old node is still in the new list.
for (j = i + 1; j < nodes.Count; ++j)
{
if (this[i] == nodes[j])
{
break;
}
}
if (j < nodes.Count)
{
// the node from existing collection is found at [j] in the new collection;
// this means the node(s) [i ~ j-1] in new collection should be inserted.
while (i < j)
{
Items.Insert(i, nodes[i]);
++i;
}
++i; // advance to next node
}
else
{
// the node from existing collection is no longer in
// the new collection, delete it.
Items.RemoveAt(i);
// do not advance to the next node
}
}
else
{
// nodes are the same; advance to the next node.
++i;
}
}
// Remove any extra nodes left over in the old collection
while (i < this.Count)
{
Items.RemoveAt(i);
}
// Add any extra new nodes from the new collection
while (i < nodes.Count)
{
Items.Insert(i, nodes[i]);
++i;
}
}
private XmlDataProvider _xds;
private XmlNamespaceManager _nsMgr;
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- QuotedPairReader.cs
- ScrollViewerAutomationPeer.cs
- Array.cs
- IPGlobalProperties.cs
- NativeRightsManagementAPIsStructures.cs
- SymDocumentType.cs
- HtmlTernaryTree.cs
- PolicyManager.cs
- ContractBase.cs
- ResolveCriteria.cs
- MenuItemBinding.cs
- SecureEnvironment.cs
- HttpCacheVary.cs
- KnownTypesProvider.cs
- HeaderCollection.cs
- SmiEventSink_Default.cs
- SpecialFolderEnumConverter.cs
- BreakRecordTable.cs
- Fonts.cs
- PropertyChangingEventArgs.cs
- OutputCacheSection.cs
- RepeatButton.cs
- ResourcesBuildProvider.cs
- InputMethodStateChangeEventArgs.cs
- CompilerResults.cs
- FixedSOMPageElement.cs
- XmlChildEnumerator.cs
- CapabilitiesSection.cs
- TranslateTransform.cs
- Converter.cs
- DbParameterCollectionHelper.cs
- diagnosticsswitches.cs
- DataControlFieldHeaderCell.cs
- TableLayoutStyle.cs
- HttpCacheParams.cs
- UriTemplateTable.cs
- SiteMapHierarchicalDataSourceView.cs
- UriTemplateClientFormatter.cs
- Set.cs
- ZipIOEndOfCentralDirectoryBlock.cs
- DataGridCaption.cs
- WebPartCatalogCloseVerb.cs
- MobileControlPersister.cs
- FixedPosition.cs
- SqlVisitor.cs
- dataprotectionpermission.cs
- EditBehavior.cs
- MultiSelector.cs
- CustomTrackingQuery.cs
- SqlBulkCopyColumnMapping.cs
- ConfigurationManagerHelperFactory.cs
- peernodeimplementation.cs
- MenuItem.cs
- WorkflowServiceAttributes.cs
- Timer.cs
- DataControlPagerLinkButton.cs
- SrgsGrammar.cs
- PointConverter.cs
- FocusManager.cs
- PackageDigitalSignatureManager.cs
- EdmComplexPropertyAttribute.cs
- ToolStripMenuItem.cs
- IOThreadTimer.cs
- RelatedCurrencyManager.cs
- VScrollProperties.cs
- NativeCppClassAttribute.cs
- XmlWriterSettings.cs
- QilReplaceVisitor.cs
- HtmlEmptyTagControlBuilder.cs
- OracleNumber.cs
- DataColumn.cs
- OpacityConverter.cs
- SqlBooleanMismatchVisitor.cs
- Typography.cs
- PathFigureCollectionValueSerializer.cs
- SqlParameterizer.cs
- WCFBuildProvider.cs
- ToolStripItemTextRenderEventArgs.cs
- BaseCollection.cs
- wgx_sdk_version.cs
- FloaterParagraph.cs
- BatchWriter.cs
- SoapTransportImporter.cs
- ImageConverter.cs
- SqlAliaser.cs
- rsa.cs
- ConnectionProviderAttribute.cs
- XComponentModel.cs
- SchemaReference.cs
- OleDbParameterCollection.cs
- GrammarBuilder.cs
- RenderData.cs
- MatchingStyle.cs
- SqlNamer.cs
- DataSetUtil.cs
- ContentDisposition.cs
- SoundPlayer.cs
- XmlDownloadManager.cs
- Repeater.cs
- WebPartEditVerb.cs