From abbcb7a8c8a9c5ae1cf2a583821fb7143de1e626 Mon Sep 17 00:00:00 2001
From: Starbeamrainbowlabs <sbrl@starbeamrainbowlabs.com>
Date: Fri, 27 Jan 2017 21:24:58 +0000
Subject: [PATCH] Start building message classes and deserialising incoming
 messages into them

---
 Nibriboard/Client/HttpEmbeddedFileHandler.cs |  2 +-
 Nibriboard/Client/NibriClient.cs             | 13 +++++++++++--
 Nibriboard/Nibriboard.csproj                 |  6 ++++++
 Nibriboard/Program.cs                        |  2 +-
 Nibriboard/Utilities/EmbeddedFiles.cs        |  2 +-
 5 files changed, 20 insertions(+), 5 deletions(-)

diff --git a/Nibriboard/Client/HttpEmbeddedFileHandler.cs b/Nibriboard/Client/HttpEmbeddedFileHandler.cs
index 172bcf9..dbe0ad8 100644
--- a/Nibriboard/Client/HttpEmbeddedFileHandler.cs
+++ b/Nibriboard/Client/HttpEmbeddedFileHandler.cs
@@ -3,7 +3,7 @@ using System.IO;
 using IotWeb.Common.Http;
 using MimeSharp;
 
-using SBRLUtilities;
+using SBRL.Utilities;
 using System.Collections.Generic;
 using System.Reflection;
 
diff --git a/Nibriboard/Client/NibriClient.cs b/Nibriboard/Client/NibriClient.cs
index 9f931ad..93d08c8 100644
--- a/Nibriboard/Client/NibriClient.cs
+++ b/Nibriboard/Client/NibriClient.cs
@@ -1,8 +1,10 @@
 ﻿using System;
 using System.Threading.Tasks;
 using System.Text;
+using System.Collections.Generic;
 
 using IotWeb.Common.Http;
+using SBRL.Utilities;
 
 namespace Nibriboard.Client
 {
@@ -11,6 +13,11 @@ namespace Nibriboard.Client
 		private readonly NibriClientManager manager;
 		private readonly WebSocket client;
 
+		private Dictionary<string, Type> messageEventTypes = new Dictionary<string, Type>()
+		{
+
+		};
+
 		public NibriClient(NibriClientManager inManager, WebSocket inClient)
 		{
 			manager = inManager;
@@ -19,7 +26,7 @@ namespace Nibriboard.Client
 			client.DataReceived += async (WebSocket clientSocket, string frame) => {
 				try
 				{
-					await onMessage(frame);
+					await handleMessage(frame);
 				}
 				catch (Exception error)
 				{
@@ -38,8 +45,10 @@ namespace Nibriboard.Client
 			client.Send(Encoding.UTF8.GetBytes(message));
 		}
 
-		private async Task onMessage(string frame)
+		private async Task handleMessage(string frame)
 		{
+			string eventName = JsonUtilities.DeserializeProperty(frame, "event");
+
 
 		}
 	}
diff --git a/Nibriboard/Nibriboard.csproj b/Nibriboard/Nibriboard.csproj
index c7743aa..5157dad 100644
--- a/Nibriboard/Nibriboard.csproj
+++ b/Nibriboard/Nibriboard.csproj
@@ -48,6 +48,7 @@
     <Reference Include="MimeSharp">
       <HintPath>..\packages\MimeSharp.1.0.0\lib\MimeSharp.dll</HintPath>
     </Reference>
+    <Reference Include="System.Drawing" />
   </ItemGroup>
   <ItemGroup>
     <Compile Include="Program.cs" />
@@ -69,6 +70,10 @@
     <Compile Include="Client\NibriClientManager.cs" />
     <Compile Include="Client\ClientSettings.cs" />
     <Compile Include="Client\HttpClientSettingsHandler.cs" />
+    <Compile Include="Utilities\PointExtensions.cs" />
+    <Compile Include="Utilities\JsonUtilities.cs" />
+    <Compile Include="Client\Messages\Message.cs" />
+    <Compile Include="Client\Messages\HandshakeRequestMessage.cs" />
   </ItemGroup>
   <ItemGroup>
     <EmbeddedResource Include="ClientFiles\index.html" />
@@ -81,6 +86,7 @@
     <Folder Include="Utilities\" />
     <Folder Include="ClientFiles\" />
     <Folder Include="Client\" />
+    <Folder Include="Client\Messages\" />
   </ItemGroup>
   <ItemGroup>
     <None Include="packages.config" />
diff --git a/Nibriboard/Program.cs b/Nibriboard/Program.cs
index 6b5306a..857e1c3 100644
--- a/Nibriboard/Program.cs
+++ b/Nibriboard/Program.cs
@@ -1,7 +1,7 @@
 ﻿using System;
 using System.Reflection;
 using System.Threading.Tasks;
-using SBRLUtilities;
+using SBRL.Utilities;
 
 namespace Nibriboard
 {
diff --git a/Nibriboard/Utilities/EmbeddedFiles.cs b/Nibriboard/Utilities/EmbeddedFiles.cs
index d94f869..bfb7f22 100644
--- a/Nibriboard/Utilities/EmbeddedFiles.cs
+++ b/Nibriboard/Utilities/EmbeddedFiles.cs
@@ -5,7 +5,7 @@ using System.Net.Configuration;
 using System.Threading.Tasks;
 using System.Collections.Generic;
 
-namespace SBRLUtilities
+namespace SBRL.Utilities
 {
 	/// <summary>
 	/// A collection of static methods for manipulating embedded resources.
