From 28242ff052755afb243e55e4da7b167113635239 Mon Sep 17 00:00:00 2001 From: Sem van der Hoeven Date: Wed, 23 Sep 2020 11:50:25 +0200 Subject: [PATCH 1/5] added message class and added references to server and client projects --- Client/Client.csproj | 6 +++++- Message/Message.csproj | 12 ++++++++++++ Message/Program.cs | 34 ++++++++++++++++++++++++++++++++++ ProftaakRH/ProftaakRH.sln | 6 ++++++ Server/Server.csproj | 4 ++++ 5 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 Message/Message.csproj create mode 100644 Message/Program.cs diff --git a/Client/Client.csproj b/Client/Client.csproj index c73e0d1..b664ee3 100644 --- a/Client/Client.csproj +++ b/Client/Client.csproj @@ -1,8 +1,12 @@ - + Exe netcoreapp3.1 + + + + diff --git a/Message/Message.csproj b/Message/Message.csproj new file mode 100644 index 0000000..0eaee1b --- /dev/null +++ b/Message/Message.csproj @@ -0,0 +1,12 @@ + + + + Exe + netcoreapp3.1 + + + + + + + diff --git a/Message/Program.cs b/Message/Program.cs new file mode 100644 index 0000000..f844f99 --- /dev/null +++ b/Message/Program.cs @@ -0,0 +1,34 @@ +using Newtonsoft.Json; +using System; + +namespace Message +{ + public class Message + { + public string Identifier + { + get;set; + } + + public string Payload + { + get;set; + } + + public Message(string identifier, string payload) + { + this.Identifier = identifier; + this.Payload = payload; + } + + public string Serialize() + { + return JsonConvert.SerializeObject(this); + } + + public static Message Deserialize(string json) + { + return (Message)JsonConvert.DeserializeObject(json); + } + } +} diff --git a/ProftaakRH/ProftaakRH.sln b/ProftaakRH/ProftaakRH.sln index 4ea030c..069a13b 100644 --- a/ProftaakRH/ProftaakRH.sln +++ b/ProftaakRH/ProftaakRH.sln @@ -11,6 +11,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Server", "..\Server\Server. EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Client", "..\Client\Client.csproj", "{5759DD20-7A4F-4D8D-B986-A70A7818C112}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Message", "..\Message\Message.csproj", "{9ED6832D-B0FB-4460-9BCD-FAA58863B0CE}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -33,6 +35,10 @@ Global {5759DD20-7A4F-4D8D-B986-A70A7818C112}.Debug|Any CPU.Build.0 = Debug|Any CPU {5759DD20-7A4F-4D8D-B986-A70A7818C112}.Release|Any CPU.ActiveCfg = Release|Any CPU {5759DD20-7A4F-4D8D-B986-A70A7818C112}.Release|Any CPU.Build.0 = Release|Any CPU + {9ED6832D-B0FB-4460-9BCD-FAA58863B0CE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9ED6832D-B0FB-4460-9BCD-FAA58863B0CE}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9ED6832D-B0FB-4460-9BCD-FAA58863B0CE}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9ED6832D-B0FB-4460-9BCD-FAA58863B0CE}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Server/Server.csproj b/Server/Server.csproj index c73e0d1..4c98a00 100644 --- a/Server/Server.csproj +++ b/Server/Server.csproj @@ -5,4 +5,8 @@ netcoreapp3.1 + + + + From 1a67e97f75e123568f2d908bc2b27874340f96fc Mon Sep 17 00:00:00 2001 From: Sem van der Hoeven Date: Wed, 23 Sep 2020 11:51:22 +0200 Subject: [PATCH 2/5] removed unused boolean warning --- ProftaakRH/BLEHandler.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/ProftaakRH/BLEHandler.cs b/ProftaakRH/BLEHandler.cs index da2d90a..9df61d8 100644 --- a/ProftaakRH/BLEHandler.cs +++ b/ProftaakRH/BLEHandler.cs @@ -24,7 +24,6 @@ namespace Hardware public BLEHandler(IDataConverter dataConverter) { this.dataConverter = dataConverter; - bool running = false; } /// From 603703b3f628596601494fec816b9647b824b3de Mon Sep 17 00:00:00 2001 From: Sem van der Hoeven Date: Wed, 23 Sep 2020 11:52:49 +0200 Subject: [PATCH 3/5] rename program to message --- Message/Program.cs | 34 ---------------------------------- 1 file changed, 34 deletions(-) delete mode 100644 Message/Program.cs diff --git a/Message/Program.cs b/Message/Program.cs deleted file mode 100644 index f844f99..0000000 --- a/Message/Program.cs +++ /dev/null @@ -1,34 +0,0 @@ -using Newtonsoft.Json; -using System; - -namespace Message -{ - public class Message - { - public string Identifier - { - get;set; - } - - public string Payload - { - get;set; - } - - public Message(string identifier, string payload) - { - this.Identifier = identifier; - this.Payload = payload; - } - - public string Serialize() - { - return JsonConvert.SerializeObject(this); - } - - public static Message Deserialize(string json) - { - return (Message)JsonConvert.DeserializeObject(json); - } - } -} From 31ef1beb821dfe7d4a82d9c667d9bab07d2843cc Mon Sep 17 00:00:00 2001 From: Sem van der Hoeven Date: Wed, 23 Sep 2020 11:57:20 +0200 Subject: [PATCH 4/5] added comments to message --- Message/Message.cs | 59 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 Message/Message.cs diff --git a/Message/Message.cs b/Message/Message.cs new file mode 100644 index 0000000..f60fe2e --- /dev/null +++ b/Message/Message.cs @@ -0,0 +1,59 @@ +using Newtonsoft.Json; +using System; + +namespace Message +{ + /// + /// Message class to handle traffic between clients and server + /// + public class Message + { + /// + /// identifier for the message + /// + public string Identifier + { + get;set; + } + + /// + /// payload of the message, the actual text + /// + public string Payload + { + get;set; + } + + /// + /// constructs a new message with the given parameters + /// + /// the identifier + /// the payload + public Message(string identifier, string payload) + { + this.Identifier = identifier; + this.Payload = payload; + } + + /// + /// serializes this object to a JSON string + /// + /// a JSON representation of this object + public string Serialize() + { + return JsonConvert.SerializeObject(this); + } + + /// + /// deserializes a JSON string into a new Message object + /// + /// the JSON string to deserialize + /// a new Message object from the JSON string + public static Message Deserialize(string json) + { + return (Message)JsonConvert.DeserializeObject(json); + } + } + + +} From 60cf23d9807592db7d3d7bd5a85e44f1857acb68 Mon Sep 17 00:00:00 2001 From: Sem van der Hoeven Date: Wed, 23 Sep 2020 11:58:36 +0200 Subject: [PATCH 5/5] added identifier enum and made message use it --- Message/Message.cs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Message/Message.cs b/Message/Message.cs index f60fe2e..3f580fb 100644 --- a/Message/Message.cs +++ b/Message/Message.cs @@ -11,7 +11,7 @@ namespace Message /// /// identifier for the message /// - public string Identifier + public Identifier Identifier { get;set; } @@ -29,7 +29,7 @@ namespace Message /// /// the identifier /// the payload - public Message(string identifier, string payload) + public Message(Identifier identifier, string payload) { this.Identifier = identifier; this.Payload = payload; @@ -55,5 +55,9 @@ namespace Message } } - + public enum Identifier + { + LOGIN, + CHAT, + } }