public static List<Record> GetRecordsFromSession(Session session, TimePeriod period, bool filterRecords = true) { var res = new List<Record>(); using (var mutex = Utils.TryLockFile(session.FileName)) using (var stream = new FileStream(session.FileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { var encoding = DetectEncoding(stream); if (filterRecords) { while (true) { var startPos = stream.Position; var line = ReadLine(stream, encoding); if (line == null) break; var record = ParseLine(line); if (!IsServiceMessage(record.Name)) { stream.Position = startPos; break; } record.SessionId = session.Id; res.Add(record); } SkipOutdatedRecords(stream, encoding, period.StartTime); } using (var reader = new StreamReader(stream, encoding, true)) { while (true) { var line = reader.ReadLine(); if (line == null) break; var record = ParseLine(line); if (filterRecords && record.Time > period.EndTime) break; if (filterRecords && record.Time < period.StartTime) continue; record.SessionId = session.Id; res.Add(record); } } } return res; }
private static string ConvertData(string recordsResponse, Session session) { var buf = new StringBuilder(); var lines = recordsResponse.Split(new[] {'\r', '\n'}, StringSplitOptions.RemoveEmptyEntries); foreach (var line in lines) { if (!line.StartsWith(session.Id)) throw new ApplicationException(); var tmp = line.Substring(session.Id.Length + 1); buf.AppendLine(tmp); } var res = buf.ToString(); return res; }
public static List<Session> Parse(string text) { var res = new List<Session>(); var lines = text.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); foreach (var line in lines) { var columns = line.Split('\t'); var cur = new Session { Id = columns[0], CreationTime = Util.ParseDateTime(columns[1]), LastUpdateTime = Util.ParseDateTime(columns[2]), }; res.Add(cur); } return res; }