static private LoadHeader ( FiftyOne.Foundation.Mobile.Detection.Entities.DataSet dataSet, |
||
dataSet | FiftyOne.Foundation.Mobile.Detection.Entities.DataSet | The data set to be loaded |
reader | Reader positioned at the beginning of the /// data source | |
return | void |
/// <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, reader, new AsciiStringFactory()); 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; } var maps = new MemoryFixedList <Map>(dataSet, reader, new MapFactory()); var properties = new PropertiesList(dataSet, reader, new PropertyFactory()); var values = new MemoryFixedList <Value>(dataSet, reader, new ValueFactory()); var profiles = new MemoryVariableList <Entities.Profile>(dataSet, reader, new ProfileMemoryFactory()); MemoryFixedList <Signature> signatures = null; MemoryFixedList <Integer> signatureNodeOffsets = null; MemoryFixedList <Integer> nodeRankedSignatureIndexes = null; switch (dataSet.VersionEnum) { case BinaryConstants.FormatVersions.PatternV31: signatures = new MemoryFixedList <Signature>(dataSet, reader, new SignatureFactoryV31(dataSet)); break; case BinaryConstants.FormatVersions.PatternV32: signatures = new MemoryFixedList <Signature>(dataSet, reader, new SignatureFactoryV32(dataSet)); signatureNodeOffsets = new MemoryFixedList <Integer>(dataSet, reader, new IntegerFactory()); nodeRankedSignatureIndexes = new MemoryFixedList <Integer>(dataSet, reader, new IntegerFactory()); break; } var rankedSignatureIndexes = new MemoryFixedList <Integer>( dataSet, reader, new IntegerFactory()); MemoryVariableList <Entities.Node> nodes = null; switch (dataSet.VersionEnum) { case BinaryConstants.FormatVersions.PatternV31: nodes = new MemoryVariableList <Entities.Node>(dataSet, reader, new NodeMemoryFactoryV31()); break; case BinaryConstants.FormatVersions.PatternV32: nodes = new MemoryVariableList <Entities.Node>(dataSet, reader, new NodeMemoryFactoryV32()); break; } var rootNodes = new MemoryFixedList <Entities.Node>(dataSet, reader, new RootNodeFactory()); var profileOffsets = new MemoryFixedList <ProfileOffset>(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> /// 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); } }