NetOpenvpnGui zum laufen gebracht

This commit is contained in:
BlubbFish 2011-01-27 10:19:41 +00:00
parent 973ac92433
commit 5b32a2a00e
10 changed files with 524 additions and 89 deletions

View File

@ -28,7 +28,7 @@
<PlatformTarget>x86</PlatformTarget> <PlatformTarget>x86</PlatformTarget>
<DebugType>pdbonly</DebugType> <DebugType>pdbonly</DebugType>
<Optimize>true</Optimize> <Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath> <OutputPath>E:\Programme\NetMonitor\</OutputPath>
<DefineConstants>TRACE</DefineConstants> <DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>

View File

@ -3,4 +3,7 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
<StartArguments>-r</StartArguments> <StartArguments>-r</StartArguments>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
<StartArguments>-r</StartArguments>
</PropertyGroup>
</Project> </Project>

View File

@ -31,15 +31,19 @@ namespace NetMonitorServer
if (par.Length != 3) if (par.Length != 3)
return; return;
this.serviceController.ServiceName = par[2]; this.serviceController.ServiceName = par[2];
try
{
this.serviceController.Start(); this.serviceController.Start();
this.serviceController.WaitForStatus(System.ServiceProcess.ServiceControllerStatus.Running,new TimeSpan(0,0,10)); this.serviceController.WaitForStatus(System.ServiceProcess.ServiceControllerStatus.Running, new TimeSpan(0, 0, 30));
String ret; }
catch (Exception)
{
this.sendStr("false");
}
if (this.serviceController.Status == System.ServiceProcess.ServiceControllerStatus.Running) if (this.serviceController.Status == System.ServiceProcess.ServiceControllerStatus.Running)
ret = "true"; this.sendStr("true");
else else
ret = "false"; this.sendStr("false");
byte[] answ = Encoding.UTF8.GetBytes(ret);
net_send.Send(answ, answ.Length, net_send_port);
} }
private void setServiceStop(string data) private void setServiceStop(string data)
@ -48,15 +52,19 @@ namespace NetMonitorServer
if (par.Length != 3) if (par.Length != 3)
return; return;
this.serviceController.ServiceName = par[2]; this.serviceController.ServiceName = par[2];
try
{
this.serviceController.Stop(); this.serviceController.Stop();
this.serviceController.WaitForStatus(System.ServiceProcess.ServiceControllerStatus.Stopped, new TimeSpan(0, 0, 10)); this.serviceController.WaitForStatus(System.ServiceProcess.ServiceControllerStatus.Stopped, new TimeSpan(0, 0, 30));
String ret; }
catch (Exception)
{
this.sendStr("false");
}
if (this.serviceController.Status == System.ServiceProcess.ServiceControllerStatus.Stopped) if (this.serviceController.Status == System.ServiceProcess.ServiceControllerStatus.Stopped)
ret = "true"; this.sendStr("true");
else else
ret = "false"; this.sendStr("false");
byte[] answ = Encoding.UTF8.GetBytes(ret);
net_send.Send(answ, answ.Length, net_send_port);
} }
private void getServiceStatus(string data) private void getServiceStatus(string data)
@ -64,13 +72,23 @@ namespace NetMonitorServer
String[] par = data.Split(' '); String[] par = data.Split(' ');
if (par.Length != 3) if (par.Length != 3)
return; return;
try
{
this.serviceController.ServiceName = par[2]; this.serviceController.ServiceName = par[2];
String ret;
if (this.serviceController.Status == System.ServiceProcess.ServiceControllerStatus.Running) if (this.serviceController.Status == System.ServiceProcess.ServiceControllerStatus.Running)
ret = "true"; this.sendStr("true");
else else
ret = "false"; this.sendStr("false");
byte[] answ = Encoding.UTF8.GetBytes(ret); }
catch (Exception)
{
this.sendStr("false");
}
}
private void sendStr(string p)
{
byte[] answ = Encoding.UTF8.GetBytes(p);
net_send.Send(answ, answ.Length, net_send_port); net_send.Send(answ, answ.Length, net_send_port);
} }
} }

175
NetOpenVPNGUI/Form1.Designer.cs generated Normal file
View File

