protected void ProcessQueuedMessages(XmlStream xml, CancellationToken canceltoken) { Message msg; while (!canceltoken.IsCancellationRequested && QueuedMessages.TryDequeue(out msg)) { foreach (XElement el in msg.Content) { if (el.Name.ToString() == "{google:push}push") { string channel = el.Attribute("channel").Value; if (Subscriptions.ContainsKey(channel)) { Logger.Log(LogLevel.Debug, "Handling message for channel {0}", channel); Subscriptions[channel](el, this); } else { Logger.Log(LogLevel.Debug, "Message for unknown channel {0}", channel); } } } } canceltoken.ThrowIfCancellationRequested(); }
protected void EnqueueMessage(XElement msg) { XAttribute from = msg.Attribute("from"); XAttribute to = msg.Attribute("to"); XAttribute type = msg.Attribute("type"); XAttribute id = msg.Attribute("id"); IEnumerable <XElement> error = msg.Elements(NamespaceClient + "error"); IEnumerable <XElement> content = msg.Elements().Where(el => el.Name != (NamespaceClient + "error")); QueuedMessages.Enqueue( new Message { From = from == null ? null : from.Value, To = to == null ? null : to.Value, Type = type == null ? "normal" : type.Value, Id = id == null ? null : id.Value, Content = content, Error = error, MessageElement = msg } ); if (MessagesQueued != null) { MessagesQueued.Set(); } }
public static void CheckStoredMessages(int id) { if (QueuedMessages.ContainsKey(id)) { QueuedMessages[id].ForEach(m => SendMessage(new ServerObject(ServerFlag.SendMessage, new SenderObjectRelation(m.SenderId, m.DestinationId, m.Data, m.Group)), id)); QueuedMessages.Remove(id); } }
public void Enqueue(MessageWrapper message, bool persist = true) { if (persist) { Persistence.SaveMessage(message); } QueuedMessages.Enqueue(message); }
public void Purge() { MessageWrapper msg; while (QueuedMessages.TryDequeue(out msg)) { Persistence.DeleteMessage(msg); } }
private static void AddToQueue(UserConnection user, SenderObjectRelation senderObjectRelation) { if (!QueuedMessages.ContainsKey(user.Id)) { QueuedMessages[user.Id] = new List <SenderObjectRelation>(); } QueuedMessages[user.Id].Add(new SenderObjectRelation(senderObjectRelation.SenderId, senderObjectRelation.DestinationId, senderObjectRelation.Data, senderObjectRelation.Group)); Printer.WriteLine($"Message stored due to unreachable client from {senderObjectRelation.SenderId} to {user.Id}:\n\t{senderObjectRelation.Data}"); }
private void ClearAndFailChannelQueuedMessages(ErrorInfo error) { lock (_lockQueue) { foreach (var messageAndCallback in QueuedMessages) { messageAndCallback.SafeExecute(false, error); } QueuedMessages.Clear(); } }
private Task StartService(CancellationToken cancellationToken) { try { var dispatcher = Application.Current.MainWindow.Dispatcher; return(Task.Factory.StartNew(async() => { do { // Gets the next display location in the screen int nextLocation = FindNextLocation(); if (nextLocation > -1) { NotifyMessage msg = null; // Retrieve the message from the queue if (QueuedMessages.TryDequeue(out msg)) { // construct a View Model and binds it to the Popup Window var viewModel = new NotifyMessageViewModel(msg, DisplayLocations[nextLocation], () => DisplayMessages[nextLocation] = null); // Free the display location when the popup window is closed DisplayMessages[nextLocation] = viewModel; // Use Application.Current.MainWindow.Dispatcher to switch back to the UI Thread to create popup window await dispatcher.BeginInvoke( new MethodInvoker(() => { var window = new AlertDialog() { Owner = Application.Current.MainWindow, DataContext = viewModel, ShowInTaskbar = false }; window.Show(); }), DispatcherPriority.Background); } } await Task.Delay(1000); } while (QueuedMessages.Count > 0 && !cancellationToken.IsCancellationRequested); Stop(); })); } catch { return(null); } }
private int SendQueuedMessages() { List <MessageAndCallback> list; lock (_lockQueue) { if (QueuedMessages.Count <= 0) { return(0); } // Swap the list. list = new List <MessageAndCallback>(QueuedMessages); QueuedMessages.Clear(); } foreach (var qpm in list) { SendMessage(qpm.Message, qpm.Callback); } return(list.Count); }
private void PublishImpl(IEnumerable <Message> messages, Action <bool, ErrorInfo> callback) { // Create protocol message var msg = new ProtocolMessage(ProtocolMessage.MessageAction.Message, Name); msg.Messages = messages.ToArray(); if (State == ChannelState.Initialized || State == ChannelState.Attaching) { if (State == ChannelState.Initialized) { Attach(); } // Not connected, queue the message lock (_lockQueue) { if (Logger.IsDebug) { Logger.Debug($"#{Name}:{State} queuing message"); } QueuedMessages.Add(new MessageAndCallback(msg, callback)); return; } } if (State == ChannelState.Attached) { SendMessage(msg, callback); return; } // Invalid state, throw throw new AblyException(new ErrorInfo("Unable to publish in detached or failed state", 40000, HttpStatusCode.BadRequest)); }
public void EnqueueMessage(NotifyMessage msg) { QueuedMessages.Enqueue(msg); Start(); }
public bool Dequeue(out MessageWrapper wrapper) { return(QueuedMessages.TryDequeue(out wrapper)); }