A data set returned from the stream factory which includes a pool of data readers that are used to fetch data from the source when the data set is used to retrieve data not already in memory.
Inheritance: Entities.DataSet, IStreamDataSet
コード例 #1
0
 /// <summary>
 /// Constructs a new instance of <see cref="NodeV32"/>
 /// </summary>
 /// <param name="dataSet">
 /// The data set the node is contained within
 /// </param>
 /// <param name="offset">
 /// The offset in the data structure to the node
 /// </param>
 /// <param name="reader">
 /// Reader connected to the source data structure and positioned to start reading
 /// </param>
 internal NodeV32(
     DataSet dataSet,
     int offset,
     BinaryReader reader)
     : base(dataSet, offset, reader)
 {
 }
コード例 #2
0
        /// <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>
        /// <returns>
        /// A <see cref="DataSet"/> configured to read entities from the array when required
        /// </returns>
        public static DataSet Create(byte[] array)
        {
            var dataSet = new DataSet(array, DataSet.Modes.MemoryMapped);

            Load(dataSet);
            return(dataSet);
        }
コード例 #3
0
        /// <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="lastModified">Date and time the source data was last modified.</param>
        /// <param name="isTempFile">True if the file should be deleted when the source is disposed</param>
        /// <returns>
        /// A <see cref="DataSet"/>configured to read entities from the file path when required
        /// </returns>
        public static DataSet Create(string filePath, DateTime lastModified, bool isTempFile)
        {
            var dataSet = new DataSet(filePath, lastModified, DataSet.Modes.File, isTempFile);

            Load(dataSet);
            return(dataSet);
        }
コード例 #4
0
 /// <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;
 }
コード例 #5
0
ファイル: Node.cs プロジェクト: axle-h/.NET-Device-Detection
 /// <summary>
 /// Constructs a new instance of <see cref="Node"/>
 /// </summary>
 /// <param name="dataSet">
 /// The data set the node is contained within
 /// </param>
 /// <param name="offset">
 /// The offset in the data structure to the node
 /// </param>
 /// <param name="reader">
 /// Reader connected to the source data structure and positioned to start reading
 /// </param>
 internal Node(
     DataSet dataSet,
     int offset,
     BinaryReader reader)
     : base(dataSet, offset, reader)
 {
     _pool = dataSet.Pool;
     _position = reader.BaseStream.Position;
 }
コード例 #6
0
 /// <summary>
 /// Constructs a new instance of the <see cref="Profile"/>.
 /// </summary>
 /// <param name="dataSet">
 /// The data set whose profile list the profile will be contained 
 /// within.
 /// </param>
 /// <param name="offset">
 /// The offset position in the data structure to the profile.
 /// </param>
 /// <param name="reader">
 /// Reader connected to the source data structure and positioned to 
 /// start reading.
 /// </param>
 internal Profile(
     DataSet dataSet,
     int offset,
     BinaryReader reader)
     : base(dataSet, offset, reader)
 {
     _pool = dataSet.Pool;
     _valueIndexesCount = reader.ReadInt32();
     _signatureIndexesCount = reader.ReadInt32();
     _position = reader.BaseStream.Position;
 }
コード例 #7
0
 /// <summary>
 /// Constructs a new instance of <see cref="NodeV31"/>.
 /// </summary>
 /// <param name="dataSet">
 /// The data set the node is contained within.
 /// </param>
 /// <param name="offset">
 /// The offset in the data structure to the node.
 /// </param>
 /// <param name="reader">
 /// Reader connected to the source data structure and positioned to 
 /// start reading.
 /// </param>
 internal NodeV31(
     DataSet dataSet,
     int offset,
     BinaryReader reader)
     : base(dataSet, offset, reader)
 {
     _rankedSignatureCount = reader.ReadInt32();
     _children = NodeFactoryShared.ReadNodeIndexesV31(
         (FiftyOne.Foundation.Mobile.Detection.Entities.DataSet)dataSet,
         reader,
         (int)((long)offset + reader.BaseStream.Position - this._nodeStartStreamPosition),
         (int)_childrenCount);
     _position = reader.BaseStream.Position;
 }
コード例 #8
0
 /// <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>
 /// <returns>
 /// A <see cref="DataSet"/> configured to read entities from the array 
 /// when required
 /// </returns>
 public static DataSet Create(byte[] array)
 {
     var dataSet = new DataSet(array, DataSet.Modes.MemoryMapped);
     Load(dataSet);
     return dataSet;
 }
