netmonitor/NetMonitorClient/Networksetter.cs

178 lines
6.4 KiB
C#
Raw Permalink Normal View History

2010-07-15 02:41:08 +02:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace NetMonitorClient
{
public class Networksetter
{
2015-03-04 23:21:34 +01:00
private NetMonitorUtils.NetworkSetter sc;
2010-07-15 02:41:08 +02:00
private InIReader networkini;
private string net_name;
private List<string> loglist;
private bool Pstatus;
private string Pname;
private string Ptext;
private enum netsetter
{
Auto,
IpAuto,
Ip,
DnsAuto,
Dns,
WinsAuto,
Wins
}
2015-03-04 23:21:34 +01:00
public Networksetter(string name, InIReader ini, NetMonitorUtils.NetworkSetter serv)
2010-07-15 02:41:08 +02:00
{
this.net_name = name;
this.networkini = ini;
loglist = new List<string>();
this.sc = serv;
}
public void setNetwork()
{
String name = networkini.getValue(net_name, "Name");
String ip = networkini.getValue(net_name, "Ip");
String subnet = networkini.getValue(net_name, "Subnet");
String gateway = networkini.getValue(net_name, "Gateway");
String dns = networkini.getValue(net_name, "Dns");
String wins = networkini.getValue(net_name, "Wins");
String adapter = networkini.getValue(net_name, "Adapter");
if (ip == "auto" && dns == "auto" && wins == "auto")
{
setNetworkAuto(adapter, name);
}
else
{
if (ip == "auto")
setNetworkIpAuto(adapter, name);
else
setNetworkIp(ip, subnet, gateway, adapter, name);
if (dns == "auto")
setNetworkDnsAuto(adapter, name);
else
setNetworkDns(dns, adapter, name);
if (wins == "auto")
setNetworkWinsAuto(adapter, name);
else
setNetworkWins(wins, adapter, name);
}
}
private void setNetworkAuto(string adapter, string name)
{
setNetwork(netsetter.Auto, null, null, null, adapter, name, null, null);
}
private void setNetworkIpAuto(string adapter, string name)
{
setNetwork(netsetter.IpAuto, null, null, null, adapter, name, null, null);
}
private void setNetworkIp(string ip, string subnet, string gateway, string adapter, string name)
{
setNetwork(netsetter.Ip, ip, subnet, gateway, adapter, name, null, null);
}
private void setNetworkDnsAuto(string adapter, string name)
{
setNetwork(netsetter.DnsAuto, null, null, null, adapter, name, null, null);
}
private void setNetworkDns(string dns, string adapter, string name)
{
setNetwork(netsetter.Dns, null, null, null, adapter, name, dns, null);
}
private void setNetworkWinsAuto(string adapter, string name)
{
setNetwork(netsetter.WinsAuto, null, null, null, adapter, name, null, null);
}
private void setNetworkWins(string wins, string adapter, string name)
{
setNetwork(netsetter.Wins, null, null, null, adapter, name, null, wins);
}
private void setNetwork(netsetter option, string ip, string subnet, string gateway, string adapter, string name, string dns, string wins)
{
bool status = false;
List<string> text = new List<string>();
if (option == netsetter.Ip)
{
text.Add("Ip: " + ip + ";Subnet: " + subnet + ";Gateway: " + gateway);
loglist.Add("Gesendet: " + text);
System.Windows.Forms.Application.DoEvents();
2015-03-04 23:21:34 +01:00
status = this.sc.setNetworkIp(ip, subnet, gateway, adapter,"");
2010-07-15 02:41:08 +02:00
}
if (option == netsetter.Auto)
{
text.Add("Netzwerk auf Auto");
loglist.Add("Gesendet: " + text);
System.Windows.Forms.Application.DoEvents();
2015-03-04 23:21:34 +01:00
status = this.sc.setNetworkAuto(adapter,"");
2010-07-15 02:41:08 +02:00
}
if (option == netsetter.IpAuto)
{
text.Add("Ip auf Auto");
loglist.Add("Gesendet: " + text);
System.Windows.Forms.Application.DoEvents();
2015-03-04 23:21:34 +01:00
status = this.sc.setNetworkIpAuto(adapter,"");
2010-07-15 02:41:08 +02:00
}
if (option == netsetter.DnsAuto)
{
text.Add("Dns auf Auto");
loglist.Add("Gesendet: " + text);
System.Windows.Forms.Application.DoEvents();
2015-03-04 23:21:34 +01:00
status = this.sc.setNetworkDnsAuto(adapter,"");
2010-07-15 02:41:08 +02:00
}
if (option == netsetter.WinsAuto)
{
text.Add("Wins auf Auto");
loglist.Add("Gesendet: " + text);
System.Windows.Forms.Application.DoEvents();
2015-03-04 23:21:34 +01:00
status = this.sc.setNetworkWinsAuto(adapter,"");
2010-07-15 02:41:08 +02:00
}
if (option == netsetter.Dns)
{
text.Add("Dns: " + dns);
loglist.Add("Gesendet: " + text);
2015-03-04 23:21:34 +01:00
status = this.sc.setNetworkDns(dns, adapter,"");
2010-07-15 02:41:08 +02:00
}
if (option == netsetter.Wins)
{
text.Add("Wins: " + wins);
loglist.Add("Gesendet: " + text);
System.Windows.Forms.Application.DoEvents();
2015-03-04 23:21:34 +01:00
status = this.sc.setNetworkWins(wins, adapter,"");
2010-07-15 02:41:08 +02:00
}
loglist.Add("Antwort: " + ((status) ? "Ok" : "Fehler"));
System.Windows.Forms.Application.DoEvents();
setPopup(status, name, String.Join("\n",text.ToArray()));
}
private void setPopup(bool status, string name, string text)
{
this.Pstatus = status;
this.Pname = name;
this.Ptext = text;
}
internal bool getPopupBool()
{
return this.Pstatus;
}
internal string getPopupTitel()
{
return this.Pname;
}
internal string getPopupText()
{
return this.Ptext;
}
public List<string> getLog()
{
return this.loglist;
}
}
}