Exemple #1
0
        void InitializeBinding() {
            //BASIC SETTINGS
            //proxy type

            proxyTypeGaMenuItem.RadioCheck = true;
            proxyTypeSshMenuItem.RadioCheck = true;
            proxyTypeHttpMenuItem.RadioCheck = true;
            proxyTypeSocksMenuItem.RadioCheck = true;

            proxyTypeContextMenu.MenuItems.Add(proxyTypeGaMenuItem);
            proxyTypeContextMenu.MenuItems.Add(proxyTypeSshMenuItem);
            proxyTypeContextMenu.MenuItems.Add(proxyTypeHttpMenuItem);
            proxyTypeContextMenu.MenuItems.Add(proxyTypeSocksMenuItem);

            initProxyType();

            settings.PropertyChanged += (o, a) => {
                switch (a.PropertyName) {
                    case "ProxyType": break;
                    default: return;
                }

                initProxyType();
            };

            var gaSelected = new Action(() => {
                if (settings.ProxyType != "GA") {
                    if (Directory.Exists(App.AppDataDirectory + settings.GaFolderName)) {
                        settings.ProxyType = "GA";
                    }
                    else {
                        initProxyType();
                        var r = MessageBox.Show(resources["GoAgentNotInstalledMessage"] as string, resources["XWall"] as string, MessageBoxButton.OKCancel);
                        if (r == MessageBoxResult.OK) {
                            settings.ToUseGoAgent = true;
                            downloadUpdate(true);
                            aboutTabItem.Focus();
                        }
                    }
                }
            });

            proxyTypeGaRadio.Checked += (sender, e) => {
                gaSelected();
            };

            proxyTypeGaMenuItem.Click += (sender, e) => {
                gaSelected();
            };

            proxyTypeSshRadio.Checked += (sender, e) => {
                if (settings.ProxyType != "SSH") {
                    settings.ProxyType = "SSH";
                }
            };

            proxyTypeSshMenuItem.Click += (sender, e) => {
                if (settings.ProxyType != "SSH") {
                    settings.ProxyType = "SSH";
                }
            };

            proxyTypeHttpRadio.Checked += (sender, e) => {
                if (settings.ProxyType != "HTTP") {
                    settings.ProxyType = "HTTP";
                }
            };

            proxyTypeHttpMenuItem.Click += (sender, e) => {
                if (settings.ProxyType != "HTTP") {
                    settings.ProxyType = "HTTP";
                }
            };

            proxyTypeSocksRadio.Checked += (sender, e) => {
                if (settings.ProxyType != "SOCKS5") {
                    settings.ProxyType = "SOCKS5";
                }
            };
            proxyTypeSocksMenuItem.Click += (sender, e) => {
                if (settings.ProxyType != "SOCKS5") {
                    settings.ProxyType = "SOCKS5";
                }
            };

            //goagent information
            gaProfilesList.SelectionChanged += (sender, e) => {
                var value = gaProfilesList.SelectedValue as string;
                if (settings.GaProfile != value) {
                    settings.GaProfile = value;
                }
            };

            gaProfilesList.Text = settings.GaProfile;

            //ssh information
            UIBinding.bindTextBox(sshServerTextBox, "SshServer");
            UIBinding.bindTextBox(sshPortTextBox, "SshPort");
            UIBinding.bindTextBox(sshUsernameTextBox, "SshUsername");
            UIBinding.bindTextBox(sshPasswordBox, "SshPassword");

            //http information
            UIBinding.bindTextBox(httpServerTextBox, "HttpServer");
            UIBinding.bindTextBox(httpPortTextBox, "HttpPort");

            //socks information
            UIBinding.bindTextBox(socksServerTextBox, "SocksServer");
            UIBinding.bindTextBox(socksPortTextBox, "SocksPort");

            //ADVANCED SETTINGS
            //x-wall
            UIBinding.bindCheckBox(autoStartCheckBox, "AutoStart");
            UIBinding.bindCheckBox(autoSetProxyCheckBox, "SetProxyAutomatically");

            settings.PropertyChanged += (sender, e) => {
                if (e.PropertyName == "SetProxyAutomatically") {
                    if (settings.SetProxyAutomatically) {
                        Operation.Proxies.SetXWallProxy();
                    }
                    else {
                        Operation.Proxies.RestoreProxy();
                    }
                }
            };

            UIBinding.bindCheckBox(listenToLocalOnlyCheckBox, "ListenToLocalOnly");
            UIBinding.bindTextBox(proxyPortTextBox, "ProxyPort");

            UIBinding.bindCheckBox(useIntranetProxyCheckBox, "UseIntranetProxy");
            UIBinding.bindTextBox(intranetProxyServerTextBox, "IntranetProxyServer");
            UIBinding.bindTextBox(intranetProxyPortTextBox, "IntranetProxyPort");
            
            //goagent
            UIBinding.bindTextBox(gaAppIdsTextBox, "GaAppIds");
            UIBinding.bindTextBox(gaPortTextBox, "GaPort");

            //ssh
            UIBinding.bindCheckBox(sshNotificationCheckBox, "SshNotification");
            UIBinding.bindCheckBox(sshCompressionCheckBox, "SshCompression");
            UIBinding.bindCheckBox(sshAutoReconnectCheckBox, "SshAutoReconnect");
            UIBinding.bindCheckBox(sshReconnectAnyConditionCheckBox, "SshReconnectAnyCondition");
            UIBinding.bindCheckBox(sshUsePlonkCheckBox, "SshUsePlonk");
            UIBinding.bindTextBox(sshPlonkKeywordTextBox, "SshPlonkKeyword");
            UIBinding.bindTextBox(sshSocksPortTextBox, "SshSocksPort");

            //PROFILES
            //ssh profiles
            sshProfiles = new Profile.SshProfilesCollection("SshProfiles");
            sshProfilesListBox.ItemsSource = sshProfiles.Items;
            sshProfilesList.ItemsSource = sshProfiles.Items;

            sshProfileEditGrid.IsEnabled =
            sshRemoveProfileButton.IsEnabled =
                sshProfilesListBox.SelectedItem != null;

            sshProfilesListBox.SelectionChanged += (sender, e) => {
                sshProfileEditGrid.IsEnabled =
                sshRemoveProfileButton.IsEnabled =
                    sshProfilesListBox.SelectedItem != null;
            };

            updateSshProfileEdit();
            updateSshInformation();


            Profile.DefaultProfile selectedSshProfile = null;

            if (settings.SshSelectedProfileIndex >= 0 && settings.SshSelectedProfileIndex < sshProfiles.Items.Count) {
                selectedSshProfile = sshProfiles.Items[settings.SshSelectedProfileIndex];
            }

            sshProfilesListBox.SelectionChanged += (sender, e) => {
                updateSshProfileEdit();
            };

            sshProfilesList.SelectedIndex = settings.SshSelectedProfileIndex;

            sshProfilesList.SelectionChanged += (sender, e) => {
                var index = sshProfilesList.SelectedIndex;
                if (settings.SshSelectedProfileIndex != index) {
                    settings.SshSelectedProfileIndex = index;
                }
            };

            sshProfiles.Items.ListChanged += (sender, e) => {
                var index = sshProfilesList.SelectedIndex;
                if (settings.SshSelectedProfileIndex != index) {
                    settings.SshSelectedProfileIndex = index;
                }
            };

            bindProfileContextMenu();

            settings.PropertyChanged += (sender, e) => {
                if (e.PropertyName == "SshSelectedProfileIndex") {
                    var index = settings.SshSelectedProfileIndex;

                    if (index >= 0 && index < sshProfiles.Items.Count) {
                        if (index != sshProfilesList.SelectedIndex) {
                            sshProfilesList.SelectedIndex = index;
                        }

                        var profile = sshProfiles.Items[index];

                        if (profile != selectedSshProfile) {
                            selectedSshProfile = profile;

                            profileContextMenu.MenuItems[index].PerformClick();
                            updateSshInformation();

                            if (plink.IsConnected || plink.IsConnecting || plink.IsReconnecting) {
                                plink.Stop();
                                plink.Start();
                            }
                        }
                    }
                }
            };

            sshProfileName.LostFocus += (sender, e) => {
                var item = sshProfilesListBox.SelectedItem as Profile.SshProfile;
                var name = sshProfileName.Text.Trim().Replace("\t", " ");
                if (item.Name != name) {
                    if (name != "") {
                        item.Name = name;
                    }
                    sshProfileName.Text = item.Name;
                    updateSshInformation();
                    sshProfiles.Items.ResetItem(sshProfilesListBox.SelectedIndex);
                    var index = sshProfilesList.SelectedIndex;
                    if (sshProfilesList.SelectedItem == item) {
                        sshProfilesList.Text = item.Name;
                    }
                }
            };
            sshProfileServer.LostFocus += (sender, e) => {
                var item = sshProfilesListBox.SelectedItem as Profile.SshProfile;
                var server = sshProfileServer.Text.Trim().ToLower();
                if (item.Server != server) {
                    if (new Regex(@"^([a-z0-9-]+(?:\.[a-z0-9-]+)*|)$").IsMatch(server)) {
                        item.Server = server;
                    }
                    sshProfileServer.Text = item.Server;
                    updateSshInformation();
                    sshProfiles.Items.ResetItem(sshProfilesListBox.SelectedIndex);
                }
            };
            sshProfilePort.LostFocus += (sender, e) => {
                var item = sshProfilesListBox.SelectedItem as Profile.SshProfile;
                var port = sshProfilePort.Text.Trim();
                if (item.Port.ToString() != port) {
                    if (new Regex(@"^[1-9]\d*$").IsMatch(port)) {
                        item.Port = int.Parse(port);
                    }
                    sshProfilePort.Text = item.Port.ToString();
                    updateSshInformation();
                    sshProfiles.Items.ResetItem(sshProfilesListBox.SelectedIndex);
                }
            };
            sshProfileUsername.LostFocus += (sender, e) => {
                var item = sshProfilesListBox.SelectedItem as Profile.SshProfile;
                var username = sshProfileUsername.Text.Trim().Replace("\t", " ");
                if (item.Username != username) {
                    item.Username = username;
                    sshProfileUsername.Text = item.Username;
                    updateSshInformation();
                    sshProfiles.Items.ResetItem(sshProfilesListBox.SelectedIndex);
                }
            };
            sshProfilePassword.LostFocus += (sender, e) => {
                var item = sshProfilesListBox.SelectedItem as Profile.SshProfile;
                var password = sshProfilePassword.Password.Replace("\t", " ");
                if (item.Password != password) {
                    item.Password = password;
                    sshProfilePassword.Password = item.Password;
                    updateSshInformation();
                    sshProfiles.Items.ResetItem(sshProfilesListBox.SelectedIndex);
                }
            };
            sshProfileName.GotFocus += selectAllWhenGetFocus;
            sshProfileServer.GotFocus += selectAllWhenGetFocus;
            sshProfilePort.GotFocus += selectAllWhenGetFocus;
            sshProfileUsername.GotFocus += selectAllWhenGetFocus;
            sshProfilePassword.GotFocus += selectAllWhenGetFocus;

            //RULES
            UIBinding.bindCheckBox(forwardAllCheckBox, "ForwardAll");
            UIBinding.bindCheckBox(useOnlineRulesCheckBox, "UseOnlineRules");
            //UIBinding.bindCheckBox(submitNewRuleCheckBox, "SubmitNewRule");
            //UIBinding.bindCheckBox(useCustomRulesCheckBox, "UseCustomRules");
        }