コード例 #9
0
        /// <summary>
        /// Initialises the dataset <see cref="DataSet"/> using the source of the data set.
        /// </summary>
        /// <para>
        /// A <see cref="DataSet"/> is initialised using the reader to retrieve 
        /// entity information. The data is only loaded when required by the detection
        /// process.
        /// </para>
        /// <param name="dataSet">A data set to be initialised ready for detection</param>
        private static void Load(DataSet dataSet)
        {
            var reader = dataSet.Pool.GetReader();
            try
            {
                reader.BaseStream.Position = 0;
                CommonFactory.LoadHeader(dataSet, reader);
                dataSet.Strings = new VariableList<AsciiString<Entities.DataSet>, DataSet>(
                    dataSet, reader, new StreamAsciiStringFactory(), Constants.StringsCacheSize);
                MemoryFixedList<Component, Entities.DataSet> components = null;
                switch (dataSet.VersionEnum)
                {
                    case BinaryConstants.FormatVersions.PatternV31:
                        components = new MemoryFixedList<Component, Entities.DataSet>(dataSet, reader, new ComponentFactoryV31());
                        break;
                    case BinaryConstants.FormatVersions.PatternV32:
                        components = new MemoryFixedList<Component, Entities.DataSet>(dataSet, reader, new ComponentFactoryV32());
                        break;
                }
                dataSet._components = components;
                var maps = new MemoryFixedList<Map, Entities.DataSet>(dataSet, reader, new MapFactory());
                dataSet._maps = maps;
                var properties = new PropertiesList(dataSet, reader, new PropertyFactory());
                dataSet._properties = properties;
                dataSet._values = new FixedCacheList<Value, DataSet>(dataSet, reader, new ValueFactory<DataSet>(), Constants.ValuesCacheSize);
                dataSet.Profiles = new VariableList<Entities.Profile, DataSet>(dataSet, reader, new ProfileStreamFactory(dataSet.Pool), Constants.ProfilesCacheSize);
                switch (dataSet.VersionEnum)
                {
                    case BinaryConstants.FormatVersions.PatternV31:
                        dataSet._signatures = new FixedCacheList<Signature, DataSet>(dataSet, reader, new SignatureFactoryV31<DataSet>(dataSet), Constants.SignaturesCacheSize);
                        break;
                    case BinaryConstants.FormatVersions.PatternV32:
                        dataSet._signatures = new FixedCacheList<Signature, DataSet>(dataSet, reader, new SignatureFactoryV32<DataSet>(dataSet), Constants.SignaturesCacheSize);
                        dataSet._signatureNodeOffsets = new IntegerList(dataSet, reader);
                        dataSet._nodeRankedSignatureIndexes = new IntegerList(dataSet, reader);
                        break;
                }
                dataSet._rankedSignatureIndexes = new IntegerList(dataSet, reader);
                switch (dataSet.VersionEnum)
                {
                    case BinaryConstants.FormatVersions.PatternV31:
                        dataSet.Nodes = new VariableList<Entities.Node, DataSet>(dataSet, reader, new NodeStreamFactoryV31(dataSet.Pool), Constants.NodesCacheSize);
                        break;
                    case BinaryConstants.FormatVersions.PatternV32:
                        dataSet.Nodes = new VariableList<Entities.Node, DataSet>(dataSet, reader, new NodeStreamFactoryV32(dataSet.Pool), Constants.NodesCacheSize);
                        break;
                }
                var rootNodes = new MemoryFixedList<Entities.Node, Entities.DataSet>(dataSet, reader, new RootNodeFactory());
                dataSet.RootNodes = rootNodes;
                var profileOffsets = new MemoryFixedList<ProfileOffset, Entities.DataSet>(dataSet, reader, new ProfileOffsetFactory());
                dataSet._profileOffsets = profileOffsets;

                // Read into memory all the small lists which are frequently accessed.
                reader.BaseStream.Position = components.Header.StartPosition;
                components.Read(reader);
                reader.BaseStream.Position = maps.Header.StartPosition;
                maps.Read(reader);
                reader.BaseStream.Position = properties.Header.StartPosition;
                properties.Read(reader);
                reader.BaseStream.Position = rootNodes.Header.StartPosition;
                rootNodes.Read(reader);
                reader.BaseStream.Position = profileOffsets.Header.StartPosition;
                profileOffsets.Read(reader);
            }
            finally
            {
                dataSet.Pool.Release(reader);
            }
        }
