Ini Reader Fertiggestellt; Auslesen der Ini begonnen

This commit is contained in:
BlubbFish 2010-04-21 08:39:16 +00:00
parent 1312ec9204
commit 27b6c5d466
6 changed files with 85 additions and 33 deletions

View File

@ -169,36 +169,6 @@
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.trayMenuNetzwerk});
this.trayMenu.Name = "trayMenu";
this.trayMenu.Size = new System.Drawing.Size(153, 48);
//
// trayMenuNetzwerk
//
this.trayMenuNetzwerk.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.homeToolStripMenuItem,
this.fhgToolStripMenuItem});
this.trayMenuNetzwerk.Name = "trayMenuNetzwerk";
this.trayMenuNetzwerk.Size = new System.Drawing.Size(152, 22);
this.trayMenuNetzwerk.Text = "Netzwerk";
//
// homeToolStripMenuItem
//
this.homeToolStripMenuItem.Name = "homeToolStripMenuItem";
this.homeToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
this.homeToolStripMenuItem.Text = "Home";
this.homeToolStripMenuItem.Click += new System.EventHandler(this.homeToolStripMenuItem_Click);
//
// fhgToolStripMenuItem
//
this.fhgToolStripMenuItem.Name = "fhgToolStripMenuItem";
this.fhgToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
this.fhgToolStripMenuItem.Text = "Fhg";
this.fhgToolStripMenuItem.Click += new System.EventHandler(this.fhgToolStripMenuItem_Click);
//
// Netzmonitor
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@ -241,6 +211,7 @@
private System.Windows.Forms.ToolStripMenuItem trayMenuNetzwerk;
private System.Windows.Forms.ToolStripMenuItem homeToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem fhgToolStripMenuItem;
private InIReader networkini;
}
}

View File

@ -15,6 +15,7 @@ namespace NetMonitorCliend
public Netzmonitor()
{
InitializeComponent();
InitNetworks();
this.serviceController1.ServiceName = "NetMonitorServer";
this.sc = new ServiceControl(this.serviceController1);
}

View File

@ -11,11 +11,11 @@ namespace NetMonitorCliend
class InIReader
{
private StreamReader file;
private ArrayList cont;
private ArrayList cont = new ArrayList();
public InIReader(string filename)
{
this.file = new StreamReader(filename);
FileSystemWatcher k = new FileSystemWatcher(filename);
FileSystemWatcher k = new FileSystemWatcher(Directory.GetCurrentDirectory(), "*.ini");
k.Changed += new FileSystemEventHandler(this.readAgain);
loadFile();
}
@ -39,12 +39,36 @@ namespace NetMonitorCliend
ArrayList ret = new ArrayList();
foreach (string sOutput in this.cont)
{
Match match = Regex.Match(sOutput, @"^\[[a-zA-Z0-9\-]\]\w*$", RegexOptions.IgnoreCase);
Match match = Regex.Match(sOutput, @"^\[[a-zA-Z0-9\-_]+\]\w*$", RegexOptions.IgnoreCase);
if (match.Success)
ret.Add(sOutput);
}
return ret;
}
public String getValue(String section, String key)
{
bool sec = false;
foreach (string sOutput in this.cont)
{
if (sOutput == section)
sec = true;
if (sec && Regex.Match(sOutput, @"^\w*$").Success)
sec = false;
Match match = Regex.Match(sOutput, @"^" + Regex.Escape(key) + "=", RegexOptions.IgnoreCase);
if (match.Success && sec)
{
try
{
return sOutput.Split('=')[1];
}
catch (Exception)
{
return null;
}
}
}
return null;
}
}
}

View File

@ -77,6 +77,9 @@
<DependentUpon>Form1.cs</DependentUpon>
</Compile>
<Compile Include="InIReader.cs" />
<Compile Include="Networks.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<EmbeddedResource Include="Form1.resx">
@ -92,6 +95,7 @@
<DependentUpon>Resources.resx</DependentUpon>
<DesignTime>True</DesignTime>
</Compile>
<None Include="network.ini" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>

View File

@ -0,0 +1,47 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using System.Windows.Forms;
namespace NetMonitorCliend
{
partial class Netzmonitor
{
private void InitNetworks()
{
this.networkini = new InIReader("network.ini");
//
// trayMenu
//
this.trayMenu.Items.AddRange(new ToolStripItem[] {this.trayMenuNetzwerk});
this.trayMenu.Name = "trayMenu";
this.trayMenu.Size = new System.Drawing.Size(153, 48);
//
// trayMenuNetzwerk
//
this.trayMenuNetzwerk.Name = "trayMenuNetzwerk";
this.trayMenuNetzwerk.Size = new System.Drawing.Size(152, 22);
this.trayMenuNetzwerk.Text = "Netzwerk";
ArrayList networks = networkini.getSections();
ToolStripItem[] tsi = new ToolStripItem[networks.Count];
int i=0;
foreach (String net in networks)
{
ToolStripMenuItem TrayItemNet = new ToolStripMenuItem();
TrayItemNet.Name = networkini.getValue(net, "Name") + "ToolStripMenuItem";
TrayItemNet.Size = new System.Drawing.Size(152, 22);
TrayItemNet.Text = networkini.getValue(net, "Name");
TrayItemNet.Click += new System.EventHandler(this.homeToolStripMenuItem_Click);
tsi[i++] = TrayItemNet;
}
this.trayMenuNetzwerk.DropDownItems.AddRange(tsi);
}
}
}

View File

@ -0,0 +1,5 @@
[network1]
Name=Home
[network2]
Name=FHG