Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / Log / System / IO / Log / SequenceNumber.cs / 1 / 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.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- HttpCookie.cs
- BufferBuilder.cs
- PropertyTabAttribute.cs
- TemplateBindingExtension.cs
- OrderByExpression.cs
- _NetworkingPerfCounters.cs
- ViewLoader.cs
- safePerfProviderHandle.cs
- SelectorAutomationPeer.cs
- SiteMapHierarchicalDataSourceView.cs
- InvalidCastException.cs
- TreeNodeMouseHoverEvent.cs
- ResXFileRef.cs
- ScrollPatternIdentifiers.cs
- DataGridItem.cs
- Utils.cs
- BinaryCommonClasses.cs
- FakeModelPropertyImpl.cs
- DecimalAnimation.cs
- ToolStripOverflowButton.cs
- BooleanProjectedSlot.cs
- FormDesigner.cs
- WebPartMovingEventArgs.cs
- ZipIOLocalFileDataDescriptor.cs
- GuidelineCollection.cs
- CodeGeneratorOptions.cs
- NativeMethods.cs
- Number.cs
- PropertyConverter.cs
- SymbolMethod.cs
- SchemaConstraints.cs
- IntPtr.cs
- BevelBitmapEffect.cs
- EndpointDesigner.cs
- Pair.cs
- ValueUnavailableException.cs
- EntitySqlQueryCacheEntry.cs
- RepeatButtonAutomationPeer.cs
- SQLDecimalStorage.cs
- KnownColorTable.cs
- ErrorProvider.cs
- SystemColors.cs
- AdapterDictionary.cs
- FileDialog_Vista_Interop.cs
- TreeViewDataItemAutomationPeer.cs
- TraceSection.cs
- InterleavedZipPartStream.cs
- ActionItem.cs
- WorkingDirectoryEditor.cs
- SchemaMapping.cs
- PrintDialogDesigner.cs
- WebBrowserContainer.cs
- EventMappingSettingsCollection.cs
- BaseCollection.cs
- ListChangedEventArgs.cs
- Boolean.cs
- ApplicationException.cs
- StringFormat.cs
- TcpTransportSecurityElement.cs
- CodeSnippetStatement.cs
- ElapsedEventArgs.cs
- CounterCreationDataCollection.cs
- ValidatorCollection.cs
- SessionStateSection.cs
- GeometryModel3D.cs
- RepeaterItem.cs
- XamlTreeBuilderBamlRecordWriter.cs
- BitmapEffectDrawingContent.cs
- DesignerActionService.cs
- ChtmlMobileTextWriter.cs
- AttachedPropertyBrowsableForChildrenAttribute.cs
- ProviderMetadataCachedInformation.cs
- StoreItemCollection.cs
- UInt64Converter.cs
- DiscreteKeyFrames.cs
- CodeTypeDeclarationCollection.cs
- SmtpFailedRecipientException.cs
- ToolboxService.cs
- PageAsyncTask.cs
- MulticastOption.cs
- XmlUtf8RawTextWriter.cs
- ProxyManager.cs
- DtdParser.cs
- OpacityConverter.cs
- SqlUdtInfo.cs
- BuildProvider.cs
- PropertyTabAttribute.cs
- EntityCommandExecutionException.cs
- CustomWebEventKey.cs
- Config.cs
- HttpAsyncResult.cs
- ServiceContractGenerator.cs
- PseudoWebRequest.cs
- EntityDesignerUtils.cs
- PropertyEmitterBase.cs
- AnnotationMap.cs
- UndoManager.cs
- Vector3DAnimation.cs
- MailAddressCollection.cs
- MachineSettingsSection.cs