Getter für Block, Compilefehler entfernt
This commit is contained in:
@@ -17,10 +17,10 @@ namespace WorldOfPeacecraft
|
||||
{
|
||||
ParserThread = new Thread (new ThreadStart (this.RunParser));
|
||||
message = new LinkedList<string> ();
|
||||
LastLineRegex = new Regex("^end:[0-9]+$");
|
||||
LastLineRegex = new Regex ("^end:[0-9]+$");
|
||||
}
|
||||
|
||||
public void RunParser ()
|
||||
private void RunParser ()
|
||||
{
|
||||
while (true) {
|
||||
bool waitRequired = false;
|
||||
@@ -38,24 +38,24 @@ namespace WorldOfPeacecraft
|
||||
}
|
||||
}
|
||||
|
||||
public void Parse ()
|
||||
private void Parse ()
|
||||
{
|
||||
// If package is not complete wait for more lines
|
||||
if (!IsCompletePackage())
|
||||
if (!IsCompletePackage ())
|
||||
return;
|
||||
Block mainBlock = new Block(message, 0, message.Count - 1);
|
||||
MapData(mainBlock);
|
||||
Block mainBlock = new Block (message, 0, message.Count - 1);
|
||||
MapData (mainBlock);
|
||||
}
|
||||
|
||||
public void MapData (Block block)
|
||||
private void MapData (Block block)
|
||||
{
|
||||
// TODO Implement
|
||||
}
|
||||
|
||||
public bool IsCompletePackage()
|
||||
private bool IsCompletePackage ()
|
||||
{
|
||||
string lastLine = message.Last.Value;
|
||||
return LastLineRegex.IsMatch(lastLine);
|
||||
return LastLineRegex.IsMatch (lastLine);
|
||||
}
|
||||
|
||||
public void Stop ()
|
||||
@@ -74,44 +74,64 @@ namespace WorldOfPeacecraft
|
||||
private class Block
|
||||
{
|
||||
private string Name;
|
||||
private ISet<Block> Blocks = new HashSet<Block>();
|
||||
private Dictionary<String, String> Values = new Dictionary<String, String>();
|
||||
private ISet<Block> Blocks = new HashSet<Block> ();
|
||||
private Dictionary<String, String> Values = new Dictionary<String, String> ();
|
||||
|
||||
public Block (String[] message, int start, int end)
|
||||
{
|
||||
int pos = start;
|
||||
Name = StringUtils.SubstringAfter(message[pos], ":");
|
||||
Name = StringUtils.SubstringAfter (message [pos], ":");
|
||||
pos++;
|
||||
while (pos < end)
|
||||
{
|
||||
while (pos < end) {
|
||||
// Is the next element a block or a value?
|
||||
if (message[pos].StartsWith("begin:"))
|
||||
{
|
||||
if (message [pos].StartsWith ("begin:")) {
|
||||
// It's a block
|
||||
int blockstart = pos;
|
||||
int begins = 1;
|
||||
while (begins > 0)
|
||||
{
|
||||
while (begins > 0) {
|
||||
pos++;
|
||||
if (pos >= end)
|
||||
throw new ParsingException("The message is missing end:-lines");
|
||||
if (message[pos].StartsWith("end:"))
|
||||
throw new ParsingException ("The message is missing end:-lines");
|
||||
if (message [pos].StartsWith ("end:"))
|
||||
begins--;
|
||||
else if(message[pos].StartsWith("begin:"))
|
||||
else if (message [pos].StartsWith ("begin:"))
|
||||
begins++;
|
||||
}
|
||||
Blocks.Add(new Block(message, blockstart, pos));
|
||||
}
|
||||
else
|
||||
{
|
||||
Blocks.Add (new Block (message, blockstart, pos));
|
||||
} else {
|
||||
// It's a value
|
||||
string name = StringUtils.SubstringBefore(message[pos], ":");
|
||||
string val = StringUtils.SubstringAfter(message[pos], ":");
|
||||
Values[name] = val;
|
||||
string name = StringUtils.SubstringBefore (message [pos], ":");
|
||||
string val = StringUtils.SubstringAfter (message [pos], ":");
|
||||
Values [name] = val;
|
||||
pos++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string GetName ()
|
||||
{
|
||||
return Name;
|
||||
}
|
||||
|
||||
public ISet<Block> GetBlocks ()
|
||||
{
|
||||
return Blocks;
|
||||
}
|
||||
|
||||
public string GetStringValue (string name)
|
||||
{
|
||||
return Values [name];
|
||||
}
|
||||
|
||||
public int GetIntValue (string name)
|
||||
{
|
||||
return int.Parse (Values [name]);
|
||||
}
|
||||
|
||||
public long GetLongValue (string name)
|
||||
{
|
||||
return long.Parse (Values [name]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,12 +5,20 @@ namespace WorldOfPeacecraft
|
||||
{
|
||||
public class ParsingException : Exception
|
||||
{
|
||||
public ParsingException () : base();
|
||||
public ParsingException () : base()
|
||||
{
|
||||
}
|
||||
|
||||
public ParsingException (string message) : base(message);
|
||||
public ParsingException (string message) : base(message)
|
||||
{
|
||||
}
|
||||
|
||||
public ParsingException (SerializationInfo info, StreamingContext context) : base(info, context);
|
||||
public ParsingException (SerializationInfo info, StreamingContext context) : base(info, context)
|
||||
{
|
||||
}
|
||||
|
||||
public ParsingException (string message, Exception innerException) : base(message, innerException);
|
||||
public ParsingException (string message, Exception innerException) : base(message, innerException)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user