Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / DataWebControls / System / Data / WebControls / EntityDataSourceWrapperCollection.cs / 1305376 / EntityDataSourceWrapperCollection.cs
//----------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// @owner [....]
// @backupOwner [....]
//---------------------------------------------------------------------
using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Collections;
using System.ComponentModel;
using System.Collections.Generic;
using System.Data.Metadata.Edm;
using System.Data.Mapping;
using System.Data.Objects;
using System.Reflection;
using System.Diagnostics;
using System.Data.Common;
using System.Data.Objects.DataClasses;
using System.Globalization;
using System.Data.EntityClient;
using System.Collections.ObjectModel;
namespace System.Web.UI.WebControls
{
///
/// Summary description for EntityDataSourceWrapperCollection
///
internal class EntityDataSourceWrapperCollection : IEnumerable, ICollection, ITypedList
{
private readonly ObjectContext _context;
private readonly List _wrapperList;
///
/// Gets the property descriptors exposed to the user.
///
private readonly PropertyDescriptorCollection _visiblePropertyDescriptors;
///
/// Gets all property descriptors.
///
internal readonly ReadOnlyCollection AllPropertyDescriptors;
private readonly bool _isReadOnly;
private readonly Type _clrEntityType;
internal EntityDataSourceWrapperCollection(ObjectContext context, EntitySet entitySet, EntityType restrictedEntityType)
{
EntityDataSourceUtil.CheckArgumentNull(context, "context");
EntityDataSourceUtil.CheckArgumentNull(entitySet, "entitySet");
_context = context;
_wrapperList = new List();
// get handles on the relevant workspaces
MetadataWorkspace csWorkspace = ((EntityConnection)context.Connection).GetMetadataWorkspace();
MetadataWorkspace ocWorkspace = context.MetadataWorkspace;
// if no restricted type is given, we assume the entity set element type is exposed
EntityType entityType = restrictedEntityType ?? entitySet.ElementType;
_clrEntityType = EntityDataSourceUtil.GetClrType(ocWorkspace, entityType);
// if no restricted type is given and the set is polymorphic, make the collection readonly
if (null == restrictedEntityType &&
1 < EntityDataSourceUtil.GetTypeAndSubtypesOf(entityType, csWorkspace.GetItemCollection(DataSpace.CSpace), true).Count())
{
_isReadOnly = true;
}
// gather the properties
Type componentType = EntityDataSourceUtil.GetClrType(context.MetadataWorkspace, entityType);
ReadOnlyCollection columns = EntityDataSourceUtil.GetNamedColumns(csWorkspace, ocWorkspace, entitySet, entityType);
List visiblePropertyDescriptors = new List(columns.Count);
List propertyDescriptors = new List(columns.Count);
foreach (EntityDataSourceColumn column in columns)
{
var descriptor = new EntityDataSourceWrapperPropertyDescriptor(this, column);
propertyDescriptors.Add(descriptor);
// if the descriptor does not have a dependent, it is exposed to the user
if (!descriptor.Column.IsHidden)
{
visiblePropertyDescriptors.Add(descriptor);
}
}
_visiblePropertyDescriptors = new PropertyDescriptorCollection(visiblePropertyDescriptors.ToArray(), true);
AllPropertyDescriptors = propertyDescriptors.AsReadOnly();
}
internal EntityDataSourceWrapper AddWrappedEntity(object entity)
{
EntityDataSourceWrapper wrapper = new EntityDataSourceWrapper(this, entity);
this._wrapperList.Add(wrapper);
return wrapper;
}
#region IEnumerable Implementation
IEnumerator IEnumerable.GetEnumerator()
{
return this._wrapperList.GetEnumerator();
}
#endregion IEnumerable Implementation
#region ICollection Implementation
public int Count
{
get { return this._wrapperList.Count; }
}
public void CopyTo(Array array, int index)
{
((ICollection)this._wrapperList).CopyTo(array, index);
}
public bool IsSynchronized
{
get { return false; }
}
public object SyncRoot
{
get { return null; }
}
#endregion
#region ITypedList Implementation
public PropertyDescriptorCollection GetItemProperties(PropertyDescriptor[] listAccessors)
{
if (null == listAccessors)
{
return this._visiblePropertyDescriptors ;
}
else
{
return null;// Implement this feature when we support traversing collections.
}
}
string ITypedList.GetListName(PropertyDescriptor[] listAccessors)
{
return null;
}
#endregion
#region Internal properties
///
/// Gets CLR type or base type for entities exposed in this collection.
///
internal Type ClrEntityType
{
get { return _clrEntityType; }
}
///
/// Indicates whether this configuration supports modifications.
///
internal bool IsReadOnly
{
get { return _isReadOnly; }
}
///
/// Gets object context tracking the contents of this collection.
///
internal ObjectContext Context
{
get { return _context; }
}
#endregion
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//----------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// @owner [....]
// @backupOwner [....]
//---------------------------------------------------------------------
using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Collections;
using System.ComponentModel;
using System.Collections.Generic;
using System.Data.Metadata.Edm;
using System.Data.Mapping;
using System.Data.Objects;
using System.Reflection;
using System.Diagnostics;
using System.Data.Common;
using System.Data.Objects.DataClasses;
using System.Globalization;
using System.Data.EntityClient;
using System.Collections.ObjectModel;
namespace System.Web.UI.WebControls
{
///
/// Summary description for EntityDataSourceWrapperCollection
///
internal class EntityDataSourceWrapperCollection : IEnumerable, ICollection, ITypedList
{
private readonly ObjectContext _context;
private readonly List _wrapperList;
///
/// Gets the property descriptors exposed to the user.
///
private readonly PropertyDescriptorCollection _visiblePropertyDescriptors;
///
/// Gets all property descriptors.
///
internal readonly ReadOnlyCollection AllPropertyDescriptors;
private readonly bool _isReadOnly;
private readonly Type _clrEntityType;
internal EntityDataSourceWrapperCollection(ObjectContext context, EntitySet entitySet, EntityType restrictedEntityType)
{
EntityDataSourceUtil.CheckArgumentNull(context, "context");
EntityDataSourceUtil.CheckArgumentNull(entitySet, "entitySet");
_context = context;
_wrapperList = new List();
// get handles on the relevant workspaces
MetadataWorkspace csWorkspace = ((EntityConnection)context.Connection).GetMetadataWorkspace();
MetadataWorkspace ocWorkspace = context.MetadataWorkspace;
// if no restricted type is given, we assume the entity set element type is exposed
EntityType entityType = restrictedEntityType ?? entitySet.ElementType;
_clrEntityType = EntityDataSourceUtil.GetClrType(ocWorkspace, entityType);
// if no restricted type is given and the set is polymorphic, make the collection readonly
if (null == restrictedEntityType &&
1 < EntityDataSourceUtil.GetTypeAndSubtypesOf(entityType, csWorkspace.GetItemCollection(DataSpace.CSpace), true).Count())
{
_isReadOnly = true;
}
// gather the properties
Type componentType = EntityDataSourceUtil.GetClrType(context.MetadataWorkspace, entityType);
ReadOnlyCollection columns = EntityDataSourceUtil.GetNamedColumns(csWorkspace, ocWorkspace, entitySet, entityType);
List visiblePropertyDescriptors = new List(columns.Count);
List propertyDescriptors = new List(columns.Count);
foreach (EntityDataSourceColumn column in columns)
{
var descriptor = new EntityDataSourceWrapperPropertyDescriptor(this, column);
propertyDescriptors.Add(descriptor);
// if the descriptor does not have a dependent, it is exposed to the user
if (!descriptor.Column.IsHidden)
{
visiblePropertyDescriptors.Add(descriptor);
}
}
_visiblePropertyDescriptors = new PropertyDescriptorCollection(visiblePropertyDescriptors.ToArray(), true);
AllPropertyDescriptors = propertyDescriptors.AsReadOnly();
}
internal EntityDataSourceWrapper AddWrappedEntity(object entity)
{
EntityDataSourceWrapper wrapper = new EntityDataSourceWrapper(this, entity);
this._wrapperList.Add(wrapper);
return wrapper;
}
#region IEnumerable Implementation
IEnumerator IEnumerable.GetEnumerator()
{
return this._wrapperList.GetEnumerator();
}
#endregion IEnumerable Implementation
#region ICollection Implementation
public int Count
{
get { return this._wrapperList.Count; }
}
public void CopyTo(Array array, int index)
{
((ICollection)this._wrapperList).CopyTo(array, index);
}
public bool IsSynchronized
{
get { return false; }
}
public object SyncRoot
{
get { return null; }
}
#endregion
#region ITypedList Implementation
public PropertyDescriptorCollection GetItemProperties(PropertyDescriptor[] listAccessors)
{
if (null == listAccessors)
{
return this._visiblePropertyDescriptors ;
}
else
{
return null;// Implement this feature when we support traversing collections.
}
}
string ITypedList.GetListName(PropertyDescriptor[] listAccessors)
{
return null;
}
#endregion
#region Internal properties
///
/// Gets CLR type or base type for entities exposed in this collection.
///
internal Type ClrEntityType
{
get { return _clrEntityType; }
}
///
/// Indicates whether this configuration supports modifications.
///
internal bool IsReadOnly
{
get { return _isReadOnly; }
}
///
/// Gets object context tracking the contents of this collection.
///
internal ObjectContext Context
{
get { return _context; }
}
#endregion
}
}
// 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
- ImageUrlEditor.cs
- QueueException.cs
- ClientConfigurationSystem.cs
- BooleanAnimationUsingKeyFrames.cs
- XmlSchemaGroupRef.cs
- EntityDataSourceContextCreatedEventArgs.cs
- IisTraceListener.cs
- JsonUriDataContract.cs
- DataGridViewRowsAddedEventArgs.cs
- FixedNode.cs
- TreeNode.cs
- HeaderedItemsControl.cs
- KerberosReceiverSecurityToken.cs
- BindableAttribute.cs
- ItemType.cs
- BackStopAuthenticationModule.cs
- OutputCacheSection.cs
- ConvertEvent.cs
- ADMembershipProvider.cs
- SHA384.cs
- Int32.cs
- BindingContext.cs
- OracleEncoding.cs
- Util.cs
- Image.cs
- loginstatus.cs
- Mouse.cs
- IdentitySection.cs
- InstanceCreationEditor.cs
- OdbcEnvironment.cs
- VectorCollection.cs
- ObjectItemCachedAssemblyLoader.cs
- MessageQueue.cs
- IOException.cs
- EasingKeyFrames.cs
- Membership.cs
- WebScriptClientGenerator.cs
- TaskFormBase.cs
- DnsPermission.cs
- PerspectiveCamera.cs
- OLEDB_Util.cs
- SyndicationDeserializer.cs
- SqlStatistics.cs
- ItemsControlAutomationPeer.cs
- VariableDesigner.xaml.cs
- WebPartMinimizeVerb.cs
- _SSPIWrapper.cs
- WebPartManagerInternals.cs
- DateRangeEvent.cs
- XmlSerializerFactory.cs
- WebConfigManager.cs
- FocusChangedEventArgs.cs
- TextServicesCompartmentEventSink.cs
- TableCellCollection.cs
- WebPartDisplayModeCollection.cs
- ErrorHandler.cs
- TableProviderWrapper.cs
- Content.cs
- PreservationFileWriter.cs
- ObjectConverter.cs
- PreviewControlDesigner.cs
- ToolStripPanelRenderEventArgs.cs
- MailBnfHelper.cs
- ReadOnlyCollection.cs
- VirtualDirectoryMapping.cs
- WebPartExportVerb.cs
- DesignerSerializationVisibilityAttribute.cs
- SqlMethodTransformer.cs
- TreeViewBindingsEditor.cs
- WebPartMovingEventArgs.cs
- HttpResponse.cs
- Normalization.cs
- RoamingStoreFile.cs
- DelegateHelpers.cs
- ProcessingInstructionAction.cs
- DocumentGrid.cs
- ClassDataContract.cs
- LogExtentCollection.cs
- ResourcePart.cs
- documentation.cs
- ISO2022Encoding.cs
- __Error.cs
- FileDialogCustomPlaces.cs
- __Error.cs
- DynamicPropertyHolder.cs
- AssemblySettingAttributes.cs
- TextEditorCharacters.cs
- CalculatedColumn.cs
- WebBrowserSiteBase.cs
- LayoutEditorPart.cs
- XmlQueryStaticData.cs
- TextDecorationCollectionConverter.cs
- EntityType.cs
- MultipleViewProviderWrapper.cs
- BeginStoryboard.cs
- MachineKeyConverter.cs
- TreePrinter.cs
- StaticSiteMapProvider.cs
- QuotedPrintableStream.cs
- COMException.cs