Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3,135 changes: 1,619 additions & 1,516 deletions Source/Libraries/Adapters/openHistorian.Adapters/LocalOutputAdapter.cs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
<LangVersion>8</LangVersion>
<LangVersion>latest</LangVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<PlatformTarget>AnyCPU</PlatformTarget>
Expand Down Expand Up @@ -142,11 +142,18 @@
<Compile Include="Security\NonceGenerator.cs" />
<Compile Include="Security\SaltGenerator.cs" />
<Compile Include="Snap\BufferedTreeStream%272.cs" />
<Compile Include="Snap\Filters\NearestTimestampSeekFilter.cs" />
<Compile Include="Snap\Filters\NearestTimestampSeekFilterDefinition.cs" />
<Compile Include="Snap\Filters\TimestampPointIDSeekFilterDefinition.cs" />
<Compile Include="Snap\Filters\TimestampPointIDSeekFilter.cs" />
<Compile Include="Snap\Filters\TimestampSearchMode.cs" />
<Compile Include="Snap\Filters\TimestampSeekFilterDefinition.cs" />
<Compile Include="Snap\Filters\PointIdMatchFilterDefinition.cs" />
<Compile Include="Snap\Services\ArchiveDirectoryFillMethod.cs" />
<Compile Include="Snap\Services\Reader\NearestTimestampReader.cs" />
<Compile Include="Snap\Storage\ArchivePointIDIndex.cs" />
<Compile Include="Snap\Storage\ArchiveTimeBucketBloomIndex.cs" />
<Compile Include="Snap\Storage\TimeBucketBloomFilterSettings.cs" />
<Compile Include="Snap\UnionTreeStreamSortHelper.cs" />
<Compile Include="Snap\Services\ArchiveDetails.cs" />
<Compile Include="Snap\Services\ArchiveDirectoryMethod.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
<LangVersion>8</LangVersion>
<LangVersion>latest</LangVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<PlatformTarget>AnyCPU</PlatformTarget>
Expand Down Expand Up @@ -272,13 +272,20 @@
<Compile Include="Snap\Filters\PointIdMatchFilter_BitArray.cs" />
<Compile Include="Snap\Filters\PointIdMatchFilter_UIntHashSet.cs" />
<Compile Include="Snap\Filters\PointIdMatchFilter_UlongHashSet.cs" />
<Compile Include="Snap\Filters\TimestampSearchMode.cs" />
<Compile Include="Snap\Filters\NearestTimestampSeekFilter.cs" />
<Compile Include="Snap\Filters\NearestTimestampSeekFilterDefinition.cs" />
<Compile Include="Snap\Services\Reader\NearestTimestampReader.cs" />
<Compile Include="Snap\Filters\TimestampSeekFilter.cs" />
<Compile Include="Snap\Filters\TimestampSeekFilter_FixedRange.cs" />
<Compile Include="Snap\Filters\TimestampSeekFilter_IntervalRanges.cs" />
<Compile Include="Snap\IDatabaseReader.cs" />
<Compile Include="Snap\Services\Net\SnapNetworkClientSettings.cs" />
<Compile Include="Snap\Services\Net\StreamingServerDatabase`2.cs" />
<Compile Include="Snap\Services\Writer\WriteProcessorSettings.cs" />
<Compile Include="Snap\Storage\ArchivePointIDIndex.cs" />
<Compile Include="Snap\Storage\ArchiveTimeBucketBloomIndex.cs" />
<Compile Include="Snap\Storage\TimeBucketBloomFilterSettings.cs" />
<Compile Include="Snap\Storage\SortedTreeFileSimpleWriter.cs" />
<Compile Include="Snap\Tree\KeyValueMethods`2.cs" />
<Compile Include="Snap\Tree\Specialized\NodeHeader%271.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,18 @@ namespace GSF.IO.FileStructure
/// Assists in the writing of a simplified file. This file can only be appended to
/// and it must be sequentially written.
/// </summary>
public class SimplifiedFileWriter
: IDisposable
public class SimplifiedFileWriter : IDisposable
{
private static readonly LogPublisher Log = Logger.CreatePublisher(typeof(SimplifiedFileWriter), MessageClass.Component);

private bool m_disposed;

private readonly FileHeaderBlock m_fileHeaderBlock;

private SimplifiedSubFileStream m_subFileStream;

public FileStream m_stream;

private readonly string m_pendingFileName;
private readonly string m_completeFileName;

public FileStream m_stream;

/// <summary>
/// Creates a simplified file writer.
/// </summary>
Expand All @@ -65,21 +61,25 @@ public SimplifiedFileWriter(string pendingFileName, string completeFileName, int
m_stream = new FileStream(pendingFileName, FileMode.CreateNew, FileAccess.ReadWrite, FileShare.None);
}

#if DEBUG
#if DEBUG
~SimplifiedFileWriter()
{
Log.Publish(MessageLevel.Info, "Finalizer Called", GetType().FullName);
}
#endif
#endif

public Guid ArchiveId => m_fileHeaderBlock.ArchiveId;

internal uint SnapshotSequenceNumber => m_fileHeaderBlock.SnapshotSequenceNumber;

private void CloseCurrentFile()
{
if (m_subFileStream is null)
return;

if (!m_subFileStream.IsDisposed)
throw new Exception("The previous file must be disposed before completing this action");

m_subFileStream = null;
}

Expand All @@ -91,10 +91,13 @@ public ISupportsBinaryStream CreateFile(SubFileName fileName)
{
if (m_disposed)
throw new ObjectDisposedException(GetType().FullName);

CloseCurrentFile();

SubFileHeader subFile = m_fileHeaderBlock.CreateNewFile(fileName);

subFile.DirectBlock = m_fileHeaderBlock.LastAllocatedBlock + 1;

m_subFileStream = new SimplifiedSubFileStream(m_stream, subFile, m_fileHeaderBlock);
return m_subFileStream;
}
Expand All @@ -106,15 +109,22 @@ public void Commit()
{
if (m_disposed)
return;

CloseCurrentFile();

m_stream.Position = 0;
m_stream.Write(m_fileHeaderBlock.GetBytes());
m_stream.Flush(true);

WinApi.FlushFileBuffers(m_stream.SafeFileHandle);

m_stream.Dispose();
m_stream = null;

File.Move(m_pendingFileName, m_completeFileName);

m_disposed = true;

Dispose();
}

Expand All @@ -133,31 +143,28 @@ public void Dispose()
/// <param name="disposing">true to release both managed and unmanaged resources; false to release only unmanaged resources.</param>
protected virtual void Dispose(bool disposing)
{
if (!m_disposed)
if (m_disposed)
return;

try
{
try
{
// This will be done regardless of whether the object is finalized or disposed.

if (disposing)
{
if (m_subFileStream != null)
{
m_subFileStream.Dispose();
m_subFileStream = null;
}
if (m_stream != null)
{
m_stream.Dispose();
}
File.Delete(m_pendingFileName);
// This will be done only when the object is disposed by calling Dispose().
}
}
finally
// This will be done regardless of whether the object is finalized or disposed.
if (!disposing)
return;

if (m_subFileStream is not null)
{
m_disposed = true; // Prevent duplicate dispose.
m_subFileStream.Dispose();
m_subFileStream = null;
}

m_stream?.Dispose();

File.Delete(m_pendingFileName);
}
finally
{
m_disposed = true; // Prevent duplicate dispose.
}
}
}
Expand Down
Loading
Loading