public void BroadcastMessage(IChatMsg message) { if (string.IsNullOrEmpty(userName)) throw new UnauthorizedAccessException("Please login first!"); chatBroker.BroadcastMessage(userName, message); }
public void BroadcastMessage(string sourceUser, IChatMsg message) { Console.WriteLine($"New message from {sourceUser}: {message.Text}"); for (int i = 0; i < clients.Count; i++) { try { clients[i].OnNewMessage(sourceUser, message); } catch (OperationCanceledException) { // connection close during send } catch (TimeoutException) { // no response in time } catch (Exception ex) { Console.WriteLine(ex.ToString()); } } }
public void OnNewMessage(string sourceName, IChatMsg msg) { WriteColorLine(sourceName == username ? ConsoleColor.White : ConsoleColor.Green, $"{sourceName}: {msg.Text}"); }