本文整理汇总了C#中System.IO.FileStream.ReadStruct方法的典型用法代码示例。如果您正苦于以下问题:C# FileStream.ReadStruct方法的具体用法?C# FileStream.ReadStruct怎么用?C# FileStream.ReadStruct使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.FileStream
的用法示例。
在下文中一共展示了FileStream.ReadStruct方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReadCandlesFromFile
public bool ReadCandlesFromFile(CandleByTicker candles, string path, out int timeframe)
{
timeframe = 0;
using (var sr = new FileStream(path, FileMode.Open, FileAccess.Read))
{
var header = sr.ReadStruct<HstFileHeader>();
if (!header.HasValue)
return false;
var mt4StartDate = new DateTime(1970, 1, 1);
timeframe = header.Value.period;
while (true)
{
var record = sr.ReadStruct<HstFileRecord>();
if (!record.HasValue) break;
var candle = new CandleData
{
timeOpen = mt4StartDate.AddSeconds(record.Value.ctm),
open = (float)record.Value.open,
high = (float)record.Value.high,
low = (float)record.Value.low,
close = (float)record.Value.close
};
candle.timeClose = candle.timeOpen.AddMinutes(candles.Timeframe);
candles.candles.Add(candle);
}
}
if (candles.candles.Count > 0)
candles.StartTime = candles.candles.Min(c => c.timeOpen);
return true;
}
示例2: load
public void load(string FileName)
{
FileStream FileStream = new FileStream(FileName, FileMode.Open, FileAccess.Read);
this.header = FileStream.ReadStruct<Header>();
if (this.header.revision >= 3)
{
this.headerExtraRevision3 = FileStream.ReadStruct<HeaderRevision3>();
}
FileStream.ReadStructVector(ref dimensionTable, header.TableDimLength);
FileStream.ReadStructVector(ref xAdjustTable, header.TableXAdjustLength);
FileStream.ReadStructVector(ref yAdjustTable, header.TableYAdjustLength);
FileStream.ReadStructVector(ref advanceTable, header.TableAdvanceLength);
packedShadowCharMap = FileStream.ReadBytes(BitsToBytesHighAligned(header.TableShadowMapLength * header.TableShadowMapBpe));
if (header.revision == 3)
{
FileStream.ReadStructVector(ref charmapCompressionTable1, headerExtraRevision3.TableCompCharMapLength1);
FileStream.ReadStructVector(ref charmapCompressionTable2, headerExtraRevision3.TableCompCharMapLength2);
}
packedCharMap = FileStream.ReadBytes(BitsToBytesHighAligned(header.TableCharMapLength * header.TableCharMapBpe));
packedCharPointerTable = FileStream.ReadBytes(BitsToBytesHighAligned(header.TableCharPointerLength * header.TableCharPointerBpe));
/*
int BytesLeft = (int)(FileStream.Length - FileStream.Position);
charData = new byte[BytesLeft];
FileStream.Read(charData, 0, BytesLeft);
*/
charData = FileStream.ReadBytes((int)(FileStream.Length - FileStream.Position));
var NumberOfCharacters = header.TableCharPointerLength;
charMap = new int[header.lastGlyph + 1];
charPointer = new int[NumberOfCharacters];
Glyphs = new Glyph[NumberOfCharacters];
reverseCharMap = new Dictionary<int, int>();
foreach (var Pair in BitReader.FixedBitReader(packedShadowCharMap, header.TableShadowMapBpe))
{
var UnicodeIndex = (int)Pair.Key + header.firstGlyph;
var GlyphIndex = (int)Pair.Value;
shadowCharMap[UnicodeIndex] = GlyphIndex;
reverseShadowCharMap[GlyphIndex] = UnicodeIndex;
}
foreach (var Pair in BitReader.FixedBitReader(packedCharMap, header.TableCharMapBpe))
{
var UnicodeIndex = (int)Pair.Key + header.firstGlyph;
var GlyphIndex = (int)Pair.Value;
charMap[UnicodeIndex] = GlyphIndex;
reverseCharMap[GlyphIndex] = UnicodeIndex;
}
foreach (var Pair in BitReader.FixedBitReader(packedCharPointerTable, header.TableCharPointerBpe))
{
charPointer[Pair.Key] = (int)Pair.Value;
}
/*
for (int n = 0; n < NumberOfCharacters; n++)
{
Glyphs[n] = new Glyph().Read(this, n);
}
*/
Console.WriteLine(this.header.fontName);
/*
Console.WriteLine(this.header.fontName);
for (int n = 0; n < 300; n++)
{
Console.WriteLine(GetGlyphId((char)n));
}
*/
}