Example #1
0
        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();
        }
Example #2
0
        public void Purge()
        {
            MessageWrapper msg;

            while (QueuedMessages.TryDequeue(out msg))
            {
                Persistence.DeleteMessage(msg);
            }
        }
        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);
            }
        }
Example #4
0
 public bool Dequeue(out MessageWrapper wrapper)
 {
     return(QueuedMessages.TryDequeue(out wrapper));
 }