@ -0,0 +1,175 @@
namespace NetOpenVpnGui
{
partial class Form1
{
/// <summary>
/// Erforderliche Designervariable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Verwendete Ressourcen bereinigen.
/// </summary>
/// <param name="disposing">True, wenn verwaltete Ressourcen gelöscht werden sollen; andernfalls False.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Vom Windows Form-Designer generierter Code
/// <summary>
/// Erforderliche Methode für die Designerunterstützung.
/// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.trayIcon = new System.Windows.Forms.NotifyIcon(this.components);
this.trayMenu = new System.Windows.Forms.ContextMenuStrip(this.components);
this.trayMenu_open = new System.Windows.Forms.ToolStripMenuItem();
this.trayMenu_start = new System.Windows.Forms.ToolStripMenuItem();
this.trayMenu_stop = new System.Windows.Forms.ToolStripMenuItem();
this.trayMenu_close = new System.Windows.Forms.ToolStripMenuItem();
this.MainMenu = new System.Windows.Forms.MenuStrip();
this.MainMenu_file = new System.Windows.Forms.ToolStripMenuItem();
this.Statuslog = new System.Windows.Forms.ListBox();
this.servicename = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.trayMenu.SuspendLayout();
this.MainMenu.SuspendLayout();
this.SuspendLayout();
//
// trayIcon
//
this.trayIcon.ContextMenuStrip = this.trayMenu;
this.trayIcon.Text = "OpenVPN-GUI";
this.trayIcon.Visible = true;
this.trayIcon.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.trayIcon_MouseDoubleClick);
//
// trayMenu
//
this.trayMenu.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.trayMenu_open,
this.trayMenu_start,
this.trayMenu_stop,
this.trayMenu_close});
this.trayMenu.Name = "trayMenu";
this.trayMenu.Size = new System.Drawing.Size(126, 92);
//
// trayMenu_open
//
this.trayMenu_open.Name = "trayMenu_open";
this.trayMenu_open.Size = new System.Drawing.Size(125, 22);
this.trayMenu_open.Text = "Öffnen";
this.trayMenu_open.Click += new System.EventHandler(this.trayMenu_open_Click);
//
// trayMenu_start
//
this.trayMenu_start.Name = "trayMenu_start";
this.trayMenu_start.Size = new System.Drawing.Size(125, 22);
this.trayMenu_start.Text = "Start";
this.trayMenu_start.Click += new System.EventHandler(this.trayMenu_start_Click);
//
// trayMenu_stop
//
this.trayMenu_stop.Name = "trayMenu_stop";
this.trayMenu_stop.Size = new System.Drawing.Size(125, 22);
this.trayMenu_stop.Text = "Stop";
this.trayMenu_stop.Click += new System.EventHandler(this.trayMenu_stop_Click);
//
// trayMenu_close
//
this.trayMenu_close.Name = "trayMenu_close";
this.trayMenu_close.Size = new System.Drawing.Size(125, 22);
this.trayMenu_close.Text = "Schließen";
this.trayMenu_close.Click += new System.EventHandler(this.trayMenu_close_Click);
//
// MainMenu
//
this.MainMenu.ContextMenuStrip = this.trayMenu;
this.MainMenu.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.MainMenu_file});
this.MainMenu.Location = new System.Drawing.Point(0, 0);
this.MainMenu.Name = "MainMenu";
this.MainMenu.Size = new System.Drawing.Size(284, 24);
this.MainMenu.TabIndex = 1;
this.MainMenu.Text = "MainMenu";
//
// MainMenu_file
//
this.MainMenu_file.DropDown = this.trayMenu;
this.MainMenu_file.Name = "MainMenu_file";
this.MainMenu_file.Size = new System.Drawing.Size(46, 20);
this.MainMenu_file.Text = "Datei";
//
// Statuslog
//
this.Statuslog.FormattingEnabled = true;
this.Statuslog.Location = new System.Drawing.Point(13, 28);
this.Statuslog.Name = "Statuslog";
this.Statuslog.Size = new System.Drawing.Size(259, 199);
this.Statuslog.TabIndex = 2;
//
// servicename
//
this.servicename.Location = new System.Drawing.Point(90, 234);
this.servicename.Name = "servicename";
this.servicename.Size = new System.Drawing.Size(182, 20);
this.servicename.TabIndex = 3;
this.servicename.Text = "OpenVPNService";
this.servicename.TextChanged += new System.EventHandler(servicename_TextChanged);
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(13, 237);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(71, 13);
this.label1.TabIndex = 4;
this.label1.Text = "Dienst Name:";
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(284, 262);
this.Controls.Add(this.label1);
this.Controls.Add(this.servicename);
this.Controls.Add(this.Statuslog);
this.Controls.Add(this.MainMenu);
this.MaximizeBox = false;
this.Name = "Form1";
this.ShowInTaskbar = false;
this.Text = "OpenVPN-GUI";
this.WindowState = System.Windows.Forms.FormWindowState.Minimized;
this.Resize += new System.EventHandler(this.EventHandler_Resize);
this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.Application_Closed);
this.trayMenu.ResumeLayout(false);
this.MainMenu.ResumeLayout(false);
this.MainMenu.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.NotifyIcon trayIcon;
private System.Windows.Forms.ContextMenuStrip trayMenu;
private System.Windows.Forms.ToolStripMenuItem trayMenu_open;
private System.Windows.Forms.ToolStripMenuItem trayMenu_start;
private System.Windows.Forms.ToolStripMenuItem trayMenu_stop;
private System.Windows.Forms.ToolStripMenuItem trayMenu_close;
private System.Windows.Forms.MenuStrip MainMenu;
private System.Windows.Forms.ToolStripMenuItem MainMenu_file;
private System.Windows.Forms.ListBox Statuslog;
private System.Windows.Forms.TextBox servicename;
private System.Windows.Forms.Label label1;
}
}

