Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / whidbey / NetFXspW7 / ndp / fx / src / Data / System / Data / Common / DataTableMappingCollection.cs / 1 / DataTableMappingCollection.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //[....] //[....] //----------------------------------------------------------------------------- namespace System.Data.Common { using System; using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Diagnostics; [ Editor("Microsoft.VSDesigner.Data.Design.DataTableMappingCollectionEditor, " + AssemblyRef.MicrosoftVSDesigner, "System.Drawing.Design.UITypeEditor, " + AssemblyRef.SystemDrawing), ListBindable(false) ] #if WINFSInternalOnly internal #else public #endif sealed class DataTableMappingCollection : MarshalByRefObject, ITableMappingCollection { private Listitems; // delay creation until AddWithoutEvents, Insert, CopyTo, GetEnumerator public DataTableMappingCollection() { } // explicit ICollection implementation bool System.Collections.ICollection.IsSynchronized { get { return false;} } object System.Collections.ICollection.SyncRoot { get { return this;} } // explicit IList implementation bool System.Collections.IList.IsReadOnly { get { return false;} } bool System.Collections.IList.IsFixedSize { get { return false;} } object System.Collections.IList.this[int index] { get { return this[index]; } set { ValidateType(value); this[index] = (DataTableMapping) value; } } object ITableMappingCollection.this[string index] { get { return this[index]; } set { ValidateType(value); this[index] = (DataTableMapping) value; } } ITableMapping ITableMappingCollection.Add(string sourceTableName, string dataSetTableName) { return Add(sourceTableName, dataSetTableName); } ITableMapping ITableMappingCollection.GetByDataSetTable(string dataSetTableName) { return GetByDataSetTable(dataSetTableName); } [ Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), ResDescriptionAttribute(Res.DataTableMappings_Count), ] public int Count { get { return ((null != items) ? items.Count : 0); } } private Type ItemType { get { return typeof(DataTableMapping); } } [ Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), ResDescriptionAttribute(Res.DataTableMappings_Item), ] public DataTableMapping this[int index] { get { RangeCheck(index); return items[index]; } set { RangeCheck(index); Replace(index, value); } } [ Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), ResDescriptionAttribute(Res.DataTableMappings_Item), ] public DataTableMapping this[string sourceTable] { get { int index = RangeCheck(sourceTable); return items[index]; } set { int index = RangeCheck(sourceTable); Replace(index, value); } } public int Add(object value) { ValidateType(value); Add((DataTableMapping) value); return Count-1; } private DataTableMapping Add(DataTableMapping value) { AddWithoutEvents(value); return value; } public void AddRange(DataTableMapping[] values) { // V1.0.3300 AddEnumerableRange(values, false); } public void AddRange(System.Array values) { // V1.2.3300 AddEnumerableRange(values, false); } private void AddEnumerableRange(IEnumerable values, bool doClone) { if (null == values) { throw ADP.ArgumentNull("values"); } foreach(object value in values) { ValidateType(value); } if (doClone) { foreach(ICloneable value in values) { AddWithoutEvents(value.Clone() as DataTableMapping); } } else { foreach(DataTableMapping value in values) { AddWithoutEvents(value); } } } /*/// public void AddCloneOfRange(IEnumerable values) { AddEnumerableRange(values, true); }*/ public DataTableMapping Add(string sourceTable, string dataSetTable) { return Add(new DataTableMapping(sourceTable, dataSetTable)); } private void AddWithoutEvents(DataTableMapping value) { Validate(-1, value); value.Parent = this; ArrayList().Add(value); } // implemented as a method, not as a property because the VS7 debugger // object browser calls properties to display their value, and we want this delayed private List ArrayList() { if (null == this.items) { this.items = new List (); } return this.items; } public void Clear() { if (0 < Count) { ClearWithoutEvents(); } } private void ClearWithoutEvents() { if (null != items) { foreach(DataTableMapping item in items) { item.Parent = null; } items.Clear(); } } public bool Contains(string value) { return (-1 != IndexOf(value)); } public bool Contains(object value) { return (-1 != IndexOf(value)); } public void CopyTo(Array array, int index) { ((ICollection)ArrayList()).CopyTo(array, index); } public void CopyTo(DataTableMapping[] array, int index) { ArrayList().CopyTo(array, index); } public DataTableMapping GetByDataSetTable(string dataSetTable) { int index = IndexOfDataSetTable(dataSetTable); if (0 > index) { throw ADP.TablesDataSetTable(dataSetTable); } return items[index]; } public IEnumerator GetEnumerator() { return ArrayList().GetEnumerator(); } public int IndexOf(object value) { if (null != value) { ValidateType(value); for (int i = 0; i < Count; ++i) { if (items[i] == value) { return i; } } } return -1; } public int IndexOf(string sourceTable) { if (!ADP.IsEmpty(sourceTable)) { for (int i = 0; i < Count; ++i) { string value = items[i].SourceTable; if ((null != value) && (0 == ADP.SrcCompare(sourceTable, value))) { return i; } } } return -1; } public int IndexOfDataSetTable(string dataSetTable) { if (!ADP.IsEmpty(dataSetTable)) { for (int i = 0; i < Count; ++i) { string value = items[i].DataSetTable; if ((null != value) && (0 == ADP.DstCompare(dataSetTable, value))) { return i; } } } return -1; } public void Insert(int index, Object value) { ValidateType(value); Insert(index, (DataTableMapping) value); } public void Insert(int index, DataTableMapping value) { if (null == value) { throw ADP.TablesAddNullAttempt("value"); } Validate(-1, value); value.Parent = this; ArrayList().Insert(index, value); } private void RangeCheck(int index) { if ((index < 0) || (Count <= index)) { throw ADP.TablesIndexInt32(index, this); } } private int RangeCheck(string sourceTable) { int index = IndexOf(sourceTable); if (index < 0) { throw ADP.TablesSourceIndex(sourceTable); } return index; } public void RemoveAt(int index) { RangeCheck(index); RemoveIndex(index); } public void RemoveAt(string sourceTable) { int index = RangeCheck(sourceTable); RemoveIndex(index); } private void RemoveIndex(int index) { Debug.Assert((null != items) && (0 <= index) && (index < Count), "RemoveIndex, invalid"); items[index].Parent = null; items.RemoveAt(index); } public void Remove(object value) { ValidateType(value); Remove((DataTableMapping) value); } public void Remove (DataTableMapping value) { if (null == value) { throw ADP.TablesAddNullAttempt ("value"); } int index = IndexOf (value); if (-1 != index) { RemoveIndex (index); } else { throw ADP.CollectionRemoveInvalidObject (ItemType, this); } } private void Replace (int index, DataTableMapping newValue) { Validate(index, newValue); items[index].Parent = null; newValue.Parent = this; items[index] = newValue; } private void ValidateType(object value) { if (null == value) { throw ADP.TablesAddNullAttempt("value"); } else if (!ItemType.IsInstanceOfType(value)) { throw ADP.NotADataTableMapping(value); } } private void Validate(int index, DataTableMapping value) { if (null == value) { throw ADP.TablesAddNullAttempt("value"); } if (null != value.Parent) { if (this != value.Parent) { throw ADP.TablesIsNotParent(this); } else if (index != IndexOf(value)) { throw ADP.TablesIsParent(this); } } String name = value.SourceTable; if (ADP.IsEmpty(name)) { index = 1; do { name = ADP.SourceTable + index.ToString(System.Globalization.CultureInfo.InvariantCulture); index++; } while (-1 != IndexOf(name)); value.SourceTable = name; } else { ValidateSourceTable(index, name); } } internal void ValidateSourceTable(int index, string value) { int pindex = IndexOf(value); if ((-1 != pindex) && (index != pindex)) { // must be non-null and unique throw ADP.TablesUniqueSourceTable(value); } } [ EditorBrowsableAttribute(EditorBrowsableState.Advanced) ] // MDAC 69508 static public DataTableMapping GetTableMappingBySchemaAction(DataTableMappingCollection tableMappings, string sourceTable, string dataSetTable, MissingMappingAction mappingAction) { if (null != tableMappings) { int index = tableMappings.IndexOf(sourceTable); if (-1 != index) { #if DEBUG if (AdapterSwitches.DataSchema.TraceWarning) { Debug.WriteLine("mapping match on SourceTable \"" + sourceTable + "\""); } #endif return tableMappings.items[index]; } } if (ADP.IsEmpty(sourceTable)) { throw ADP.InvalidSourceTable("sourceTable"); } switch (mappingAction) { case MissingMappingAction.Passthrough: #if DEBUG if (AdapterSwitches.DataSchema.TraceInfo) { Debug.WriteLine("mapping passthrough of SourceTable \"" + sourceTable + "\" -> \"" + dataSetTable + "\""); } #endif return new DataTableMapping(sourceTable, dataSetTable); case MissingMappingAction.Ignore: #if DEBUG if (AdapterSwitches.DataSchema.TraceWarning) { Debug.WriteLine("mapping filter of SourceTable \"" + sourceTable + "\""); } #endif return null; case MissingMappingAction.Error: #if DEBUG if (AdapterSwitches.DataSchema.TraceError) { Debug.WriteLine("mapping error on SourceTable \"" + sourceTable + "\""); } #endif throw ADP.MissingTableMapping(sourceTable); default: throw ADP.InvalidMissingMappingAction(mappingAction); } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------------------ // // Copyright (c) Microsoft Corporation. All rights reserved. // //[....] //[....] //----------------------------------------------------------------------------- namespace System.Data.Common { using System; using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Diagnostics; [ Editor("Microsoft.VSDesigner.Data.Design.DataTableMappingCollectionEditor, " + AssemblyRef.MicrosoftVSDesigner, "System.Drawing.Design.UITypeEditor, " + AssemblyRef.SystemDrawing), ListBindable(false) ] #if WINFSInternalOnly internal #else public #endif sealed class DataTableMappingCollection : MarshalByRefObject, ITableMappingCollection { private Listitems; // delay creation until AddWithoutEvents, Insert, CopyTo, GetEnumerator public DataTableMappingCollection() { } // explicit ICollection implementation bool System.Collections.ICollection.IsSynchronized { get { return false;} } object System.Collections.ICollection.SyncRoot { get { return this;} } // explicit IList implementation bool System.Collections.IList.IsReadOnly { get { return false;} } bool System.Collections.IList.IsFixedSize { get { return false;} } object System.Collections.IList.this[int index] { get { return this[index]; } set { ValidateType(value); this[index] = (DataTableMapping) value; } } object ITableMappingCollection.this[string index] { get { return this[index]; } set { ValidateType(value); this[index] = (DataTableMapping) value; } } ITableMapping ITableMappingCollection.Add(string sourceTableName, string dataSetTableName) { return Add(sourceTableName, dataSetTableName); } ITableMapping ITableMappingCollection.GetByDataSetTable(string dataSetTableName) { return GetByDataSetTable(dataSetTableName); } [ Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), ResDescriptionAttribute(Res.DataTableMappings_Count), ] public int Count { get { return ((null != items) ? items.Count : 0); } } private Type ItemType { get { return typeof(DataTableMapping); } } [ Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), ResDescriptionAttribute(Res.DataTableMappings_Item), ] public DataTableMapping this[int index] { get { RangeCheck(index); return items[index]; } set { RangeCheck(index); Replace(index, value); } } [ Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), ResDescriptionAttribute(Res.DataTableMappings_Item), ] public DataTableMapping this[string sourceTable] { get { int index = RangeCheck(sourceTable); return items[index]; } set { int index = RangeCheck(sourceTable); Replace(index, value); } } public int Add(object value) { ValidateType(value); Add((DataTableMapping) value); return Count-1; } private DataTableMapping Add(DataTableMapping value) { AddWithoutEvents(value); return value; } public void AddRange(DataTableMapping[] values) { // V1.0.3300 AddEnumerableRange(values, false); } public void AddRange(System.Array values) { // V1.2.3300 AddEnumerableRange(values, false); } private void AddEnumerableRange(IEnumerable values, bool doClone) { if (null == values) { throw ADP.ArgumentNull("values"); } foreach(object value in values) { ValidateType(value); } if (doClone) { foreach(ICloneable value in values) { AddWithoutEvents(value.Clone() as DataTableMapping); } } else { foreach(DataTableMapping value in values) { AddWithoutEvents(value); } } } /*/// public void AddCloneOfRange(IEnumerable values) { AddEnumerableRange(values, true); }*/ public DataTableMapping Add(string sourceTable, string dataSetTable) { return Add(new DataTableMapping(sourceTable, dataSetTable)); } private void AddWithoutEvents(DataTableMapping value) { Validate(-1, value); value.Parent = this; ArrayList().Add(value); } // implemented as a method, not as a property because the VS7 debugger // object browser calls properties to display their value, and we want this delayed private List ArrayList() { if (null == this.items) { this.items = new List (); } return this.items; } public void Clear() { if (0 < Count) { ClearWithoutEvents(); } } private void ClearWithoutEvents() { if (null != items) { foreach(DataTableMapping item in items) { item.Parent = null; } items.Clear(); } } public bool Contains(string value) { return (-1 != IndexOf(value)); } public bool Contains(object value) { return (-1 != IndexOf(value)); } public void CopyTo(Array array, int index) { ((ICollection)ArrayList()).CopyTo(array, index); } public void CopyTo(DataTableMapping[] array, int index) { ArrayList().CopyTo(array, index); } public DataTableMapping GetByDataSetTable(string dataSetTable) { int index = IndexOfDataSetTable(dataSetTable); if (0 > index) { throw ADP.TablesDataSetTable(dataSetTable); } return items[index]; } public IEnumerator GetEnumerator() { return ArrayList().GetEnumerator(); } public int IndexOf(object value) { if (null != value) { ValidateType(value); for (int i = 0; i < Count; ++i) { if (items[i] == value) { return i; } } } return -1; } public int IndexOf(string sourceTable) { if (!ADP.IsEmpty(sourceTable)) { for (int i = 0; i < Count; ++i) { string value = items[i].SourceTable; if ((null != value) && (0 == ADP.SrcCompare(sourceTable, value))) { return i; } } } return -1; } public int IndexOfDataSetTable(string dataSetTable) { if (!ADP.IsEmpty(dataSetTable)) { for (int i = 0; i < Count; ++i) { string value = items[i].DataSetTable; if ((null != value) && (0 == ADP.DstCompare(dataSetTable, value))) { return i; } } } return -1; } public void Insert(int index, Object value) { ValidateType(value); Insert(index, (DataTableMapping) value); } public void Insert(int index, DataTableMapping value) { if (null == value) { throw ADP.TablesAddNullAttempt("value"); } Validate(-1, value); value.Parent = this; ArrayList().Insert(index, value); } private void RangeCheck(int index) { if ((index < 0) || (Count <= index)) { throw ADP.TablesIndexInt32(index, this); } } private int RangeCheck(string sourceTable) { int index = IndexOf(sourceTable); if (index < 0) { throw ADP.TablesSourceIndex(sourceTable); } return index; } public void RemoveAt(int index) { RangeCheck(index); RemoveIndex(index); } public void RemoveAt(string sourceTable) { int index = RangeCheck(sourceTable); RemoveIndex(index); } private void RemoveIndex(int index) { Debug.Assert((null != items) && (0 <= index) && (index < Count), "RemoveIndex, invalid"); items[index].Parent = null; items.RemoveAt(index); } public void Remove(object value) { ValidateType(value); Remove((DataTableMapping) value); } public void Remove (DataTableMapping value) { if (null == value) { throw ADP.TablesAddNullAttempt ("value"); } int index = IndexOf (value); if (-1 != index) { RemoveIndex (index); } else { throw ADP.CollectionRemoveInvalidObject (ItemType, this); } } private void Replace (int index, DataTableMapping newValue) { Validate(index, newValue); items[index].Parent = null; newValue.Parent = this; items[index] = newValue; } private void ValidateType(object value) { if (null == value) { throw ADP.TablesAddNullAttempt("value"); } else if (!ItemType.IsInstanceOfType(value)) { throw ADP.NotADataTableMapping(value); } } private void Validate(int index, DataTableMapping value) { if (null == value) { throw ADP.TablesAddNullAttempt("value"); } if (null != value.Parent) { if (this != value.Parent) { throw ADP.TablesIsNotParent(this); } else if (index != IndexOf(value)) { throw ADP.TablesIsParent(this); } } String name = value.SourceTable; if (ADP.IsEmpty(name)) { index = 1; do { name = ADP.SourceTable + index.ToString(System.Globalization.CultureInfo.InvariantCulture); index++; } while (-1 != IndexOf(name)); value.SourceTable = name; } else { ValidateSourceTable(index, name); } } internal void ValidateSourceTable(int index, string value) { int pindex = IndexOf(value); if ((-1 != pindex) && (index != pindex)) { // must be non-null and unique throw ADP.TablesUniqueSourceTable(value); } } [ EditorBrowsableAttribute(EditorBrowsableState.Advanced) ] // MDAC 69508 static public DataTableMapping GetTableMappingBySchemaAction(DataTableMappingCollection tableMappings, string sourceTable, string dataSetTable, MissingMappingAction mappingAction) { if (null != tableMappings) { int index = tableMappings.IndexOf(sourceTable); if (-1 != index) { #if DEBUG if (AdapterSwitches.DataSchema.TraceWarning) { Debug.WriteLine("mapping match on SourceTable \"" + sourceTable + "\""); } #endif return tableMappings.items[index]; } } if (ADP.IsEmpty(sourceTable)) { throw ADP.InvalidSourceTable("sourceTable"); } switch (mappingAction) { case MissingMappingAction.Passthrough: #if DEBUG if (AdapterSwitches.DataSchema.TraceInfo) { Debug.WriteLine("mapping passthrough of SourceTable \"" + sourceTable + "\" -> \"" + dataSetTable + "\""); } #endif return new DataTableMapping(sourceTable, dataSetTable); case MissingMappingAction.Ignore: #if DEBUG if (AdapterSwitches.DataSchema.TraceWarning) { Debug.WriteLine("mapping filter of SourceTable \"" + sourceTable + "\""); } #endif return null; case MissingMappingAction.Error: #if DEBUG if (AdapterSwitches.DataSchema.TraceError) { Debug.WriteLine("mapping error on SourceTable \"" + sourceTable + "\""); } #endif throw ADP.MissingTableMapping(sourceTable); default: throw ADP.InvalidMissingMappingAction(mappingAction); } } } } // 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
- XmlSerializableServices.cs
- ItemContainerGenerator.cs
- HtmlInputFile.cs
- DATA_BLOB.cs
- NullRuntimeConfig.cs
- ModelItemImpl.cs
- MessageDispatch.cs
- SortQuery.cs
- ContextMenu.cs
- RuleDefinitions.cs
- PropertiesTab.cs
- XmlAttributeCache.cs
- FillRuleValidation.cs
- ComPlusDiagnosticTraceRecords.cs
- StringValidatorAttribute.cs
- SlipBehavior.cs
- SystemIPGlobalProperties.cs
- XmlChildNodes.cs
- InstanceData.cs
- LoginAutoFormat.cs
- TextEndOfSegment.cs
- HtmlElementEventArgs.cs
- ConnectionManagementSection.cs
- ObjectHandle.cs
- QilLiteral.cs
- MemberMemberBinding.cs
- SafeUserTokenHandle.cs
- HttpHandlerAction.cs
- TimeoutException.cs
- Compiler.cs
- DLinqAssociationProvider.cs
- ResumeStoryboard.cs
- SafeSecurityHelper.cs
- codemethodreferenceexpression.cs
- Utility.cs
- InlineObject.cs
- Run.cs
- Process.cs
- MimeMultiPart.cs
- LineSegment.cs
- PaperSize.cs
- DataView.cs
- StringInfo.cs
- MdImport.cs
- SafeNativeMethodsCLR.cs
- CustomCategoryAttribute.cs
- WeakReadOnlyCollection.cs
- RuleAttributes.cs
- DataGridCellAutomationPeer.cs
- ButtonField.cs
- RankException.cs
- DynamicRenderer.cs
- DataGridViewRowConverter.cs
- Soap.cs
- CharUnicodeInfo.cs
- BaseAsyncResult.cs
- ThreadStateException.cs
- RTTrackingProfile.cs
- TypeToArgumentTypeConverter.cs
- TextParaClient.cs
- ErrorEventArgs.cs
- DictionaryManager.cs
- BrowserDefinition.cs
- SourceCollection.cs
- CqlLexerHelpers.cs
- TemplatedWizardStep.cs
- SettingsPropertyCollection.cs
- SafeEventLogReadHandle.cs
- ChangePasswordAutoFormat.cs
- DbConnectionPoolGroup.cs
- StorageModelBuildProvider.cs
- UnsafeNativeMethods.cs
- SerializerDescriptor.cs
- KeyInstance.cs
- Span.cs
- bidPrivateBase.cs
- TextAdaptor.cs
- DataStreams.cs
- WebBrowser.cs
- DetailsViewRowCollection.cs
- HealthMonitoringSectionHelper.cs
- WebZone.cs
- SqlCacheDependencyDatabaseCollection.cs
- DriveInfo.cs
- StringResourceManager.cs
- ListControlStringCollectionEditor.cs
- StylusPointDescription.cs
- SinglePageViewer.cs
- EntityDataSourceEntityTypeFilterItem.cs
- ThousandthOfEmRealDoubles.cs
- HandleCollector.cs
- HttpResponseInternalBase.cs
- WriteLine.cs
- XmlnsDictionary.cs
- MetadataUtil.cs
- SerializationException.cs
- DrawListViewSubItemEventArgs.cs
- WebControlAdapter.cs
- ProfileInfo.cs
- ExtentCqlBlock.cs