From 96485f3f0eb6499375de0a7ba3f3bd846dc1e0ec Mon Sep 17 00:00:00 2001 From: Starbeamrainbowlabs Date: Mon, 24 Apr 2017 18:09:18 +0100 Subject: [PATCH] [server] Fix LineIncubator->LineExists() --- Nibriboard/Client/LineIncubator.cs | 2 +- Nibriboard/Client/NibriClient.cs | 29 +++++++++++++++++++---------- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/Nibriboard/Client/LineIncubator.cs b/Nibriboard/Client/LineIncubator.cs index 80fca10..367844b 100644 --- a/Nibriboard/Client/LineIncubator.cs +++ b/Nibriboard/Client/LineIncubator.cs @@ -39,7 +39,7 @@ namespace Nibriboard.Client /// The line id to check for. public bool LineExists(string lineId) { - if(currentLines[lineId] != null) + if(currentLines.ContainsKey(lineId)) return true; return false; } diff --git a/Nibriboard/Client/NibriClient.cs b/Nibriboard/Client/NibriClient.cs index a898c96..af386f6 100644 --- a/Nibriboard/Client/NibriClient.cs +++ b/Nibriboard/Client/NibriClient.cs @@ -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