Exemple #2
0
        void InitializeBinding()
        {
            //BASIC SETTINGS
            //proxy type

            proxyTypeGaMenuItem.RadioCheck    = true;
            proxyTypeSshMenuItem.RadioCheck   = true;
            proxyTypeHttpMenuItem.RadioCheck  = true;
            proxyTypeSocksMenuItem.RadioCheck = true;

            proxyTypeContextMenu.MenuItems.Add(proxyTypeGaMenuItem);
            proxyTypeContextMenu.MenuItems.Add(proxyTypeSshMenuItem);
            proxyTypeContextMenu.MenuItems.Add(proxyTypeHttpMenuItem);
            proxyTypeContextMenu.MenuItems.Add(proxyTypeSocksMenuItem);

            initProxyType();

            settings.PropertyChanged += (o, a) => {
                switch (a.PropertyName)
                {
                case "ProxyType": break;

                default: return;
                }

                initProxyType();
            };

            var gaSelected = new Action(() => {
                if (settings.ProxyType != "GA")
                {
                    if (Directory.Exists(App.AppDataDirectory + settings.GaFolderName))
                    {
                        settings.ProxyType = "GA";
                    }
                    else
                    {
                        initProxyType();
                        var r = MessageBox.Show(resources["GoAgentNotInstalledMessage"] as string, resources["XWall"] as string, MessageBoxButton.OKCancel);
                        if (r == MessageBoxResult.OK)
                        {
                            settings.ToUseGoAgent = true;
                            downloadUpdate(true);
                            aboutTabItem.Focus();
                        }
                    }
                }
            });

            proxyTypeGaRadio.Checked += (sender, e) => {
                gaSelected();
            };

            proxyTypeGaMenuItem.Click += (sender, e) => {
                gaSelected();
            };

            proxyTypeSshRadio.Checked += (sender, e) => {
                if (settings.ProxyType != "SSH")
                {
                    settings.ProxyType = "SSH";
                }
            };

            proxyTypeSshMenuItem.Click += (sender, e) => {
                if (settings.ProxyType != "SSH")
                {
                    settings.ProxyType = "SSH";
                }
            };

            proxyTypeHttpRadio.Checked += (sender, e) => {
                if (settings.ProxyType != "HTTP")
                {
                    settings.ProxyType = "HTTP";
                }
            };

            proxyTypeHttpMenuItem.Click += (sender, e) => {
                if (settings.ProxyType != "HTTP")
                {
                    settings.ProxyType = "HTTP";
                }
            };

            proxyTypeSocksRadio.Checked += (sender, e) => {
                if (settings.ProxyType != "SOCKS5")
                {
                    settings.ProxyType = "SOCKS5";
                }
            };
            proxyTypeSocksMenuItem.Click += (sender, e) => {
                if (settings.ProxyType != "SOCKS5")
                {
                    settings.ProxyType = "SOCKS5";
                }
            };

            //goagent information
            gaProfilesList.SelectionChanged += (sender, e) => {
                var value = gaProfilesList.SelectedValue as string;
                if (settings.GaProfile != value)
                {
                    settings.GaProfile = value;
                }
            };

            gaProfilesList.Text = settings.GaProfile;

            //ssh information
            UIBinding.bindTextBox(sshServerTextBox, "SshServer");
            UIBinding.bindTextBox(sshPortTextBox, "SshPort");
            UIBinding.bindTextBox(sshUsernameTextBox, "SshUsername");
            UIBinding.bindTextBox(sshPasswordBox, "SshPassword");

            //http information
            UIBinding.bindTextBox(httpServerTextBox, "HttpServer");
            UIBinding.bindTextBox(httpPortTextBox, "HttpPort");

            //socks information
            UIBinding.bindTextBox(socksServerTextBox, "SocksServer");
            UIBinding.bindTextBox(socksPortTextBox, "SocksPort");

            //ADVANCED SETTINGS
            //x-wall
            UIBinding.bindCheckBox(autoStartCheckBox, "AutoStart");
            UIBinding.bindCheckBox(autoSetProxyCheckBox, "SetProxyAutomatically");

            settings.PropertyChanged += (sender, e) => {
                if (e.PropertyName == "SetProxyAutomatically")
                {
                    if (settings.SetProxyAutomatically)
                    {
                        Operation.Proxies.SetXWallProxy();
                    }
                    else
                    {
                        Operation.Proxies.RestoreProxy();
                    }
                }
            };

            UIBinding.bindCheckBox(listenToLocalOnlyCheckBox, "ListenToLocalOnly");
            UIBinding.bindTextBox(proxyPortTextBox, "ProxyPort");

            UIBinding.bindCheckBox(useIntranetProxyCheckBox, "UseIntranetProxy");
            UIBinding.bindTextBox(intranetProxyServerTextBox, "IntranetProxyServer");
            UIBinding.bindTextBox(intranetProxyPortTextBox, "IntranetProxyPort");

            //goagent
            UIBinding.bindTextBox(gaAppIdsTextBox, "GaAppIds");
            UIBinding.bindTextBox(gaPortTextBox, "GaPort");

            //ssh
            UIBinding.bindCheckBox(sshNotificationCheckBox, "SshNotification");
            UIBinding.bindCheckBox(sshCompressionCheckBox, "SshCompression");
            UIBinding.bindCheckBox(sshAutoReconnectCheckBox, "SshAutoReconnect");
            UIBinding.bindCheckBox(sshReconnectAnyConditionCheckBox, "SshReconnectAnyCondition");
            UIBinding.bindCheckBox(sshUsePlonkCheckBox, "SshUsePlonk");
            UIBinding.bindTextBox(sshPlonkKeywordTextBox, "SshPlonkKeyword");
            UIBinding.bindTextBox(sshSocksPortTextBox, "SshSocksPort");

            //PROFILES
            //ssh profiles
            sshProfiles = new Profile.SshProfilesCollection("SshProfiles");
            sshProfilesListBox.ItemsSource = sshProfiles.Items;
            sshProfilesList.ItemsSource    = sshProfiles.Items;

            sshProfileEditGrid.IsEnabled         =
                sshRemoveProfileButton.IsEnabled =
                    sshProfilesListBox.SelectedItem != null;

            sshProfilesListBox.SelectionChanged += (sender, e) => {
                sshProfileEditGrid.IsEnabled         =
                    sshRemoveProfileButton.IsEnabled =
                        sshProfilesListBox.SelectedItem != null;
            };

            updateSshProfileEdit();
            updateSshInformation();


            Profile.DefaultProfile selectedSshProfile = null;

            if (settings.SshSelectedProfileIndex >= 0 && settings.SshSelectedProfileIndex < sshProfiles.Items.Count)
            {
                selectedSshProfile = sshProfiles.Items[settings.SshSelectedProfileIndex];
            }

            sshProfilesListBox.SelectionChanged += (sender, e) => {
                updateSshProfileEdit();
            };

            sshProfilesList.SelectedIndex = settings.SshSelectedProfileIndex;

            sshProfilesList.SelectionChanged += (sender, e) => {
                var index = sshProfilesList.SelectedIndex;
                if (settings.SshSelectedProfileIndex != index)
                {
                    settings.SshSelectedProfileIndex = index;
                }
            };

            sshProfiles.Items.ListChanged += (sender, e) => {
                var index = sshProfilesList.SelectedIndex;
                if (settings.SshSelectedProfileIndex != index)
                {
                    settings.SshSelectedProfileIndex = index;
                }
            };

            bindProfileContextMenu();

            settings.PropertyChanged += (sender, e) => {
                if (e.PropertyName == "SshSelectedProfileIndex")
                {
                    var index = settings.SshSelectedProfileIndex;

                    if (index >= 0 && index < sshProfiles.Items.Count)
                    {
                        if (index != sshProfilesList.SelectedIndex)
                        {
                            sshProfilesList.SelectedIndex = index;
                        }

                        var profile = sshProfiles.Items[index];

                        if (profile != selectedSshProfile)
                        {
                            selectedSshProfile = profile;

                            profileContextMenu.MenuItems[index].PerformClick();
                            updateSshInformation();

                            if (plink.IsConnected || plink.IsConnecting || plink.IsReconnecting)
                            {
                                plink.Stop();
                                plink.Start();
                            }
                        }
                    }
                }
            };

            sshProfileName.LostFocus += (sender, e) => {
                var item = sshProfilesListBox.SelectedItem as Profile.SshProfile;
                var name = sshProfileName.Text.Trim().Replace("\t", " ");
                if (item.Name != name)
                {
                    if (name != "")
                    {
                        item.Name = name;
                    }
                    sshProfileName.Text = item.Name;
                    updateSshInformation();
                    sshProfiles.Items.ResetItem(sshProfilesListBox.SelectedIndex);
                    var index = sshProfilesList.SelectedIndex;
                    if (sshProfilesList.SelectedItem == item)
                    {
                        sshProfilesList.Text = item.Name;
                    }
                }
            };
            sshProfileServer.LostFocus += (sender, e) => {
                var item   = sshProfilesListBox.SelectedItem as Profile.SshProfile;
                var server = sshProfileServer.Text.Trim().ToLower();
                if (item.Server != server)
                {
                    if (new Regex(@"^([a-z0-9-]+(?:\.[a-z0-9-]+)*|)$").IsMatch(server))
                    {
                        item.Server = server;
                    }
                    sshProfileServer.Text = item.Server;
                    updateSshInformation();
                    sshProfiles.Items.ResetItem(sshProfilesListBox.SelectedIndex);
                }
            };
            sshProfilePort.LostFocus += (sender, e) => {
                var item = sshProfilesListBox.SelectedItem as Profile.SshProfile;
                var port = sshProfilePort.Text.Trim();
                if (item.Port.ToString() != port)
                {
                    if (new Regex(@"^[1-9]\d*$").IsMatch(port))
                    {
                        item.Port = int.Parse(port);
                    }
                    sshProfilePort.Text = item.Port.ToString();
                    updateSshInformation();
                    sshProfiles.Items.ResetItem(sshProfilesListBox.SelectedIndex);
                }
            };
            sshProfileUsername.LostFocus += (sender, e) => {
                var item     = sshProfilesListBox.SelectedItem as Profile.SshProfile;
                var username = sshProfileUsername.Text.Trim().Replace("\t", " ");
                if (item.Username != username)
                {
                    item.Username           = username;
                    sshProfileUsername.Text = item.Username;
                    updateSshInformation();
                    sshProfiles.Items.ResetItem(sshProfilesListBox.SelectedIndex);
                }
            };
            sshProfilePassword.LostFocus += (sender, e) => {
                var item     = sshProfilesListBox.SelectedItem as Profile.SshProfile;
                var password = sshProfilePassword.Password.Replace("\t", " ");
                if (item.Password != password)
                {
                    item.Password = password;
                    sshProfilePassword.Password = item.Password;
                    updateSshInformation();
                    sshProfiles.Items.ResetItem(sshProfilesListBox.SelectedIndex);
                }
            };
            sshProfileName.GotFocus     += selectAllWhenGetFocus;
            sshProfileServer.GotFocus   += selectAllWhenGetFocus;
            sshProfilePort.GotFocus     += selectAllWhenGetFocus;
            sshProfileUsername.GotFocus += selectAllWhenGetFocus;
            sshProfilePassword.GotFocus += selectAllWhenGetFocus;

            //RULES
            UIBinding.bindCheckBox(forwardAllCheckBox, "ForwardAll");
            UIBinding.bindCheckBox(useOnlineRulesCheckBox, "UseOnlineRules");
            //UIBinding.bindCheckBox(submitNewRuleCheckBox, "SubmitNewRule");
            //UIBinding.bindCheckBox(useCustomRulesCheckBox, "UseCustomRules");
        }