private void OnFileEvent(string topic, object source, FileSystemEventArgs e) { var filePath = e.FullPath; string[] fileLines = null; PubSubMessage msg = null; lock (messageLocker) { // Yes it's nasty, I know... Stopwatch s = new Stopwatch(); s.Start(); while (s.Elapsed < TimeSpan.FromMilliseconds(500)) { try { fileLines = File.ReadAllLines(filePath); break; } catch (IOException) { } } s.Stop(); if (!fileLines.IsNullOrEmpty()) { bool hasParsedGui = Guid.TryParse(fileLines.FirstOrDefault(), out var newGuid); var previousGuid = this.messageGuids.GetValueOrDefault(topic); if (OnMessage != null && hasParsedGui && previousGuid != newGuid) { this.messageGuids[topic] = newGuid; var contentLines = new List <string>(fileLines); contentLines.RemoveFirst(); var contentString = String.Join(string.Empty, contentLines); msg = new PubSubMessage(topic, contentString); } } if (msg != null) { RaiseOnMessage(msg); } } }
public void RaiseOnMessage(PubSubMessage msg) { OnMessage?.Invoke(msg); }
public void RaiseOnMessage(PubSubMessage message) { OnMessage?.Invoke(message); }