As multiple threads need to read from the SourceBase concurrently this class provides a mechanisim for readers to be recycled across threads and requests.
The DataSet must be disposed of to ensure the readers in the pool are closed.
Inheritance: IDisposable
コード例 #1
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;
 }
コード例 #2
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;
 }
コード例 #3
0
 /// <summary>
 /// Constructs a new instance of a trie provider.
 /// </summary>
 /// <param name="copyright">The copyright notice for the data file.</param>
 /// <param name="strings">Array containing all strings in the output.</param>
 /// <param name="httpHeaders">Array of http headers.</param>
 /// <param name="properties">Array of properties.</param>
 /// <param name="devices">Array of devices.</param>
 /// <param name="lookupList">Lookups data array.</param>
 /// <param name="nodesLength">The length of the node data.</param>
 /// <param name="nodesOffset">The position of the start of the nodes in the file provided.</param>
 /// <param name="pool">Pool connected to the data source.</param>
 internal TrieProviderV32(string copyright, byte[] strings, byte[] httpHeaders, byte[] properties, byte[] devices,
     byte[] lookupList, long nodesLength, long nodesOffset, Pool pool)
     : base(copyright, strings, properties, devices, lookupList, nodesLength, nodesOffset, pool)
 {
     for (int i = 0; i < _properties.Length / PROPERTY_LENGTH; i++)
     {
         var value = GetStringValue(BitConverter.ToInt32(_properties, i * PROPERTY_LENGTH));
         var headerCount = BitConverter.ToInt32(_properties, (i * PROPERTY_LENGTH) + sizeof(int));
         var headerFirstIndex = BitConverter.ToInt32(_properties, (i * PROPERTY_LENGTH) + (sizeof(int) * 2));
         _propertyIndex.Add(value, i);
         _propertyNames.Add(value);
         _propertyHttpHeaders.Add(GetHeaders(httpHeaders, headerCount, headerFirstIndex));
     }
 }
コード例 #4
0
 /// <summary>
 /// Constructs a new instance of a trie provider.
 /// </summary>
 /// <param name="copyright">The copyright notice for the data file.</param>
 /// <param name="strings">Array containing all strings in the output.</param>
 /// <param name="properties">Array of properties.</param>
 /// <param name="devices">Array of devices.</param>
 /// <param name="lookupList">Lookups data array.</param>
 /// <param name="nodesLength">The length of the node data.</param>
 /// <param name="nodesOffset">The position of the start of the nodes in the file provided.</param>
 /// <param name="pool">Pool connected to the data source.</param>
 internal TrieProviderV3(string copyright, byte[] strings, byte[] properties, byte[] devices,
     byte[] lookupList, long nodesLength, long nodesOffset, Pool pool)
     : base(copyright, strings, properties, devices, lookupList, nodesLength, nodesOffset, pool)
 {
     #pragma warning disable 618
     var headers = new string[] { Constants.UserAgentHeader };
     #pragma warning restore 618
     var count = _properties.Length / sizeof(int);
     for (int i = 0; i < count; i++)
     {
         var value = GetStringValue(BitConverter.ToInt32(_properties, i * sizeof(int)));
         _propertyIndex.Add(value, i);
         _propertyNames.Add(value);
         _propertyHttpHeaders.Add(headers);
     }
 }
コード例 #5
0
        private static TrieProvider Create(Pool pool)
        {
            var reader = pool.GetReader();
            try
            {
                // Check the version number is correct for this API.
                var version = reader.ReadUInt16();

                // Construct the right provider.
                switch(version)
                {
                    case 3:
                        return new TrieProviderV3(
                            Encoding.ASCII.GetString(reader.ReadBytes((int)reader.ReadUInt32())),
                            ReadStrings(reader),
                            ReadProperties(reader),
                            ReadDevices(reader),
                            ReadLookupList(reader),
                            reader.ReadInt64(),
                            reader.BaseStream.Position,
                            pool);
                    case 32:
                        return new TrieProviderV32(
                            Encoding.ASCII.GetString(reader.ReadBytes((int)reader.ReadUInt32())),
                            ReadStrings(reader),
                            ReadHeaders(reader),
                            ReadProperties(reader),
                            ReadDevices(reader),
                            ReadLookupList(reader),
                            reader.ReadInt64(),
                            reader.BaseStream.Position,
                            pool);
                    default:
                        throw new MobileException(String.Format(
                            "Version mismatch. Data is version '{0}' for '{1}' reader",
                            version,
                            String.Join(",", BinaryConstants.SupportedTrieFormatVersions.Select(i => i.Value.ToString()))));
                }
            }
            finally
            {
                // Return the reader back to the pool.
                pool.Release(reader);
            }
        }
コード例 #6
0
 /// <summary>
 /// Constructs a new instance of a tree provider.
 /// </summary>
 /// <param name="copyright">The copyright notice for the data file.</param>
 /// <param name="strings">Array containing all strings in the output.</param>
 /// <param name="properties">Array of properties.</param>
 /// <param name="devices">Array of devices.</param>
 /// <param name="lookupList">Lookups data array.</param>
 /// <param name="nodesLength">The length of the node data.</param>
 /// <param name="nodesOffset">The position of the start of the nodes in the file provided.</param>
 /// <param name="pool">Pool connected to the data source.</param>
 internal TrieProvider(string copyright, byte[] strings, byte[] properties, byte[] devices,
     byte[] lookupList, long nodesLength, long nodesOffset, Pool pool)
 {
     Copyright = copyright;
     _strings = strings;
     _properties = properties;
     _devices = devices;
     _lookupList = lookupList;
     _nodesOffset = nodesOffset;
     _pool = pool;
 }
コード例 #7
0
 /// <summary>
 /// Creates a new stream data set connected to the byte array
 /// data source provided.
 /// </summary>
 /// <param name="data">Byte array containing uncompressed data set</param>
 /// <param name="mode">
 /// The mode of operation the data set will be using.
 /// </param>
 internal DataSet(byte[] data, Modes mode)
     : base(DateTime.MinValue, mode)
 {
     Pool = new Pool(new SourceMemory(data));
 }
コード例 #8
0
 /// <summary>
 /// /Creates a new stream data set connected to the data
 /// file provided.
 /// </summary>
 /// <param name="fileName">Valid path to the uncompressed data set file</param>
 /// <param name="lastModified">Date and time the source data was last modified.</param>
 /// <param name="mode">
 /// The mode of operation the data set will be using.
 /// </param>
 /// <param name="isTempFile">True if the file should be deleted when the source is disposed</param>
 internal DataSet(string fileName, DateTime lastModified, Modes mode, bool isTempFile)
     : base(lastModified, mode)
 {
     Pool = new Pool(new SourceFile(fileName, isTempFile));
 }