示例#1
0
        /// <summary>
        /// Creates a new in memory archive file.
        /// </summary>
        /// <param name="blockSize">The number of bytes per block in the file.</param>
        /// <param name="flags">Flags to write to the file</param>
        public static SortedTreeFile CreateInMemory(int blockSize = 4096, params Guid[] flags)
        {
            SortedTreeFile file = new SortedTreeFile();

            file.m_filePath      = string.Empty;
            file.m_fileStructure = TransactionalFileStructure.CreateInMemory(blockSize, flags);
            return(file);
        }
示例#2
0
        /// <summary>
        /// Creates an archive file.
        /// </summary>
        /// <param name="file">the path for the file.</param>
        /// <param name="blockSize">The number of bytes per block in the file.</param>
        /// <param name="flags">Flags to write to the file</param>
        public static SortedTreeFile CreateFile(string file, int blockSize = 4096, params Guid[] flags)
        {
            SortedTreeFile af = new SortedTreeFile();

            file               = Path.GetFullPath(file);
            af.m_filePath      = file;
            af.m_fileStructure = TransactionalFileStructure.CreateFile(file, blockSize, flags);
            return(af);
        }
示例#3
0
 /// <summary>
 /// Creates a SortedTreeTable
 /// </summary>
 /// <param name="fileStructure"></param>
 /// <param name="fileName"></param>
 /// <param name="baseFile"></param>
 internal SortedTreeTable(TransactionalFileStructure fileStructure, SubFileName fileName, SortedTreeFile baseFile)
 {
     BaseFile        = baseFile;
     m_fileName      = fileName;
     m_fileStructure = fileStructure;
     m_firstKey      = new TKey();
     m_lastKey       = new TKey();
     using (SortedTreeTableReadSnapshot <TKey, TValue> snapshot = BeginRead())
     {
         snapshot.GetKeyRange(m_firstKey, m_lastKey);
     }
 }
示例#4
0
        /// <summary>
        /// Opens an archive file.
        /// </summary>
        /// <param name="file"></param>
        /// <param name="isReadOnly"></param>
        /// <returns></returns>
        public static SortedTreeFile OpenFile(string file, bool isReadOnly)
        {
            SortedTreeFile af = new SortedTreeFile();

            file               = Path.GetFullPath(file);
            af.m_filePath      = file;
            af.m_fileStructure = TransactionalFileStructure.OpenFile(file, isReadOnly);
            if (af.m_fileStructure.Snapshot.Header.ArchiveType != FileType)
            {
                throw new Exception("Archive type is unknown");
            }
            return(af);
        }
        private static SortedTreeTable <TKey, TValue> CreateMemoryFile(EncodingDefinition treeNodeType, SortedPointBuffer <TKey, TValue> buffer)
        {
            buffer.IsReadingMode = true;

            SortedTreeFile file = SortedTreeFile.CreateInMemory(4096);
            SortedTreeTable <TKey, TValue> table = file.OpenOrCreateTable <TKey, TValue>(treeNodeType);

            using (SortedTreeTableEditor <TKey, TValue> edit = table.BeginEdit())
            {
                edit.AddPoints(buffer);
                edit.Commit();
            }

            buffer.IsReadingMode = false;
            return(table);
        }
示例#6
0
        public void TestNonSequential(int pointCount, bool verify)
        {
            SortedPointBuffer <HistorianKey, HistorianValue> points = new SortedPointBuffer <HistorianKey, HistorianValue>(pointCount, true);

            HistorianKey   key   = new HistorianKey();
            HistorianValue value = new HistorianValue();

            for (int x = 0; x < pointCount; x++)
            {
                key.PointID = (ulong)x;
                points.TryEnqueue(key, value);
            }

            points.IsReadingMode = true;

            File.Delete(@"C:\Temp\fileTemp.~d2i");
            File.Delete(@"C:\Temp\fileTemp.d2i");

            SortedTreeFileSimpleWriter <HistorianKey, HistorianValue> .CreateNonSequential(@"C:\Temp\fileTemp.~d2i", @"C:\Temp\fileTemp.d2i", 4096, null, EncodingDefinition.FixedSizeCombinedEncoding, points);

            if (!verify)
            {
                return;
            }
            using (SortedTreeFile file = SortedTreeFile.OpenFile(@"C:\Temp\fileTemp.d2i", true))
                using (SortedTreeTable <HistorianKey, HistorianValue> table = file.OpenTable <HistorianKey, HistorianValue>())
                    using (SortedTreeTableReadSnapshot <HistorianKey, HistorianValue> read = table.AcquireReadSnapshot().CreateReadSnapshot())
                        using (SortedTreeScannerBase <HistorianKey, HistorianValue> scanner = read.GetTreeScanner())
                        {
                            scanner.SeekToStart();
                            int cnt = 0;
                            while (scanner.Read(key, value))
                            {
                                if (key.PointID != (ulong)cnt)
                                {
                                    throw new Exception();
                                }
                                cnt++;
                            }
                            if (cnt != pointCount)
                            {
                                throw new Exception();
                            }
                        }
        }
示例#7
0
        public void TestOld()
        {
            Test(1000, false);

            int pointCount = 10000000;
            SortedPointBuffer <HistorianKey, HistorianValue> points = new SortedPointBuffer <HistorianKey, HistorianValue>(pointCount, true);

            HistorianKey   key   = new HistorianKey();
            HistorianValue value = new HistorianValue();

            for (int x = 0; x < pointCount; x++)
            {
                key.PointID = (ulong)x;
                points.TryEnqueue(key, value);
            }

            points.IsReadingMode = true;

            File.Delete(@"C:\Temp\fileTemp.~d2i");
            File.Delete(@"C:\Temp\fileTemp.d2i");

            Stopwatch sw = new Stopwatch();

            sw.Start();

            using (SortedTreeFile file = SortedTreeFile.CreateFile(@"C:\Temp\fileTemp.~d2i"))
                using (SortedTreeTable <HistorianKey, HistorianValue> table = file.OpenOrCreateTable <HistorianKey, HistorianValue>(EncodingDefinition.FixedSizeCombinedEncoding))
                {
                    using (SortedTreeTableEditor <HistorianKey, HistorianValue> edit = table.BeginEdit())
                    {
                        edit.AddPoints(points);
                        edit.Commit();
                    }
                }

            //SortedTreeFileSimpleWriter<HistorianKey, HistorianValue>.Create(@"C:\Temp\fileTemp.~d2i", @"C:\Temp\fileTemp.d2i", 4096, SortedTree.FixedSizeNode, points);

            sw.Stop();

            System.Console.WriteLine(SimplifiedSubFileStreamIoSession.ReadBlockCount);
            System.Console.WriteLine(SimplifiedSubFileStreamIoSession.WriteBlockCount);
            System.Console.WriteLine(sw.Elapsed.TotalSeconds.ToString());
        }