Exemple #1
0
        public static void EnqueueMessage(params Message[] message)
        {
            var e = MessageEnqueued;
            var be = BeforeMessageEnqueued;
            foreach (var m in message)
            {
                var args = new MessageEventArgs(m);

                if (be != null)
                {
                    try
                    {
                        be(args);
                        if (args.Cancel)
                        {
                            continue;
                        }
                    }
                    catch (Exception ex)
                    {
                        Logger.Error(ex, "on before message enqueued " + m.ToPrettyString());
                    }
                }

                if (e != null)
                {
                    try
                    {
                        e(args);
                    }
                    catch (Exception ex)
                    {
                        Logger.Error(ex, "on message enqueued " + m.ToPrettyString());
                    }
                }
            }
        }
Exemple #2
0
 void Manager_MessageEnqueued(MessageEventArgs e)
 {
     Logger.Info(e.Message.ToString(), " >");
 }
Exemple #3
0
        static void SendMessage(object o)
        {
            if (o is byte[])
            {
                iBus.Write((byte[])o);
                Thread.Sleep(iBus.AfterWriteDelay);
                return;
            }

            Message m = (Message)o;

            #if DEBUG
            m.PerformanceInfo.TimeStartedProcessing = DateTime.Now;
            #endif

            MessageEventArgs args = null;
            var e = BeforeMessageSent;
            if (e != null)
            {
                args = new MessageEventArgs(m);
                e(args);
                if (args.Cancel)
                {
                    return;
                }
            }

            iBus.Write(m.Packet);

            #if DEBUG
            m.PerformanceInfo.TimeEndedProcessing = DateTime.Now;
            #endif

            e = AfterMessageSent;
            if (e != null)
            {
                if (args == null)
                {
                    args = new MessageEventArgs(m);
                }
                e(args);
            }

            Thread.Sleep(m.AfterSendDelay > 0 ? m.AfterSendDelay : iBus.AfterWriteDelay); // Don't flood iBus
        }
Exemple #4
0
 static void SaveFoundDevice(MessageEventArgs e)
 {
     if (!foundDevices.Contains(e.Message.SourceDevice))
     {
         foundDevices.Add(e.Message.SourceDevice);
     }
     if (findDevice == e.Message.SourceDevice)
     {
         findDeviceSync.Set();
     }
 }
Exemple #5
0
        public static void ProcessMessage(Message m)
        {
            #if DEBUG
            m.PerformanceInfo.TimeStartedProcessing = DateTime.Now;
            #endif

            MessageEventArgs args = null;
            try
            {
                var e = BeforeMessageReceived;
                if (e != null)
                {
                    args = new MessageEventArgs(m);
                    e(args);
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex, "on before message received " + m.ToPrettyString());
            }

            if (args != null && args.Cancel)
            {
                return;
            }

            foreach (MessageReceiverRegistration receiver in MessageReceiverList)
            {
                try
                {
                    receiver.Process(m);
                }
                catch (Exception ex)
                {
                    Logger.Error(ex, "while processing message: " + m.ToPrettyString());
                }
            }

            #if DEBUG
            m.PerformanceInfo.TimeEndedProcessing = DateTime.Now;
            #endif

            try
            {
                var e = AfterMessageReceived;
                if (e != null)
                {
                    if (args == null)
                    {
                        args = new MessageEventArgs(m);
                    }
                    e(args);
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex, "on after message received " + m.ToPrettyString());
            }
        }
 private void Manager_AfterMessageReceived(MessageEventArgs e)
 {
     if (testTimer?.IsEnabled == true)
     {
         return;
     }
     if (MS43AnalogValues.CanParse(e.Message))
     {
         var av = new MS43JMGAnalogValues();
         av.Parse(e.Message);
         Gauges.ForEach(g => g.Update(av));
     }
 }
Exemple #7
0
 async void Manager_MessageEnqueued(MessageEventArgs e)
 {
     await SendMessage(e.Message);
 }