Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / DataEntity / System / Data / Common / DbXmlEnabledProviderManifest.cs / 1305376 / DbXmlEnabledProviderManifest.cs
//----------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// @owner [....]
//---------------------------------------------------------------------
using System.Data.Common;
using System.Diagnostics;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Xml;
using System.Data.EntityModel.SchemaObjectModel;
using System.Data.EntityModel;
using System.Data.Entity;
using System.Data.Metadata.Edm;
namespace System.Data.Common
{
///
/// A specialization of the ProviderManifest that accepts an XmlReader
///
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "Db")]
public abstract class DbXmlEnabledProviderManifest : DbProviderManifest
{
private string _namespaceName;
private System.Collections.ObjectModel.ReadOnlyCollection _primitiveTypes;
private Dictionary> _facetDescriptions = new Dictionary>();
private System.Collections.ObjectModel.ReadOnlyCollection _functions;
private Dictionary _storeTypeNameToEdmPrimitiveType = new Dictionary();
private Dictionary _storeTypeNameToStorePrimitiveType = new Dictionary();
protected DbXmlEnabledProviderManifest(XmlReader reader)
{
if (reader == null)
{
throw EntityUtil.ProviderIncompatible(Strings.IncorrectProviderManifest, new ArgumentNullException("reader"));
}
Load(reader);
}
#region Protected Properties For Fields
public override string NamespaceName
{
get
{
return this._namespaceName;
}
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Edm")]
protected Dictionary StoreTypeNameToEdmPrimitiveType
{
get
{
return this._storeTypeNameToEdmPrimitiveType;
}
}
protected Dictionary StoreTypeNameToStorePrimitiveType
{
get
{
return this._storeTypeNameToStorePrimitiveType;
}
}
#endregion
///
/// Returns all the FacetDescriptions for a particular type
///
/// the type to return FacetDescriptions for.
/// The FacetDescriptions for the type given.
public override System.Collections.ObjectModel.ReadOnlyCollection GetFacetDescriptions(EdmType type)
{
Debug.Assert(type is PrimitiveType, "DbXmlEnabledProviderManifest.GetFacetDescriptions(): Argument is not a PrimitiveType");
return GetReadOnlyCollection(type as PrimitiveType, _facetDescriptions, Helper.EmptyFacetDescriptionEnumerable);
}
public override System.Collections.ObjectModel.ReadOnlyCollection GetStoreTypes()
{
return _primitiveTypes;
}
///
/// Returns all the edm functions supported by the provider manifest.
///
/// A collection of edm functions.
public override System.Collections.ObjectModel.ReadOnlyCollection GetStoreFunctions()
{
return _functions;
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Globalization", "CA1308:NormalizeStringsToUppercase")]
private void Load(XmlReader reader)
{
Schema schema;
IList errors = SchemaManager.LoadProviderManifest(reader, reader.BaseURI.Length > 0 ? reader.BaseURI : null, true /*checkForSystemNamespace*/, out schema);
if (errors.Count != 0)
{
throw EntityUtil.ProviderIncompatible(Strings.IncorrectProviderManifest + Helper.CombineErrorMessage(errors));
}
_namespaceName = schema.Namespace;
List listOfPrimitiveTypes = new List();
foreach (System.Data.EntityModel.SchemaObjectModel.SchemaType schemaType in schema.SchemaTypes)
{
TypeElement typeElement = schemaType as TypeElement;
if (typeElement != null)
{
PrimitiveType type = typeElement.PrimitiveType;
type.ProviderManifest = this;
type.DataSpace = DataSpace.SSpace;
type.SetReadOnly();
listOfPrimitiveTypes.Add(type);
_storeTypeNameToStorePrimitiveType.Add(type.Name.ToLowerInvariant(), type);
_storeTypeNameToEdmPrimitiveType.Add(type.Name.ToLowerInvariant(), EdmProviderManifest.Instance.GetPrimitiveType(type.PrimitiveTypeKind));
System.Collections.ObjectModel.ReadOnlyCollection descriptions;
if (EnumerableToReadOnlyCollection(typeElement.FacetDescriptions, out descriptions))
{
_facetDescriptions.Add(type, descriptions);
}
}
}
this._primitiveTypes = Array.AsReadOnly(listOfPrimitiveTypes.ToArray());
// load the functions
ItemCollection collection = new EmptyItemCollection();
IEnumerable items = Converter.ConvertSchema(schema, this, collection);
if (!EnumerableToReadOnlyCollection(items, out this._functions))
{
this._functions = Helper.EmptyEdmFunctionReadOnlyCollection;
}
//SetReadOnly on all the Functions
foreach (EdmFunction function in this._functions)
{
function.SetReadOnly();
}
}
private static System.Collections.ObjectModel.ReadOnlyCollection GetReadOnlyCollection(PrimitiveType type, Dictionary> typeDictionary, System.Collections.ObjectModel.ReadOnlyCollection useIfEmpty)
{
System.Collections.ObjectModel.ReadOnlyCollection collection;
if (typeDictionary.TryGetValue(type, out collection))
{
return collection;
}
else
{
return useIfEmpty;
}
}
private static bool EnumerableToReadOnlyCollection(IEnumerable enumerable, out System.Collections.ObjectModel.ReadOnlyCollection collection) where Target : BaseType
{
List list = new List();
foreach (BaseType item in enumerable)
{
if (typeof(Target) == typeof(BaseType) || item is Target)
{
list.Add((Target)item);
}
}
if (list.Count != 0)
{
collection = list.AsReadOnly();
return true;
}
collection = null;
return false;
}
private class EmptyItemCollection : ItemCollection
{
public EmptyItemCollection()
: base(DataSpace.SSpace)
{
}
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//----------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// @owner [....]
//---------------------------------------------------------------------
using System.Data.Common;
using System.Diagnostics;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Xml;
using System.Data.EntityModel.SchemaObjectModel;
using System.Data.EntityModel;
using System.Data.Entity;
using System.Data.Metadata.Edm;
namespace System.Data.Common
{
///
/// A specialization of the ProviderManifest that accepts an XmlReader
///
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "Db")]
public abstract class DbXmlEnabledProviderManifest : DbProviderManifest
{
private string _namespaceName;
private System.Collections.ObjectModel.ReadOnlyCollection _primitiveTypes;
private Dictionary> _facetDescriptions = new Dictionary>();
private System.Collections.ObjectModel.ReadOnlyCollection _functions;
private Dictionary _storeTypeNameToEdmPrimitiveType = new Dictionary();
private Dictionary _storeTypeNameToStorePrimitiveType = new Dictionary();
protected DbXmlEnabledProviderManifest(XmlReader reader)
{
if (reader == null)
{
throw EntityUtil.ProviderIncompatible(Strings.IncorrectProviderManifest, new ArgumentNullException("reader"));
}
Load(reader);
}
#region Protected Properties For Fields
public override string NamespaceName
{
get
{
return this._namespaceName;
}
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Edm")]
protected Dictionary StoreTypeNameToEdmPrimitiveType
{
get
{
return this._storeTypeNameToEdmPrimitiveType;
}
}
protected Dictionary StoreTypeNameToStorePrimitiveType
{
get
{
return this._storeTypeNameToStorePrimitiveType;
}
}
#endregion
///
/// Returns all the FacetDescriptions for a particular type
///
/// the type to return FacetDescriptions for.
/// The FacetDescriptions for the type given.
public override System.Collections.ObjectModel.ReadOnlyCollection GetFacetDescriptions(EdmType type)
{
Debug.Assert(type is PrimitiveType, "DbXmlEnabledProviderManifest.GetFacetDescriptions(): Argument is not a PrimitiveType");
return GetReadOnlyCollection(type as PrimitiveType, _facetDescriptions, Helper.EmptyFacetDescriptionEnumerable);
}
public override System.Collections.ObjectModel.ReadOnlyCollection GetStoreTypes()
{
return _primitiveTypes;
}
///
/// Returns all the edm functions supported by the provider manifest.
///
/// A collection of edm functions.
public override System.Collections.ObjectModel.ReadOnlyCollection GetStoreFunctions()
{
return _functions;
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Globalization", "CA1308:NormalizeStringsToUppercase")]
private void Load(XmlReader reader)
{
Schema schema;
IList errors = SchemaManager.LoadProviderManifest(reader, reader.BaseURI.Length > 0 ? reader.BaseURI : null, true /*checkForSystemNamespace*/, out schema);
if (errors.Count != 0)
{
throw EntityUtil.ProviderIncompatible(Strings.IncorrectProviderManifest + Helper.CombineErrorMessage(errors));
}
_namespaceName = schema.Namespace;
List listOfPrimitiveTypes = new List();
foreach (System.Data.EntityModel.SchemaObjectModel.SchemaType schemaType in schema.SchemaTypes)
{
TypeElement typeElement = schemaType as TypeElement;
if (typeElement != null)
{
PrimitiveType type = typeElement.PrimitiveType;
type.ProviderManifest = this;
type.DataSpace = DataSpace.SSpace;
type.SetReadOnly();
listOfPrimitiveTypes.Add(type);
_storeTypeNameToStorePrimitiveType.Add(type.Name.ToLowerInvariant(), type);
_storeTypeNameToEdmPrimitiveType.Add(type.Name.ToLowerInvariant(), EdmProviderManifest.Instance.GetPrimitiveType(type.PrimitiveTypeKind));
System.Collections.ObjectModel.ReadOnlyCollection descriptions;
if (EnumerableToReadOnlyCollection(typeElement.FacetDescriptions, out descriptions))
{
_facetDescriptions.Add(type, descriptions);
}
}
}
this._primitiveTypes = Array.AsReadOnly(listOfPrimitiveTypes.ToArray());
// load the functions
ItemCollection collection = new EmptyItemCollection();
IEnumerable items = Converter.ConvertSchema(schema, this, collection);
if (!EnumerableToReadOnlyCollection(items, out this._functions))
{
this._functions = Helper.EmptyEdmFunctionReadOnlyCollection;
}
//SetReadOnly on all the Functions
foreach (EdmFunction function in this._functions)
{
function.SetReadOnly();
}
}
private static System.Collections.ObjectModel.ReadOnlyCollection GetReadOnlyCollection(PrimitiveType type, Dictionary> typeDictionary, System.Collections.ObjectModel.ReadOnlyCollection useIfEmpty)
{
System.Collections.ObjectModel.ReadOnlyCollection collection;
if (typeDictionary.TryGetValue(type, out collection))
{
return collection;
}
else
{
return useIfEmpty;
}
}
private static bool EnumerableToReadOnlyCollection(IEnumerable enumerable, out System.Collections.ObjectModel.ReadOnlyCollection collection) where Target : BaseType
{
List list = new List();
foreach (BaseType item in enumerable)
{
if (typeof(Target) == typeof(BaseType) || item is Target)
{
list.Add((Target)item);
}
}
if (list.Count != 0)
{
collection = list.AsReadOnly();
return true;
}
collection = null;
return false;
}
private class EmptyItemCollection : ItemCollection
{
public EmptyItemCollection()
: base(DataSpace.SSpace)
{
}
}
}
}
// 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
- Evidence.cs
- ApplicationCommands.cs
- ConfigXmlWhitespace.cs
- lengthconverter.cs
- PropertyEntry.cs
- TreeWalker.cs
- ResourcePart.cs
- PaginationProgressEventArgs.cs
- SystemSounds.cs
- ApplicationActivator.cs
- SamlAttribute.cs
- TargetParameterCountException.cs
- ModuleBuilderData.cs
- MatrixAnimationUsingKeyFrames.cs
- DataGridViewColumnCollection.cs
- SqlInternalConnection.cs
- InputBinding.cs
- TransformDescriptor.cs
- AdapterSwitches.cs
- ScrollContentPresenter.cs
- HtmlTextArea.cs
- ConnectionOrientedTransportBindingElement.cs
- TransactedBatchContext.cs
- Resources.Designer.cs
- EntityAdapter.cs
- Subtree.cs
- SmiTypedGetterSetter.cs
- Pen.cs
- EditingCoordinator.cs
- sqlmetadatafactory.cs
- ToolStripRenderer.cs
- MetadataItemCollectionFactory.cs
- UpdateRecord.cs
- Converter.cs
- ItemsPanelTemplate.cs
- EditorResources.cs
- OleDbException.cs
- SinglePageViewer.cs
- CustomErrorsSection.cs
- RankException.cs
- MetadataExchangeClient.cs
- BamlReader.cs
- UserPersonalizationStateInfo.cs
- CommentEmitter.cs
- SafeProcessHandle.cs
- CacheForPrimitiveTypes.cs
- IERequestCache.cs
- DropShadowBitmapEffect.cs
- SqlDataSourceFilteringEventArgs.cs
- TextElementEnumerator.cs
- Int16.cs
- PermissionListSet.cs
- DataGridViewRowsAddedEventArgs.cs
- RegionInfo.cs
- RetriableClipboard.cs
- ListBoxChrome.cs
- BuildProvidersCompiler.cs
- DataBoundLiteralControl.cs
- VirtualPathProvider.cs
- ECDsaCng.cs
- FixedSOMPageElement.cs
- InvalidProgramException.cs
- VectorCollection.cs
- PointCollection.cs
- EntitySqlQueryBuilder.cs
- TableCell.cs
- FaultCode.cs
- ItemCheckedEvent.cs
- DPCustomTypeDescriptor.cs
- Boolean.cs
- NativeMethods.cs
- CompiledXpathExpr.cs
- ComponentResourceKey.cs
- CallbackHandler.cs
- DrawingState.cs
- BitmapEffect.cs
- OrderedHashRepartitionEnumerator.cs
- Timer.cs
- configsystem.cs
- TextBox.cs
- Matrix.cs
- StylusPoint.cs
- TreeNodeStyleCollection.cs
- DescendantOverDescendantQuery.cs
- HTTPNotFoundHandler.cs
- Ipv6Element.cs
- MemberInfoSerializationHolder.cs
- VScrollBar.cs
- ProcessThreadDesigner.cs
- CacheOutputQuery.cs
- SqlUserDefinedAggregateAttribute.cs
- DecodeHelper.cs
- SqlCacheDependency.cs
- DataGridViewToolTip.cs
- SmiMetaData.cs
- ECDsa.cs
- HttpApplicationStateBase.cs
- PropertyPanel.cs
- JulianCalendar.cs
- MachineSettingsSection.cs