1
0
Fork 0
mirror of https://github.com/sbrl/Nibriboard.git synced 2018-01-10 21:33:49 +00:00

[server] Fix LineIncubator->LineExists()

This commit is contained in:
Starbeamrainbowlabs 2017-04-24 18:09:18 +01:00
parent 9cd578512b
commit 96485f3f0e
2 changed files with 20 additions and 11 deletions

View file

@ -39,7 +39,7 @@ namespace Nibriboard.Client
/// <param name="lineId">The line id to check for.</param>
public bool LineExists(string lineId)
{
if(currentLines[lineId] != null)
if(currentLines.ContainsKey(lineId))
return true;
return false;
}

View file

@ -161,17 +161,26 @@ namespace Nibriboard.Client
}
if(eventName != "CursorPosition")
Log.WriteLine("[NibriClient#{0}] Recieved message with event {1}.", Id, eventName);
try
{
Type messageType = messageEventTypes[eventName];
Type jsonNet = typeof(JsonConvert);
MethodInfo deserialiserInfo = jsonNet.GetMethods().First(method => method.Name == "DeserializeObject" && method.IsGenericMethod);
MethodInfo genericInfo = deserialiserInfo.MakeGenericMethod(messageType);
var decodedMessage = genericInfo.Invoke(null, new object[] { frame });
Type messageType = messageEventTypes[eventName];
Type jsonNet = typeof(JsonConvert);
MethodInfo deserialiserInfo = jsonNet.GetMethods().First(method => method.Name == "DeserializeObject" && method.IsGenericMethod);
MethodInfo genericInfo = deserialiserInfo.MakeGenericMethod(messageType);
var decodedMessage = genericInfo.Invoke(null, new object[] { frame });
string handlerMethodName = "handle" + decodedMessage.GetType().Name;
Type clientType = this.GetType();
MethodInfo handlerInfo = clientType.GetMethod(handlerMethodName, BindingFlags.Instance | BindingFlags.NonPublic);
await (Task)handlerInfo.Invoke(this, new object[] { decodedMessage });
string handlerMethodName = "handle" + decodedMessage.GetType().Name;
Type clientType = this.GetType();
MethodInfo handlerInfo = clientType.GetMethod(handlerMethodName, BindingFlags.Instance | BindingFlags.NonPublic);
await (Task)handlerInfo.Invoke(this, new object[] { decodedMessage });
}
catch(Exception error)
{
Log.WriteLine("[NibriClient#{0}] Error decoding and / or handling message.", Id);
Log.WriteLine("[NibriClient#{0}] Raw frame content: {1}", Id, frame);
Log.WriteLine("[NibriClient#{0}] Exception details: {1}", Id, error);
}
}
#endregion