SVN Ignore geändert, erste Funktionierende Komunikation so das Befehle ausgeführt werden

This commit is contained in:
BlubbFish 2010-04-28 14:34:35 +00:00
parent 96fe859f9a
commit 890cfc839a
9 changed files with 242 additions and 14 deletions

View File

@ -32,9 +32,10 @@ namespace NetMonitorClient
String gateway = networkini.getValue(Item.Name, "Gateway"); String gateway = networkini.getValue(Item.Name, "Gateway");
String dns = networkini.getValue(Item.Name, "Dns"); String dns = networkini.getValue(Item.Name, "Dns");
String wins = networkini.getValue(Item.Name, "Wins"); String wins = networkini.getValue(Item.Name, "Wins");
String adapter = networkini.getValue(Item.Name, "Adapter");
if (ip == "auto" && dns == "auto" && wins == "auto") if (ip == "auto" && dns == "auto" && wins == "auto")
this.sc.setNetworkAuto(); this.sc.setNetworkAuto(adapter);
else else
{ {
this.sc.setNetworkIp(ip, subnet, gateway); this.sc.setNetworkIp(ip, subnet, gateway);

View File

@ -24,9 +24,14 @@ namespace NetMonitorClient
this.rep = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 34523); this.rep = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 34523);
} }
internal void setNetworkAuto() internal void setNetworkAuto(string networkcard)
{ {
byte[] data = Encoding.UTF8.GetBytes("NET AUTO"); if (networkcard == null)
{
System.Windows.Forms.MessageBox.Show("Adapter ist not Set!");
return;
}
byte[] data = Encoding.UTF8.GetBytes("NET AUTO "+networkcard);
this.client.Send(data, data.Length, this.rep); this.client.Send(data, data.Length, this.rep);
//throw new NotImplementedException(); //throw new NotImplementedException();
} }

View File

@ -3,3 +3,4 @@ Name=Home
Ip=auto Ip=auto
Dns=auto Dns=auto
Wins=auto Wins=auto
Adapter=LAN-Verbindung

View File

@ -19,7 +19,7 @@
<DebugSymbols>true</DebugSymbols> <DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType> <DebugType>full</DebugType>
<Optimize>false</Optimize> <Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath> <OutputPath>E:\Programme\NetMonitor\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants> <DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
@ -35,6 +35,7 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Configuration.Install" />
<Reference Include="System.Core" /> <Reference Include="System.Core" />
<Reference Include="System.Windows.Forms" /> <Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml.Linq" /> <Reference Include="System.Xml.Linq" />
@ -51,8 +52,11 @@
<Compile Include="Service1.Designer.cs"> <Compile Include="Service1.Designer.cs">
<DependentUpon>Service1.cs</DependentUpon> <DependentUpon>Service1.cs</DependentUpon>
</Compile> </Compile>
<Compile Include="Program.cs" /> <Compile Include="Program.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SetNetworks.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<EmbeddedResource Include="Service1.resx"> <EmbeddedResource Include="Service1.resx">

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
<StartArguments>-r</StartArguments>
</PropertyGroup>
</Project>

View File

@ -3,6 +3,8 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.ServiceProcess; using System.ServiceProcess;
using System.Text; using System.Text;
using System.Configuration.Install;
using System.ComponentModel;
namespace NetMonitorServer namespace NetMonitorServer
{ {
@ -11,7 +13,9 @@ namespace NetMonitorServer
/// <summary> /// <summary>
/// The main entry point for the application. /// The main entry point for the application.
/// </summary> /// </summary>
static void Main() static void Main(string[] args)
{
if (args.Length == 0)
{ {
ServiceBase[] ServicesToRun; ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[] ServicesToRun = new ServiceBase[]
@ -20,5 +24,36 @@ namespace NetMonitorServer
}; };
ServiceBase.Run(ServicesToRun); ServiceBase.Run(ServicesToRun);
} }
else if (args.Length == 1 || args[0] == "-r")
{
Service1 s = new Service1();
s.StartServiceConsole(args);
while (true)
{
System.Threading.Thread.Sleep(100);
}
}
}
}
[RunInstaller(true)]
public class TestWinInstaller : Installer
{
private ServiceInstaller m_ThisService;
private ServiceProcessInstaller m_ThisServiceProcess;
public TestWinInstaller()
{
m_ThisService = new ServiceInstaller();
m_ThisServiceProcess = new ServiceProcessInstaller();
m_ThisServiceProcess.Account = ServiceAccount.LocalSystem;
m_ThisService.ServiceName = "NetMonitorServer";
m_ThisService.StartType = ServiceStartMode.Automatic;
m_ThisService.Description = "Teil von NetMonitor der die Systemnahen Befele ausführt";
m_ThisService.DisplayName = "Netzwerk Settings Tool";
Installers.Add(m_ThisService);
Installers.Add(m_ThisServiceProcess);
}
} }
} }

View File

@ -20,7 +20,6 @@ namespace NetMonitorServer
InitializeComponent(); InitializeComponent();
this.ot = new Thread(new ThreadStart(overwatch)); this.ot = new Thread(new ThreadStart(overwatch));
this.ot.IsBackground = true; this.ot.IsBackground = true;
this.ot.Start();
} }
private static void overwatch() private static void overwatch()
{ {
@ -41,6 +40,8 @@ namespace NetMonitorServer
private static void switchCommand(string data) private static void switchCommand(string data)
{ {
if (data.Substring(0, 3).ToLower() == "net")
new SetNetworks(data);
Console.WriteLine(data); Console.WriteLine(data);
} }
@ -53,5 +54,10 @@ namespace NetMonitorServer
{ {
this.ot.Abort(); this.ot.Abort();
} }
public void StartServiceConsole(string[] args)
{
this.OnStart(args);
}
} }
} }

View File

@ -0,0 +1,126 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="timer1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>143, 71</value>
</metadata>
<metadata name="$this.TrayLargeIcon" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>False</value>
</metadata>
</root>

View File

@ -0,0 +1,44 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
namespace NetMonitorServer
{
class SetNetworks
{
public SetNetworks(string data)
{
if (data.Substring(0,8).ToLower() == "net auto")
setNetworkAuto(data);
}
private void setNetworkAuto(string data)
{
String[] par = data.Split(' ');
if (par.Length != 3)
return;
Process p1 = new Process();
p1.StartInfo.Arguments = "interface ipv4 set address name=\""+par[2]+"\" source=dhcp";
p1.StartInfo.FileName = "netsh";
p1.Start();
p1.WaitForExit();
Console.WriteLine(p1.ExitCode);
Process p2 = new Process();
p2.StartInfo.Arguments = "interface ipv4 set dnsservers name=\"" + par[2] + "\" source=dhcp";
p2.StartInfo.FileName = "netsh";
p2.Start();
p2.WaitForExit();
Console.WriteLine(p2.ExitCode);
Process p3 = new Process();
p3.StartInfo.Arguments = "interface ipv4 set winsservers name=\"" + par[2] + "\" source=dhcp";
p3.StartInfo.FileName = "netsh";
p3.Start();
p3.WaitForExit();
Console.WriteLine(p3.ExitCode);
}
}
}