/// <summary> /// Default constructor, only for design mode /// </summary> public MainViewModel() { if (DesignerProperties.GetIsInDesignMode(new DependencyObject())) { // Generate some configurations _configurationsList = new List <NetworkConfiguration>(); NetworkRulesSet rulesSet = new NetworkRulesSet(); rulesSet.Rules.Add(new AutoProxySwitcherLib.Rules.NetworkRuleDNS("10.0.0.1")); for (int i = 0; i < 5; i++) { _configurationsList.Add(new NetworkConfiguration("Config #" + i, rulesSet, new StandardProxySettings("http://test:8080", null, null))); } _activeConfiguration = _configurationsList[2]; // Generate some networks for (int i = 0; i < 10; i++) { _currentNetworks.Add(new NetworkInfo() { IfName = "Sample Network #" + i, IP = { "10.0.0.1" }, DNS = { "10.0.0.5" }, NetworkIP = { "10.0.0.0/24" } }); } _currentNetwork = _currentNetworks[3]; _currentProxySettings = _activeConfiguration.ProxySettings; // reason = "Network matching IP x.y.z.t"; } else { string rulesFile = System.Environment.GetFolderPath(System.Environment.SpecialFolder.CommonApplicationData) + "\\AutoProxySwitcher\\" + Environment.ExpandEnvironmentVariables(System.Configuration.ConfigurationManager.AppSettings["RulesFile"]); // Create default rules files if it doesn't exists if (!System.IO.File.Exists(rulesFile)) { System.IO.File.Copy("Examples/rules.xml", rulesFile); } // Load configurations _networkChangeDetector = new NetworkChangeDetector(); _networkChangeDetector.ProxyChanged += _networkChangeDetector_ProxyChanged; _networkChangeDetector.LoadConfigurations(rulesFile); _configurationsList = _networkChangeDetector.Configurations; // Init commands relay DebugCommand = new RelayCommand <string>(m => MessageBox.Show("toto: " + m)); SetConfigurationCommand = new RelayCommand <string>((conf) => _networkChangeDetector.SetConfiguration(conf)); AutoDetectCommand = new RelayCommand(() => _networkChangeDetector.SetConfiguration(null)); ExitCommand = new RelayCommand(() => { Messenger.Default.Send <ExitMessage>(new ExitMessage()); }); } }
private void buttonSetProxy_Click(object sender, EventArgs e) { if (comboProxy.Text == "auto") { m_networkChangeDetector.SetConfiguration(null); } else { m_networkChangeDetector.SetConfiguration(comboProxy.Text); } }