Parser erkennt nun ob Paket vollständig ist

This commit is contained in:
2014-04-03 21:51:48 +02:00
parent 2ad5676adb
commit 99faa40dea

View File

@@ -1,6 +1,7 @@
using System; using System;
using System.Threading; using System.Threading;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text.RegularExpressions;
namespace WorldOfPeacecraft namespace WorldOfPeacecraft
{ {
@@ -10,11 +11,13 @@ namespace WorldOfPeacecraft
private AutoResetEvent BufferFilledEvent = new AutoResetEvent (false); private AutoResetEvent BufferFilledEvent = new AutoResetEvent (false);
private Thread ParserThread; private Thread ParserThread;
private List<string> message; private List<string> message;
private Regex LastLineRegex;
public Parser () public Parser ()
{ {
ParserThread = new Thread (new ThreadStart (this.RunParser)); ParserThread = new Thread (new ThreadStart (this.RunParser));
message = new LinkedList<string> (); message = new LinkedList<string> ();
LastLineRegex = new Regex("^end:[0-9]+$");
} }
public void RunParser () public void RunParser ()
@@ -35,11 +38,20 @@ namespace WorldOfPeacecraft
} }
} }
public static void Parse (List<string> message) public void Parse ()
{ {
// If package is not complete wait for more lines
if (!IsCompletePackage())
return;
// TODO Implement // TODO Implement
} }
public bool IsCompletePackage()
{
string lastLine = message.Last.Value;
return LastLineRegex.IsMatch(lastLine);
}
public void Stop () public void Stop ()
{ {
ParserThread.Abort (); ParserThread.Abort ();