LogBuffer(LogFileReader reader) { this.Header = Header.Read(reader); while (reader.Position < reader.Length) { buffers.Add(Buffer.Read(reader)); } }
public LogBuffer(string fileName, EventVisitor visitor) { this.fileName = fileName; this.Visitor = visitor; // thread = new Thread (delegate () { long position = 0; // while (running) { bool shouldUpdate = false; // lock (fileLock) { do { try { stream = new FileStream(fileName, FileMode.Open, FileSystemRights.Read, FileShare.Read, 1024, FileOptions.RandomAccess); } catch (Exception) { // Thread.Sleep (100); } } while (running && stream == null); if (!running) { return; } reader = new BinaryReader(stream); if (this.Header == null) { try { stream.Position = 0; this.Header = Header.Read(reader); position = reader.BaseStream.Position; } catch (Exception e) { System.Console.WriteLine(e); Thread.Sleep(200); // continue; } } stream.Position = position; while (stream.Position < stream.Length) { try { var buffer = Buffer.Read(reader); bufferPositions.Add(position); position = stream.Position; if (Visitor != null) { Visitor.CurrentBuffer = buffer; buffer.Events.ForEach(e => e.Accept(Visitor)); } shouldUpdate = true; } catch (Exception e) { System.Console.WriteLine(e); Thread.Sleep(200); continue; } } // reader.Close (); // stream.Close (); // } if (shouldUpdate) { OnUpdated(EventArgs.Empty); } // Thread.Sleep (1000); // } // }); // thread.IsBackground = true; // thread.Start (); }