Exemple #1
0
        /// <summary>
        /// Check for updates in updateBackgroundWorker
        /// </summary>
        private async void updateBackgroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            InvisibleManCore invisibleManCore = new InvisibleManCore();
            string           result           = await invisibleManCore.CheckForUpdatesVPN();

            // Show update menu
            await Dispatcher.BeginInvoke(new Action(delegate
            {
                if (result == "NewUpdate")
                {
                    GridNewUpdate.Visibility = System.Windows.Visibility.Visible;
                }
            }));
        }
Exemple #2
0
        public MainWindow()
        {
            InitializeComponent();

            // Show and control the tray icon
            TrayIconHandler();

            // Set BackgroundWorkers and Dispatchers
            connectBackgroundWorker.DoWork      += connectBackgroundWorker_DoWork;
            updateBackgroundWorker.DoWork       += updateBackgroundWorker_DoWork;
            messageBackgroundWorker.DoWork      += messageBackgroundWorker_DoWork;
            connectDispatcherTimer.Tick         += connectDispatcherTimer_Tick;
            connectDispatcherTimer.Interval      = TimeSpan.FromSeconds(1);
            disconnectDispatcherTimer.Tick      += disconnectDispatcherTimer_Tick;
            disconnectDispatcherTimer.Interval   = TimeSpan.FromSeconds(1);
            cancelDispatcherTimer.Tick          += cancelDispatcherTimer_Tick;
            cancelDispatcherTimer.Interval       = TimeSpan.FromSeconds(1);
            changeServerDispatcherTimer.Tick    += changeServerDispatcherTimer_Tick;
            changeServerDispatcherTimer.Interval = TimeSpan.FromSeconds(1);

            // Load server data from file
            InvisibleManCore invisibleManCore = new InvisibleManCore();

            if (invisibleManCore.LoadServerFromFile())
            {
                // Set LabelCountry
                LabelCountry.Content = InvisibleManCore.serverInformations[InvisibleManCore.index].serverName;

                // Start to connecting when start
                ButtonConnect_Click(null, null);
            }
            else
            {
                // Reset to first server and set LabelCountry
                InvisibleManCore.index = 0;
                LabelCountry.Content   = InvisibleManCore.serverInformations[InvisibleManCore.index].serverName;

                // Save the first server information and disconnect (if need)
                invisibleManCore.SaveServerInFile();
                ChangeServer();
            }

            // Check for new version of Invisible Man
            updateBackgroundWorker.RunWorkerAsync();

            // Check for message of Invisible Man
            messageBackgroundWorker.RunWorkerAsync();
        }
        /// <summary>
        /// Check for updates in updateBackgroundWorker
        /// </summary>
        private async void updateBackgroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            // Show waiting
            await Dispatcher.BeginInvoke(new Action(delegate
            {
                ShowUpdateMenu("Waiting");
            }));

            InvisibleManCore invisibleManCore = new InvisibleManCore();
            string           result           = await invisibleManCore.CheckForUpdatesVPN();

            // Show update menu
            await Dispatcher.BeginInvoke(new Action(delegate
            {
                ShowUpdateMenu(result);
            }));
        }
Exemple #4
0
        /// <summary>
        /// Check for message in messageBackgroundWorker
        /// </summary>
        private async void messageBackgroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            InvisibleManCore invisibleManCore = new InvisibleManCore();
            Message          message          = await invisibleManCore.CheckForMessage();

            await Dispatcher.BeginInvoke(new Action(delegate
            {
                if (message.content != "FailedToConnect")
                {
                    LabelMessage.Content = message.content;
                    messageLink = message.link;
                    if (!string.IsNullOrEmpty(messageLink))
                    {
                        GridMessageContent.Cursor = Cursors.Hand;
                    }

                    GridMessage.Visibility = System.Windows.Visibility.Visible;

                    // Run the animation
                    Storyboard messageStoryboard = this.TryFindResource("AnimMessage") as Storyboard;
                    messageStoryboard.Begin();
                }
            }));
        }
Exemple #5
0
        /// <summary>
        /// Connect, disconnect, check, cancel and change server, runs in background with connectBackgroundWorker
        /// </summary>
        private void connectBackgroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            if (connectingState == 0) // If you want to disconnecting
            {
                // Show disconnecting
                Dispatcher.BeginInvoke(new Action(delegate
                {
                    ShowConnectingMenu("Disconnecting");
                }));

                // Disconnect from VPN
                InvisibleManCore invisibleManCore = new InvisibleManCore();
                invisibleManCore.DisconnectVPN();

                // Result
                Dispatcher.BeginInvoke(new Action(delegate
                {
                    ShowConnectingMenu("NotConnected");
                }));
            }
            else if (connectingState == 1) // If you want to connecting
            {
                // Show connecting
                Dispatcher.BeginInvoke(new Action(delegate
                {
                    ShowConnectingMenu("Connecting");
                }));

                // Connect to VPN
                InvisibleManCore invisibleManCore = new InvisibleManCore();
                bool             isConnect        = invisibleManCore.ConnectVPN();

                connectDispatcherTimer.Start();

                // Result
                Dispatcher.BeginInvoke(new Action(delegate
                {
                    if (isConnect)
                    {
                        ShowConnectingMenu("Connected");
                        notifyIcon.ShowBalloonTip(500, "Invisible Man is connected", "Enjoy total Internet freedom!", System.Windows.Forms.ToolTipIcon.Info);
                    }
                }));
            }
            else if (connectingState == 2) // If you want to check connection
            {
                // Check the VPN
                InvisibleManCore invisibleManCore = new InvisibleManCore();
                bool             isConnect        = invisibleManCore.ConnectVPN();

                connectDispatcherTimer.Start();

                // Result
                Dispatcher.BeginInvoke(new Action(delegate
                {
                    if (isConnect)
                    {
                        ShowConnectingMenu("Connected");
                    }
                    else
                    {
                        ShowConnectingMenu("Connecting");
                    }
                }));
            }
            else if (connectingState == 3) // If you want to cancel
            {
                // Show cancelling
                Dispatcher.BeginInvoke(new Action(delegate
                {
                    ShowConnectingMenu("Cancelling");
                }));

                // Check the VPN
                InvisibleManCore invisibleManCore = new InvisibleManCore();
                invisibleManCore.DisconnectVPN();

                // Result
                Dispatcher.BeginInvoke(new Action(delegate
                {
                    ShowConnectingMenu("NotConnected");
                }));
            }
            else if (connectingState == 4) // If you change the server
            {
                // Show disconnecting
                Dispatcher.BeginInvoke(new Action(delegate
                {
                    ShowConnectingMenu("Disconnecting");
                }));

                // Disconnect from VPN
                InvisibleManCore invisibleManCore = new InvisibleManCore();
                invisibleManCore.DisconnectVPN();

                // Show connecting
                Dispatcher.BeginInvoke(new Action(delegate
                {
                    ShowConnectingMenu("Connecting");
                }));

                // Connect to VPN
                invisibleManCore = new InvisibleManCore();
                bool isConnect = invisibleManCore.ConnectVPN();

                connectDispatcherTimer.Start();

                // Result
                Dispatcher.BeginInvoke(new Action(delegate
                {
                    if (isConnect)
                    {
                        ShowConnectingMenu("Connected");
                        notifyIcon.ShowBalloonTip(500, "Invisible Man is connected", "Enjoy total Internet freedom!", System.Windows.Forms.ToolTipIcon.Info);
                    }
                }));
            }
        }