private static void ScanChat() { var lastMessage = _view.ReadAsJsonOrNull <Sample1LastReadMessage>("sample1.dat"); var nextOffset = lastMessage == null ? new EventStoreOffset(0) : new EventStoreOffset(lastMessage.LastOffset); while (true) { var last = EventStoreOffset.Zero; var existMessages = false; foreach (var message in _client.ReadAllEvents(nextOffset)) { last = message.Next; existMessages = true; var text = Encoding.UTF8.GetString(message.EventData); var userName = text.Split('|')[0]; var msg = text.Split(new[] { '|' }, 2)[1]; if (userName == _userName) { continue; } ClearCurrentConsoleLine(); if (userName != "") { WriteColorText(userName + ">", ConsoleColor.Red); Console.WriteLine(msg); } else { WriteColorText(msg + Environment.NewLine, ConsoleColor.DarkCyan); } WriteColorText(_userName + ">", ConsoleColor.Green); Console.Write(_userMessage); } if (existMessages) { _view.WriteAsJson(new Sample1LastReadMessage(last.OffsetInBytes), "sample1.dat"); nextOffset = last; } Thread.Sleep(1000); } }