Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / WCF / Log / System / IO / Log / LogExtentCollection.cs / 1305376 / LogExtentCollection.cs
//------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
namespace System.IO.Log
{
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Threading;
using Microsoft.Win32.SafeHandles;
public sealed class LogExtentCollection : IEnumerable
{
LogStore store;
int version;
internal LogExtentCollection(LogStore store)
{
this.store = store;
}
public int Count
{
get
{
CLFS_INFORMATION info;
this.store.GetLogFileInformation(out info);
return (int)info.TotalContainers;
}
}
public int FreeCount
{
get
{
CLFS_INFORMATION info;
this.store.GetLogFileInformation(out info);
return (int)info.FreeContainers;
}
}
int Version
{
get
{
return this.version;
}
}
LogStore Store
{
get
{
return this.store;
}
}
public void Add(string path)
{
if(string.IsNullOrEmpty(path))
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ArgumentNull("path"));
}
if (this.Count == 0)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.InvalidOperation(SR.LogStore_SizeRequired));
}
UnsafeNativeMethods.AddLogContainerNoSizeSync(
this.store.Handle,
path);
this.version++;
}
public void Add(string path, long size)
{
if(string.IsNullOrEmpty(path))
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ArgumentNull("path"));
}
if (size <= 0)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ArgumentOutOfRange("size"));
}
CLFS_INFORMATION info;
this.store.GetLogFileInformation(out info);
if ((ulong)size < info.ContainerSize)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ArgumentInvalid(SR.LogStore_SizeTooSmall));
}
ulong ulSize = (ulong)size;
UnsafeNativeMethods.AddLogContainerSync(
this.store.Handle,
ref ulSize,
path);
this.version++;
}
IEnumerator IEnumerable.GetEnumerator()
{
return this.GetEnumerator();
}
public IEnumerator GetEnumerator()
{
return new LogExtentEnumerator(this);
}
public void Remove(string path, bool force)
{
if(string.IsNullOrEmpty(path))
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ArgumentNull("path"));
}
UnsafeNativeMethods.RemoveLogContainerSync(
this.store.Handle,
path,
force);
this.version++;
}
public void Remove(LogExtent extent, bool force)
{
if(extent == null)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ArgumentNull("extent"));
}
UnsafeNativeMethods.RemoveLogContainerSync(
this.store.Handle,
extent.Path,
force);
this.version++;
}
class LogExtentEnumerator : IEnumerator
{
LogExtentCollection collection;
List.Enumerator innerEnum;
int version;
public LogExtentEnumerator(LogExtentCollection collection)
{
this.collection = collection;
this.version = this.collection.Version;
SafeFileHandle logHandle = this.collection.Store.Handle;
CLFS_SCAN_CONTEXT scanContext = new CLFS_SCAN_CONTEXT();
try
{
List extents = new List();
CLFS_INFORMATION logInfo;
this.collection.Store.GetLogFileInformation(out logInfo);
if (logInfo.TotalContainers > 0)
{
UnsafeNativeMethods.CreateLogContainerScanContextSync(
logHandle,
0,
logInfo.TotalContainers,
CLFS_SCAN_MODE.CLFS_SCAN_FORWARD,
ref scanContext);
long containerPointer = scanContext.pinfoContainer.ToInt64();
CLFS_CONTAINER_INFORMATION_WRAPPER info;
info = new CLFS_CONTAINER_INFORMATION_WRAPPER();
int infoSize;
infoSize = Marshal.SizeOf(typeof(CLFS_CONTAINER_INFORMATION_WRAPPER));
for (uint i = 0; i < scanContext.cContainersReturned; i++)
{
Marshal.PtrToStructure(new IntPtr(containerPointer),
info);
LogExtent extent = new LogExtent(
info.info.GetActualFileName(logHandle),
info.info.FileSize,
(LogExtentState)info.info.State);
extents.Add(extent);
containerPointer += infoSize;
}
}
this.innerEnum = extents.GetEnumerator();
}
finally
{
if ((scanContext.eScanMode & CLFS_SCAN_MODE.CLFS_SCAN_INITIALIZED) != 0)
{
UnsafeNativeMethods.ScanLogContainersSyncClose(
ref scanContext);
}
}
}
object IEnumerator.Current
{
get
{
return this.Current;
}
}
public LogExtent Current
{
get { return this.innerEnum.Current; }
}
public bool MoveNext()
{
if (this.version != this.collection.Version)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
Error.InvalidOperation(SR.InvalidOperation_EnumFailedVersion));
}
return this.innerEnum.MoveNext();
}
public void Dispose()
{
this.innerEnum.Dispose();
}
public void Reset()
{
((IEnumerator)this.innerEnum).Reset();
this.version = this.collection.Version;
}
}
}
}
// 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.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Threading;
using Microsoft.Win32.SafeHandles;
public sealed class LogExtentCollection : IEnumerable
{
LogStore store;
int version;
internal LogExtentCollection(LogStore store)
{
this.store = store;
}
public int Count
{
get
{
CLFS_INFORMATION info;
this.store.GetLogFileInformation(out info);
return (int)info.TotalContainers;
}
}
public int FreeCount
{
get
{
CLFS_INFORMATION info;
this.store.GetLogFileInformation(out info);
return (int)info.FreeContainers;
}
}
int Version
{
get
{
return this.version;
}
}
LogStore Store
{
get
{
return this.store;
}
}
public void Add(string path)
{
if(string.IsNullOrEmpty(path))
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ArgumentNull("path"));
}
if (this.Count == 0)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.InvalidOperation(SR.LogStore_SizeRequired));
}
UnsafeNativeMethods.AddLogContainerNoSizeSync(
this.store.Handle,
path);
this.version++;
}
public void Add(string path, long size)
{
if(string.IsNullOrEmpty(path))
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ArgumentNull("path"));
}
if (size <= 0)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ArgumentOutOfRange("size"));
}
CLFS_INFORMATION info;
this.store.GetLogFileInformation(out info);
if ((ulong)size < info.ContainerSize)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ArgumentInvalid(SR.LogStore_SizeTooSmall));
}
ulong ulSize = (ulong)size;
UnsafeNativeMethods.AddLogContainerSync(
this.store.Handle,
ref ulSize,
path);
this.version++;
}
IEnumerator IEnumerable.GetEnumerator()
{
return this.GetEnumerator();
}
public IEnumerator GetEnumerator()
{
return new LogExtentEnumerator(this);
}
public void Remove(string path, bool force)
{
if(string.IsNullOrEmpty(path))
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ArgumentNull("path"));
}
UnsafeNativeMethods.RemoveLogContainerSync(
this.store.Handle,
path,
force);
this.version++;
}
public void Remove(LogExtent extent, bool force)
{
if(extent == null)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ArgumentNull("extent"));
}
UnsafeNativeMethods.RemoveLogContainerSync(
this.store.Handle,
extent.Path,
force);
this.version++;
}
class LogExtentEnumerator : IEnumerator
{
LogExtentCollection collection;
List.Enumerator innerEnum;
int version;
public LogExtentEnumerator(LogExtentCollection collection)
{
this.collection = collection;
this.version = this.collection.Version;
SafeFileHandle logHandle = this.collection.Store.Handle;
CLFS_SCAN_CONTEXT scanContext = new CLFS_SCAN_CONTEXT();
try
{
List extents = new List();
CLFS_INFORMATION logInfo;
this.collection.Store.GetLogFileInformation(out logInfo);
if (logInfo.TotalContainers > 0)
{
UnsafeNativeMethods.CreateLogContainerScanContextSync(
logHandle,
0,
logInfo.TotalContainers,
CLFS_SCAN_MODE.CLFS_SCAN_FORWARD,
ref scanContext);
long containerPointer = scanContext.pinfoContainer.ToInt64();
CLFS_CONTAINER_INFORMATION_WRAPPER info;
info = new CLFS_CONTAINER_INFORMATION_WRAPPER();
int infoSize;
infoSize = Marshal.SizeOf(typeof(CLFS_CONTAINER_INFORMATION_WRAPPER));
for (uint i = 0; i < scanContext.cContainersReturned; i++)
{
Marshal.PtrToStructure(new IntPtr(containerPointer),
info);
LogExtent extent = new LogExtent(
info.info.GetActualFileName(logHandle),
info.info.FileSize,
(LogExtentState)info.info.State);
extents.Add(extent);
containerPointer += infoSize;
}
}
this.innerEnum = extents.GetEnumerator();
}
finally
{
if ((scanContext.eScanMode & CLFS_SCAN_MODE.CLFS_SCAN_INITIALIZED) != 0)
{
UnsafeNativeMethods.ScanLogContainersSyncClose(
ref scanContext);
}
}
}
object IEnumerator.Current
{
get
{
return this.Current;
}
}
public LogExtent Current
{
get { return this.innerEnum.Current; }
}
public bool MoveNext()
{
if (this.version != this.collection.Version)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
Error.InvalidOperation(SR.InvalidOperation_EnumFailedVersion));
}
return this.innerEnum.MoveNext();
}
public void Dispose()
{
this.innerEnum.Dispose();
}
public void Reset()
{
((IEnumerator)this.innerEnum).Reset();
this.version = this.collection.Version;
}
}
}
}
// 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
- PropertyDescriptorGridEntry.cs
- Effect.cs
- Int32Animation.cs
- Drawing.cs
- TextStore.cs
- ColumnHeaderConverter.cs
- LambdaCompiler.Unary.cs
- FileUtil.cs
- SpecialFolderEnumConverter.cs
- BinaryFormatter.cs
- HtmlInputImage.cs
- InstallerTypeAttribute.cs
- PageSetupDialog.cs
- RowSpanVector.cs
- ProjectionCamera.cs
- DataProviderNameConverter.cs
- MouseCaptureWithinProperty.cs
- SubtreeProcessor.cs
- SingleAnimationUsingKeyFrames.cs
- figurelengthconverter.cs
- nulltextcontainer.cs
- ProviderIncompatibleException.cs
- HelpProvider.cs
- CodeIndexerExpression.cs
- DynamicValueConverter.cs
- DeflateStream.cs
- ReferenceAssemblyAttribute.cs
- IDQuery.cs
- DESCryptoServiceProvider.cs
- SessionStateContainer.cs
- Object.cs
- XmlSchemaCompilationSettings.cs
- EventWaitHandle.cs
- MulticastOption.cs
- PenContext.cs
- Menu.cs
- XmlSchemaComplexContentExtension.cs
- IdentitySection.cs
- WindowsComboBox.cs
- Merger.cs
- SchemaNotation.cs
- QilList.cs
- EntityDataSourceColumn.cs
- SourceElementsCollection.cs
- PrintingPermission.cs
- DefaultTypeArgumentAttribute.cs
- TextServicesCompartmentEventSink.cs
- ActivityStateRecord.cs
- DataGridViewCellEventArgs.cs
- IChannel.cs
- InlinedAggregationOperatorEnumerator.cs
- SQLBoolean.cs
- SmtpException.cs
- AxParameterData.cs
- WebPartConnection.cs
- RichTextBox.cs
- CustomCategoryAttribute.cs
- OdbcHandle.cs
- HttpPostClientProtocol.cs
- PropertyGroupDescription.cs
- ItemsPresenter.cs
- ContentElement.cs
- XPathNodeInfoAtom.cs
- BypassElement.cs
- EmbeddedMailObjectsCollection.cs
- PrivacyNoticeElement.cs
- ScaleTransform3D.cs
- SafeFileHandle.cs
- CodeArgumentReferenceExpression.cs
- SystemIPInterfaceStatistics.cs
- PreloadedPackages.cs
- View.cs
- WizardSideBarListControlItemEventArgs.cs
- DecimalConverter.cs
- DispatcherProcessingDisabled.cs
- EntityStoreSchemaFilterEntry.cs
- HtmlToClrEventProxy.cs
- AutomationProperties.cs
- ConstraintStruct.cs
- HttpResponseWrapper.cs
- Pair.cs
- KeyedHashAlgorithm.cs
- SystemSounds.cs
- WebPartUtil.cs
- IndependentlyAnimatedPropertyMetadata.cs
- TextPenaltyModule.cs
- ConfigWriter.cs
- ImportContext.cs
- IntegerValidatorAttribute.cs
- XPathException.cs
- DataObject.cs
- VisualBrush.cs
- DiscreteKeyFrames.cs
- DeferrableContentConverter.cs
- FindCriteriaElement.cs
- UnwrappedTypesXmlSerializerManager.cs
- CellPartitioner.cs
- DropShadowBitmapEffect.cs
- XNodeSchemaApplier.cs
- ReadOnlyHierarchicalDataSource.cs