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 / QueryCache / EntityClientCacheKey.cs / 1 / EntityClientCacheKey.cs
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// @owner [....], [....]
//-----------------------------------------------------------------------------
namespace System.Data.Common.QueryCache
{
using System;
using System.Collections.Generic;
using System.Text;
using System.Data.EntityClient;
using System.Globalization;
using System.Diagnostics;
using System.Data.Metadata.Edm;
///
/// Represents EntityCommand Cache key context
///
internal sealed class EntityClientCacheKey : QueryCacheKey
{
///
/// Stored procedure or command text?
///
readonly CommandType _commandType;
///
/// Entity Sql statement
///
readonly string _eSqlStatement;
///
/// parameter collection token
///
readonly string _parametersToken;
///
/// number of parameters
///
readonly int _parameterCount;
///
/// Combined Hashcode based on component hashcodes
///
readonly int _hashCode;
///
/// Creates a new instance of EntityClientCacheKey given a entityCommand instance
///
///
internal EntityClientCacheKey(EntityCommand entityCommand)
: base()
{
// Command Type
_commandType = entityCommand.CommandType;
// Statement
_eSqlStatement = entityCommand.CommandText;
// Parameters
_parametersToken = GetParametersToken(entityCommand);
_parameterCount = entityCommand.Parameters.Count;
// Hashcode
_hashCode = _commandType.GetHashCode() ^
_eSqlStatement.GetHashCode() ^
_parametersToken.GetHashCode();
}
///
/// determines equality of two cache keys based on cache context values
///
///
///
public override bool Equals( object otherObject )
{
Debug.Assert(null != otherObject, "otherObject must not be null");
if (typeof(EntityClientCacheKey) != otherObject.GetType())
{
return false;
}
EntityClientCacheKey otherEntityClientCacheKey = (EntityClientCacheKey)otherObject;
return (_commandType == otherEntityClientCacheKey._commandType &&
_parameterCount == otherEntityClientCacheKey._parameterCount) &&
Equals(otherEntityClientCacheKey._eSqlStatement, _eSqlStatement) &&
Equals(otherEntityClientCacheKey._parametersToken, _parametersToken);
}
///
/// Returns Context Hash Code
///
///
public override int GetHashCode()
{
return _hashCode;
}
///
/// Returns a string representation of the parameter list
///
///
///
private static string GetParametersToken(EntityCommand entityCommand)
{
if (null == entityCommand.Parameters || 0 == entityCommand.Parameters.Count)
{
//
// means no parameters
//
return "@@0";
}
else if (1 == entityCommand.Parameters.Count)
{
// if its one parameter only, there is no need to use stringbuilder
Dictionary paramTypeUsage = entityCommand.GetParameterTypeUsage();
Debug.Assert(paramTypeUsage.Count == entityCommand.Parameters.Count, "entityParameter collection and query parameter collection must have the same number of entries");
return "@@1:" +
entityCommand.Parameters[0].ParameterName + ":" +
paramTypeUsage[entityCommand.Parameters[0].ParameterName].EdmType.FullName;
}
else
{
StringBuilder sb = new StringBuilder(entityCommand.Parameters.Count * EstimatedParameterStringSize);
Dictionary paramTypeUsage = entityCommand.GetParameterTypeUsage();
Debug.Assert(paramTypeUsage.Count == entityCommand.Parameters.Count, "entityParameter collection and query parameter collection must have the same number of entries");
sb.Append("@@");
sb.Append(entityCommand.Parameters.Count);
sb.Append(":");
string separator = "";
foreach (KeyValuePair param in paramTypeUsage)
{
sb.Append(separator);
sb.Append(param.Key);
sb.Append(":");
sb.Append(param.Value.EdmType.FullName);
separator = ";";
}
return sb.ToString();
}
}
///
/// returns the composed cache key
///
///
public override string ToString()
{
return String.Join("|", new string[] { Enum.GetName(typeof(CommandType), _commandType), _eSqlStatement, _parametersToken });
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// @owner [....], [....]
//-----------------------------------------------------------------------------
namespace System.Data.Common.QueryCache
{
using System;
using System.Collections.Generic;
using System.Text;
using System.Data.EntityClient;
using System.Globalization;
using System.Diagnostics;
using System.Data.Metadata.Edm;
///
/// Represents EntityCommand Cache key context
///
internal sealed class EntityClientCacheKey : QueryCacheKey
{
///
/// Stored procedure or command text?
///
readonly CommandType _commandType;
///
/// Entity Sql statement
///
readonly string _eSqlStatement;
///
/// parameter collection token
///
readonly string _parametersToken;
///
/// number of parameters
///
readonly int _parameterCount;
///
/// Combined Hashcode based on component hashcodes
///
readonly int _hashCode;
///
/// Creates a new instance of EntityClientCacheKey given a entityCommand instance
///
///
internal EntityClientCacheKey(EntityCommand entityCommand)
: base()
{
// Command Type
_commandType = entityCommand.CommandType;
// Statement
_eSqlStatement = entityCommand.CommandText;
// Parameters
_parametersToken = GetParametersToken(entityCommand);
_parameterCount = entityCommand.Parameters.Count;
// Hashcode
_hashCode = _commandType.GetHashCode() ^
_eSqlStatement.GetHashCode() ^
_parametersToken.GetHashCode();
}
///
/// determines equality of two cache keys based on cache context values
///
///
///
public override bool Equals( object otherObject )
{
Debug.Assert(null != otherObject, "otherObject must not be null");
if (typeof(EntityClientCacheKey) != otherObject.GetType())
{
return false;
}
EntityClientCacheKey otherEntityClientCacheKey = (EntityClientCacheKey)otherObject;
return (_commandType == otherEntityClientCacheKey._commandType &&
_parameterCount == otherEntityClientCacheKey._parameterCount) &&
Equals(otherEntityClientCacheKey._eSqlStatement, _eSqlStatement) &&
Equals(otherEntityClientCacheKey._parametersToken, _parametersToken);
}
///
/// Returns Context Hash Code
///
///
public override int GetHashCode()
{
return _hashCode;
}
///
/// Returns a string representation of the parameter list
///
///
///
private static string GetParametersToken(EntityCommand entityCommand)
{
if (null == entityCommand.Parameters || 0 == entityCommand.Parameters.Count)
{
//
// means no parameters
//
return "@@0";
}
else if (1 == entityCommand.Parameters.Count)
{
// if its one parameter only, there is no need to use stringbuilder
Dictionary paramTypeUsage = entityCommand.GetParameterTypeUsage();
Debug.Assert(paramTypeUsage.Count == entityCommand.Parameters.Count, "entityParameter collection and query parameter collection must have the same number of entries");
return "@@1:" +
entityCommand.Parameters[0].ParameterName + ":" +
paramTypeUsage[entityCommand.Parameters[0].ParameterName].EdmType.FullName;
}
else
{
StringBuilder sb = new StringBuilder(entityCommand.Parameters.Count * EstimatedParameterStringSize);
Dictionary paramTypeUsage = entityCommand.GetParameterTypeUsage();
Debug.Assert(paramTypeUsage.Count == entityCommand.Parameters.Count, "entityParameter collection and query parameter collection must have the same number of entries");
sb.Append("@@");
sb.Append(entityCommand.Parameters.Count);
sb.Append(":");
string separator = "";
foreach (KeyValuePair param in paramTypeUsage)
{
sb.Append(separator);
sb.Append(param.Key);
sb.Append(":");
sb.Append(param.Value.EdmType.FullName);
separator = ";";
}
return sb.ToString();
}
}
///
/// returns the composed cache key
///
///
public override string ToString()
{
return String.Join("|", new string[] { Enum.GetName(typeof(CommandType), _commandType), _eSqlStatement, _parametersToken });
}
}
}
// 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
- RequestQueue.cs
- CompressEmulationStream.cs
- ContainsRowNumberChecker.cs
- DesignerMetadata.cs
- ReadOnlyCollectionBuilder.cs
- FlowchartSizeFeature.cs
- XmlDictionaryReaderQuotas.cs
- CssTextWriter.cs
- DesignerTextWriter.cs
- SessionEndingEventArgs.cs
- HttpHostedTransportConfiguration.cs
- TcpClientCredentialType.cs
- TimeSpanOrInfiniteConverter.cs
- _SslState.cs
- LessThanOrEqual.cs
- HandlerMappingMemo.cs
- RadioButtonPopupAdapter.cs
- IsolatedStorageFile.cs
- TypefaceCollection.cs
- TreeNodeStyle.cs
- MenuCommands.cs
- EraserBehavior.cs
- DecimalKeyFrameCollection.cs
- precedingsibling.cs
- FontWeightConverter.cs
- CounterSet.cs
- FontFamily.cs
- WebPartConnection.cs
- PlatformNotSupportedException.cs
- MarkupCompilePass2.cs
- selecteditemcollection.cs
- IndexedString.cs
- ServiceDeploymentInfo.cs
- AsyncPostBackTrigger.cs
- RSACryptoServiceProvider.cs
- WindowsClaimSet.cs
- FixedSOMContainer.cs
- XmlNamespaceDeclarationsAttribute.cs
- FragmentQuery.cs
- StringValueSerializer.cs
- FormatException.cs
- ProfileService.cs
- SQLMoneyStorage.cs
- ParagraphVisual.cs
- CodeIndexerExpression.cs
- XmlBinaryWriterSession.cs
- NativeRightsManagementAPIsStructures.cs
- User.cs
- RegexStringValidator.cs
- XmlJsonReader.cs
- XmlBinaryReader.cs
- SafeFileHandle.cs
- FixUp.cs
- DBDataPermissionAttribute.cs
- PrivateFontCollection.cs
- CryptoProvider.cs
- EntityContainerAssociationSet.cs
- TreeBuilder.cs
- HtmlImage.cs
- HtmlTableRowCollection.cs
- PartialList.cs
- ToolTip.cs
- CapabilitiesRule.cs
- ErrorHandler.cs
- ReleaseInstanceMode.cs
- WorkflowRuntime.cs
- ToolStripComboBox.cs
- CheckoutException.cs
- ArrayHelper.cs
- OperationPickerDialog.cs
- codemethodreferenceexpression.cs
- IPAddress.cs
- EntityStoreSchemaGenerator.cs
- UpdatePanel.cs
- AccessDataSource.cs
- DbConnectionPoolGroup.cs
- SqlFacetAttribute.cs
- NamespaceCollection.cs
- Brush.cs
- DataGridViewIntLinkedList.cs
- GridViewColumnHeaderAutomationPeer.cs
- BasicExpandProvider.cs
- RepeatButtonAutomationPeer.cs
- GridViewSortEventArgs.cs
- EndpointDiscoveryElement.cs
- CaseInsensitiveHashCodeProvider.cs
- OdbcFactory.cs
- EmbeddedMailObjectsCollection.cs
- PrinterUnitConvert.cs
- BulletDecorator.cs
- ToolTipService.cs
- NetCodeGroup.cs
- ErrorFormatterPage.cs
- RealProxy.cs
- PageCatalogPart.cs
- MutexSecurity.cs
- ReachVisualSerializerAsync.cs
- Pen.cs
- IHttpResponseInternal.cs
- PackageRelationship.cs