/// <summary> /// build the dataset from a buffer /// </summary> /// <param name="buffer">the buffer</param> /// <returns> /// An <see cref="IndirectDataSet"/> built from the specified buffer /// </returns> public IndirectDataSet Build(byte[] buffer) { IndirectDataSet dataSet = new IndirectDataSet(buffer, DataSet.Modes.MemoryMapped); LoadForStreaming(dataSet, _cacheConfiguration); return(dataSet); }
/// <summary> /// build the dataset from a file /// </summary> /// <param name="filename">the filename to build from</param> /// <returns> /// An <see cref="IndirectDataSet"/> built from the specified file /// </returns> public IndirectDataSet Build(string filename) { DateTime?modDate = _lastModified; if (modDate == null) { modDate = new FileInfo(filename).LastWriteTimeUtc; } IndirectDataSet dataSet = new IndirectDataSet(filename, modDate.Value, DataSet.Modes.File, _isTempFile); LoadForStreaming(dataSet, _cacheConfiguration); return(dataSet); }
/// <summary> /// Load the necessary values from the data file in to the DataSet. /// Initially, this will only load data such as file headers /// and the smaller lists. /// </summary> /// <param name="dataSet">The dataset object to load in to</param> /// <param name="cacheConfiguration">the cache configuration to use when creating the caches</param> private static void LoadForStreaming(IndirectDataSet dataSet, Dictionary <CacheType, ICacheOptions> cacheConfiguration) { var reader = dataSet.Pool.GetReader(); try { CacheMap cacheMap = BuildCaches(cacheConfiguration); dataSet.CacheMap = cacheMap; reader.BaseStream.Position = 0; CommonFactory.LoadHeader(dataSet, reader); // ---- Create AsciiString list var stringLoader = EntityLoaderFactory.GetLoaderFor( new Header(reader), cacheMap.StringCache, dataSet, new StreamAsciiStringFactory()); dataSet.Strings = new StreamList <AsciiString, IStreamDataSet>(stringLoader); 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; } dataSet._components = components; var maps = new MemoryFixedList <Map, DataSet>( dataSet, reader, new MapFactory()); dataSet._maps = maps; var properties = new PropertiesList( dataSet, reader, new PropertyFactory()); dataSet._properties = properties; // ---- Create Value list var valueLoader = EntityLoaderFactory.GetLoaderFor(new Header(reader), cacheMap.ValueCache, dataSet, new ValueFactory <IStreamDataSet>()); dataSet._values = new StreamList <Value, IStreamDataSet>(valueLoader); // ---- Create Profile list var profileLoader = EntityLoaderFactory.GetLoaderFor(new Header(reader), cacheMap.ProfileCache, dataSet, new ProfileStreamFactory(dataSet.Pool)); dataSet.Profiles = new StreamList <Entities.Profile, IStreamDataSet>(profileLoader); switch (dataSet.VersionEnum) { case BinaryConstants.FormatVersions.PatternV31: // ---- Create Signature list for V31 var signatureLoaderV31 = EntityLoaderFactory.GetLoaderFor( new Header(reader), cacheMap.SignatureCache, dataSet, new SignatureFactoryV31 <IndirectDataSet>(dataSet)); dataSet._signatures = new StreamList <Signature, IndirectDataSet>( signatureLoaderV31); break; case BinaryConstants.FormatVersions.PatternV32: // ---- Create Signature list for V32 var signatureLoaderV32 = EntityLoaderFactory.GetLoaderFor( new Header(reader), cacheMap.SignatureCache, dataSet, new SignatureFactoryV32 <IndirectDataSet>(dataSet)); dataSet._signatures = new StreamList <Signature, IndirectDataSet>( signatureLoaderV32); 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: // ---- Create Nodes list for V31 var nodeLoaderV31 = EntityLoaderFactory.GetLoaderFor( new Header(reader), cacheMap.NodeCache, dataSet, new NodeStreamFactoryV31(dataSet.Pool)); dataSet.Nodes = new StreamList <Entities.Node, IStreamDataSet>( nodeLoaderV31); break; case BinaryConstants.FormatVersions.PatternV32: // ---- Create Nodes list for V31 var nodeLoaderV32 = EntityLoaderFactory.GetLoaderFor( new Header(reader), cacheMap.NodeCache, dataSet, new NodeStreamFactoryV32(dataSet.Pool)); dataSet.Nodes = new StreamList <Entities.Node, IStreamDataSet>( nodeLoaderV32); break; } var rootNodes = new MemoryFixedList <Entities.Node, DataSet>( dataSet, reader, new RootNodeFactory()); dataSet.RootNodes = rootNodes; var profileOffsets = new MemoryFixedList <ProfileOffset, 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); } }