105 lines
4.5 KiB
C#
105 lines
4.5 KiB
C#
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Linq;
|
|||
|
using System.Text;
|
|||
|
using System.Threading.Tasks;
|
|||
|
using System.Windows.Forms;
|
|||
|
using NetMonitorTray.Properties;
|
|||
|
using BlubbFish.Utils;
|
|||
|
|
|||
|
namespace NetMonitorTray.Models {
|
|||
|
public class Tray : OwnModel<Tray> {
|
|||
|
private InIReader networks;
|
|||
|
private InIReader vpns;
|
|||
|
private Tray() {
|
|||
|
this.init();
|
|||
|
}
|
|||
|
|
|||
|
override protected void init() {
|
|||
|
this.networks = InIReader.getInstance("network.ini");
|
|||
|
this.vpns = InIReader.getInstance("vpn.ini");
|
|||
|
}
|
|||
|
|
|||
|
internal Dictionary<string, Dictionary<string, Tuple<string, System.Drawing.Bitmap, bool, bool>>> getMenuNetwork() {
|
|||
|
Dictionary<string, Dictionary<string, Tuple<string, System.Drawing.Bitmap, bool, bool>>> ret = new Dictionary<string, Dictionary<string, Tuple<string, System.Drawing.Bitmap, bool, bool>>>();
|
|||
|
List<String> l = this.networks.getSections();
|
|||
|
foreach(String name in l) {
|
|||
|
String adapter = this.networks.getValue(name, "Adapter");
|
|||
|
if(ret.Keys.Contains(adapter)) {
|
|||
|
ret[adapter].Add(adapter + "|" + name, new Tuple<string, System.Drawing.Bitmap, bool, bool>("Netzwerk " + this.networks.getValue(name, "Name"), Properties.Resources.MenuImagesNetwork, true, (this.NetworkSelected.Keys.Contains(adapter) && this.NetworkSelected[adapter] == name)));
|
|||
|
} else {
|
|||
|
Dictionary<string, Tuple<string, System.Drawing.Bitmap, bool, bool>> tmp = new Dictionary<string, Tuple<string, System.Drawing.Bitmap, bool, bool>>();
|
|||
|
tmp.Add(adapter + "|" + name, new Tuple<string, System.Drawing.Bitmap, bool, bool>("Netzwerk " + this.networks.getValue(name, "Name"), Properties.Resources.MenuImagesNetwork, true, (this.NetworkSelected.Keys.Contains(adapter) && this.NetworkSelected[adapter] == name)));
|
|||
|
ret.Add(adapter, tmp);
|
|||
|
}
|
|||
|
}
|
|||
|
return ret;
|
|||
|
}
|
|||
|
|
|||
|
internal Dictionary<string, Dictionary<string, Tuple<string, System.Drawing.Bitmap, bool, bool>>> getMenuVpn() {
|
|||
|
Dictionary<string, Dictionary<string, Tuple<string, System.Drawing.Bitmap, bool, bool>>> ret = new Dictionary<string, Dictionary<string, Tuple<string, System.Drawing.Bitmap, bool, bool>>>();
|
|||
|
List<String> l = this.vpns.getSections();
|
|||
|
Dictionary<string, Tuple<string, System.Drawing.Bitmap, bool, bool>> tmp = new Dictionary<string, Tuple<string, System.Drawing.Bitmap, bool, bool>>();
|
|||
|
|
|||
|
foreach(String vpn in l) {
|
|||
|
String name = this.vpns.getValue(vpn, "Name");
|
|||
|
String conf = this.vpns.getValue(vpn, "Config");
|
|||
|
tmp.Add(vpn + "|" + conf, new Tuple<string, System.Drawing.Bitmap, bool, bool>("VPN " + name, Properties.Resources.MenuImagesOpenvpn, true, (this.VpnSelected.Keys.Contains(conf) && this.VpnSelected[conf] == "connected")));
|
|||
|
|
|||
|
}
|
|||
|
ret.Add("OpenVpn", tmp);
|
|||
|
return ret;
|
|||
|
}
|
|||
|
|
|||
|
private bool connectedStatusValue = false;
|
|||
|
internal bool connectedStatus {
|
|||
|
get { return connectedStatusValue; }
|
|||
|
set { connectedStatusValue = value; this.update(); }
|
|||
|
}
|
|||
|
|
|||
|
private Dictionary<String, String> VpnSelectedValue = new Dictionary<string, string>();
|
|||
|
/// <summary>
|
|||
|
/// Item1 = configfile
|
|||
|
/// Item2 = status ("unknown";"connected";"disconnected")
|
|||
|
/// </summary>
|
|||
|
internal Dictionary<String, String> VpnSelected {
|
|||
|
get { return VpnSelectedValue; }
|
|||
|
set { VpnSelectedValue = value; this.update(); }
|
|||
|
}
|
|||
|
|
|||
|
private Dictionary<String, String> networkSelectedValue = new Dictionary<string, string>();
|
|||
|
/// <summary>
|
|||
|
/// Item1 = adapter
|
|||
|
/// Item2 = network
|
|||
|
/// </summary>
|
|||
|
public Dictionary<String, String> NetworkSelected {
|
|||
|
get { return networkSelectedValue; }
|
|||
|
set { networkSelectedValue = value; this.update(); }
|
|||
|
}
|
|||
|
|
|||
|
internal List<string> getAdapterList() {
|
|||
|
List<String> ret = new List<string>();
|
|||
|
List<String> l = this.networks.getSections();
|
|||
|
foreach(String name in l) {
|
|||
|
String adapter = this.networks.getValue(name, "Adapter");
|
|||
|
if(!ret.Contains(adapter)) {
|
|||
|
ret.Add(adapter);
|
|||
|
}
|
|||
|
}
|
|||
|
return ret;
|
|||
|
}
|
|||
|
|
|||
|
internal List<string> getVpnList() {
|
|||
|
List<String> ret = new List<string>();
|
|||
|
List<String> l = this.vpns.getSections();
|
|||
|
foreach(String name in l) {
|
|||
|
String adapter = this.vpns.getValue(name, "Config");
|
|||
|
if(!ret.Contains(adapter)) {
|
|||
|
ret.Add(adapter);
|
|||
|
}
|
|||
|
}
|
|||
|
return ret;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|