Ejemplo n.º 1
0
        public virtual void Send(string from, string to, string message)
        {
            // using dict's key as receiver, no need for actual value/object
            IParticipant participant = Participants[to];

            // checking if participant excists, needed because sender may not have correct key
            if (participant != null)
            {
                participant.Receive(from, message);
            }
        }
Ejemplo n.º 2
0
        public void Send(string from, string to, string message)
        {
            IParticipant target = participants[to];

            if (target != null)
            {
                target.Receive(from, message);
            }
            else
            {
                throw new Exception("Invalid chat participant!");
            }
        }
Ejemplo n.º 3
0
 public void Send(string from, string to, string message)
 {
     Console.WriteLine($"Chatroom got message: {message}. From: {from}. To: {to}");
     if (to.ToLower() == "all")
     {
         foreach (var pair in participants)
         {
             if (pair.Value.Name != from)
             {
                 pair.Value.Receive(from, message);
             }
         }
     }
     else
     {
         IParticipant receiver = participants[to];
         if (receiver != null)
         {
             receiver.Receive(from, message);
         }
     }
 }