private static void ProcessUdpMessageQueue(Queue <LWRF.Message> udpMessageQueue) { try { while (!abort) { if (UdpMessageQueue.Count == 0) { Thread.Sleep(1000); continue; } while (UdpMessageQueue.Count != 0) { LWRF.Message m = UdpMessageQueue.Peek(); logger.Info("ProcessUdpMessageQueue|{0}|Dequeueing {1}", m.msgId, m.msgId.ToString("000") + m.messageText); SendUdpMessage(m); logger.Info("ProcessUdpMessageQueue|{0}|Pausing for {1} seconds", m.msgId, m.delay); Thread.Sleep(m.delay * 1000); continue; } } } catch (Exception e) { logger.Error(e); } }
private static void SendUdpMessage(LWRF.Message m) { try { logger.Info("SendUdpMessage|{0}|Sending: {1} Attempt: {2}", m.msgId, m.msgId.ToString("000") + m.messageText, m.attenpt); UDPSocket c = new UDPSocket(); c.Client(LWRF.lwrfHubIP, 9760); c.Send(m.msgId, m.messageText); if (m.system) { UdpMessageQueue.Dequeue(); } else { bool ack = UdpMessageAcknowledged(m.msgId, 10); if (!ack) { if (m.attenpt <= 5) { logger.Info("SendUdpMessage|{0}|Requeueing {1}", m.msgId, m.msgId.ToString("000") + m.messageText); } else { logger.Info("SendUdpMessage|{0}|Cancelling {1}", m.msgId, m.msgId.ToString("000") + m.messageText); UdpMessageQueue.Dequeue(); } } else { logger.Info("SendUdpMessage|{0}|LWRF Hub Acknowledged {1}", m.msgId, m.msgId.ToString("000") + m.messageText); UdpMessageQueue.Dequeue(); } } } catch (Exception e) { logger.Error(e); } }
public static void QueueUdpMessage(LWRF.Message m) { try { if (m.messageText == null) { return; } msgId++; if (msgId > 999) { msgId = 1; } m.msgId = msgId; if (LWRF.messageList.Count == 0) { logger.Debug("QueueUdpMessage|{0}|messageList: Empty", msgId); } else { foreach (var list in LWRF.messageList) { logger.Debug("QueueUdpMessage|{0}|messageList: {1} {2}", msgId, list.Key, list.Value.room); } } logger.Info("QueueUdpMessage|{0}|Queueing {1}", msgId, m.msgId.ToString("000") + m.messageText); LWRF.messageList.Add(msgId, m); UdpMessageQueue.Enqueue(m); logger.Debug("QueueUdpMessage|{0}|UdpMessageQueue Count: {1}", msgId, UdpMessageQueue.Count); } catch (Exception e) { logger.Error(e); logger.Error("QueueUdpMessage|{0}", msgId); } }