netmonitor/NetMonitorCliend/InIReader.cs

51 lines
1.4 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Collections;
using System.Text.RegularExpressions;
namespace NetMonitorCliend
{
class InIReader
{
private StreamReader file;
private ArrayList cont;
public InIReader(string filename)
{
this.file = new StreamReader(filename);
FileSystemWatcher k = new FileSystemWatcher(filename);
k.Changed += new FileSystemEventHandler(this.readAgain);
loadFile();
}
private void readAgain(object sender, EventArgs e)
{
this.file.BaseStream.Seek(0, SeekOrigin.Begin);
loadFile();
}
private void loadFile()
{
string fline = "";
while (fline != null)
{
fline = this.file.ReadLine();
if (fline != null)
cont.Add(fline);
}
}
public ArrayList getSections()
{
ArrayList ret = new ArrayList();
foreach (string sOutput in this.cont)
{
Match match = Regex.Match(sOutput, @"^\[[a-zA-Z0-9\-]\]\w*$", RegexOptions.IgnoreCase);
if (match.Success)
ret.Add(sOutput);
}
return ret;
}
}
}