private void TestFile(int pageSize, string fileName) { HistorianKey key = new HistorianKey(); HistorianValue value = new HistorianValue(); value.Value3 = 0; value.AsSingle = 65.20f; if (File.Exists(fileName)) { File.Delete(fileName); } Stopwatch sw = new Stopwatch(); sw.Start(); using (SortedTreeFile af = SortedTreeFile.CreateFile(fileName, blockSize: pageSize)) using (SortedTreeTable <HistorianKey, HistorianValue> af2 = af.OpenOrCreateTable <HistorianKey, HistorianValue>(HistorianFileEncodingDefinition.TypeGuid)) using (var edit = af2.BeginEdit()) { for (uint x = 0; x < 10000000; x++) { key.Timestamp = 1; key.PointID = x; edit.AddPoint(key, value); } edit.Commit(); } sw.Stop(); System.Console.WriteLine("Size: " + pageSize + " Rate: " + (10 / sw.Elapsed.TotalSeconds).ToString()); }
public void WriteFile() { HistorianKey key = new HistorianKey(); HistorianValue value = new HistorianValue(); if (File.Exists("c:\\temp\\ArchiveTestFileBig.d2")) { File.Delete("c:\\temp\\ArchiveTestFileBig.d2"); } //using (var af = ArchiveFile.CreateInMemory(CompressionMethod.TimeSeriesEncoded)) using (SortedTreeFile af = SortedTreeFile.CreateFile("c:\\temp\\ArchiveTestFileBig.d2")) using (SortedTreeTable <HistorianKey, HistorianValue> af2 = af.OpenOrCreateTable <HistorianKey, HistorianValue>(EncodingDefinition.FixedSizeCombinedEncoding)) { Random r = new Random(3); for (ulong v1 = 1; v1 < 36; v1++) { using (var edit = af2.BeginEdit()) { for (ulong v2 = 1; v2 < 86000; v2++) { key.Timestamp = v1 * 2342523; key.PointID = v2; value.Value1 = (ulong)r.Next(); value.Value3 = 0; edit.AddPoint(key, value); } edit.Commit(); } af2.Count(); } af2.Count(); } }
/// <summary> /// Creates a new <see cref="SortedTreeTable{TKey,TValue}"/> based on the settings passed to this class. /// Once created, it is up to he caller to make sure that this class is properly disposed of. /// </summary> /// <param name="estimatedSize">The estimated size of the file. -1 to ignore this feature and write to the first available directory.</param> /// <returns></returns> public SortedTreeTable <TKey, TValue> CreateArchiveFile(long estimatedSize = -1) { using (m_lock.EnterReadLock()) { if (m_settings.IsMemoryArchive) { SortedTreeFile af = SortedTreeFile.CreateInMemory(blockSize: 4096, flags: m_settings.Flags.ToArray()); return(af.OpenOrCreateTable <TKey, TValue>(m_settings.EncodingMethod)); } else { string fileName = CreateArchiveName(GetPathWithEnoughSpace(estimatedSize)); SortedTreeFile af = SortedTreeFile.CreateFile(fileName, blockSize: 4096, flags: m_settings.Flags.ToArray()); return(af.OpenOrCreateTable <TKey, TValue>(m_settings.EncodingMethod)); } } }
public void WriteDataToAFile() { Logger.Console.Verbose = VerboseLevel.All; string fileName = @"C:\Temp\ArchiveFile.d2"; if (File.Exists(fileName)) { File.Delete(fileName); } HistorianKey key = new HistorianKey(); HistorianValue value = new HistorianValue(); using (SortedTreeFile file = SortedTreeFile.CreateFile(fileName)) using (SortedTreeTable <HistorianKey, HistorianValue> table = file.OpenOrCreateTable <HistorianKey, HistorianValue>(EncodingDefinition.FixedSizeCombinedEncoding)) using (SortedTreeTableEditor <HistorianKey, HistorianValue> editor = table.BeginEdit()) { key.TimestampAsDate = DateTime.Now; key.PointID = 1; value.AsString = "Test Write"; editor.AddPoint(key, value); editor.Commit(); } }