Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / WCF / Log / System / IO / Log / LogLogRecord.cs / 1305376 / LogLogRecord.cs
//------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
namespace System.IO.Log
{
using System;
using System.IO;
using System.Runtime.InteropServices;
class LogLogRecord : LogRecord
{
RecordStream stream;
SequenceNumber sequenceNumber;
SequenceNumber previous;
SequenceNumber user;
unsafe internal LogLogRecord(
SequenceNumber sequenceNumber,
SequenceNumber user,
SequenceNumber previous,
byte *data,
long length)
{
this.sequenceNumber = sequenceNumber;
this.previous = previous;
this.user = user;
if (length < LogLogRecordHeader.Size)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.LogCorrupt());
}
byte[] headerBits = new byte[LogLogRecordHeader.Size];
Marshal.Copy(new IntPtr(data),
headerBits,
0,
LogLogRecordHeader.Size);
LogLogRecordHeader header = new LogLogRecordHeader(headerBits);
if (header.MajorVersion > LogLogRecordHeader.CurrentMajorVersion)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.IncompatibleVersion());
}
length -= LogLogRecordHeader.Size;
data += LogLogRecordHeader.Size;
if (header.Padding)
{
long paddingSize = LogLogRecordHeader.DecodePaddingSize(data, length);
if ((paddingSize < 0) || (paddingSize > length))
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.LogCorrupt());
}
length -= paddingSize;
data += paddingSize;
}
this.stream = new RecordStream(
new UnmanagedMemoryStream(data, length));
}
public override Stream Data
{
get
{
return this.stream;
}
}
public override SequenceNumber Previous
{
get
{
return this.previous;
}
}
public override SequenceNumber SequenceNumber
{
get
{
return this.sequenceNumber;
}
}
public override SequenceNumber User
{
get
{
return this.user;
}
}
public override void Dispose()
{
this.stream.Dispose();
}
internal void Detach()
{
this.stream.MakeLocalCopy();
}
class RecordStream : Stream
{
Stream innerStream;
object syncRoot;
internal RecordStream(Stream innerStream)
{
this.innerStream = innerStream;
this.syncRoot = new object();
}
public override bool CanRead { get { return true; } }
public override bool CanSeek { get { return true; } }
public override bool CanWrite { get { return false; } }
public override long Length
{
get
{
lock(this.syncRoot)
{
CheckDisposed();
return this.innerStream.Length;
}
}
}
public override long Position
{
get
{
lock(this.syncRoot)
{
CheckDisposed();
return this.innerStream.Position;
}
}
set
{
lock(this.syncRoot)
{
CheckDisposed();
this.innerStream.Position = value;
}
}
}
public override void Flush()
{
lock(this.syncRoot)
{
if(this.innerStream != null)
{
this.innerStream.Flush();
}
}
}
public override int Read(byte[] buffer, int offset, int count)
{
lock(this.syncRoot)
{
CheckDisposed();
return this.innerStream.Read(buffer, offset, count);
}
}
public override long Seek(long offset, SeekOrigin origin)
{
lock(this.syncRoot)
{
CheckDisposed();
return this.innerStream.Seek(offset, origin);
}
}
public override void SetLength(long value)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.NotSupported());
}
public override void Write(byte[] buffer, int offset, int count)
{
if (this.innerStream == null)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ObjectDisposed());
}
else
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.NotSupported());
}
}
public override void WriteByte(byte value)
{
if (this.innerStream == null)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ObjectDisposed());
}
else
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.NotSupported());
}
}
internal void MakeLocalCopy()
{
lock(this.syncRoot)
{
if (this.innerStream != null)
{
long originalPosition = this.innerStream.Position;
try
{
try
{
byte[] newData = new byte[this.innerStream.Length];
this.innerStream.Position = 0;
this.innerStream.Read(newData, 0, newData.Length);
Stream oldStream = this.innerStream;
this.innerStream = new MemoryStream(newData);
oldStream.Close();
}
finally
{
this.innerStream.Position = originalPosition;
}
}
catch
{
// This outer catch block is needed to prevent an exception filter
// from running while we're in an inconsistent state before
// restoring the inner stream's original position.
// See http://msdn2.microsoft.com/en-US/library/8cd7yaws.aspx
throw;
}
}
}
}
protected override void Dispose(bool disposing)
{
try
{
if (disposing)
{
lock (this.syncRoot)
{
if (this.innerStream != null)
{
this.innerStream.Close();
this.innerStream = null;
}
}
}
}
finally
{
base.Dispose(disposing);
}
}
void CheckDisposed()
{
if (this.innerStream == null)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ObjectDisposed());
}
}
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
namespace System.IO.Log
{
using System;
using System.IO;
using System.Runtime.InteropServices;
class LogLogRecord : LogRecord
{
RecordStream stream;
SequenceNumber sequenceNumber;
SequenceNumber previous;
SequenceNumber user;
unsafe internal LogLogRecord(
SequenceNumber sequenceNumber,
SequenceNumber user,
SequenceNumber previous,
byte *data,
long length)
{
this.sequenceNumber = sequenceNumber;
this.previous = previous;
this.user = user;
if (length < LogLogRecordHeader.Size)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.LogCorrupt());
}
byte[] headerBits = new byte[LogLogRecordHeader.Size];
Marshal.Copy(new IntPtr(data),
headerBits,
0,
LogLogRecordHeader.Size);
LogLogRecordHeader header = new LogLogRecordHeader(headerBits);
if (header.MajorVersion > LogLogRecordHeader.CurrentMajorVersion)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.IncompatibleVersion());
}
length -= LogLogRecordHeader.Size;
data += LogLogRecordHeader.Size;
if (header.Padding)
{
long paddingSize = LogLogRecordHeader.DecodePaddingSize(data, length);
if ((paddingSize < 0) || (paddingSize > length))
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.LogCorrupt());
}
length -= paddingSize;
data += paddingSize;
}
this.stream = new RecordStream(
new UnmanagedMemoryStream(data, length));
}
public override Stream Data
{
get
{
return this.stream;
}
}
public override SequenceNumber Previous
{
get
{
return this.previous;
}
}
public override SequenceNumber SequenceNumber
{
get
{
return this.sequenceNumber;
}
}
public override SequenceNumber User
{
get
{
return this.user;
}
}
public override void Dispose()
{
this.stream.Dispose();
}
internal void Detach()
{
this.stream.MakeLocalCopy();
}
class RecordStream : Stream
{
Stream innerStream;
object syncRoot;
internal RecordStream(Stream innerStream)
{
this.innerStream = innerStream;
this.syncRoot = new object();
}
public override bool CanRead { get { return true; } }
public override bool CanSeek { get { return true; } }
public override bool CanWrite { get { return false; } }
public override long Length
{
get
{
lock(this.syncRoot)
{
CheckDisposed();
return this.innerStream.Length;
}
}
}
public override long Position
{
get
{
lock(this.syncRoot)
{
CheckDisposed();
return this.innerStream.Position;
}
}
set
{
lock(this.syncRoot)
{
CheckDisposed();
this.innerStream.Position = value;
}
}
}
public override void Flush()
{
lock(this.syncRoot)
{
if(this.innerStream != null)
{
this.innerStream.Flush();
}
}
}
public override int Read(byte[] buffer, int offset, int count)
{
lock(this.syncRoot)
{
CheckDisposed();
return this.innerStream.Read(buffer, offset, count);
}
}
public override long Seek(long offset, SeekOrigin origin)
{
lock(this.syncRoot)
{
CheckDisposed();
return this.innerStream.Seek(offset, origin);
}
}
public override void SetLength(long value)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.NotSupported());
}
public override void Write(byte[] buffer, int offset, int count)
{
if (this.innerStream == null)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ObjectDisposed());
}
else
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.NotSupported());
}
}
public override void WriteByte(byte value)
{
if (this.innerStream == null)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ObjectDisposed());
}
else
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.NotSupported());
}
}
internal void MakeLocalCopy()
{
lock(this.syncRoot)
{
if (this.innerStream != null)
{
long originalPosition = this.innerStream.Position;
try
{
try
{
byte[] newData = new byte[this.innerStream.Length];
this.innerStream.Position = 0;
this.innerStream.Read(newData, 0, newData.Length);
Stream oldStream = this.innerStream;
this.innerStream = new MemoryStream(newData);
oldStream.Close();
}
finally
{
this.innerStream.Position = originalPosition;
}
}
catch
{
// This outer catch block is needed to prevent an exception filter
// from running while we're in an inconsistent state before
// restoring the inner stream's original position.
// See http://msdn2.microsoft.com/en-US/library/8cd7yaws.aspx
throw;
}
}
}
}
protected override void Dispose(bool disposing)
{
try
{
if (disposing)
{
lock (this.syncRoot)
{
if (this.innerStream != null)
{
this.innerStream.Close();
this.innerStream = null;
}
}
}
}
finally
{
base.Dispose(disposing);
}
}
void CheckDisposed()
{
if (this.innerStream == null)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ObjectDisposed());
}
}
}
}
}
// 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
- StrokeNodeEnumerator.cs
- Parallel.cs
- Page.cs
- ArraySubsetEnumerator.cs
- CollectionViewGroupInternal.cs
- TraversalRequest.cs
- GeneralTransformGroup.cs
- DecimalAnimationUsingKeyFrames.cs
- Repeater.cs
- ActivityBindForm.cs
- IntMinMaxAggregationOperator.cs
- GroupBox.cs
- FormViewInsertEventArgs.cs
- CookielessData.cs
- NamespaceDecl.cs
- CodeIdentifier.cs
- MULTI_QI.cs
- AnnotationHelper.cs
- ImageListStreamer.cs
- CodeCompileUnit.cs
- FileVersion.cs
- TextSelectionHelper.cs
- Rotation3DKeyFrameCollection.cs
- RequestFactory.cs
- SystemColors.cs
- VisualBasicHelper.cs
- SyndicationElementExtension.cs
- Italic.cs
- FastPropertyAccessor.cs
- EncodedStreamFactory.cs
- BufferBuilder.cs
- QueryOptionExpression.cs
- XmlSchemaRedefine.cs
- mil_commands.cs
- WebControlsSection.cs
- Convert.cs
- TextModifier.cs
- HttpModuleAction.cs
- MimeReflector.cs
- ParallelTimeline.cs
- ThreadSafeList.cs
- CodeConstructor.cs
- GradientBrush.cs
- RewritingPass.cs
- TrayIconDesigner.cs
- CodeTypeParameter.cs
- SeekableReadStream.cs
- DataProtection.cs
- OracleInternalConnection.cs
- ContainerAction.cs
- XmlSchemaValidator.cs
- QueuePathDialog.cs
- ResXDataNode.cs
- DoubleStorage.cs
- EntitySqlQueryCacheKey.cs
- StylusPointProperty.cs
- IPAddress.cs
- SimpleHandlerBuildProvider.cs
- CanonicalizationDriver.cs
- ImmutableAssemblyCacheEntry.cs
- SafeRightsManagementPubHandle.cs
- InertiaExpansionBehavior.cs
- CommentEmitter.cs
- StylusPointPropertyUnit.cs
- mil_commands.cs
- ThicknessAnimation.cs
- TdsParserHelperClasses.cs
- ImageBrush.cs
- ManagedFilter.cs
- Axis.cs
- OutOfProcStateClientManager.cs
- BamlTreeMap.cs
- SliderAutomationPeer.cs
- IncrementalHitTester.cs
- IncrementalCompileAnalyzer.cs
- AutomationEvent.cs
- DataGridViewColumnDividerDoubleClickEventArgs.cs
- FontWeight.cs
- ModelUtilities.cs
- EntityConnection.cs
- ConfigurationManager.cs
- DataGridViewCellStateChangedEventArgs.cs
- SqlDataAdapter.cs
- WindowsFont.cs
- TextParagraph.cs
- BufferedReadStream.cs
- FactoryGenerator.cs
- _DisconnectOverlappedAsyncResult.cs
- BufferedWebEventProvider.cs
- CompressedStack.cs
- CardSpacePolicyElement.cs
- RoleGroup.cs
- CacheEntry.cs
- WebPartConnectionsCancelEventArgs.cs
- ArrayHelper.cs
- DbConnectionStringBuilder.cs
- DataGridRow.cs
- ZipIOCentralDirectoryDigitalSignature.cs
- ConnectionsZoneDesigner.cs
- Process.cs