public void Replay() { using StreamReader reader = (Path == "stdin") ? new StreamReader(Console.OpenStandardInput()) : new StreamReader(new FileStream(Path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)); LogEntry log; string line; long lastMaxOffset = 0; int sendCount = 0; while (true) { if (Follow && Path != "stdin") { //if the file size has not changed, idle if (reader.BaseStream.Length == lastMaxOffset) { Thread.Sleep(100); continue; } //seek to the last max offset reader.BaseStream.Seek(lastMaxOffset, SeekOrigin.Begin); } //read out of the file until the EOF while ((line = reader.ReadLine()) != null) { log = new LogEntry(line); if (Delay > 0) { IdleByLogTime(log); } if (log.Key != null && !log.Key.StartsWith("__")) { Tio.SendCommand(log.ToFullCommand()); this.Logger.OnLogEntry(log); sendCount += 1; if (sendCount % 30000 == 0) { this.Logger.Log(); Console.WriteLine($"Sent: {line}"); } } } if (Follow && Path != "stdin") { Console.WriteLine("\nWaiting for file to grow..."); //update the last max offset lastMaxOffset = reader.BaseStream.Position; } } }
public void Replay() { using (StreamReader reader = new StreamReader(new FileStream(Path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))) { LogEntry log; string line; //start at the end of the file long lastMaxOffset = reader.BaseStream.Length; Console.WriteLine("\nWaiting for file to grow..."); bool commandSent = false; while (true) { //if a command was not sent, don't print that the program is waiting if (commandSent) { Console.WriteLine("\nWaiting for file to grow..."); commandSent = false; } Thread.Sleep(100); //if the file size has not changed, idle if (reader.BaseStream.Length == lastMaxOffset) { continue; } //seek to the last max offset reader.BaseStream.Seek(lastMaxOffset, SeekOrigin.Begin); //read out of the file until the EOF while ((line = reader.ReadLine()) != null) { log = new LogEntry(line); if (Delay > 0) { IdleByLogTime(log); } Tio.SendCommand(log.ToFullCommand()); } commandSent = true; //update the last max offset lastMaxOffset = reader.BaseStream.Position; } } }
public void Clone() { string entry; LogEntry log; using (StreamReader reader = new StreamReader(new FileStream(Path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))) { while ((entry = reader.ReadLine()) != null) { log = new LogEntry(entry); Tio.SendCommand(log.ToFullCommand()); } } }
public int GetHandle() { var line = $"open {Container}"; var answer = Tio.SendCommand(line); if (answer.Contains("error")) { throw new KeyNotFoundException(); } var handle = int.Parse(answer); return(handle); }
public new Item this[int index] { get { var line = $"get {this.Handle} key int {index}"; var answer = Tio.SendCommand(line); // format is "data key {key} value {value} metadata {metadata}" var results = answer.Split(' '); var key = results[2]; var value = results[4]; var metadata = results[6]; return(new Item() { Container = this.Container, Key = key, Value = value, Metadata = metadata }); } }