本文整理汇总了C#中SparseStream.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# SparseStream.Dispose方法的具体用法?C# SparseStream.Dispose怎么用?C# SparseStream.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SparseStream
的用法示例。
在下文中一共展示了SparseStream.Dispose方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OpenContent
public override SparseStream OpenContent(SparseStream parent, Ownership ownsParent)
{
if (ownsParent == Ownership.Dispose && parent != null)
{
parent.Dispose();
}
return SparseStream.FromStream(Content, Ownership.None);
}
示例2: OpenExtent
private SparseStream OpenExtent(ExtentDescriptor extent, long extentStart, SparseStream parent, Ownership ownsParent)
{
FileAccess access = FileAccess.Read;
FileShare share = FileShare.Read;
if(extent.Access == ExtentAccess.ReadWrite && _access != FileAccess.Read)
{
access = FileAccess.ReadWrite;
share = FileShare.None;
}
if (extent.Type != ExtentType.Sparse && extent.Type != ExtentType.VmfsSparse)
{
if (ownsParent == Ownership.Dispose && parent != null)
{
parent.Dispose();
}
}
switch (extent.Type)
{
case ExtentType.Flat:
case ExtentType.Vmfs:
return SparseStream.FromStream(
_fileLocator.Open(extent.FileName, FileMode.Open, access, share),
Ownership.Dispose);
case ExtentType.Zero:
return new ZeroStream(extent.SizeInSectors * Utilities.SectorSize);
case ExtentType.Sparse:
return new HostedSparseExtentStream(
_fileLocator.Open(extent.FileName, FileMode.Open, access, share),
Ownership.Dispose,
extentStart,
parent,
ownsParent);
case ExtentType.VmfsSparse:
return new ServerSparseExtentStream(
_fileLocator.Open(extent.FileName, FileMode.Open, access, share),
Ownership.Dispose,
extentStart,
parent,
ownsParent);
default:
throw new NotSupportedException();
}
}
示例3: OpenContent
/// <summary>
/// Gets the contents of this disk as a stream.
/// </summary>
internal SparseStream OpenContent(SparseStream parent, Ownership ownsParent)
{
if (_descriptor.ParentContentId == uint.MaxValue)
{
if (parent != null && ownsParent == Ownership.Dispose)
{
parent.Dispose();
}
parent = null;
}
if (parent == null)
{
parent = new ZeroStream(Capacity);
ownsParent = Ownership.Dispose;
}
if (_descriptor.Extents.Count == 1)
{
if (_monolithicStream != null)
{
return new HostedSparseExtentStream(
_monolithicStream,
Ownership.None,
0,
parent,
ownsParent);
}
else
{
return OpenExtent(_descriptor.Extents[0], 0, parent, ownsParent);
}
}
else
{
long extentStart = 0;
SparseStream[] streams = new SparseStream[_descriptor.Extents.Count];
for (int i = 0; i < streams.Length; ++i)
{
streams[i] = OpenExtent(_descriptor.Extents[i], extentStart, parent, (i == streams.Length - 1) ? ownsParent : Ownership.None);
extentStart += _descriptor.Extents[i].SizeInSectors * Sizes.Sector;
}
return new ConcatStream(Ownership.Dispose, streams);
}
}
示例4: OpenContent
public override SparseStream OpenContent(SparseStream parentStream, Ownership ownsStream)
{
if (parentStream != null && ownsStream == Ownership.Dispose)
{
parentStream.Dispose();
}
if (_buffer != null)
{
SparseStream rawStream = new BufferStream(_buffer, FileAccess.Read);
return new BlockCacheStream(rawStream, Ownership.Dispose);
}
else
{
return SparseStream.FromStream(_stream, Ownership.None);
}
}
示例5: OpenContent
public override MappedStream OpenContent(SparseStream parent, Ownership ownsParent)
{
FileAccess access = FileAccess.Read;
FileShare share = FileShare.Read;
if (_descriptor.Access == ExtentAccess.ReadWrite && _access != FileAccess.Read)
{
access = FileAccess.ReadWrite;
share = FileShare.None;
}
if (_descriptor.Type != ExtentType.Sparse && _descriptor.Type != ExtentType.VmfsSparse && _descriptor.Type != ExtentType.Zero)
{
if (ownsParent == Ownership.Dispose && parent != null)
{
parent.Dispose();
}
}
else if (parent == null)
{
parent = new ZeroStream(_descriptor.SizeInSectors * Sizes.Sector);
}
if (_monolithicStream != null)
{
// Early-out for monolithic VMDKs
return new HostedSparseExtentStream(
_monolithicStream,
Ownership.None,
_diskOffset,
parent,
ownsParent);
}
else
{
switch (_descriptor.Type)
{
case ExtentType.Flat:
case ExtentType.Vmfs:
return MappedStream.FromStream(
_fileLocator.Open(_descriptor.FileName, FileMode.Open, access, share),
Ownership.Dispose);
case ExtentType.Zero:
return new ZeroStream(_descriptor.SizeInSectors * Utilities.SectorSize);
case ExtentType.Sparse:
return new HostedSparseExtentStream(
_fileLocator.Open(_descriptor.FileName, FileMode.Open, access, share),
Ownership.Dispose,
_diskOffset,
parent,
ownsParent);
case ExtentType.VmfsSparse:
return new ServerSparseExtentStream(
_fileLocator.Open(_descriptor.FileName, FileMode.Open, access, share),
Ownership.Dispose,
_diskOffset,
parent,
ownsParent);
default:
throw new NotSupportedException();
}
}
}
示例6: OpenContent
/// <summary>
/// Opens the content of the disk image file as a stream.
/// </summary>
/// <param name="parent">The parent file's content (if any)</param>
/// <param name="ownsParent">Whether the created stream assumes ownership of parent stream</param>
/// <returns>The new content stream</returns>
public override SparseStream OpenContent(SparseStream parent, Ownership ownsParent)
{
if (parent != null && ownsParent == Ownership.Dispose)
{
// Not needed until differencing disks supported.
parent.Dispose();
}
DiskStream stream = new DiskStream(_stream, Ownership.None, _header);
stream.WriteOccurred += OnWriteOccurred;
return stream;
}
示例7: DoOpenContent
internal MappedStream DoOpenContent(SparseStream parent, Ownership ownsParent)
{
if (_footer.DiskType == FileType.Fixed)
{
if (parent != null && ownsParent == Ownership.Dispose)
{
parent.Dispose();
}
return new SubStream(_fileStream, 0, _fileStream.Length - 512);
}
else if (_footer.DiskType == FileType.Dynamic)
{
if (parent != null && ownsParent == Ownership.Dispose)
{
parent.Dispose();
}
return new DynamicStream(_fileStream, _dynamicHeader, _footer.CurrentSize, new ZeroStream(_footer.CurrentSize), Ownership.Dispose);
}
else
{
if (parent == null)
{
parent = new ZeroStream(_footer.CurrentSize);
ownsParent = Ownership.Dispose;
}
return new DynamicStream(_fileStream, _dynamicHeader, _footer.CurrentSize, parent, ownsParent);
}
}
示例8: OpenContent
/// <summary>
/// Opens the content of the disk layer as a stream.
/// </summary>
/// <param name="parent">The parent file's content (if any)</param>
/// <param name="ownsParent">Whether the created stream assumes ownership of parent stream</param>
/// <returns>The new content stream</returns>
public override SparseStream OpenContent(SparseStream parent, Ownership ownsParent)
{
if (ownsParent == Ownership.Dispose && parent != null)
{
parent.Dispose();
}
return new DiskStream(_vm.Archive, _capacity, _location);
}