Пример #1
0
 private void Local_MessageReceived(object sender, MessageReceivedEventArgs e)
 {
     if (!ReceivedMessages.Any(i => i.Id == e.Message.Id))
         {
             ReceivedMessages.Add(e.Message);
             if (MessageReceived != null)
                 MessageReceived(this, e);
         }
 }
Пример #2
0
        private void Service_MessageReceived(object sender, MessageReceivedEventArgs e)
        {
            var node = Local.FirstOrDefault(i => i.GUID.ToString() == e.Message.To);

            if (node != null)
            {
                //Message was for one of my nodes (Hand over the message to that node)
                node.CallMessageReceived(e.Message);
            }
            else
            {
                //Message was not to any of my nodes (relay the message and decrease ttl)
                e.Message.TTL--;
                if (e.Message.TTL > 0)
                    foreach (ServiceConnection connection in Connections.Where(i => i != (ServiceConnection)sender).Where(i => i.Available))
                        connection.Send(e.Message.ToString());
            }
        }