Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / WCF / Log / System / IO / Log / SequenceNumber.cs / 1305376 / SequenceNumber.cs
//------------------------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------------------------- namespace System.IO.Log { // Add property for sequence number size using System; using System.Collections.Generic; [Serializable] public struct SequenceNumber : IComparable{ ulong sequenceNumberHigh; ulong sequenceNumberLow; public SequenceNumber(byte[] sequenceNumber) { if(sequenceNumber == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ArgumentNull("sequenceNumber")); } if ((sequenceNumber.Length != 8) && (sequenceNumber.Length != 16)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ArgumentInvalid(SR.Argument_SequenceNumberLength)); } this.sequenceNumberHigh = BitConverter.ToUInt64(sequenceNumber, 0); if (sequenceNumber.Length > 8) { this.sequenceNumberLow = BitConverter.ToUInt64(sequenceNumber, 8); } else { this.sequenceNumberLow = 0; } } internal SequenceNumber(ulong value) { this.sequenceNumberHigh = value; // Ensure that SequenceNumber.Invalid round-trips. // if (value == UInt64.MaxValue) { this.sequenceNumberLow = UInt64.MaxValue; } else { this.sequenceNumberLow = 0; } } internal SequenceNumber(ulong high, ulong low) { this.sequenceNumberHigh = high; this.sequenceNumberLow = low; } internal ulong High { get { return this.sequenceNumberHigh; } } internal ulong Low { get { return this.sequenceNumberLow; } } public static SequenceNumber Invalid { get { return new SequenceNumber(UInt64.MaxValue, UInt64.MaxValue); } } public static bool operator !=( SequenceNumber c1, SequenceNumber c2) { return (c1.CompareTo(c2) != 0); } public static bool operator <( SequenceNumber c1, SequenceNumber c2) { return (c1.CompareTo(c2) < 0); } public static bool operator <=(SequenceNumber c1, SequenceNumber c2) { return (c1.CompareTo(c2) <= 0); } public static bool operator ==( SequenceNumber c1, SequenceNumber c2) { return (c1.CompareTo(c2) == 0); } public static bool operator >( SequenceNumber c1, SequenceNumber c2) { return (c1.CompareTo(c2) > 0); } public static bool operator >=( SequenceNumber c1, SequenceNumber c2) { return (c1.CompareTo(c2) >= 0); } public int CompareTo(SequenceNumber other) { int result = this.sequenceNumberHigh.CompareTo(other.sequenceNumberHigh); if (result == 0) result = this.sequenceNumberLow.CompareTo(other.sequenceNumberLow); return result; } public bool Equals(SequenceNumber other) { return (this.CompareTo(other) == 0); } public override bool Equals(object other) { if (!(other is SequenceNumber)) return false; SequenceNumber otherSeq = (SequenceNumber)(other); return this.Equals(otherSeq); } public byte[] GetBytes() { byte[] bytes; if (this.sequenceNumberLow == 0) { bytes = new byte[8]; WriteUInt64(this.sequenceNumberHigh, bytes, 0); } else { bytes = new byte[16]; WriteUInt64(this.sequenceNumberHigh, bytes, 0); WriteUInt64(this.sequenceNumberLow, bytes, 8); } return bytes; } public override int GetHashCode() { return this.sequenceNumberHigh.GetHashCode() ^ this.sequenceNumberLow.GetHashCode(); } internal static void WriteUInt64(ulong value, byte[] bits, int offset) { bits[offset + 0] = (byte)((value >> 0) & 0xFF); bits[offset + 1] = (byte)((value >> 8) & 0xFF); bits[offset + 2] = (byte)((value >> 16) & 0xFF); bits[offset + 3] = (byte)((value >> 24) & 0xFF); bits[offset + 4] = (byte)((value >> 32) & 0xFF); bits[offset + 5] = (byte)((value >> 40) & 0xFF); bits[offset + 6] = (byte)((value >> 48) & 0xFF); bits[offset + 7] = (byte)((value >> 56) & 0xFF); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------------------------- namespace System.IO.Log { // Add property for sequence number size using System; using System.Collections.Generic; [Serializable] public struct SequenceNumber : IComparable { ulong sequenceNumberHigh; ulong sequenceNumberLow; public SequenceNumber(byte[] sequenceNumber) { if(sequenceNumber == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ArgumentNull("sequenceNumber")); } if ((sequenceNumber.Length != 8) && (sequenceNumber.Length != 16)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ArgumentInvalid(SR.Argument_SequenceNumberLength)); } this.sequenceNumberHigh = BitConverter.ToUInt64(sequenceNumber, 0); if (sequenceNumber.Length > 8) { this.sequenceNumberLow = BitConverter.ToUInt64(sequenceNumber, 8); } else { this.sequenceNumberLow = 0; } } internal SequenceNumber(ulong value) { this.sequenceNumberHigh = value; // Ensure that SequenceNumber.Invalid round-trips. // if (value == UInt64.MaxValue) { this.sequenceNumberLow = UInt64.MaxValue; } else { this.sequenceNumberLow = 0; } } internal SequenceNumber(ulong high, ulong low) { this.sequenceNumberHigh = high; this.sequenceNumberLow = low; } internal ulong High { get { return this.sequenceNumberHigh; } } internal ulong Low { get { return this.sequenceNumberLow; } } public static SequenceNumber Invalid { get { return new SequenceNumber(UInt64.MaxValue, UInt64.MaxValue); } } public static bool operator !=( SequenceNumber c1, SequenceNumber c2) { return (c1.CompareTo(c2) != 0); } public static bool operator <( SequenceNumber c1, SequenceNumber c2) { return (c1.CompareTo(c2) < 0); } public static bool operator <=(SequenceNumber c1, SequenceNumber c2) { return (c1.CompareTo(c2) <= 0); } public static bool operator ==( SequenceNumber c1, SequenceNumber c2) { return (c1.CompareTo(c2) == 0); } public static bool operator >( SequenceNumber c1, SequenceNumber c2) { return (c1.CompareTo(c2) > 0); } public static bool operator >=( SequenceNumber c1, SequenceNumber c2) { return (c1.CompareTo(c2) >= 0); } public int CompareTo(SequenceNumber other) { int result = this.sequenceNumberHigh.CompareTo(other.sequenceNumberHigh); if (result == 0) result = this.sequenceNumberLow.CompareTo(other.sequenceNumberLow); return result; } public bool Equals(SequenceNumber other) { return (this.CompareTo(other) == 0); } public override bool Equals(object other) { if (!(other is SequenceNumber)) return false; SequenceNumber otherSeq = (SequenceNumber)(other); return this.Equals(otherSeq); } public byte[] GetBytes() { byte[] bytes; if (this.sequenceNumberLow == 0) { bytes = new byte[8]; WriteUInt64(this.sequenceNumberHigh, bytes, 0); } else { bytes = new byte[16]; WriteUInt64(this.sequenceNumberHigh, bytes, 0); WriteUInt64(this.sequenceNumberLow, bytes, 8); } return bytes; } public override int GetHashCode() { return this.sequenceNumberHigh.GetHashCode() ^ this.sequenceNumberLow.GetHashCode(); } internal static void WriteUInt64(ulong value, byte[] bits, int offset) { bits[offset + 0] = (byte)((value >> 0) & 0xFF); bits[offset + 1] = (byte)((value >> 8) & 0xFF); bits[offset + 2] = (byte)((value >> 16) & 0xFF); bits[offset + 3] = (byte)((value >> 24) & 0xFF); bits[offset + 4] = (byte)((value >> 32) & 0xFF); bits[offset + 5] = (byte)((value >> 40) & 0xFF); bits[offset + 6] = (byte)((value >> 48) & 0xFF); bits[offset + 7] = (byte)((value >> 56) & 0xFF); } } } // 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
- DateTimePicker.cs
- HashCryptoHandle.cs
- WS2007HttpBindingCollectionElement.cs
- RegisteredDisposeScript.cs
- DateTimeSerializationSection.cs
- Confirm.cs
- Int16.cs
- PhysicalOps.cs
- Root.cs
- EllipticalNodeOperations.cs
- VerificationException.cs
- PriorityBindingExpression.cs
- LiteralTextContainerControlBuilder.cs
- BeginCreateSecurityTokenRequest.cs
- ObjectConverter.cs
- CheckBoxBaseAdapter.cs
- DbProviderConfigurationHandler.cs
- RightsManagementInformation.cs
- Freezable.cs
- CodeComment.cs
- XPathException.cs
- PowerModeChangedEventArgs.cs
- storepermission.cs
- InfoCardX509Validator.cs
- ResourceIDHelper.cs
- SmtpClient.cs
- MouseActionConverter.cs
- Vector3DConverter.cs
- GroupJoinQueryOperator.cs
- SyndicationElementExtension.cs
- HierarchicalDataBoundControlAdapter.cs
- ClonableStack.cs
- ManipulationStartedEventArgs.cs
- ZipIOExtraFieldZip64Element.cs
- WorkflowServiceAttributes.cs
- hwndwrapper.cs
- UIElement.cs
- WSSecureConversationDec2005.cs
- TrueReadOnlyCollection.cs
- CallSite.cs
- RegexFCD.cs
- AttributeEmitter.cs
- clipboard.cs
- Unit.cs
- TextContainerChangedEventArgs.cs
- Compiler.cs
- Logging.cs
- EntityDataSourceConfigureObjectContext.cs
- VerticalAlignConverter.cs
- SharedUtils.cs
- ExpressionLexer.cs
- XmlNodeChangedEventArgs.cs
- SerializerDescriptor.cs
- ParserContext.cs
- XamlFrame.cs
- AxisAngleRotation3D.cs
- DesignerTextBoxAdapter.cs
- OneWayBindingElement.cs
- ProxyAttribute.cs
- basevalidator.cs
- ProfileGroupSettingsCollection.cs
- SID.cs
- CommunicationException.cs
- XmlAttributeAttribute.cs
- HttpListener.cs
- Vector3DValueSerializer.cs
- ResourcePool.cs
- IdentitySection.cs
- EventsTab.cs
- GAC.cs
- DataExpression.cs
- TagNameToTypeMapper.cs
- WebContentFormatHelper.cs
- CTreeGenerator.cs
- IndependentAnimationStorage.cs
- ZipIOFileItemStream.cs
- InternalBufferOverflowException.cs
- cookiecontainer.cs
- AuthenticodeSignatureInformation.cs
- ApplicationContext.cs
- DiagnosticsConfiguration.cs
- BaseParaClient.cs
- DiffuseMaterial.cs
- Transform3DCollection.cs
- ValidationUtility.cs
- DataPagerFieldCommandEventArgs.cs
- Vector3dCollection.cs
- PrincipalPermission.cs
- NullableLongSumAggregationOperator.cs
- PathParser.cs
- FunctionUpdateCommand.cs
- RequestDescription.cs
- Panel.cs
- PopOutPanel.cs
- ListViewDataItem.cs
- DragEventArgs.cs
- PairComparer.cs
- ReadOnlyDataSourceView.cs
- StyleSheetRefUrlEditor.cs
- CompilerScope.cs