public void bConnect_Click(object sender, EventArgs e) { ///////////////////////////////////////////////// //List<string> list = xml.readXML("Servers"); //foreach (string childnode in list) //{ // MessageBox.Show(childnode); //}//////////////////////////////////////////////////////// Presharedkeybox = tKey.Text; Usernamebox = tUsername.Text; Passwordbox = tPassword.Text; if ((Presharedkeybox != Presharedkey) || (Usernamebox != Username) || (Passwordbox != Password)) { appconfig.setAppSetting("presharedkey", Presharedkeybox); //We slaan alle ingevoerde gegevens op in de config file. appconfig.setAppSetting("username", Usernamebox); //We slaan alle ingevoerde gegevens op in de config file. appconfig.setAppSetting("password", Passwordbox); //We slaan alle ingevoerde gegevens op in de config file. Presharedkey = Presharedkeybox; Username = Usernamebox; Password = Passwordbox; } credentials = new System.Net.NetworkCredential(Usernamebox, Passwordbox); dialerclass.setEntryName(dialer, Vpnname); dialerclass.setPhoneBookPath(dialer); dialerclass.setCredentials(dialer, credentials); dialerclass.setTimeout(dialer, 1000); book.openPhoneBook(); //We openen het zojuist aangemaakte telefoonboek. if (book.contains(Vpnname)) //We checken of de naam van de entry al in het telefoonboek voorkomt. { VpnEntry vpnentryclass = new VpnEntry(); RasEntry vpnentry = book.getEntry(); vpnentryclass.setCredentials(vpnentry, credentials); vpnentryclass.setPreSharedKey(vpnentry, Presharedkeybox); //MessageBox.Show("Er bestaat al een connectie met dezelfde naam."); try { connectionHandler = dialerclass.Dial(dialer); //LETOP OF DIT WERKT. //We proberen de verbinding tot stand te brengen. } catch (Exception ex) { MessageBox.Show(ex.ToString()); } System.Threading.Thread.Sleep(1500); connection = RasConnection.GetActiveConnectionByHandle(connectionHandler); if (dialerclass.checkIfConnectionExist(connection)) { lStatusstate.Text = "Active"; lStatusstate.BackColor = System.Drawing.Color.Green; bConnect.Enabled = false; //We disabelen de Disconect button. bDisconnect.Enabled = true; //We enabelen de Disconect button. bReset.Enabled = false; tKey.Enabled = false; tUsername.Enabled = false; tPassword.Enabled = false; connectItem.Enabled = false; disconnectItem.Enabled = true; exitItem.Enabled = false; } else { MessageBox.Show("Failed to establish a connection, sometimes the connection is not established immediately. Try again. Are you sure that the data entered is correct?", "Failed to connect"); } } else { List <string> list = xml.readXML("Servers", Serverlocation); int randomvalue = xml.randomValue(list); Destination = xml.randomValueFromList(list, randomvalue); lLocationname.Text = Serverlocation.ElementAt(randomvalue); appconfig.setAppSetting("serverlocation", Serverlocation.ElementAt(randomvalue)); Presharedkeybox = tKey.Text; Usernamebox = tUsername.Text; Passwordbox = tPassword.Text; credentials = new System.Net.NetworkCredential(Usernamebox, Passwordbox); VpnEntry vpnentryclass = new VpnEntry(); //We maken een nieuwe entry class aan. RasEntry vpnentry = new VpnEntry().createEntry(Vpnname, Destination); //We maken een entry aan met de gewenste gegevens. vpnentryclass.loadOptions(vpnentry); //We laten bepaalde opties in voor een specifieke 'vpnentry'. book.addEntry(vpnentry); //We voegen de entry toe aan het telefoonboek. (DIT MOET ALTIJD NA DE LOADOPTIONS). vpnentryclass.setCredentials(vpnentry, credentials); vpnentryclass.setPreSharedKey(vpnentry, Presharedkeybox); dialerclass.setEntryName(dialer, Vpnname); dialerclass.setPhoneBookPath(dialer); dialerclass.setCredentials(dialer, credentials); dialerclass.setTimeout(dialer, 1500); try { connectionHandler = dialerclass.Dial(dialer); //LETOP OF DIT WERKT. //We proberen de verbinding tot stand te brengen. } catch (Exception ex) { MessageBox.Show(ex.ToString()); } System.Threading.Thread.Sleep(3500); connection = RasConnection.GetActiveConnectionByHandle(connectionHandler); if (dialerclass.checkIfConnectionExist(connection)) { lStatusstate.Text = "Active"; lStatusstate.BackColor = System.Drawing.Color.Green; bConnect.Enabled = false; //We disabelen de Connect button. bDisconnect.Enabled = true; //We enabelen de Disconect button. bReset.Enabled = false; tKey.Enabled = false; tUsername.Enabled = false; tPassword.Enabled = false; connectItem.Enabled = false; disconnectItem.Enabled = true; exitItem.Enabled = false; } else { MessageBox.Show("Failed to establish a connection. The most likely reason is that the information you entered is incorrect. If you are sure that these are correct, click on 'connect' again, sometimes the connection will not be established immediately.", "Connection failed"); } } }
public void bConnect_Click(object sender, EventArgs e) { System.Net.NetworkCredential credentials = new System.Net.NetworkCredential("mart", "welkom"); PhoneBook book = new PhoneBook(); //We maken een nieuw telefoonboek aan. dialerclass.setEntryName(dialer, Vpnname); dialerclass.setPhoneBookPath(dialer); dialerclass.setCredentials(dialer, credentials); dialerclass.setTimeout(dialer, 1000); book.openPhoneBook(); //We openen het zojuist aangemaakte telefoonboek. if (book.contains(Vpnname)) //We checken of de naam van de entry al in het telefoonboek voorkomt. { //MessageBox.Show("Er bestaat al een connectie met dezelfde naam."); try { connectionHandler = dialerclass.Dial(dialer); //LETOP OF DIT WERKT. //We proberen de verbinding tot stand te brengen. } catch (Exception ex) { MessageBox.Show(ex.ToString()); } System.Threading.Thread.Sleep(1500); connection = RasConnection.GetActiveConnectionByHandle(connectionHandler); if (dialerclass.checkIfConnectionExist(connection)) { bDisconnect.Enabled = true; bConnect.Enabled = false; lStatusstate.Text = "Connected"; } } else { VpnEntry vpnentryclass = new VpnEntry(); //We maken een nieuwe entry class aan. RasEntry vpnentry = new VpnEntry().createEntry("Transip", "149.210.200.145"); //We maken een entry aan met de gewenste gegevens. vpnentryclass.loadOptions(vpnentry); //We laten bepaalde opties in voor een specifieke 'vpnentry'. book.addEntry(vpnentry); //We voegen de entry toe aan het telefoonboek. (DIT MOET ALTIJD NA DE LOADOPTIONS). vpnentryclass.setCredentials(vpnentry, credentials); vpnentryclass.setPreSharedKey(vpnentry, Presharedkey); dialerclass.setEntryName(dialer, Vpnname); dialerclass.setPhoneBookPath(dialer); dialerclass.setCredentials(dialer, credentials); dialerclass.setTimeout(dialer, 1500); lStatusstate.Text = "Connected"; try { connectionHandler = dialerclass.Dial(dialer); //LETOP OF DIT WERKT. //We proberen de verbinding tot stand te brengen. } catch (Exception ex) { MessageBox.Show(ex.ToString()); } System.Threading.Thread.Sleep(1500); connection = RasConnection.GetActiveConnectionByHandle(connectionHandler); if (dialerclass.checkIfConnectionExist(connection)) { bDisconnect.Enabled = true; //We enabelen de Disconect button. bConnect.Enabled = false; //We disabelen de Connect button. lStatusstate.Text = "Connected"; } } }