Ejemplo n.º 1
0
 public void call(string type, object payload, MessageDoneDelegate callback = null)
 {
     Nanome.Core.Daemon.Dispatcher.queue(delegate()
     {
         var toCall = new List <MessageReaderDelegate>();
         lock (messengers)
         {
             history.messages += 1;
             foreach (var item in messengers)
             {
                 foreach (var subscribe in item.Value)
                 {
                     toCall.Add(subscribe);
                 }
             }
         }
         if (toCall.Count <= 0)
         {
             if (payload != null)
             {
                 Logs.warningOnChannel("Communication", "Message on empty channel", name, "{" + type + "}", "(" + payload.GetType() + ")");
             }
             else
             {
                 Logs.warningOnChannel("Communication", "Message on empty channel", name, "{" + type + "}", "(NULL)");
             }
         }
         else
         {
             var results = new List <object>(toCall.Count);
             var running = new Sync();
             running.queue(toCall.Count);
             running.onDone(delegate()
             {
                 if (callback != null)
                 {
                     callback(results);
                 }
             });
             foreach (var call in toCall)
             {
                 try
                 {
                     call(type, payload, delegate(object result)
                     {
                         if (result != null)
                         {
                             results.Add(result);
                         }
                         running.done();
                     });
                 }
                 catch (Exception e)
                 {
                     Logs.errorOnChannel("Communication", "Exception in messenger callback", e);
                     running.done();
                 }
             }
         }
     });
 }
Ejemplo n.º 2
0
        public static void messageToChannel(string channelName, string type, object payload = null, MessageDoneDelegate callback = null)
        {
            if (displayLogs)
            {
                Logs.timedOnChannel("Communication", "Message on", channelName, "{" + type + "}");
            }
            Channel channel = null;

            lock (channelsByName)
            {
                if (channelsByName.ContainsKey(channelName))
                {
                    channel = channelsByName[channelName];
                }
            }
            if (channel != null)
            {
                channel.call(type, payload, callback);
            }
            else
            {
                if (payload != null)
                {
                    Logs.warningOnChannel("Communication", "Message on unknown channel", channelName, "{" + type + "}", "(" + payload.GetType() + ")");
                }
                else
                {
                    Logs.warningOnChannel("Communication", "Message on unknown channel", channelName, "{" + type + "}", "(NULL)");
                }
            }
        }