Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / xsp / System / Web / Util / HashCodeCombiner.cs / 1305376 / HashCodeCombiner.cs
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
/*
* HashCodeCombiner class
*
* Copyright (c) 1999 Microsoft Corporation
*/
namespace System.Web.Util {
using System.Text;
using System.Collections;
using System.IO;
using System.Globalization;
/*
* Class used to combine several hashcodes into a single hashcode
*/
internal class HashCodeCombiner {
private long _combinedHash;
internal HashCodeCombiner() {
// Start with a seed (obtained from String.GetHashCode implementation)
_combinedHash = 5381;
}
internal HashCodeCombiner(long initialCombinedHash) {
_combinedHash = initialCombinedHash;
}
internal static int CombineHashCodes(int h1, int h2) {
return ((h1 << 5) + h1) ^ h2;
}
internal static int CombineHashCodes(int h1, int h2, int h3) {
return CombineHashCodes(CombineHashCodes(h1, h2), h3);
}
internal static int CombineHashCodes(int h1, int h2, int h3, int h4) {
return CombineHashCodes(CombineHashCodes(h1, h2), CombineHashCodes(h3, h4));
}
internal static int CombineHashCodes(int h1, int h2, int h3, int h4, int h5) {
return CombineHashCodes(CombineHashCodes(h1, h2, h3, h4), h5);
}
internal static string GetDirectoryHash(VirtualPath virtualDir) {
HashCodeCombiner hashCodeCombiner = new HashCodeCombiner();
hashCodeCombiner.AddDirectory(virtualDir.MapPathInternal());
return hashCodeCombiner.CombinedHashString;
}
internal void AddArray(string[] a) {
if (a != null) {
int n = a.Length;
for (int i = 0; i < n; i++) {
AddObject(a[i]);
}
}
}
internal void AddInt(int n) {
_combinedHash = ((_combinedHash << 5) + _combinedHash) ^ n;
Debug.Trace("HashCodeCombiner", "Adding " + n.ToString("x") + " --> " + _combinedHash.ToString("x"));
}
internal void AddObject(int n) {
AddInt(n);
}
internal void AddObject(byte b) {
AddInt(b.GetHashCode());
}
internal void AddObject(long l) {
AddInt(l.GetHashCode());
}
internal void AddObject(bool b) {
AddInt(b.GetHashCode());
}
internal void AddObject(string s) {
if (s != null)
AddInt(StringUtil.GetStringHashCode(s));
}
internal void AddObject(Type t) {
if (t != null)
AddObject(System.Web.UI.Util.GetAssemblyQualifiedTypeName(t));
}
internal void AddObject(object o) {
if (o != null)
AddInt(o.GetHashCode());
}
internal void AddCaseInsensitiveString(string s) {
if (s != null)
AddInt((StringComparer.InvariantCultureIgnoreCase).GetHashCode(s));
}
internal void AddDateTime(DateTime dt) {
Debug.Trace("HashCodeCombiner", "Ticks: " + dt.Ticks.ToString("x"));
Debug.Trace("HashCodeCombiner", "Hashcode: " + dt.GetHashCode().ToString("x"));
AddInt(dt.GetHashCode());
}
private void AddFileSize(long fileSize) {
Debug.Trace("HashCodeCombiner", "file size: " + fileSize.ToString("x"));
Debug.Trace("HashCodeCombiner", "Hashcode: " + fileSize.GetHashCode().ToString("x"));
AddInt(fileSize.GetHashCode());
}
internal void AddFile(string fileName) {
Debug.Trace("HashCodeCombiner", "AddFile: " + fileName);
if (!FileUtil.FileExists(fileName)) {
// Review: Should we change the dependency model to take directory into account?
if (FileUtil.DirectoryExists(fileName)) {
// Add as a directory dependency if it's a directory.
AddDirectory(fileName);
return;
}
Debug.Trace("HashCodeCombiner", "Could not find target " + fileName);
return;
}
AddExistingFile(fileName);
}
// Same as AddFile, but only called for a file which is known to exist
private void AddExistingFile(string fileName) {
Debug.Trace("HashCodeCombiner", "AddExistingFile: " + fileName);
Debug.Assert(FileUtil.FileExists(fileName));
AddInt(StringUtil.GetStringHashCode(fileName));
FileInfo file = new FileInfo(fileName);
AddDateTime(file.CreationTimeUtc);
AddDateTime(file.LastWriteTimeUtc);
AddFileSize(file.Length);
}
internal void AddDirectory(string directoryName) {
DirectoryInfo directory = new DirectoryInfo(directoryName);
if (!directory.Exists) {
return;
}
AddObject(directoryName);
// Go through all the files in the directory
foreach (FileData fileData in FileEnumerator.Create(directoryName)) {
if (fileData.IsDirectory)
AddDirectory(fileData.FullName);
else
AddExistingFile(fileData.FullName);
}
AddDateTime(directory.CreationTimeUtc);
AddDateTime(directory.LastWriteTimeUtc);
}
// Same as AddDirectory, but only look at files that don't have a culture
internal void AddResourcesDirectory(string directoryName) {
DirectoryInfo directory = new DirectoryInfo(directoryName);
if (!directory.Exists) {
return;
}
AddObject(directoryName);
// Go through all the files in the directory
foreach (FileData fileData in FileEnumerator.Create(directoryName)) {
if (fileData.IsDirectory)
AddResourcesDirectory(fileData.FullName);
else {
// Ignore the file if it has a culture, since only neutral files
// need to re-trigger compilation (VSWhidbey 359029)
string fullPath = fileData.FullName;
if (System.Web.UI.Util.GetCultureName(fullPath) == null) {
AddExistingFile(fullPath);
}
}
}
AddDateTime(directory.CreationTimeUtc);
}
internal long CombinedHash { get { return _combinedHash; } }
internal int CombinedHash32 { get { return _combinedHash.GetHashCode(); } }
internal string CombinedHashString {
get {
return _combinedHash.ToString("x", CultureInfo.InvariantCulture);
}
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
/*
* HashCodeCombiner class
*
* Copyright (c) 1999 Microsoft Corporation
*/
namespace System.Web.Util {
using System.Text;
using System.Collections;
using System.IO;
using System.Globalization;
/*
* Class used to combine several hashcodes into a single hashcode
*/
internal class HashCodeCombiner {
private long _combinedHash;
internal HashCodeCombiner() {
// Start with a seed (obtained from String.GetHashCode implementation)
_combinedHash = 5381;
}
internal HashCodeCombiner(long initialCombinedHash) {
_combinedHash = initialCombinedHash;
}
internal static int CombineHashCodes(int h1, int h2) {
return ((h1 << 5) + h1) ^ h2;
}
internal static int CombineHashCodes(int h1, int h2, int h3) {
return CombineHashCodes(CombineHashCodes(h1, h2), h3);
}
internal static int CombineHashCodes(int h1, int h2, int h3, int h4) {
return CombineHashCodes(CombineHashCodes(h1, h2), CombineHashCodes(h3, h4));
}
internal static int CombineHashCodes(int h1, int h2, int h3, int h4, int h5) {
return CombineHashCodes(CombineHashCodes(h1, h2, h3, h4), h5);
}
internal static string GetDirectoryHash(VirtualPath virtualDir) {
HashCodeCombiner hashCodeCombiner = new HashCodeCombiner();
hashCodeCombiner.AddDirectory(virtualDir.MapPathInternal());
return hashCodeCombiner.CombinedHashString;
}
internal void AddArray(string[] a) {
if (a != null) {
int n = a.Length;
for (int i = 0; i < n; i++) {
AddObject(a[i]);
}
}
}
internal void AddInt(int n) {
_combinedHash = ((_combinedHash << 5) + _combinedHash) ^ n;
Debug.Trace("HashCodeCombiner", "Adding " + n.ToString("x") + " --> " + _combinedHash.ToString("x"));
}
internal void AddObject(int n) {
AddInt(n);
}
internal void AddObject(byte b) {
AddInt(b.GetHashCode());
}
internal void AddObject(long l) {
AddInt(l.GetHashCode());
}
internal void AddObject(bool b) {
AddInt(b.GetHashCode());
}
internal void AddObject(string s) {
if (s != null)
AddInt(StringUtil.GetStringHashCode(s));
}
internal void AddObject(Type t) {
if (t != null)
AddObject(System.Web.UI.Util.GetAssemblyQualifiedTypeName(t));
}
internal void AddObject(object o) {
if (o != null)
AddInt(o.GetHashCode());
}
internal void AddCaseInsensitiveString(string s) {
if (s != null)
AddInt((StringComparer.InvariantCultureIgnoreCase).GetHashCode(s));
}
internal void AddDateTime(DateTime dt) {
Debug.Trace("HashCodeCombiner", "Ticks: " + dt.Ticks.ToString("x"));
Debug.Trace("HashCodeCombiner", "Hashcode: " + dt.GetHashCode().ToString("x"));
AddInt(dt.GetHashCode());
}
private void AddFileSize(long fileSize) {
Debug.Trace("HashCodeCombiner", "file size: " + fileSize.ToString("x"));
Debug.Trace("HashCodeCombiner", "Hashcode: " + fileSize.GetHashCode().ToString("x"));
AddInt(fileSize.GetHashCode());
}
internal void AddFile(string fileName) {
Debug.Trace("HashCodeCombiner", "AddFile: " + fileName);
if (!FileUtil.FileExists(fileName)) {
// Review: Should we change the dependency model to take directory into account?
if (FileUtil.DirectoryExists(fileName)) {
// Add as a directory dependency if it's a directory.
AddDirectory(fileName);
return;
}
Debug.Trace("HashCodeCombiner", "Could not find target " + fileName);
return;
}
AddExistingFile(fileName);
}
// Same as AddFile, but only called for a file which is known to exist
private void AddExistingFile(string fileName) {
Debug.Trace("HashCodeCombiner", "AddExistingFile: " + fileName);
Debug.Assert(FileUtil.FileExists(fileName));
AddInt(StringUtil.GetStringHashCode(fileName));
FileInfo file = new FileInfo(fileName);
AddDateTime(file.CreationTimeUtc);
AddDateTime(file.LastWriteTimeUtc);
AddFileSize(file.Length);
}
internal void AddDirectory(string directoryName) {
DirectoryInfo directory = new DirectoryInfo(directoryName);
if (!directory.Exists) {
return;
}
AddObject(directoryName);
// Go through all the files in the directory
foreach (FileData fileData in FileEnumerator.Create(directoryName)) {
if (fileData.IsDirectory)
AddDirectory(fileData.FullName);
else
AddExistingFile(fileData.FullName);
}
AddDateTime(directory.CreationTimeUtc);
AddDateTime(directory.LastWriteTimeUtc);
}
// Same as AddDirectory, but only look at files that don't have a culture
internal void AddResourcesDirectory(string directoryName) {
DirectoryInfo directory = new DirectoryInfo(directoryName);
if (!directory.Exists) {
return;
}
AddObject(directoryName);
// Go through all the files in the directory
foreach (FileData fileData in FileEnumerator.Create(directoryName)) {
if (fileData.IsDirectory)
AddResourcesDirectory(fileData.FullName);
else {
// Ignore the file if it has a culture, since only neutral files
// need to re-trigger compilation (VSWhidbey 359029)
string fullPath = fileData.FullName;
if (System.Web.UI.Util.GetCultureName(fullPath) == null) {
AddExistingFile(fullPath);
}
}
}
AddDateTime(directory.CreationTimeUtc);
}
internal long CombinedHash { get { return _combinedHash; } }
internal int CombinedHash32 { get { return _combinedHash.GetHashCode(); } }
internal string CombinedHashString {
get {
return _combinedHash.ToString("x", CultureInfo.InvariantCulture);
}
}
}
}
// 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
- COAUTHINFO.cs
- NameValueConfigurationCollection.cs
- ImageList.cs
- TraceHandlerErrorFormatter.cs
- SiteMembershipCondition.cs
- LocalFileSettingsProvider.cs
- CFStream.cs
- XamlClipboardData.cs
- ApplyImportsAction.cs
- coordinatorfactory.cs
- MemberProjectedSlot.cs
- Size3D.cs
- HandlerBase.cs
- UmAlQuraCalendar.cs
- SmtpException.cs
- StickyNoteContentControl.cs
- HtmlMobileTextWriter.cs
- Binding.cs
- StaticContext.cs
- ConnectionConsumerAttribute.cs
- CanonicalFormWriter.cs
- FixedSchema.cs
- ArgIterator.cs
- EntityViewGenerationConstants.cs
- MediaContext.cs
- CallContext.cs
- OptimalBreakSession.cs
- XdrBuilder.cs
- AuthorizationRuleCollection.cs
- SQLStringStorage.cs
- ToolTipAutomationPeer.cs
- XmlSchemaSubstitutionGroup.cs
- ValidatingReaderNodeData.cs
- MarkupCompilePass2.cs
- TransactionProxy.cs
- CrossSiteScriptingValidation.cs
- ToolBarPanel.cs
- UrlEncodedParameterWriter.cs
- XmlLoader.cs
- CodeTypeReferenceCollection.cs
- MailHeaderInfo.cs
- ExpressionBuilderContext.cs
- StateItem.cs
- PipeStream.cs
- DocumentOutline.cs
- OrderedDictionaryStateHelper.cs
- TraceXPathNavigator.cs
- SessionConnectionReader.cs
- Resources.Designer.cs
- RSAOAEPKeyExchangeDeformatter.cs
- ImageIndexConverter.cs
- ParallelLoopState.cs
- TextBoxBaseDesigner.cs
- AppDomainManager.cs
- OdbcStatementHandle.cs
- NotifyCollectionChangedEventArgs.cs
- WS2007HttpBindingCollectionElement.cs
- WeakReferenceList.cs
- PocoPropertyAccessorStrategy.cs
- ObjectDataSourceDisposingEventArgs.cs
- DataGridColumnCollection.cs
- TimelineCollection.cs
- Number.cs
- CommandManager.cs
- SponsorHelper.cs
- AuthenticationServiceManager.cs
- WasAdminWrapper.cs
- Cursor.cs
- HwndHostAutomationPeer.cs
- RichTextBox.cs
- TrackingRecord.cs
- RuntimeConfig.cs
- CreateUserWizardStep.cs
- Document.cs
- QueryResult.cs
- List.cs
- MediaContext.cs
- XmlSerializationGeneratedCode.cs
- ActivityValidator.cs
- OleDbSchemaGuid.cs
- EasingKeyFrames.cs
- DynamicRendererThreadManager.cs
- _AutoWebProxyScriptEngine.cs
- InkCanvasAutomationPeer.cs
- DependsOnAttribute.cs
- DocumentationServerProtocol.cs
- Package.cs
- TriggerActionCollection.cs
- ConfigurationFileMap.cs
- StaticResourceExtension.cs
- DefaultParameterValueAttribute.cs
- PerfCounters.cs
- WebPartMenuStyle.cs
- Rect.cs
- PersonalizationStateInfoCollection.cs
- HitTestParameters3D.cs
- wgx_commands.cs
- EntityCommandCompilationException.cs
- ColorConvertedBitmap.cs
- CroppedBitmap.cs