/// <summary> /// Creates a stream data set for the file provided and /// returns the published data of the file. Throws an /// exception if there's a problem accessing the file. /// </summary> /// <param name="fileName"></param> /// <returns>The date time from the file, or null if the file is not a valid data file</returns> internal static DateTime?GetDataFileDate(string fileName) { try { using (var stream = File.OpenRead(fileName)) { using (var reader = new BinaryReader(stream)) { using (var dataSet = new DataSet(File.GetLastWriteTimeUtc(fileName), DataSet.Modes.File)) { CommonFactory.LoadHeader(dataSet, reader); return(dataSet.Published); } } } } catch (Exception ex) { EventLog.Info(String.Format( "Exception getting data file date from file '{0}'", fileName)); EventLog.Debug(ex); return(null); } }
/// <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); } }