/// <summary> /// Constructs a new instance of <see cref="IntegerList"/> ready to /// read entities from the source. /// </summary> /// <param name="dataSet"> /// Dataset being created. /// </param> /// <param name="reader"> /// Reader used to initialise the header only. /// </param> internal IntegerList( DataSet dataSet, Reader reader) { _header = new Header(reader); _dataSet = dataSet; }
/// <summary> /// Constructs a new instance of <see cref="SignatureV31"/>. /// </summary> /// <param name="dataSet"> /// The data set the signature is contained within. /// </param> /// <param name="index"> /// The index in the data structure to the signature. /// </param> /// <param name="reader"> /// Reader connected to the source data structure and positioned to /// start reading. /// </param> internal SignatureV31( DataSet dataSet, int index, Reader reader) : base(dataSet, index, reader) { _nodeOffsets = ReadOffsets(dataSet, reader, dataSet.SignatureNodesCount); }
/// <summary> /// Creates a new reader and stores a reference to it. /// </summary> /// <returns>A reader open for read access to the stream</returns> internal Reader CreateReader() { var reader = new Reader(CreateStream()); lock (_readers) { _readers.Enqueue(reader); } return reader; }
/// <summary> /// Creates a new <see cref="DataSet"/> from the byte array. /// </summary> /// <param name="array">Array of bytes to build the data set from</param> /// <param name="init">True to indicate that the data set should be fulling initialised</param> /// <returns>A <see cref="DataSet"/> filled with data from the array</returns> public static DataSet Create(byte[] array, bool init) { DataSet dataSet = new DataSet(DateTime.MinValue, DataSet.Modes.Memory); using (var reader = new Reader(new MemoryStream(array))) { Load(dataSet, reader, init); } return dataSet; }
/// <summary> /// Constructs a new instance of <see cref="SignatureV32"/>. /// </summary> /// <param name="dataSet"> /// The data set the signature is contained within. /// </param> /// <param name="index"> /// The index in the data structure to the signature. /// </param> /// <param name="reader"> /// Reader connected to the source data structure and positioned to /// start reading. /// </param> internal SignatureV32( DataSet dataSet, int index, Reader reader) : base(dataSet, index, reader) { NodeCount = reader.ReadByte(); FirstNodeOffsetIndex = reader.ReadInt32(); _rank = reader.ReadInt32(); Flags = reader.ReadByte(); }
/// <summary> /// Returns the reader to the pool to be used by another /// process later. /// </summary> /// <param name="reader">Reader open and ready to read from the temp file</param> internal void Release(Reader reader) { lock (_readers) { _readers.Enqueue(reader); } }
protected override Entities.Profile Construct(DataSet dataSet, int offset, Reader reader) { return new Entities.Memory.Profile(dataSet, offset, reader); }
protected override Entities.Node Construct(DataSet dataSet, int offset, Reader reader) { return new NodeV32(dataSet, offset, reader); }
/// <summary> /// Constructs a new instance of <see cref="MemoryIntegerList"/>. /// </summary> /// <param name="reader"> /// Reader connected to the source data structure and positioned to /// start reading. /// </param> internal MemoryIntegerList(Reader reader) { Header = new Header(reader); _array = new int[Header.Count]; }
/// <summary> /// Reads the list into memory. /// </summary> /// <param name="reader"> /// Reader connected to the source data structure and positioned to /// start reading. /// </param> internal void Read(Reader reader) { for (int index = 0; index < Header.Count; index++) { _array[index] = reader.ReadInt32(); } }
/// <summary> /// Creates a new <see cref="DataSet"/> from the binary reader provided. /// </summary> /// <param name="dataSet">The data set to be loaded with data from the reader</param> /// <param name="reader"> /// Reader connected to the source data structure and positioned to start reading /// </param> /// <param name="init"> /// True to indicate that the data set should be fulling initialised /// </param> /// <para> /// A <see cref="DataSet"/> is constructed using the reader to retrieve /// the header information. This is then passed to the Read methods to create the /// lists before reading the data into memory. Finally it initialise is required /// references between entities are worked out and stored. /// </para> internal static void Load(DataSet dataSet, Reader reader, bool init) { CommonFactory.LoadHeader(dataSet, reader); var strings = new MemoryVariableList<AsciiString<DataSet>, DataSet>(dataSet, reader, new MemoryAsciiStringFactory()); MemoryFixedList<Component, DataSet> components = null; switch(dataSet.VersionEnum) { case BinaryConstants.FormatVersions.PatternV31: components = new MemoryFixedList<Component, DataSet>(dataSet, reader, new ComponentFactoryV31()); break; case BinaryConstants.FormatVersions.PatternV32: components = new MemoryFixedList<Component, DataSet>(dataSet, reader, new ComponentFactoryV32()); break; } var maps = new MemoryFixedList<Map, DataSet>(dataSet, reader, new MapFactory()); var properties = new PropertiesList(dataSet, reader, new PropertyFactory()); var values = new MemoryFixedList<Value, DataSet>(dataSet, reader, new ValueFactory<DataSet>()); var profiles = new MemoryVariableList<Entities.Profile, DataSet>(dataSet, reader, new ProfileMemoryFactory()); MemoryFixedList<Signature, DataSet> signatures = null; MemoryIntegerList signatureNodeOffsets = null; MemoryIntegerList nodeRankedSignatureIndexes = null; switch(dataSet.VersionEnum) { case BinaryConstants.FormatVersions.PatternV31: signatures = new MemoryFixedList<Signature, DataSet>(dataSet, reader, new SignatureFactoryV31<DataSet>(dataSet)); break; case BinaryConstants.FormatVersions.PatternV32: signatures = new MemoryFixedList<Signature, DataSet>(dataSet, reader, new SignatureFactoryV32<DataSet>(dataSet)); signatureNodeOffsets = new MemoryIntegerList(reader); nodeRankedSignatureIndexes = new MemoryIntegerList(reader); break; } var rankedSignatureIndexes = new MemoryIntegerList(reader); MemoryVariableList<Entities.Node, DataSet> nodes = null; switch (dataSet.VersionEnum) { case BinaryConstants.FormatVersions.PatternV31: nodes = new MemoryVariableList<Entities.Node, DataSet>(dataSet, reader, new NodeMemoryFactoryV31()); break; case BinaryConstants.FormatVersions.PatternV32: nodes = new MemoryVariableList<Entities.Node, DataSet>(dataSet, reader, new NodeMemoryFactoryV32()); break; } var rootNodes = new MemoryFixedList<Entities.Node, DataSet>(dataSet, reader, new RootNodeFactory()); var profileOffsets = new MemoryFixedList<ProfileOffset, DataSet>(dataSet, reader, new ProfileOffsetFactory()); dataSet.Strings = strings; dataSet._components = components; dataSet._maps = maps; dataSet._properties = properties; dataSet._values = values; dataSet.Profiles = profiles; dataSet._signatures = signatures; dataSet._rankedSignatureIndexes = rankedSignatureIndexes; switch (dataSet.VersionEnum) { case BinaryConstants.FormatVersions.PatternV32: dataSet._signatureNodeOffsets = signatureNodeOffsets; dataSet._nodeRankedSignatureIndexes = nodeRankedSignatureIndexes; break; } dataSet.Nodes = nodes; dataSet.RootNodes = rootNodes; dataSet._profileOffsets = profileOffsets; strings.Read(reader); components.Read(reader); maps.Read(reader); properties.Read(reader); values.Read(reader); profiles.Read(reader); signatures.Read(reader); switch (dataSet.VersionEnum) { case BinaryConstants.FormatVersions.PatternV32: signatureNodeOffsets.Read(reader); nodeRankedSignatureIndexes.Read(reader); break; } rankedSignatureIndexes.Read(reader); nodes.Read(reader); rootNodes.Read(reader); profileOffsets.Read(reader); if (init) { // Set references between objects. dataSet.Init(); // The following lists will not be needed anymore // so they can be freed. dataSet._signatureNodeOffsets = null; dataSet._nodeRankedSignatureIndexes = null; // Force garbage collection as a lot of memory has been freed. GC.Collect(); } }
/// <summary> /// Creates a new <see cref="DataSet"/> from the file provided. /// </summary> /// <param name="filePath"> /// Uncompressed file containing the data for the data set /// </param> /// <param name="init"> /// True to indicate that the data set should be fully initialised /// </param> /// <param name="lastModified">Date and time the source data was last /// modified.</param> /// <returns>A <see cref="DataSet"/> filled with data from the array /// </returns> public static DataSet Create(string filePath, bool init, DateTime lastModified) { DataSet dataSet = new DataSet(lastModified, DataSet.Modes.Memory); using (var reader = new Reader( File.Open(filePath, FileMode.Open, FileAccess.Read, FileShare.Read))) { Load(dataSet, reader, init); } return dataSet; }
/// <summary> /// Returns the reader to the pool to be used by another /// process later. /// </summary> /// <param name="reader"> /// Reader open and ready to read from the temp file. /// </param> public void Release(Reader reader) { lock (_readers) { _readers.Enqueue(reader); } }