/// <summary> /// Used with deserialized channels, doesn't bind any event handlers /// </summary> /// <param name="log"></param> /// <param name="hint"></param> /// <param name="channel"></param> /// <param name="eventCount"></param> public ChannelLogger(FileLog log, FileLog.ChannelInfo hint, IChannel channel, int eventCount) { this.log = log; this.hint = hint; this.channel = channel; this.eventCount = eventCount; }
/// <summary> /// Reads several consecutive events - more efficient than reading one by one using ReadEvent. /// Note that all required events must already be written, this method doesn't check that. /// </summary> /// <param name="hint">channel info hint</param> /// <param name="firstID">ID of the first required event</param> /// <param name="count">number of consecutive events to return</param> /// <returns></returns> public IList <Event> ReadEvents(FileLog.ChannelInfo hint, int firstID, int count) { var ret = new List <Event>(count); int off; var table = getEventTableByIndex(hint.Hint + 2 * sizeof(long), firstID, out off); lock (streamLock) { var initialPos = stream.Position; while (count > 0) { while (count > 0 && off <= FileLog.EventsPerBlock) { stream.Position = table + off * sizeof(long); ret.Add(readEventByPointer(binReader.ReadInt64())); off++; count--; } stream.Position = table; // next table table = binReader.ReadInt64(); off = 1; // 0 is a pointer to next table } stream.Position = initialPos; } return(ret); }
/// <summary> /// Normal constructor /// </summary> /// <param name="log"></param> /// <param name="hint"></param> /// <param name="channel"></param> public ChannelLogger(FileLog log, FileLog.ChannelInfo hint, IChannel channel): this() { this.log = log; this.hint = hint; this.channel = channel; generalHandler(EventType.ChannelCreated); channel.BindAllEvents(handlers); }
/// <summary> /// Get channels event count /// </summary> /// <param name="hint">a pointer to correct channelInfo structure</param> /// <returns>channel's event count</returns> public int GetEventCount(FileLog.ChannelInfo hint) { lock (streamLock) { var initialPos = stream.Position; // first (long) is a pointer to channel data stream.Position = hint.Hint + sizeof(long); var ret = binReader.ReadInt64(); stream.Position = initialPos; return((int)ret); } }
/// <summary> /// Reads Event from log /// </summary> /// <param name="hint">a pointer to channel info structure</param> /// <param name="id">1-based Event ID</param> /// <returns>Event</returns> public Event ReadEvent(FileLog.ChannelInfo hint, int id) { lock (streamLock) { var initialPos = stream.Position; int off; // + 2*sizeof(long) to skip the pointer to channel data and event count var table = getEventTableByIndex(hint.Hint + 2 * sizeof(long), id, out off); stream.Position = table + off * sizeof(long); var ret = readEventByPointer(binReader.ReadInt64()); stream.Position = initialPos; return(ret); } }