118
NetOpenVPNGUI/Form1.cs Normal file
View File

@ -0,0 +1,118 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace NetOpenVpnGui
{
public partial class Form1 : Form
{
private Runner sr;
public Form1()
{
InitializeComponent();
sr = new Runner(this.servicename.Text);
this.setIcon();
}
private void EventHandler_Resize(object sender, System.EventArgs e)
{
if (this.WindowState == FormWindowState.Minimized)
{
this.ShowInTaskbar = false;
this.WindowState = FormWindowState.Minimized;
}
}
private void setIcon()
{
if (sr.check_service())
{
this.trayMenu_isRunning(true);
this.trayIcon.Icon = Resources.icon_ok;
this.Icon = Resources.icon_ok;
}
else
{
this.trayMenu_isRunning(false);
this.trayIcon.Icon = Resources.icon_no;
this.Icon = Resources.icon_no;
}
}
private void trayMenu_open_Click(object sender, EventArgs e)
{
this.WindowState = FormWindowState.Normal;
this.ShowInTaskbar = true;
}
private void trayMenu_start_Click(object sender, EventArgs e)
{
if (sr.run_service())
{
this.showPopup("OpenVPN-GUI", "Service succesful started", ToolTipIcon.Info);
this.setIcon();
}
else
{
this.showPopup("OpenVPN-GUI", "Error while starting Service", ToolTipIcon.Error);
this.setIcon();
}
this.trayIcon.ShowBalloonTip(100);
}
private void trayMenu_isRunning(bool p)
{
this.trayMenu_start.Enabled = !p;
this.trayMenu_stop.Enabled = p;
}
private void trayMenu_stop_Click(object sender, EventArgs e)
{
if (sr.stop_service())
{
this.showPopup("OpenVPN-GUI", "Service succesful stopped", ToolTipIcon.Info);
this.setIcon();
}
else
{
this.showPopup("OpenVPN-GUI", "Error while stopping Service", ToolTipIcon.Error);
this.setIcon();
}
this.trayIcon.ShowBalloonTip(100);
}
private void trayMenu_close_Click(object sender, EventArgs e)
{
sr.stop_service();
Application.Exit();
}
private void Application_Closed(object sender, FormClosedEventArgs e)
{
this.trayMenu_close_Click(sender, (EventArgs)e);
}
private void trayIcon_MouseDoubleClick(object sender, MouseEventArgs e)
{
if (this.trayMenu_start.Enabled)
this.trayMenu_start_Click(sender, e);
else if (this.trayMenu_stop.Enabled)
this.trayMenu_stop_Click(sender, e);
}
private void servicename_TextChanged(object sender, EventArgs e)
{
this.sr.service = this.servicename.Text;
this.setIcon();
}
private void showPopup(string title, string text, ToolTipIcon toolTipIcon)
{
this.Statuslog.Items.Add(text);
this.trayIcon.BalloonTipIcon = toolTipIcon;
this.trayIcon.BalloonTipText = text;
this.trayIcon.BalloonTipTitle = title;
}
}
}

129
NetOpenVPNGUI/Form1.resx Normal file
View File

@ -0,0 +1,129 @@
<?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="trayIcon.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="trayMenu.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>112, 17</value>
</metadata>
<metadata name="MainMenu.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>216, 17</value>
</metadata>
</root>

View File

@ -28,7 +28,7 @@
<PlatformTarget>x86</PlatformTarget> <PlatformTarget>x86</PlatformTarget>
<DebugType>pdbonly</DebugType> <DebugType>pdbonly</DebugType>
<Optimize>true</Optimize> <Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath> <OutputPath>E:\Programme\NetMonitor\</OutputPath>
<DefineConstants>TRACE</DefineConstants> <DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
@ -46,6 +46,12 @@
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Form1.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Form1.Designer.cs">
<DependentUpon>Form1.cs</DependentUpon>
</Compile>
<Compile Include="Resources.Designer.cs"> <Compile Include="Resources.Designer.cs">
<DependentUpon>Resources.resx</DependentUpon> <DependentUpon>Resources.resx</DependentUpon>
<AutoGen>True</AutoGen> <AutoGen>True</AutoGen>
@ -54,6 +60,9 @@
<Compile Include="Runner.cs" /> <Compile Include="Runner.cs" />
<Compile Include="Program.cs" /> <Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<EmbeddedResource Include="Form1.resx">
<DependentUpon>Form1.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Properties\Resources.resx"> <EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator> <Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput> <LastGenOutput>Resources.Designer.cs</LastGenOutput>

