public String LoadAPsFromFile(string file = Global.APSaveFile) { try { file = Path.Combine(System.IO.Path.GetDirectoryName(Application.ExecutablePath), file); if (File.Exists(file)) { string xmltext = File.ReadAllText(file); using (XmlReader reader = XmlReader.Create(file)) { WLanAP ap = null; while (reader.Read()) { switch (reader.NodeType) { case XmlNodeType.Element: switch (reader.Name) { case "AccessPoint": ap = new WLanAP(); this.WLanAPs.Add(ap); break; case "APName": ap.APName = reader.ReadString(); break; case "proxyIP": ap.proxyIP = reader.ReadString(); break; case "proxyPort": ap.proxyPort = Convert.ToInt32(reader.ReadString()); break; case "exceptions": ap.Exceptions = reader.ReadString(); break; } break; } } } } else { File.Create(file); } return(""); } catch (Exception ex) { return(ex.Message); } }
private void WLanCheck_Tick(object sender, EventArgs e) { // El proxy debe estar activado if (WlanManager.Instance.IsConnectedToAnySSID()) { // Boolean alreadyConfigured = false; Boolean anyDefinedAPConfigured = false; WLanAP connectedNotConfiguredAP = null; foreach (WLanAP ap in WLanAPManager.Instance.GetWLanAPs()) { if (WlanManager.Instance.IsConnectedToSSID(ap.APName)) { if (ProxyManager.Instance.ConfiguredProxyName.Equals(ap.APName)) { alreadyConfigured = true; } anyDefinedAPConfigured = true; connectedNotConfiguredAP = ap; break; } } if (connectedNotConfiguredAP != null) { if (!alreadyConfigured) { ChangeConnectedStatus(Color.Green, "Connected to " + connectedNotConfiguredAP.APName + ". Proxy enabled. (" + connectedNotConfiguredAP.proxyIP + ":" + connectedNotConfiguredAP.proxyPort + ")"); ProxyToggleAll(true, connectedNotConfiguredAP.proxyIP, connectedNotConfiguredAP.proxyPort, connectedNotConfiguredAP.APName, connectedNotConfiguredAP.Exceptions); ProxyManager.Instance.ConfiguredProxyName = connectedNotConfiguredAP.APName; L_Proxy_System.ForeColor = ProxyManager.Instance.ProxyStateSystem.Color; L_Proxy_System.Text = ProxyManager.Instance.ProxyStateSystem.Text; } } else if (!anyDefinedAPConfigured) { ChangeConnectedStatus(Color.Red, "Not connected to any defined wireless network."); ProxyToggleAll(false); } // } // El proxy debe estar apagado else { ChangeConnectedStatus(Color.Orange, "Not connected to any wireless network"); ProxyToggleAll(false); } }