Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / Orcas / NetFXw7 / ndp / fx / src / DataEntity / System / Data / Common / DbProviderServices.cs / 1 / DbProviderServices.cs
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// @owner [....], [....]
//-----------------------------------------------------------------------------
namespace System.Data.Common
{
using System.Collections.Generic;
using System.Data.Common.CommandTrees;
using System.Data.Metadata.Edm;
using System.Xml;
using System.Reflection;
using System.IO;
using System.Data.Entity;
using System.Diagnostics;
///
/// The factory for building command definitions; use the type of this object
/// as the argument to the IServiceProvider.GetService method on the provider
/// factory;
///
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "Db")]
abstract public class DbProviderServices
{
///
/// Create a Command Definition object given a command tree.
///
/// command tree for the statement
/// an exectable command definition object
///
/// This method simply delegates to the provider's implementation of CreateDbCommandDefinition.
///
public DbCommandDefinition CreateCommandDefinition(DbCommandTree commandTree)
{
EntityUtil.CheckArgumentNull(commandTree, "commandTree");
StoreItemCollection storeMetadata = (StoreItemCollection)commandTree.MetadataWorkspace.GetItemCollection(DataSpace.SSpace);
Debug.Assert(storeMetadata.StoreProviderManifest != null, "StoreItemCollection has null StoreProviderManifest?");
return CreateDbCommandDefinition(storeMetadata.StoreProviderManifest, commandTree);
}
///
/// Create a Command Definition object, given the provider manifest and command tree
///
/// provider manifest previously retrieved from the store provider
/// command tree for the statement
/// an exectable command definition object
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "Db")]
protected abstract DbCommandDefinition CreateDbCommandDefinition(DbProviderManifest providerManifest, DbCommandTree commandTree);
///
/// Create a DbCommand object given a command tree.
///
/// command tree for the statement
/// a command object
internal virtual DbCommand CreateCommand(DbCommandTree commandTree) {
DbCommandDefinition commandDefinition = CreateCommandDefinition(commandTree);
DbCommand command = commandDefinition.CreateCommand();
return command;
}
///
/// Create the default DbCommandDefinition object based on the prototype command
/// This method is intended for provider writers to build a default command definition
/// from a command.
/// Note: This will clone the prototype
///
/// the prototype command
/// an executable command definition object
public virtual DbCommandDefinition CreateCommandDefinition(DbCommand prototype) {
return DbCommandDefinition.CreateCommandDefinition(prototype);
}
///
/// Retrieve the provider manifest token based on the specified connection.
///
/// The connection for which the provider manifest token should be retrieved.
///
/// The provider manifest token that describes the specified connection, as determined by the provider.
///
///
/// This method simply delegates to the provider's implementation of GetDbProviderManifestToken.
///
public string GetProviderManifestToken(DbConnection connection) {
try
{
string providerManifestToken = GetDbProviderManifestToken(connection);
if (providerManifestToken == null)
{
throw EntityUtil.ProviderIncompatible(Strings.ProviderDidNotReturnAProviderManifestToken);
}
return providerManifestToken;
}
catch (ProviderIncompatibleException)
{
throw;
}
catch (Exception e)
{
if (EntityUtil.IsCatchableExceptionType(e))
{
throw EntityUtil.ProviderIncompatible(Strings.ProviderDidNotReturnAProviderManifestToken, e);
}
throw;
}
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "Db")]
protected abstract string GetDbProviderManifestToken(DbConnection connection);
public DbProviderManifest GetProviderManifest(string manifestToken) {
try
{
DbProviderManifest providerManifest = GetDbProviderManifest(manifestToken);
if (providerManifest == null)
{
throw EntityUtil.ProviderIncompatible(Strings.ProviderDidNotReturnAProviderManifest);
}
return providerManifest;
}
catch (ProviderIncompatibleException)
{
throw;
}
catch (Exception e)
{
if (EntityUtil.IsCatchableExceptionType(e)) {
throw EntityUtil.ProviderIncompatible(System.Data.Entity.Strings.ProviderDidNotReturnAProviderManifest, e);
}
throw;
}
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "Db")]
protected abstract DbProviderManifest GetDbProviderManifest(string manifestToken);
///
/// Create an instance of DbProviderServices based on the supplied DbConnection
///
/// The DbConnection to use
/// An instance of DbProviderServices
public static DbProviderServices GetProviderServices(DbConnection connection) {
return GetProviderServices(GetProviderFactory(connection));
}
internal static DbProviderFactory GetProviderFactory(string providerInvariantName)
{
EntityUtil.CheckArgumentNull(providerInvariantName, "providerInvariantName");
DbProviderFactory factory;
try
{
factory = DbProviderFactories.GetFactory(providerInvariantName);
}
catch (ArgumentException e)
{
throw EntityUtil.Argument(Strings.EntityClient_InvalidStoreProvider, e);
}
return factory;
}
internal static DbProviderFactory GetProviderFactory(DbConnection connection)
{
EntityUtil.CheckArgumentNull(connection, "connection");
DbProviderFactory factory = connection.ProviderFactory;
if (factory == null)
{
throw EntityUtil.ProviderIncompatible(
System.Data.Entity.Strings.EntityClient_ReturnedNullOnProviderMethod(
"get_ProviderFactory",
connection.GetType().ToString()));
}
return factory;
}
internal static DbProviderServices GetProviderServices(DbProviderFactory factory) {
EntityUtil.CheckArgumentNull(factory, "factory");
IServiceProvider serviceProvider = factory as IServiceProvider;
if (serviceProvider == null) {
throw EntityUtil.ProviderIncompatible(System.Data.Entity.Strings.EntityClient_DoesNotImplementIServiceProvider(
factory.GetType().ToString()));
}
DbProviderServices providerServices = serviceProvider.GetService(typeof(DbProviderServices)) as DbProviderServices;
if (providerServices == null) {
throw EntityUtil.ProviderIncompatible(
System.Data.Entity.Strings.EntityClient_ReturnedNullOnProviderMethod(
"GetService",
factory.GetType().ToString()));
}
return providerServices;
}
///
/// Return an XML reader which represents the CSDL description
///
/// An XmlReader that represents the CSDL description
internal static XmlReader GetConceptualSchemaDescription() {
return DbProviderServices.GetXmlResource("System.Data.Resources.DbProviderServices.ConceptualSchemaDefinition.csdl");
}
internal static XmlReader GetXmlResource(string resourceName) {
Assembly executingAssembly = Assembly.GetExecutingAssembly();
Stream stream = executingAssembly.GetManifestResourceStream(resourceName);
return XmlReader.Create(stream, null, resourceName);
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// @owner [....], [....]
//-----------------------------------------------------------------------------
namespace System.Data.Common
{
using System.Collections.Generic;
using System.Data.Common.CommandTrees;
using System.Data.Metadata.Edm;
using System.Xml;
using System.Reflection;
using System.IO;
using System.Data.Entity;
using System.Diagnostics;
///
/// The factory for building command definitions; use the type of this object
/// as the argument to the IServiceProvider.GetService method on the provider
/// factory;
///
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "Db")]
abstract public class DbProviderServices
{
///
/// Create a Command Definition object given a command tree.
///
/// command tree for the statement
/// an exectable command definition object
///
/// This method simply delegates to the provider's implementation of CreateDbCommandDefinition.
///
public DbCommandDefinition CreateCommandDefinition(DbCommandTree commandTree)
{
EntityUtil.CheckArgumentNull(commandTree, "commandTree");
StoreItemCollection storeMetadata = (StoreItemCollection)commandTree.MetadataWorkspace.GetItemCollection(DataSpace.SSpace);
Debug.Assert(storeMetadata.StoreProviderManifest != null, "StoreItemCollection has null StoreProviderManifest?");
return CreateDbCommandDefinition(storeMetadata.StoreProviderManifest, commandTree);
}
///
/// Create a Command Definition object, given the provider manifest and command tree
///
/// provider manifest previously retrieved from the store provider
/// command tree for the statement
/// an exectable command definition object
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "Db")]
protected abstract DbCommandDefinition CreateDbCommandDefinition(DbProviderManifest providerManifest, DbCommandTree commandTree);
///
/// Create a DbCommand object given a command tree.
///
/// command tree for the statement
/// a command object
internal virtual DbCommand CreateCommand(DbCommandTree commandTree) {
DbCommandDefinition commandDefinition = CreateCommandDefinition(commandTree);
DbCommand command = commandDefinition.CreateCommand();
return command;
}
///
/// Create the default DbCommandDefinition object based on the prototype command
/// This method is intended for provider writers to build a default command definition
/// from a command.
/// Note: This will clone the prototype
///
/// the prototype command
/// an executable command definition object
public virtual DbCommandDefinition CreateCommandDefinition(DbCommand prototype) {
return DbCommandDefinition.CreateCommandDefinition(prototype);
}
///
/// Retrieve the provider manifest token based on the specified connection.
///
/// The connection for which the provider manifest token should be retrieved.
///
/// The provider manifest token that describes the specified connection, as determined by the provider.
///
///
/// This method simply delegates to the provider's implementation of GetDbProviderManifestToken.
///
public string GetProviderManifestToken(DbConnection connection) {
try
{
string providerManifestToken = GetDbProviderManifestToken(connection);
if (providerManifestToken == null)
{
throw EntityUtil.ProviderIncompatible(Strings.ProviderDidNotReturnAProviderManifestToken);
}
return providerManifestToken;
}
catch (ProviderIncompatibleException)
{
throw;
}
catch (Exception e)
{
if (EntityUtil.IsCatchableExceptionType(e))
{
throw EntityUtil.ProviderIncompatible(Strings.ProviderDidNotReturnAProviderManifestToken, e);
}
throw;
}
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "Db")]
protected abstract string GetDbProviderManifestToken(DbConnection connection);
public DbProviderManifest GetProviderManifest(string manifestToken) {
try
{
DbProviderManifest providerManifest = GetDbProviderManifest(manifestToken);
if (providerManifest == null)
{
throw EntityUtil.ProviderIncompatible(Strings.ProviderDidNotReturnAProviderManifest);
}
return providerManifest;
}
catch (ProviderIncompatibleException)
{
throw;
}
catch (Exception e)
{
if (EntityUtil.IsCatchableExceptionType(e)) {
throw EntityUtil.ProviderIncompatible(System.Data.Entity.Strings.ProviderDidNotReturnAProviderManifest, e);
}
throw;
}
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "Db")]
protected abstract DbProviderManifest GetDbProviderManifest(string manifestToken);
///
/// Create an instance of DbProviderServices based on the supplied DbConnection
///
/// The DbConnection to use
/// An instance of DbProviderServices
public static DbProviderServices GetProviderServices(DbConnection connection) {
return GetProviderServices(GetProviderFactory(connection));
}
internal static DbProviderFactory GetProviderFactory(string providerInvariantName)
{
EntityUtil.CheckArgumentNull(providerInvariantName, "providerInvariantName");
DbProviderFactory factory;
try
{
factory = DbProviderFactories.GetFactory(providerInvariantName);
}
catch (ArgumentException e)
{
throw EntityUtil.Argument(Strings.EntityClient_InvalidStoreProvider, e);
}
return factory;
}
internal static DbProviderFactory GetProviderFactory(DbConnection connection)
{
EntityUtil.CheckArgumentNull(connection, "connection");
DbProviderFactory factory = connection.ProviderFactory;
if (factory == null)
{
throw EntityUtil.ProviderIncompatible(
System.Data.Entity.Strings.EntityClient_ReturnedNullOnProviderMethod(
"get_ProviderFactory",
connection.GetType().ToString()));
}
return factory;
}
internal static DbProviderServices GetProviderServices(DbProviderFactory factory) {
EntityUtil.CheckArgumentNull(factory, "factory");
IServiceProvider serviceProvider = factory as IServiceProvider;
if (serviceProvider == null) {
throw EntityUtil.ProviderIncompatible(System.Data.Entity.Strings.EntityClient_DoesNotImplementIServiceProvider(
factory.GetType().ToString()));
}
DbProviderServices providerServices = serviceProvider.GetService(typeof(DbProviderServices)) as DbProviderServices;
if (providerServices == null) {
throw EntityUtil.ProviderIncompatible(
System.Data.Entity.Strings.EntityClient_ReturnedNullOnProviderMethod(
"GetService",
factory.GetType().ToString()));
}
return providerServices;
}
///
/// Return an XML reader which represents the CSDL description
///
/// An XmlReader that represents the CSDL description
internal static XmlReader GetConceptualSchemaDescription() {
return DbProviderServices.GetXmlResource("System.Data.Resources.DbProviderServices.ConceptualSchemaDefinition.csdl");
}
internal static XmlReader GetXmlResource(string resourceName) {
Assembly executingAssembly = Assembly.GetExecutingAssembly();
Stream stream = executingAssembly.GetManifestResourceStream(resourceName);
return XmlReader.Create(stream, null, resourceName);
}
}
}
// 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
- CompatibleIComparer.cs
- Compiler.cs
- _Win32.cs
- NamedPermissionSet.cs
- RelatedPropertyManager.cs
- RegexCompilationInfo.cs
- AbandonedMutexException.cs
- HostingEnvironmentSection.cs
- CapiNative.cs
- InlineObject.cs
- GroupBox.cs
- TimeIntervalCollection.cs
- basecomparevalidator.cs
- SpellerStatusTable.cs
- XmlSerializationReader.cs
- Tokenizer.cs
- FontResourceCache.cs
- CqlQuery.cs
- XmlUnspecifiedAttribute.cs
- ToolStripMenuItemCodeDomSerializer.cs
- DelayedRegex.cs
- InputBuffer.cs
- OutputScope.cs
- Attribute.cs
- HWStack.cs
- XmlHelper.cs
- OdbcHandle.cs
- KeyEvent.cs
- DbDataSourceEnumerator.cs
- PathGeometry.cs
- WebPartTransformerCollection.cs
- AttachedPropertyMethodSelector.cs
- SqlBuffer.cs
- LogicalExpr.cs
- StyleHelper.cs
- LayoutTable.cs
- SynchronizedDispatch.cs
- AutoSizeComboBox.cs
- DbgUtil.cs
- PackWebResponse.cs
- SmiTypedGetterSetter.cs
- ResourcesBuildProvider.cs
- DisplayNameAttribute.cs
- NamedPipeTransportManager.cs
- DataTableReaderListener.cs
- AppSettingsReader.cs
- Lease.cs
- CreateInstanceBinder.cs
- HttpCapabilitiesSectionHandler.cs
- SafeNativeMethods.cs
- LeaseManager.cs
- EdgeModeValidation.cs
- OutputScopeManager.cs
- UniqueTransportManagerRegistration.cs
- WindowsToolbarItemAsMenuItem.cs
- ColumnCollection.cs
- ZipIOLocalFileHeader.cs
- SerTrace.cs
- WebPartConnectionsEventArgs.cs
- EdgeProfileValidation.cs
- DeclarativeCatalogPart.cs
- KeyMatchBuilder.cs
- RecordsAffectedEventArgs.cs
- BoundsDrawingContextWalker.cs
- HttpProfileBase.cs
- SiblingIterators.cs
- OledbConnectionStringbuilder.cs
- ChildrenQuery.cs
- ImageAttributes.cs
- RectConverter.cs
- ELinqQueryState.cs
- MethodBuilderInstantiation.cs
- MetricEntry.cs
- _LoggingObject.cs
- SubMenuStyleCollection.cs
- COM2ColorConverter.cs
- SiteMapNodeItem.cs
- DataGridViewEditingControlShowingEventArgs.cs
- ShapingWorkspace.cs
- DataTemplateSelector.cs
- FontStyle.cs
- metadatamappinghashervisitor.hashsourcebuilder.cs
- XmlSchemaExternal.cs
- XsdValidatingReader.cs
- MaskedTextBoxDesigner.cs
- MouseEvent.cs
- LayoutSettings.cs
- CodeTryCatchFinallyStatement.cs
- UpdateCompiler.cs
- DocumentStream.cs
- XamlInt32CollectionSerializer.cs
- CodeTypeMember.cs
- WebPartConnectionsCloseVerb.cs
- GeometryGroup.cs
- GacUtil.cs
- Graphics.cs
- SourceElementsCollection.cs
- PageHandlerFactory.cs
- Memoizer.cs
- EtwTrace.cs