Beispiel #1
0
        private void HandleMessage([NotNull] object sender, [NotNull] MessageReceivedEventArgs e)
        {
            Assert.ArgumentNotNull(sender, "sender");
            Assert.ArgumentNotNull(e, "e");

            var message = e.Message as OutputToMainWindowMessage;

            if (message != null)
            {
                lock (_messageQueueLockObject)
                {
                    _messageQueue.Enqueue(message);
                }

                if (Application.Current != null)
                {
                    if (_window?.IsVisible == true)
                    {
                        Application.Current.Dispatcher.BeginInvoke((Action)ProcessMessageQueue, DispatcherPriority.Normal);
                    }
                    else
                    {
                        Application.Current.Dispatcher.BeginInvoke((Action)ProcessMessageQueue, DispatcherPriority.Background);
                    }
                }
                return;
            }

            var fullScreenModeMessage = e.Message as ToggleFullScreenModeMessage;

            if (fullScreenModeMessage != null)
            {
                _mainWindow.ToggleFullScreenMode();
                return;
            }

            var showOutputWindowMessage = e.Message as ShowOutputWindowMessage;

            if (showOutputWindowMessage != null)
            {
                _mainWindow.ShowOutputWindow(showOutputWindowMessage.WindowName);
            }

            var showStatusBarMessage = e.Message as ShowStatusBarMessage;

            if (showStatusBarMessage != null)
            {
                _window.DisplayStatusBar(showStatusBarMessage.State, true);
            }

            var setStatusMessage = e.Message as SetStatusMessage;

            if (setStatusMessage != null)
            {
                _window.SetStatusBar(setStatusMessage.Id, setStatusMessage.Msg, setStatusMessage.Color);
            }
        }
Beispiel #2
0
        private void HandleMessage([NotNull] object sender, [NotNull] MessageReceivedEventArgs e)
        {
            Assert.ArgumentNotNull(sender, "sender");
            Assert.ArgumentNotNull(e, "e");

            var message = e.Message as OutputToMainWindowMessage;

            if (message != null)
            {
                lock (_messageQueueLockObject)
                {
                    _messageQueue.Enqueue(message);
                }

                if (Application.Current != null)
                {
                    if (_window?.IsVisible == true)
                    {
                        Application.Current.Dispatcher.BeginInvoke((Action)ProcessMessageQueue, DispatcherPriority.Normal);
                    }
                    else
                    {
                        Application.Current.Dispatcher.BeginInvoke((Action)ProcessMessageQueue, DispatcherPriority.Background);
                    }
                }
                return;
            }

            var fullScreenModeMessage = e.Message as ToggleFullScreenModeMessage;

            if (fullScreenModeMessage != null)
            {
                _mainWindow.ToggleFullScreenMode();
                return;
            }

            var showOutputWindowMessage = e.Message as ShowOutputWindowMessage;

            if (showOutputWindowMessage != null)
            {
                _mainWindow.ShowOutputWindow(showOutputWindowMessage.WindowName);
            }

            var showStatusBarMessage = e.Message as ShowStatusBarMessage;

            if (showStatusBarMessage != null)
            {
                // for some reason, if called from a trigger, we'll have an exception thrown
                // due to not being on the UI thread
                var context = System.Threading.Tasks.TaskScheduler.FromCurrentSynchronizationContext();
                var token   = System.Threading.Tasks.Task.Factory.CancellationToken;
                System.Threading.Tasks.Task.Factory.StartNew(() =>
                {
                    _window.DisplayStatusBar(showStatusBarMessage.State, true);
                }, token, System.Threading.Tasks.TaskCreationOptions.None, context);
            }

            var setStatusMessage = e.Message as SetStatusMessage;

            if (setStatusMessage != null)
            {
                // for some reason, if called from a trigger, we'll have an exception thrown
                // due to not being on the UI thread
                var context = System.Threading.Tasks.TaskScheduler.FromCurrentSynchronizationContext();
                var token   = System.Threading.Tasks.Task.Factory.CancellationToken;
                System.Threading.Tasks.Task.Factory.StartNew(() =>
                {
                    _window.SetStatusBar(setStatusMessage.Id, setStatusMessage.Msg, setStatusMessage.Color);
                }, token, System.Threading.Tasks.TaskCreationOptions.None, context);
            }
        }