Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / WCF / Log / System / IO / Log / AppendHelper.cs / 1305376 / AppendHelper.cs
//------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
namespace System.IO.Log
{
class AppendHelper : IDisposable
{
SequenceNumber prev;
SequenceNumber next;
FileLogRecordHeader header;
UnmanagedBlob[] blobs;
GCHandle[] handles;
public AppendHelper(IList> data,
SequenceNumber prev,
SequenceNumber next,
bool restartArea)
{
this.prev = prev;
this.next = next;
this.header = new FileLogRecordHeader(null);
this.header.IsRestartArea = restartArea;
this.header.PreviousLsn = prev;
this.header.NextUndoLsn = next;
this.blobs = new UnmanagedBlob[data.Count + 1];
this.handles = new GCHandle[data.Count + 1];
try
{
this.handles[0] = GCHandle.Alloc(header.Bits, GCHandleType.Pinned);
this.blobs[0].cbSize = (uint)FileLogRecordHeader.Size;
this.blobs[0].pBlobData = Marshal.UnsafeAddrOfPinnedArrayElement(header.Bits, 0);
for (int i = 0; i < data.Count; i++)
{
handles[i + 1] = GCHandle.Alloc(data[i].Array, GCHandleType.Pinned);
blobs[i + 1].cbSize = (uint)data[i].Count;
blobs[i + 1].pBlobData = Marshal.UnsafeAddrOfPinnedArrayElement(data[i].Array, data[i].Offset);
}
}
catch
{
Dispose();
throw;
}
}
public UnmanagedBlob[] Blobs
{
get { return this.blobs; }
}
// Caller should always call Dispose. Finalizer not implemented.
public void Dispose()
{
try
{
lock(this)
{
for (int i = 0; i < handles.Length; i++)
{
if (handles[i].IsAllocated)
handles[i].Free();
}
}
}
catch(InvalidOperationException exception)
{
// This indicates something is broken in IO.Log's memory management,
// so it's not safe to continue executing
DiagnosticUtility.InvokeFinalHandler(exception);
}
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
namespace System.IO.Log
{
class AppendHelper : IDisposable
{
SequenceNumber prev;
SequenceNumber next;
FileLogRecordHeader header;
UnmanagedBlob[] blobs;
GCHandle[] handles;
public AppendHelper(IList> data,
SequenceNumber prev,
SequenceNumber next,
bool restartArea)
{
this.prev = prev;
this.next = next;
this.header = new FileLogRecordHeader(null);
this.header.IsRestartArea = restartArea;
this.header.PreviousLsn = prev;
this.header.NextUndoLsn = next;
this.blobs = new UnmanagedBlob[data.Count + 1];
this.handles = new GCHandle[data.Count + 1];
try
{
this.handles[0] = GCHandle.Alloc(header.Bits, GCHandleType.Pinned);
this.blobs[0].cbSize = (uint)FileLogRecordHeader.Size;
this.blobs[0].pBlobData = Marshal.UnsafeAddrOfPinnedArrayElement(header.Bits, 0);
for (int i = 0; i < data.Count; i++)
{
handles[i + 1] = GCHandle.Alloc(data[i].Array, GCHandleType.Pinned);
blobs[i + 1].cbSize = (uint)data[i].Count;
blobs[i + 1].pBlobData = Marshal.UnsafeAddrOfPinnedArrayElement(data[i].Array, data[i].Offset);
}
}
catch
{
Dispose();
throw;
}
}
public UnmanagedBlob[] Blobs
{
get { return this.blobs; }
}
// Caller should always call Dispose. Finalizer not implemented.
public void Dispose()
{
try
{
lock(this)
{
for (int i = 0; i < handles.Length; i++)
{
if (handles[i].IsAllocated)
handles[i].Free();
}
}
}
catch(InvalidOperationException exception)
{
// This indicates something is broken in IO.Log's memory management,
// so it's not safe to continue executing
DiagnosticUtility.InvokeFinalHandler(exception);
}
}
}
}
// 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
- ResourceDisplayNameAttribute.cs
- Registry.cs
- TdsValueSetter.cs
- SymbolUsageManager.cs
- InheritanceContextHelper.cs
- GlyphsSerializer.cs
- ResourceDefaultValueAttribute.cs
- HiddenFieldPageStatePersister.cs
- ClusterRegistryConfigurationProvider.cs
- CheckoutException.cs
- StyleXamlParser.cs
- InvokeSchedule.cs
- ForeignKeyConstraint.cs
- PassportPrincipal.cs
- DataSourceHelper.cs
- FrameworkElement.cs
- XmlSchemaDocumentation.cs
- XmlSchemaComplexContentExtension.cs
- QuaternionAnimationBase.cs
- CapabilitiesAssignment.cs
- _Win32.cs
- XslTransform.cs
- NativeCompoundFileAPIs.cs
- DataTemplateSelector.cs
- ListBox.cs
- NativeMethods.cs
- TabItemAutomationPeer.cs
- ActiveXSite.cs
- RtfToken.cs
- WebEvents.cs
- Region.cs
- InvalidateEvent.cs
- DTCTransactionManager.cs
- OleDbMetaDataFactory.cs
- AppDomain.cs
- Pair.cs
- Attribute.cs
- PrtTicket_Editor.cs
- RuleProcessor.cs
- TextDecorationCollectionConverter.cs
- SqlDataSourceFilteringEventArgs.cs
- StatusBarDrawItemEvent.cs
- PropertyChange.cs
- DataSourceDesigner.cs
- cookiecontainer.cs
- ProfessionalColorTable.cs
- SqlCommand.cs
- TextDecoration.cs
- EntityDataSourceChangingEventArgs.cs
- TcpChannelHelper.cs
- WebServiceMethodData.cs
- Track.cs
- sortedlist.cs
- AndAlso.cs
- Animatable.cs
- EventMappingSettings.cs
- ApplicationHost.cs
- HttpProfileGroupBase.cs
- XmlMessageFormatter.cs
- JulianCalendar.cs
- OpenTypeLayoutCache.cs
- DiscreteKeyFrames.cs
- SpellerInterop.cs
- XmlObjectSerializerWriteContext.cs
- UserNamePasswordValidator.cs
- UrlPath.cs
- XamlReaderHelper.cs
- ClientEventManager.cs
- ObjectSet.cs
- userdatakeys.cs
- TargetException.cs
- AttachedAnnotationChangedEventArgs.cs
- VBIdentifierTrimConverter.cs
- BaseWebProxyFinder.cs
- TimerElapsedEvenArgs.cs
- HtmlContainerControl.cs
- AtomMaterializerLog.cs
- SqlServices.cs
- DbConnectionInternal.cs
- XPathBinder.cs
- StyleXamlTreeBuilder.cs
- PeerTransportElement.cs
- ObjectStateFormatter.cs
- NumericUpDownAcceleration.cs
- TableDetailsCollection.cs
- PropertyRef.cs
- PathBox.cs
- LoadMessageLogger.cs
- _MultipleConnectAsync.cs
- ScrollProperties.cs
- SizeAnimationBase.cs
- DocumentViewerBase.cs
- ScrollChrome.cs
- JpegBitmapEncoder.cs
- KnownTypesHelper.cs
- securitycriticaldata.cs
- XmlNodeComparer.cs
- PageParserFilter.cs
- designeractionlistschangedeventargs.cs
- FormViewDeletedEventArgs.cs