コード例 #10
0
 /// <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="lastModified">Date and time the source data was last
 /// modified.</param>
 /// <param name="isTempFile">True if the file should be deleted when
 /// the source is disposed</param>
 /// <returns>
 /// A <see cref="DataSet"/>configured to read entities from the file
 /// path when required
 /// </returns>
 public static DataSet Create(string filePath, DateTime lastModified, bool isTempFile)
 {
     var dataSet = new DataSet(filePath, lastModified, DataSet.Modes.File, isTempFile);
     Load(dataSet);
     return dataSet;
 }
コード例 #11
0
        /// <summary>
        /// Initialises the dataset <see cref="DataSet"/> using the source of the data set.
        /// </summary>
        /// <para>
        /// A <see cref="DataSet"/> is initialised using the reader to retrieve
        /// entity information. The data is only loaded when required by the detection
        /// process.
        /// </para>
        /// <param name="dataSet">A data set to be initialised ready for detection</param>
        private static void Load(DataSet dataSet)
        {
            var reader = dataSet.Pool.GetReader();

            try
            {
                reader.BaseStream.Position = 0;
                CommonFactory.LoadHeader(dataSet, reader);
                dataSet.Strings = new VariableList <AsciiString>(dataSet, reader, new AsciiStringFactory(), Constants.StringsCacheSize);
                MemoryFixedList <Component> components = null;
                switch (dataSet.VersionEnum)
                {
                case BinaryConstants.FormatVersions.PatternV31:
                    components = new MemoryFixedList <Component>(dataSet, reader, new ComponentFactoryV31());
                    break;

                case BinaryConstants.FormatVersions.PatternV32:
                    components = new MemoryFixedList <Component>(dataSet, reader, new ComponentFactoryV32());
                    break;
                }
                dataSet._components = components;
                var maps = new MemoryFixedList <Map>(dataSet, reader, new MapFactory());
                dataSet._maps = maps;
                var properties = new PropertiesList(dataSet, reader, new PropertyFactory());
                dataSet._properties = properties;
                dataSet._values     = new FixedCacheList <Value>(dataSet, reader, new ValueFactory(), Constants.ValuesCacheSize);
                dataSet.Profiles    = new VariableList <Entities.Profile>(dataSet, reader, new ProfileStreamFactory(dataSet.Pool), Constants.ProfilesCacheSize);
                switch (dataSet.VersionEnum)
                {
                case BinaryConstants.FormatVersions.PatternV31:
                    dataSet._signatures = new FixedCacheList <Signature>(dataSet, reader, new SignatureFactoryV31(dataSet), Constants.SignaturesCacheSize);
                    break;

                case BinaryConstants.FormatVersions.PatternV32:
                    dataSet._signatures                 = new FixedCacheList <Signature>(dataSet, reader, new SignatureFactoryV32(dataSet), Constants.SignaturesCacheSize);
                    dataSet._signatureNodeOffsets       = new FixedList <Integer>(dataSet, reader, new IntegerFactory());
                    dataSet._nodeRankedSignatureIndexes = new FixedList <Integer>(dataSet, reader, new IntegerFactory());
                    break;
                }
                dataSet._rankedSignatureIndexes = new FixedCacheList <Integer>(
                    dataSet, reader, new IntegerFactory(), Constants.RankedSignaturesCacheSize);
                switch (dataSet.VersionEnum)
                {
                case BinaryConstants.FormatVersions.PatternV31:
                    dataSet.Nodes = new VariableList <Entities.Node>(dataSet, reader, new NodeStreamFactoryV31(dataSet.Pool), Constants.NodesCacheSize);
                    break;

                case BinaryConstants.FormatVersions.PatternV32:
                    dataSet.Nodes = new VariableList <Entities.Node>(dataSet, reader, new NodeStreamFactoryV32(dataSet.Pool), Constants.NodesCacheSize);
                    break;
                }
                var rootNodes = new MemoryFixedList <Entities.Node>(dataSet, reader, new RootNodeFactory());
                dataSet.RootNodes = rootNodes;
                var profileOffsets = new MemoryFixedList <ProfileOffset>(dataSet, reader, new ProfileOffsetFactory());
                dataSet._profileOffsets = profileOffsets;

                // Read into memory all the small lists which are frequently accessed.
                reader.BaseStream.Position = components.Header.StartPosition;
                components.Read(reader);
                reader.BaseStream.Position = maps.Header.StartPosition;
                maps.Read(reader);
                reader.BaseStream.Position = properties.Header.StartPosition;
                properties.Read(reader);
                reader.BaseStream.Position = rootNodes.Header.StartPosition;
                rootNodes.Read(reader);
                reader.BaseStream.Position = profileOffsets.Header.StartPosition;
                profileOffsets.Read(reader);
            }
            finally
            {
                dataSet.Pool.Release(reader);
            }
        }