Changed a lot

This commit is contained in:
2015-03-04 22:21:34 +00:00
parent cd21034b41
commit 8264cbfa7b
54 changed files with 2014 additions and 529 deletions
+140
View File
@@ -0,0 +1,140 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using NetMonitorUtils;
using BlubbFish.Utils;
namespace NetMonitorTray.Controller {
public class Tray : OwnController {
private static View.Tray tray;
private static OpenVpnSetter vpn;
private static NetworkSetter network;
private static Controller.Window window;
/// <summary>
/// Tray Controller
/// </summary>
public Tray() {
vpn = new OpenVpnSetter("vpn.ini", "config.ini");
network = new NetworkSetter("network.ini", "config.ini");
}
/// <summary>
/// Init!
/// </summary>
override protected void init() {
tray = new View.Tray();
window = new Controller.Window();
tray.setWorkingIcon();
try {
tray.Model.connectedStatus = false;
List<string> vpns = tray.Model.getVpnList();
tray.Model.VpnSelected = vpn.getStatus(vpns);
List<string> adapter = tray.Model.getAdapterList();
tray.Model.NetworkSelected = network.getNetwork(adapter);
} catch(Exception e) {
tray.showError(e.Message);
tray.Model.connectedStatus = false;
}
}
/// <summary>
/// User klickt auf den Eintrag Beenden
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
internal static void Click_Quit(object sender, EventArgs e) {
tray.Dispose();
//Application.ExitThread();
Application.Exit();
}
/// <summary>
/// User klick auf einen Eintrag Service Starten/Stoppen
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
internal static void Click_Vpn(object sender, EventArgs e) {
tray.setWorkingIcon();
string[] conf = ((ToolStripMenuItem)sender).Name.Split('|');
switch(tray.Model.VpnSelected[conf[1]]) {
case "disconnected":
case "unknown":
try {
vpn.setStart(conf[1]);
for(int i = 0; i < 10; i++) {
string status = vpn.getStatus(conf[1]);
if(status.StartsWith("[connected|")) {
tray.Model.VpnSelected[conf[1]] = "connected";
status = status.Substring(0, status.Length - 1).Substring(1);
string[] ip = status.Split('|');
tray.setVpn(true, "Verbunden am: " + ip[5] + "\nmit IP: " + ip[1] + "\nConfig: " + conf[1]);
break;
}
System.Threading.Thread.Sleep(3000);
}
} catch(Exception ex) {
tray.Model.connectedStatus = false;
tray.showError("Fehler beim starten von Openvpn mit " + conf[1] + ": " + ex.Message);
}
break;
case "connected":
try {
vpn.setStop(conf[1]);
for(int i = 0; i < 10; i++) {
string status = vpn.getStatus(conf[1]);
if(status == "[disconnected]") {
tray.Model.VpnSelected[conf[1]] = "disconnected";
tray.setVpn(false, "Config: " + conf[1]);
break;
}
System.Threading.Thread.Sleep(1000);
}
} catch(Exception ex) {
tray.Model.connectedStatus = false;
tray.showError("Fehler beim beenden von Openvpn mit " + conf + ": " + ex.Message);
}
break;
}
}
/// <summary>
/// User klickt Doppelt auf das TrayIcon
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
internal static void Click_Tray(object sender, EventArgs e) {
Click_Open(sender, e);
}
/// <summary>
/// User klickt auf den Tray-Ballon
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
internal static void Click_Ballon(object sender, EventArgs e) {
throw new NotImplementedException();
}
/// <summary>
/// User klickt auf einen Eintrag Netzwerk
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
internal static void Click_Network(object sender, EventArgs e) {
tray.setWorkingIcon();
try {
network.setNetwork(((ToolStripMenuItem)sender).Name);
string n = ((ToolStripMenuItem)sender).Name;
tray.Model.NetworkSelected[n.Split('|')[0]] = n.Split('|')[1];
} catch(Exception ex) {
tray.showError("Fehler beim setzen des Netzwerks: " + ex.Message);
}
}
/// <summary>
/// User klickt auf den Eintrag Öffnen
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
internal static void Click_Open(object sender, EventArgs e) {
window.execute();
}
}
}
@@ -0,0 +1,38 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using NetMonitorUtils;
using BlubbFish.Utils;
namespace NetMonitorTray.Controller
{
public class Window : OwnController
{
private static View.Window window;
/// <summary>
/// Tray Controller
/// </summary>
public Window()
{
}
override protected void init()
{
window = new View.Window();
}
public static void FormClosed(object sender, FormClosedEventArgs e)
{
window.Dispose();
}
internal static void NetworkSelected(object sender, EventArgs e)
{
MessageBox.Show("Angeklickt!");
}
}
}
-84
View File
@@ -1,84 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace NetMonitorTray.Controller
{
public class Tray
{
private static View.Tray tray;
public Tray()
{
tray = new View.Tray();
}
public void view()
{
Application.Run();
}
/// <summary>
/// User klickt auf den Eintrag Beenden
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
internal static void Click_Quit(object sender, EventArgs e)
{
tray.Dispose();
Application.ExitThread();
}
/// <summary>
/// User klick auf einen Eintrag Service Starten/Stoppen
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
internal static void Click_Service(object sender, EventArgs e)
{
throw new NotImplementedException();
//tray.showError("Fehler beim Starten/Stoppen von Service!");
/*switch (((ToolStripMenuItem)sender).Name)
{
case "StartService": tray.setService(true); break;
case "StopService": tray.setService(false); break;
}*/
}
/// <summary>
/// User klickt Doppelt auf das TrayIcon
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
internal static void Click_Tray(object sender, EventArgs e)
{
//Doppelklick auf das Trayicon
throw new NotImplementedException();
}
/// <summary>
/// User klickt auf den Tray-Ballon
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
internal static void Click_Ballon(object sender, EventArgs e)
{
throw new NotImplementedException();
}
/// <summary>
/// User klickt auf einen Eintrag Netzwerk
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
internal static void Click_Network(object sender, EventArgs e)
{
throw new NotImplementedException();
}
/// <summary>
/// User klickt auf den Eintrag Öffnen
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
internal static void Click_Open(object sender, EventArgs e)
{
throw new NotImplementedException();
}
}
}