View File

@ -1,10 +1,21 @@
namespace NetOpenVPNGUI using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
namespace NetOpenVpnGui
{ {
static class Program static class Program
{ {
/// <summary>
/// Der Haupteinstiegspunkt für die Anwendung.
/// </summary>
[STAThread]
static void Main() static void Main()
{ {
new Runner(); Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
} }
} }
} }

View File

@ -8,7 +8,7 @@
// </auto-generated> // </auto-generated>
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
namespace NetOpenVPNGUI { namespace NetOpenVpnGui {
using System; using System;

View File

@ -6,81 +6,53 @@ using System.Net.Sockets;
using System.Net; using System.Net;
using System.Windows.Forms; using System.Windows.Forms;
namespace NetOpenVPNGUI namespace NetOpenVpnGui
{ {
class Runner class Runner
{ {
private NotifyIcon trayIcon;
private UdpClient net_send; private UdpClient net_send;
private IPEndPoint net_send_port; private IPEndPoint net_send_port;
private UdpClient net_gets; private UdpClient net_gets;
private IPEndPoint net_gets_port; private IPEndPoint net_gets_port;
public Runner() public Runner(String p)
{
this.trayIcon = new System.Windows.Forms.NotifyIcon();
this.start();
this.draw_icon(false);
if (!this.check_service("Apache2.2"))
this.run_service("Apache2.2");
else
this.draw_icon(true);
this.wait();
}
private void wait()
{
while (true)
{
System.Threading.Thread.Sleep(100);
}
}
private void draw_icon(bool p)
{
this.trayIcon.Visible = true;
if(p)
this.trayIcon.Icon = Resources.icon_ok;
else
this.trayIcon.Icon = Resources.icon_no;
}
private void run_service(string p)
{
byte[] data = Encoding.UTF8.GetBytes("service start " + p);
this.net_send.Send(data, data.Length, this.net_send_port);
String ret = Encoding.UTF8.GetString(net_gets.Receive(ref net_gets_port));
this.trayIcon.BalloonTipIcon = ToolTipIcon.Info;
if (Boolean.Parse(ret))
{
this.trayIcon.BalloonTipText = "Service " + p + " Started";
this.draw_icon(true);
}
else
{
this.trayIcon.BalloonTipText = "Service " + p + " NOT Started";
this.draw_icon(false);
}
this.trayIcon.ShowBalloonTip(200);
}
private bool check_service(string p)
{
byte[] data = Encoding.UTF8.GetBytes("service status " + p);
this.net_send.Send(data, data.Length, this.net_send_port);
int ret = int.Parse(Encoding.UTF8.GetString(net_gets.Receive(ref net_gets_port)));
if (ret == 1)
return true;
return false;
}
private void start()
{ {
this.service = p;
this.net_send = new UdpClient(); this.net_send = new UdpClient();
this.net_send_port = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 34523); this.net_send_port = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 34523);
this.net_gets = new UdpClient(34524); this.net_gets = new UdpClient(34524);
this.net_gets_port = new IPEndPoint(IPAddress.Loopback, 0); this.net_gets_port = new IPEndPoint(IPAddress.Loopback, 0);
} }
public bool run_service()
{
byte[] data = Encoding.UTF8.GetBytes("service start " + this.service);
this.net_send.Send(data, data.Length, this.net_send_port);
bool ret = Boolean.Parse(Encoding.UTF8.GetString(net_gets.Receive(ref net_gets_port)));
if (ret)
return true;
return false;
}
public bool stop_service()
{
byte[] data = Encoding.UTF8.GetBytes("service stop " + this.service);
this.net_send.Send(data, data.Length, this.net_send_port);
bool ret = Boolean.Parse(Encoding.UTF8.GetString(net_gets.Receive(ref net_gets_port)));
if (ret)
return true;
return false;
}
public bool check_service()
{
byte[] data = Encoding.UTF8.GetBytes("service status " + this.service);
this.net_send.Send(data, data.Length, this.net_send_port);
bool ret = Boolean.Parse(Encoding.UTF8.GetString(net_gets.Receive(ref net_gets_port)));
if (ret)
return true;
return false;
}
public string service { get; set; }
} }
} }