/// <summary>Serves as a hash function for a particular type.</summary> /// <returns>A hash code for the current Object.</returns> public override int GetHashCode() { string fullName = FullName; string name = Name; unchecked { int hash = Primes[_random]; if (!Utils.IsNullOrWhiteSpace(fullName)) { hash = hash * Primes[1] + fullName.GetHashCode(); } if (!Utils.IsNullOrWhiteSpace(name)) { hash = hash * Primes[1] + name.GetHashCode(); } hash = hash * Primes[1] + Attributes.GetHashCode(); hash = hash * Primes[1] + CreationTimeUtc.GetHashCode(); hash = hash * Primes[1] + LastWriteTimeUtc.GetHashCode(); return(hash); } }
public override void ReuseSha256s(IFile matching) { if (Name.Equals(matching.Name, StringComparison.Ordinal) && CreationTimeUtc.Equals(matching.CreationTimeUtc) && LastWriteTimeUtc.Equals(matching.LastWriteTimeUtc) && SizeBytes == matching.SizeBytes) { _Sha256 = matching.Sha256; } else { _Sha256 = null; } }
public override int GetHashCode() { unchecked { var hashCode = (BaseMap != null ? BaseMap.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (Name?.GetHashCode() ?? 0); hashCode = (hashCode * 397) ^ (Description?.GetHashCode() ?? 0); hashCode = (hashCode * 397) ^ (int)AccessControl; hashCode = (hashCode * 397) ^ (Links?.GetHashCode() ?? 0); hashCode = (hashCode * 397) ^ (CreationTimeUtc != null ? CreationTimeUtc.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (LastModifiedTimeUtc != null ? LastModifiedTimeUtc.GetHashCode() : 0); hashCode = (hashCode * 397) ^ Banned.GetHashCode(); hashCode = (hashCode * 397) ^ (Identity != null ? Identity.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (Stats != null ? Stats.GetHashCode() : 0); return(hashCode); } }
public override int GetHashCode() { unchecked { var hashCode = (int)AccessControl; hashCode = (hashCode * 397) ^ Banned.GetHashCode(); hashCode = (hashCode * 397) ^ (BaseGame != null ? BaseGame.GetHashCode() : 0); hashCode = (hashCode * 397) ^ BaseGameEngineType; hashCode = (hashCode * 397) ^ (CreationTimeUtc != null ? CreationTimeUtc.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (Description?.GetHashCode() ?? 0); hashCode = (hashCode * 397) ^ GameType; hashCode = (hashCode * 397) ^ (Identity != null ? Identity.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (LastModifiedTimeUtc != null ? LastModifiedTimeUtc.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (Links?.GetHashCode() ?? 0); hashCode = (hashCode * 397) ^ MatchDurationInSeconds; hashCode = (hashCode * 397) ^ (Name?.GetHashCode() ?? 0); hashCode = (hashCode * 397) ^ NumberOfLives; hashCode = (hashCode * 397) ^ NumberOfRounds; hashCode = (hashCode * 397) ^ ScoreToWin; hashCode = (hashCode * 397) ^ (Stats != null ? Stats.GetHashCode() : 0); return(hashCode); } }
internal void ValidateFreshness(TimeSpan timeToLive, TimeSpan allowedClockSkew) { DateTime now = DateTime.UtcNow; // check that the message has not expired if (ExpiryTimeUtc <= TimeoutHelper.Subtract(now, allowedClockSkew)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MessageSecurityException(SR.Format(SR.TimeStampHasExpiryTimeInPast, ExpiryTimeUtc.ToString(DefaultFormat, CultureInfo.CurrentCulture), now.ToString(DefaultFormat, CultureInfo.CurrentCulture), allowedClockSkew))); } // check that creation time is not in the future (modulo clock skew) if (CreationTimeUtc >= TimeoutHelper.Add(now, allowedClockSkew)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MessageSecurityException(SR.Format(SR.TimeStampHasCreationTimeInFuture, CreationTimeUtc.ToString(DefaultFormat, CultureInfo.CurrentCulture), now.ToString(DefaultFormat, CultureInfo.CurrentCulture), allowedClockSkew))); } // check that the creation time is not more than timeToLive in the past if (CreationTimeUtc <= TimeoutHelper.Subtract(now, TimeoutHelper.Add(timeToLive, allowedClockSkew))) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MessageSecurityException(SR.Format(SR.TimeStampWasCreatedTooLongAgo, CreationTimeUtc.ToString(DefaultFormat, CultureInfo.CurrentCulture), now.ToString(DefaultFormat, CultureInfo.CurrentCulture), timeToLive, allowedClockSkew))); } // this is a fresh timestamp }
/// <summary> /// Internal method that checks if the timestamp is fresh with respect to the /// timeToLive and allowedClockSkew values passed in. /// Throws if the timestamp is stale. /// </summary> /// <param name="timeToLive"></param> /// <param name="allowedClockSkew"></param> internal void ValidateRangeAndFreshness(TimeSpan timeToLive, TimeSpan allowedClockSkew) { // Check that the creation time is less than expiry time if (CreationTimeUtc >= ExpiryTimeUtc) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MessageSecurityException(SR.Format(SR.TimeStampHasCreationAheadOfExpiry, CreationTimeUtc.ToString(DefaultFormat, CultureInfo.CurrentCulture), ExpiryTimeUtc.ToString(DefaultFormat, CultureInfo.CurrentCulture)))); } ValidateFreshness(timeToLive, allowedClockSkew); }
public bool Equals(DuplicateFileModel other) { if (ReferenceEquals(null, other)) { return(false); } if (ReferenceEquals(this, other)) { return(true); } return(LastWriteTime.Equals(other.LastWriteTime) && LastAccessTimeUtc.Equals(other.LastAccessTimeUtc) && LastAccessTime.Equals(other.LastAccessTime) && CreationTimeUtc.Equals(other.CreationTimeUtc) && CreationTime.Equals(other.CreationTime) && LastWriteTimeUtc.Equals(other.LastWriteTimeUtc) && string.Equals(FullName, other.FullName) && string.Equals(Name, other.Name) && string.Equals(HashValue, other.HashValue) && string.Equals(UniqueIdHashValue, other.UniqueIdHashValue) && IsMaster == other.IsMaster && Equals(DuplicateFiles, other.DuplicateFiles) && FileSize == other.FileSize); }