/// <summary> /// Opens a <see cref="LogReader"/> to read the content of a compressed or uncompressed stream. /// The stream will be closed when <see cref="LogReader.Dispose"/> will be called. /// </summary> /// <param name="seekableStream">Stream that must support Seek operations (<see cref="Stream.CanSeek"/> must be true).</param> /// <param name="dataOffset"> /// An optional offset where the stream position must be initially set: this is the position of an entry in the actual (potentially uncompressed stream), /// not the offset in the original stream. /// </param> /// <param name="filter">An optional <see cref="MulticastFilter"/>.</param> /// <returns>A <see cref="LogReader"/> that will close the file when disposed.</returns> /// <remarks> /// .ckmon files exist in different file versions, depending on headers. /// The file can be compressed using GZipStream, in which case the header will be the magic GZIP header: 1F 8B. /// New header (applies to version 5), the file will start with 43 4B 4D 4F 4E (CKMON in ASCII), followed by the version number, instead of only the version number. /// </remarks> public static LogReader Open(Stream seekableStream, long dataOffset = 0, MulticastFilter?filter = null) { Throw.CheckNotNullArgument(seekableStream); Throw.CheckArgument(seekableStream.CanSeek); LogReaderStreamInfo i = LogReaderStreamInfo.OpenStream(seekableStream); var s = i.LogStream; if (dataOffset > 0) { if (s.CanSeek) { s.Seek(dataOffset, SeekOrigin.Current); } else { var buffer = new byte[8192]; int toRead; while ((toRead = (int)Math.Min(8192, dataOffset)) > 0 && s.Read(buffer, 0, toRead) == toRead) { dataOffset -= toRead; } } } var r = new LogReader(s, i.Version, i.HeaderLength) { CurrentFilter = filter }; return(r); }
public OneLogReader(RawLogFileMonitorOccurence file, DateTimeStamp firstLogTime) { File = file; _reader = file.CreateFilteredReaderAndMoveTo(firstLogTime); FirstGroupDepth = _reader.CurrentMulticast.GroupDepth; Head = _reader.CurrentMulticastWithOffset; }
public OneLogReader(RawLogFileMonitorOccurence file, long offset) { _reader = file.CreateFilteredReader(offset); _reader.MoveNext(); FirstGroupDepth = _reader.CurrentMulticast.GroupDepth; Head = _reader.CurrentMulticastWithOffset; }
/// <summary> /// Opens a <see cref="LogReader"/> to read the content of a compressed or uncompressed stream. /// The stream will be closed when <see cref="LogReader.Dispose"/> will be called. /// </summary> /// <param name="seekableStream">Stream that must support Seek operations (<see cref="Stream.CanSeek"/> must be true).</param> /// <param name="dataOffset"> /// An optional offset where the stream position must be initially set: this is the position of an entry in the actual (potentially uncompressed stream), /// not the offset in the original stream. /// </param> /// <param name="filter">An optional <see cref="MulticastFilter"/>.</param> /// <returns>A <see cref="LogReader"/> that will close the file when disposed.</returns> /// <remarks> /// .ckmon files exist in different file versions, depending on headers. /// The file can be compressed using GZipStream, in which case the header will be the magic GZIP header: 1F 8B. /// New header (applies to version 5), the file will start with 43 4B 4D 4F 4E (CKMON in ASCII), followed by the version number, instead of only the version number. /// </remarks> public static LogReader Open(Stream seekableStream, long dataOffset = 0, MulticastFilter filter = null) { if (seekableStream == null) { throw new ArgumentNullException("seekableStream"); } if (!seekableStream.CanSeek) { throw new ArgumentException("Stream must support seek operations.", "seekableStream"); } LogReaderStreamInfo i = LogReaderStreamInfo.OpenStream(seekableStream); var s = i.LogStream; if (dataOffset > 0) { if (s.CanSeek) { s.Seek(dataOffset, SeekOrigin.Current); } else { var buffer = new byte[8192]; int toRead; while ((toRead = (int)Math.Min(8192, dataOffset)) > 0 && s.Read(buffer, 0, toRead) == toRead) { dataOffset -= toRead; } } } var r = new LogReader(s, i.Version, i.HeaderLength); r.CurrentFilter = filter; return(r); }
public void Dispose() { if (_reader != null) { _reader.Dispose(); _reader = null; } }
OneLogReader(RawLogFileMonitorOccurence file, LogReader positioned) { File = file; _reader = positioned; Debug.Assert(_reader.CurrentMulticast != null); FirstGroupDepth = _reader.CurrentMulticast.GroupDepth; Head = _reader.CurrentMulticastWithOffset; }
/// <summary> /// Opens a <see cref="LogReader"/> that reads unicast entries only from this monitor and positions it on the first entry /// with the given time (i.e. <see cref="LogReader.MoveNext"/> has been called). /// </summary> /// <param name="logTime">Log time. Must exist in the stream otherwise an exception is thrown.</param> /// <returns>A log reader that will read only entries from this monitor.</returns> public LogReader CreateFilteredReaderAndMoveTo(DateTimeStamp logTime) { var r = LogReader.Open(LogFile.FileName, FirstOffset, new LogReader.MulticastFilter(MonitorId, LastOffset)); while (r.MoveNext() && r.Current.LogTime < logTime) { ; } return(r); }
public bool Forward() { Debug.Assert(_reader != null); if (_reader.MoveNext()) { Head = _reader.CurrentMulticastWithOffset; return(true); } _reader.Dispose(); _reader = null; return(false); }
/// <summary> /// Opens a <see cref="LogReader"/> that reads unicast entries only from this monitor and positions it on the first entry /// with the given time (i.e. <see cref="LogReader.MoveNext"/> has been called). /// </summary> /// <param name="logTime">Log time. Must exist in the stream otherwise an exception is thrown.</param> /// <returns>A log reader that will read only entries from this monitor.</returns> public LogReader CreateFilteredReaderAndMoveTo(DateTimeStamp logTime) { var r = LogReader.Open(LogFile.FileName, FirstOffset, new LogReader.MulticastFilter(MonitorId, LastOffset)); while (r.MoveNext() && r.Current.LogTime < logTime) { ; } if (r.ReadException != null || r.BadEndOfFileMarker) { r.Dispose(); Throw.InvalidDataException($"Unable to read '{LogFile.FileName}' for monitor '{MonitorId}' from offset {LastOffset}.", r.ReadException); } return(r); }
/// <summary> /// Creates and opens a <see cref="LogReader"/> that reads unicast entries only from this monitor. /// The reader is positioned on the entry (i.e. <see cref="LogReader.MoveNext"/> has been called). /// </summary> /// <param name="streamOffset">Initial stream position.</param> /// <returns>A log reader that will read only entries from this monitor.</returns> public LogReader CreateFilteredReaderAndMoveTo(long streamOffset) { if (streamOffset == -1) { streamOffset = FirstOffset; } var r = LogReader.Open(LogFile.FileName, streamOffset, new LogReader.MulticastFilter(MonitorId, LastOffset)); if (!r.MoveNext()) { r.Dispose(); Throw.InvalidDataException($"Unable to read '{LogFile.FileName}' for monitor '{MonitorId}' from offset {streamOffset}.", r.ReadException); } return(r); }
internal void Initialize(MultiLogReader reader) { try { var monitorOccurrences = new Dictionary <Guid, RawLogFileMonitorOccurence>(); var monitorOccurrenceList = new List <RawLogFileMonitorOccurence>(); using (var r = LogReader.Open(_fileName)) { if (r.MoveNext()) { _fileVersion = r.StreamVersion; do { var log = r.Current as IMulticastLogEntry; if (log != null) { ++_totalEntryCount; if (_firstEntryTime > log.LogTime) { _firstEntryTime = log.LogTime; } if (_lastEntryTime < log.LogTime) { _lastEntryTime = log.LogTime; } UpdateMonitor(reader, r.StreamOffset, monitorOccurrences, monitorOccurrenceList, log); } }while(r.MoveNext()); } _badEndOfFile = r.BadEndOfFileMarker; _error = r.ReadException; } _monitors = monitorOccurrenceList.ToArray(); } catch (Exception ex) { _error = ex; } }
/// <summary> /// Creates and opens a <see cref="LogReader"/> that reads unicast entries only from this monitor. /// The reader is initially positioned before the entry (i.e. <see cref="LogReader.MoveNext"/> must be called). /// </summary> /// <param name="streamOffset">Initial stream position.</param> /// <returns>A log reader that will read only entries from this monitor.</returns> public LogReader CreateFilteredReader(long streamOffset) { return(LogReader.Open(LogFile.FileName, streamOffset != -1 ? streamOffset : FirstOffset, new LogReader.MulticastFilter(MonitorId, LastOffset))); }