From de4bb67216d81b46ebe144e7bdbebbb8cfb1195e Mon Sep 17 00:00:00 2001 From: Kenneth van Ewijk Date: Mon, 21 Sep 2015 12:58:01 +0200 Subject: [PATCH 01/12] Implemented most common classes --- ErgometerLibrary/ErgometerLibrary.csproj | 34 ++++++++----------- .../{Class1.cs => FileHandler.cs} | 3 +- ErgometerLibrary/NetCommand.cs | 23 +++++++++++++ ErgometerLibrary/Properties/AssemblyInfo.cs | 8 ++--- 4 files changed, 44 insertions(+), 24 deletions(-) rename ErgometerLibrary/{Class1.cs => FileHandler.cs} (87%) create mode 100644 ErgometerLibrary/NetCommand.cs diff --git a/ErgometerLibrary/ErgometerLibrary.csproj b/ErgometerLibrary/ErgometerLibrary.csproj index ec42b20..74739fe 100644 --- a/ErgometerLibrary/ErgometerLibrary.csproj +++ b/ErgometerLibrary/ErgometerLibrary.csproj @@ -1,10 +1,10 @@ - + Debug AnyCPU - cc20ff4e-8751-42a1-a32b-0e5b22452cac + {CC20FF4E-8751-42A1-A32B-0E5B22452CAC} Library Properties ErgometerLibrary @@ -30,23 +30,20 @@ 4 - - - - - - - - - - - - - - + + + + + + + + - + + + + @@ -57,5 +54,4 @@ --> - - + \ No newline at end of file diff --git a/ErgometerLibrary/Class1.cs b/ErgometerLibrary/FileHandler.cs similarity index 87% rename from ErgometerLibrary/Class1.cs rename to ErgometerLibrary/FileHandler.cs index 1d1b5b4..4a0e52e 100644 --- a/ErgometerLibrary/Class1.cs +++ b/ErgometerLibrary/FileHandler.cs @@ -6,7 +6,8 @@ using System.Threading.Tasks; namespace ErgometerLibrary { - public class Class1 + class FileHandler { + } } diff --git a/ErgometerLibrary/NetCommand.cs b/ErgometerLibrary/NetCommand.cs new file mode 100644 index 0000000..a1bc505 --- /dev/null +++ b/ErgometerLibrary/NetCommand.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ErgometerLibrary +{ + class NetCommand + { + + public int Session { get; set; } + public string DisplayName { get; set; } + public double Timestamp { get; set; } + + public NetCommand(int session, string displayname) + { + Session = session; + DisplayName = displayname; + Timestamp = (DateTime.Now - DateTime.Parse("1/1/1870 0:0:0")).TotalMilliseconds; + } + } +} diff --git a/ErgometerLibrary/Properties/AssemblyInfo.cs b/ErgometerLibrary/Properties/AssemblyInfo.cs index a1697ab..ae62c7a 100644 --- a/ErgometerLibrary/Properties/AssemblyInfo.cs +++ b/ErgometerLibrary/Properties/AssemblyInfo.cs @@ -6,9 +6,9 @@ using System.Runtime.InteropServices; // set of attributes. Change these attribute values to modify the information // associated with an assembly. [assembly: AssemblyTitle("ErgometerLibrary")] -[assembly: AssemblyDescription("")] +[assembly: AssemblyDescription("Library with the most common methods and classes for the Ergometer")] [assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] +[assembly: AssemblyCompany("Projectgroep A5")] [assembly: AssemblyProduct("ErgometerLibrary")] [assembly: AssemblyCopyright("Copyright © 2015")] [assembly: AssemblyTrademark("")] @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] +[assembly: AssemblyVersion("1.0.0.2")] +[assembly: AssemblyFileVersion("1.0.0.2")] From f05e9a7779f0464ff2c871c0ed116f1ded46fada Mon Sep 17 00:00:00 2001 From: Kenneth van Ewijk Date: Fri, 25 Sep 2015 09:44:56 +0200 Subject: [PATCH 02/12] Added missing files --- ErgometerLibrary/ComPort.cs | 65 ++++++++++++++++++++++++++++++++++ ErgometerLibrary/Meting.cs | 69 +++++++++++++++++++++++++++++++++++++ 2 files changed, 134 insertions(+) create mode 100644 ErgometerLibrary/ComPort.cs create mode 100644 ErgometerLibrary/Meting.cs diff --git a/ErgometerLibrary/ComPort.cs b/ErgometerLibrary/ComPort.cs new file mode 100644 index 0000000..176a372 --- /dev/null +++ b/ErgometerLibrary/ComPort.cs @@ -0,0 +1,65 @@ +using System; +using System.Collections.Generic; +using System.IO.Ports; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ErgometerLibrary +{ + public class ComPort + { + private SerialPort comPort; + + public ComPort() + { + comPort = null; + } + + public Boolean Connect(string port) + { + comPort = new SerialPort(); + comPort.PortName = port; + comPort.DataBits = 8; + comPort.Parity = Parity.None; + comPort.StopBits = StopBits.One; + comPort.BaudRate = 9600; + + comPort.Open(); + + return comPort.IsOpen; + } + + public Boolean Disconnect() + { + comPort.Close(); + return !comPort.IsOpen; + } + + public Boolean IsOpen() + { + if (comPort != null) + return comPort.IsOpen; + else + return false; + } + + public void Write(string input) + { + if (IsOpen()) + { + comPort.WriteLine(input); + } + } + + public string Read() + { + if (IsOpen()) + { + return comPort.ReadLine(); + } + + return ""; + } + } +} diff --git a/ErgometerLibrary/Meting.cs b/ErgometerLibrary/Meting.cs new file mode 100644 index 0000000..b0b352d --- /dev/null +++ b/ErgometerLibrary/Meting.cs @@ -0,0 +1,69 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ErgometerLibrary +{ + public class Meting + { + public int HeartBeat { get; set; } + public int RPM { get; set; } + public double Speed { get; set; } + public double Distance { get; set; } + public int Power { get; set; } + public int Energy { get; set; } + public int Seconds { get; set; } + public int ActualPower { get; set; } + public double TimeStamp { get; } + + public Meting(int heartbeat, int rpm, double speed, double distance, int power, int energy, int seconds, int actualpower, double timestamp) + { + HeartBeat = heartbeat; + RPM = rpm; + Speed = speed; + Distance = distance; + Power = power; + Energy = energy; + Seconds = seconds; + ActualPower = actualpower; + TimeStamp = timestamp; + } + + public override string ToString() + { + string temp = ""; + temp += "Heartbeat: " + HeartBeat + "\n"; + temp += "RPM: " + RPM + "\n"; + temp += "Speed: " + Speed + "\n"; + temp += "Distance: " + Distance + "\n"; + temp += "Power: " + Power + "\n"; + temp += "Energy: " + Energy + "\n"; + temp += "Seconds: " + Seconds + "\n"; + temp += "ActualPower: " + ActualPower + "\n"; + return temp; + } + + public static Meting Parse(string input) + { + String[] status = input.Split('\t'); + + if (status.Length != 8) + return null; + + int heartbeat = int.Parse(status[0]); + int rpm = int.Parse(status[1]); + double speed = double.Parse(status[2]) / 10; + double distance = double.Parse(status[3]) / 10; + int power = int.Parse(status[4]); + int energy = int.Parse(status[5]); + int actualpower = int.Parse(status[7]); + + string[] temp = status[6].Split(':'); + int seconds = (int.Parse(temp[0]) * 60) + (int.Parse(temp[1])); + + return new Meting(heartbeat, rpm, speed, distance, power, energy, seconds, actualpower, (DateTime.Now - DateTime.Parse("1/1/1870 0:0:0")).TotalMilliseconds); + } + } +} From 31dc7f0319609f1fce1108235ee47659f33b8ab5 Mon Sep 17 00:00:00 2001 From: Kenneth van Ewijk Date: Fri, 25 Sep 2015 11:24:00 +0200 Subject: [PATCH 03/12] Added network protocol --- ErgometerLibrary/FileHandler.cs | 5 +- ErgometerLibrary/Meting.cs | 32 ++++++- ErgometerLibrary/NetCommand.cs | 149 +++++++++++++++++++++++++++++++- 3 files changed, 178 insertions(+), 8 deletions(-) diff --git a/ErgometerLibrary/FileHandler.cs b/ErgometerLibrary/FileHandler.cs index 4a0e52e..87cd890 100644 --- a/ErgometerLibrary/FileHandler.cs +++ b/ErgometerLibrary/FileHandler.cs @@ -8,6 +8,9 @@ namespace ErgometerLibrary { class FileHandler { - + public static int GenerateSession() + { + return 0; + } } } diff --git a/ErgometerLibrary/Meting.cs b/ErgometerLibrary/Meting.cs index b0b352d..f0741b0 100644 --- a/ErgometerLibrary/Meting.cs +++ b/ErgometerLibrary/Meting.cs @@ -45,11 +45,31 @@ namespace ErgometerLibrary return temp; } + public string ToCommand() + { + string temp = ""; + temp += HeartBeat + "»"; + temp += RPM + "»"; + temp += Speed + "»"; + temp += Distance + "»"; + temp += Power + "»"; + temp += Energy + "»"; + temp += Seconds + "»"; + temp += ActualPower + "»"; + temp += TimeStamp; + return temp; + } + public static Meting Parse(string input) { - String[] status = input.Split('\t'); + return Parse(input, '\t'); + } - if (status.Length != 8) + public static Meting Parse(string input, char delimiter) + { + String[] status = input.Split(delimiter); + + if (status.Length != 8 || status.Length != 9) return null; int heartbeat = int.Parse(status[0]); @@ -60,10 +80,16 @@ namespace ErgometerLibrary int energy = int.Parse(status[5]); int actualpower = int.Parse(status[7]); + double timestamp = 0; + if (status.Length == 9) + timestamp = double.Parse(status[8]); + else + timestamp = (DateTime.Now - DateTime.Parse("1/1/1870 0:0:0")).TotalMilliseconds; + string[] temp = status[6].Split(':'); int seconds = (int.Parse(temp[0]) * 60) + (int.Parse(temp[1])); - return new Meting(heartbeat, rpm, speed, distance, power, energy, seconds, actualpower, (DateTime.Now - DateTime.Parse("1/1/1870 0:0:0")).TotalMilliseconds); + return new Meting(heartbeat, rpm, speed, distance, power, energy, seconds, actualpower,timestamp); } } } diff --git a/ErgometerLibrary/NetCommand.cs b/ErgometerLibrary/NetCommand.cs index a1bc505..adab0f5 100644 --- a/ErgometerLibrary/NetCommand.cs +++ b/ErgometerLibrary/NetCommand.cs @@ -8,16 +8,157 @@ namespace ErgometerLibrary { class NetCommand { + public enum CommandType { LOGIN, DATA, CHAT, LOGOUT }; + - public int Session { get; set; } - public string DisplayName { get; set; } public double Timestamp { get; set; } + public int Session { get; set; } + public CommandType Type { get; set; } + public string DisplayName { get; set; } + public bool IsDoctor { get; set; } + public string Password { get; set; } + public string ChatMessage { get; set; } + public Meting Meting { get; set; } - public NetCommand(int session, string displayname) + + public NetCommand(CommandType commandtype, int session) { + Type = commandtype; Session = session; - DisplayName = displayname; Timestamp = (DateTime.Now - DateTime.Parse("1/1/1870 0:0:0")).TotalMilliseconds; } + + public NetCommand(Meting m, int session) + { + Type = CommandType.DATA; + Session = session; + Timestamp = (DateTime.Now - DateTime.Parse("1/1/1870 0:0:0")).TotalMilliseconds; + + Meting = m; + } + + public NetCommand(string chat, int session) + { + Type = CommandType.CHAT; + Session = session; + Timestamp = (DateTime.Now - DateTime.Parse("1/1/1870 0:0:0")).TotalMilliseconds; + + ChatMessage = chat; + } + + public NetCommand(string name, bool doctor, int session) + { + Type = CommandType.LOGIN; + Session = session; + Timestamp = (DateTime.Now - DateTime.Parse("1/1/1870 0:0:0")).TotalMilliseconds; + + DisplayName = name; + IsDoctor = doctor; + } + + public NetCommand Parse(string command) + { + string[] com = command.Split('»'); + + int comType = int.Parse(com[0]); + int session = 0; + if (com[1].StartsWith("ses")) + session = int.Parse(com[1].Substring(3)); + else + throw new FormatException("Error in NetCommend: " + com[1] + " is not a valid session."); + + string[] args = (string[]) com.Skip(2); + + switch (comType) + { + case 1: + return ParseLoginRequest(session, args); + case 2: + return ParseData(session, args); + case 3: + return ParseChatMessage(session, args); + case 4: + return ParseLogoutRequest(session, args); + default: + throw new FormatException("Error in NetCommand: " + comType + " is not a valid command type."); + } + } + + private NetCommand ParseLogoutRequest(int session, string[] args) + { + if (args.Length != 1) + throw new MissingFieldException("Error in NetCommand: Logout Request is missing arguments"); + + NetCommand temp = new NetCommand(CommandType.LOGOUT, session); + if (args[0] != "logout") + throw new FormatException("Error in NetCommand: " + args[0] + " is not a valid logout request"); + + return temp; + } + + private NetCommand ParseChatMessage(int session, string[] args) + { + if (args.Length != 1) + throw new MissingFieldException("Error in NetCommand: Chat Message is missing arguments"); + + NetCommand temp = new NetCommand(CommandType.CHAT, session); + temp.ChatMessage = args[0]; + + return temp; + } + + private NetCommand ParseData(int session, string[] args) + { + if (args.Length != 9) + throw new MissingFieldException("Error in NetCommand: Data is missing arguments"); + + NetCommand temp = new NetCommand(CommandType.DATA, session); + temp.Meting = Meting.Parse(string.Join("\t", args)); + + return temp; + } + + private NetCommand ParseLoginRequest(int session, string[] args) + { + bool doctor = bool.Parse(args[1]); + if (doctor && args.Length != 5) + throw new MissingFieldException("Error in NetCommand: Doctor login is missing arguments"); + else if(args.Length != 4) + throw new MissingFieldException("Error in NetCommand: Client login is missing arguments"); + + NetCommand temp = new NetCommand(CommandType.LOGIN, session); + temp.IsDoctor = doctor; + temp.DisplayName = args[0]; + if (doctor) + temp.Password = args[2]; + + return temp; + } + + public override string ToString() + { + string command = ""; + + switch(Type) + { + case CommandType.LOGIN: + command += "1»ses" + Session + "»" + DisplayName + "»" + IsDoctor + (IsDoctor ? "»" + Password : ""); + break; + case CommandType.DATA: + command += "2»ses" + Session + "»" + Meting.ToCommand(); + break; + case CommandType.CHAT: + command += "3»ses" + Session + "»" + ChatMessage; + break; + case CommandType.LOGOUT: + command += "4»ses" + Session + "»logout"; + break; + + default: + throw new FormatException("Error in NetCommand: Cannot find type of command"); + } + + return command; + } } } From ce93db22b2e061b88a34340d977139189036de94 Mon Sep 17 00:00:00 2001 From: Aareschluchtje Date: Fri, 25 Sep 2015 11:42:11 +0200 Subject: [PATCH 04/12] Made NetCommand public. --- ErgometerLibrary/NetCommand.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ErgometerLibrary/NetCommand.cs b/ErgometerLibrary/NetCommand.cs index adab0f5..91c85ad 100644 --- a/ErgometerLibrary/NetCommand.cs +++ b/ErgometerLibrary/NetCommand.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace ErgometerLibrary { - class NetCommand + public class NetCommand { public enum CommandType { LOGIN, DATA, CHAT, LOGOUT }; From 5ef796341a7a2b801104a8f278bf2da4c5804027 Mon Sep 17 00:00:00 2001 From: Kenneth van Ewijk Date: Fri, 25 Sep 2015 11:48:38 +0200 Subject: [PATCH 05/12] Fixed stuff --- ErgometerLibrary/FileHandler.cs | 2 +- ErgometerLibrary/NetCommand.cs | 19 ++++++++++++++++++- ErgometerLibrary/Properties/AssemblyInfo.cs | 4 ++-- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/ErgometerLibrary/FileHandler.cs b/ErgometerLibrary/FileHandler.cs index 87cd890..c84c8ab 100644 --- a/ErgometerLibrary/FileHandler.cs +++ b/ErgometerLibrary/FileHandler.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace ErgometerLibrary { - class FileHandler + public class FileHandler { public static int GenerateSession() { diff --git a/ErgometerLibrary/NetCommand.cs b/ErgometerLibrary/NetCommand.cs index 91c85ad..7df5d57 100644 --- a/ErgometerLibrary/NetCommand.cs +++ b/ErgometerLibrary/NetCommand.cs @@ -8,7 +8,7 @@ namespace ErgometerLibrary { public class NetCommand { - public enum CommandType { LOGIN, DATA, CHAT, LOGOUT }; + public enum CommandType { LOGIN, DATA, CHAT, LOGOUT, SESSION }; public double Timestamp { get; set; } @@ -20,6 +20,12 @@ namespace ErgometerLibrary public string ChatMessage { get; set; } public Meting Meting { get; set; } + public NetCommand(int session) + { + Type = CommandType.SESSION; + Session = session; + Timestamp = (DateTime.Now - DateTime.Parse("1/1/1870 0:0:0")).TotalMilliseconds; + } public NetCommand(CommandType commandtype, int session) { @@ -79,11 +85,19 @@ namespace ErgometerLibrary return ParseChatMessage(session, args); case 4: return ParseLogoutRequest(session, args); + case 5: + return ParseSession(session); default: throw new FormatException("Error in NetCommand: " + comType + " is not a valid command type."); } } + private NetCommand ParseSession(int session) + { + NetCommand temp = new NetCommand(CommandType.SESSION, session); + return temp; + } + private NetCommand ParseLogoutRequest(int session, string[] args) { if (args.Length != 1) @@ -153,6 +167,9 @@ namespace ErgometerLibrary case CommandType.LOGOUT: command += "4»ses" + Session + "»logout"; break; + case CommandType.SESSION: + command += "5»ses" + Session; + break; default: throw new FormatException("Error in NetCommand: Cannot find type of command"); diff --git a/ErgometerLibrary/Properties/AssemblyInfo.cs b/ErgometerLibrary/Properties/AssemblyInfo.cs index ae62c7a..63ec27d 100644 --- a/ErgometerLibrary/Properties/AssemblyInfo.cs +++ b/ErgometerLibrary/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.2")] -[assembly: AssemblyFileVersion("1.0.0.2")] +[assembly: AssemblyVersion("1.0.1.0")] +[assembly: AssemblyFileVersion("1.0.1.0")] From 47ccada5756b4279e3df780551235dad174f0b6b Mon Sep 17 00:00:00 2001 From: Kenneth van Ewijk Date: Fri, 25 Sep 2015 12:26:45 +0200 Subject: [PATCH 06/12] Added new methods. Changed to static. --- ErgometerLibrary/FileHandler.cs | 51 ++++++++++++++++++++++++++++++++- ErgometerLibrary/NetCommand.cs | 12 ++++---- 2 files changed, 56 insertions(+), 7 deletions(-) diff --git a/ErgometerLibrary/FileHandler.cs b/ErgometerLibrary/FileHandler.cs index c84c8ab..53b4e51 100644 --- a/ErgometerLibrary/FileHandler.cs +++ b/ErgometerLibrary/FileHandler.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -8,9 +9,57 @@ namespace ErgometerLibrary { public class FileHandler { + public static string DataFolder { get; } = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments), "Ergometer"); + + public static void CheckDataFolder() + { + if(! Directory.Exists(DataFolder)) + { + Directory.CreateDirectory(DataFolder); + } + } + public static int GenerateSession() { - return 0; + string[] existingSessions = Directory.GetDirectories(DataFolder); + + Random rand = new Random(); + int sessionID = rand.Next(int.MinValue, int.MaxValue); + + + while (existingSessions.Contains(sessionID.ToString())) + { + sessionID = rand.Next(int.MinValue, int.MaxValue); + } + + return sessionID; + } + + public static void CreateSession(string naam, int session) + { + Directory.CreateDirectory(GetSessionFolder(session)); + File.Create(Path.Combine(GetSessionFolder(session), "session.prop")); + File.Create(Path.Combine(GetSessionFolder(session), "metingen.ergo")); + File.Create(Path.Combine(GetSessionFolder(session), "chat.log")); + + File.WriteAllText() + } + + private static string GetSessionFolder(int session) + { + return Path.Combine(DataFolder, session.ToString()); + } + private static string GetSessionFile(int session) + { + return Path.Combine(DataFolder, session.ToString(), "session.prop"); + } + private static string GetSessionMetingen(int session) + { + return Path.Combine(DataFolder, session.ToString(), "metingen.ergo"); + } + private static string GetSessionChat(int session) + { + return Path.Combine(DataFolder, session.ToString(), "chat.log"); } } } diff --git a/ErgometerLibrary/NetCommand.cs b/ErgometerLibrary/NetCommand.cs index 7df5d57..1334c8f 100644 --- a/ErgometerLibrary/NetCommand.cs +++ b/ErgometerLibrary/NetCommand.cs @@ -62,7 +62,7 @@ namespace ErgometerLibrary IsDoctor = doctor; } - public NetCommand Parse(string command) + public static NetCommand Parse(string command) { string[] com = command.Split('»'); @@ -92,13 +92,13 @@ namespace ErgometerLibrary } } - private NetCommand ParseSession(int session) + private static NetCommand ParseSession(int session) { NetCommand temp = new NetCommand(CommandType.SESSION, session); return temp; } - private NetCommand ParseLogoutRequest(int session, string[] args) + private static NetCommand ParseLogoutRequest(int session, string[] args) { if (args.Length != 1) throw new MissingFieldException("Error in NetCommand: Logout Request is missing arguments"); @@ -110,7 +110,7 @@ namespace ErgometerLibrary return temp; } - private NetCommand ParseChatMessage(int session, string[] args) + private static NetCommand ParseChatMessage(int session, string[] args) { if (args.Length != 1) throw new MissingFieldException("Error in NetCommand: Chat Message is missing arguments"); @@ -121,7 +121,7 @@ namespace ErgometerLibrary return temp; } - private NetCommand ParseData(int session, string[] args) + private static NetCommand ParseData(int session, string[] args) { if (args.Length != 9) throw new MissingFieldException("Error in NetCommand: Data is missing arguments"); @@ -132,7 +132,7 @@ namespace ErgometerLibrary return temp; } - private NetCommand ParseLoginRequest(int session, string[] args) + private static NetCommand ParseLoginRequest(int session, string[] args) { bool doctor = bool.Parse(args[1]); if (doctor && args.Length != 5) From 34d8b9c40fbf57e1bd10140dec7933144d40e8cb Mon Sep 17 00:00:00 2001 From: Kenneth van Ewijk Date: Fri, 25 Sep 2015 12:27:30 +0200 Subject: [PATCH 07/12] Fixed argument --- ErgometerLibrary/FileHandler.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ErgometerLibrary/FileHandler.cs b/ErgometerLibrary/FileHandler.cs index 53b4e51..70192cf 100644 --- a/ErgometerLibrary/FileHandler.cs +++ b/ErgometerLibrary/FileHandler.cs @@ -42,7 +42,7 @@ namespace ErgometerLibrary File.Create(Path.Combine(GetSessionFolder(session), "metingen.ergo")); File.Create(Path.Combine(GetSessionFolder(session), "chat.log")); - File.WriteAllText() + File.WriteAllText(GetSessionFile(session), naam); } private static string GetSessionFolder(int session) From 698748eefb463299b88effc46818813fd5acd024 Mon Sep 17 00:00:00 2001 From: Kenneth van Ewijk Date: Fri, 25 Sep 2015 12:47:00 +0200 Subject: [PATCH 08/12] Added data saving methods --- ErgometerLibrary/FileHandler.cs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/ErgometerLibrary/FileHandler.cs b/ErgometerLibrary/FileHandler.cs index 70192cf..2aab1ab 100644 --- a/ErgometerLibrary/FileHandler.cs +++ b/ErgometerLibrary/FileHandler.cs @@ -35,7 +35,7 @@ namespace ErgometerLibrary return sessionID; } - public static void CreateSession(string naam, int session) + public static void CreateSession(int session, string naam) { Directory.CreateDirectory(GetSessionFolder(session)); File.Create(Path.Combine(GetSessionFolder(session), "session.prop")); @@ -45,6 +45,16 @@ namespace ErgometerLibrary File.WriteAllText(GetSessionFile(session), naam); } + public static void AddMeting(int session, params Meting[] metingen) + { + + } + + public static void AddChat(int session, string name, string chatmessage) + { + + } + private static string GetSessionFolder(int session) { return Path.Combine(DataFolder, session.ToString()); From 659b481c4325d79cd48bd3453a3a66adb8aac3d6 Mon Sep 17 00:00:00 2001 From: Aareschluchtje Date: Mon, 28 Sep 2015 12:54:21 +0200 Subject: [PATCH 09/12] Fixed some errors in library. --- ErgometerLibrary/NetCommand.cs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/ErgometerLibrary/NetCommand.cs b/ErgometerLibrary/NetCommand.cs index 1334c8f..ace8cce 100644 --- a/ErgometerLibrary/NetCommand.cs +++ b/ErgometerLibrary/NetCommand.cs @@ -73,7 +73,8 @@ namespace ErgometerLibrary else throw new FormatException("Error in NetCommend: " + com[1] + " is not a valid session."); - string[] args = (string[]) com.Skip(2); + string[] args = com; + Array.Clear(args, 0, 2); switch (comType) { @@ -134,7 +135,7 @@ namespace ErgometerLibrary private static NetCommand ParseLoginRequest(int session, string[] args) { - bool doctor = bool.Parse(args[1]); + bool doctor = bool.Parse(args[3]); if (doctor && args.Length != 5) throw new MissingFieldException("Error in NetCommand: Doctor login is missing arguments"); else if(args.Length != 4) @@ -142,9 +143,9 @@ namespace ErgometerLibrary NetCommand temp = new NetCommand(CommandType.LOGIN, session); temp.IsDoctor = doctor; - temp.DisplayName = args[0]; + temp.DisplayName = args[2]; if (doctor) - temp.Password = args[2]; + temp.Password = args[4]; return temp; } From 62901bc6ecf0a3f655f883f7d06b649aa55b2203 Mon Sep 17 00:00:00 2001 From: Aareschluchtje Date: Mon, 28 Sep 2015 18:46:59 +0200 Subject: [PATCH 10/12] Fixed even more bugs --- ErgometerLibrary/Meting.cs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/ErgometerLibrary/Meting.cs b/ErgometerLibrary/Meting.cs index f0741b0..46807b7 100644 --- a/ErgometerLibrary/Meting.cs +++ b/ErgometerLibrary/Meting.cs @@ -67,11 +67,12 @@ namespace ErgometerLibrary public static Meting Parse(string input, char delimiter) { - String[] status = input.Split(delimiter); - - if (status.Length != 8 || status.Length != 9) + string[] status = input.Split(delimiter); + Console.WriteLine(status.Length); + if (status.Length != 8 && status.Length != 9) + { return null; - + } int heartbeat = int.Parse(status[0]); int rpm = int.Parse(status[1]); double speed = double.Parse(status[2]) / 10; From 3c9450462e4c061b93fc035224d8024c3cf54981 Mon Sep 17 00:00:00 2001 From: Aareschluchtje Date: Fri, 2 Oct 2015 10:57:35 +0200 Subject: [PATCH 11/12] Fixed skip/clear bug --- ErgometerLibrary/NetCommand.cs | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/ErgometerLibrary/NetCommand.cs b/ErgometerLibrary/NetCommand.cs index ace8cce..10683e1 100644 --- a/ErgometerLibrary/NetCommand.cs +++ b/ErgometerLibrary/NetCommand.cs @@ -73,8 +73,11 @@ namespace ErgometerLibrary else throw new FormatException("Error in NetCommend: " + com[1] + " is not a valid session."); - string[] args = com; - Array.Clear(args, 0, 2); + string[] args = new string[9]; + for (int i = 2; i < com.Length; i++) + { + args[i - 2] = com[i]; + } switch (comType) { @@ -135,17 +138,17 @@ namespace ErgometerLibrary private static NetCommand ParseLoginRequest(int session, string[] args) { - bool doctor = bool.Parse(args[3]); - if (doctor && args.Length != 5) + bool doctor = bool.Parse(args[1]); + if (doctor && args.Length != 3) throw new MissingFieldException("Error in NetCommand: Doctor login is missing arguments"); - else if(args.Length != 4) + else if (args.Length != 2) throw new MissingFieldException("Error in NetCommand: Client login is missing arguments"); NetCommand temp = new NetCommand(CommandType.LOGIN, session); temp.IsDoctor = doctor; - temp.DisplayName = args[2]; + temp.DisplayName = args[0]; if (doctor) - temp.Password = args[4]; + temp.Password = args[2]; return temp; } @@ -154,7 +157,7 @@ namespace ErgometerLibrary { string command = ""; - switch(Type) + switch (Type) { case CommandType.LOGIN: command += "1»ses" + Session + "»" + DisplayName + "»" + IsDoctor + (IsDoctor ? "»" + Password : ""); From d34fa53e9ef459dee8cd0ec8f9dde69bd8009339 Mon Sep 17 00:00:00 2001 From: Kenneth van Ewijk Date: Fri, 2 Oct 2015 10:57:55 +0200 Subject: [PATCH 12/12] Added new classes and fixed bugs --- ErgometerLibrary/ChatMessage.cs | 21 ++++++++++++ ErgometerLibrary/ErgometerLibrary.csproj | 10 ++++++ ErgometerLibrary/FileHandler.cs | 19 +++++++---- ErgometerLibrary/Helper.cs | 13 ++++++++ ErgometerLibrary/Meting.cs | 2 +- ErgometerLibrary/NetCommand.cs | 10 +++--- ErgometerLibrary/NetHelper.cs | 36 +++++++++++++++++++++ ErgometerLibrary/Properties/AssemblyInfo.cs | 4 +-- ErgometerLibrary/packages.config | 4 +++ 9 files changed, 105 insertions(+), 14 deletions(-) create mode 100644 ErgometerLibrary/ChatMessage.cs create mode 100644 ErgometerLibrary/Helper.cs create mode 100644 ErgometerLibrary/NetHelper.cs create mode 100644 ErgometerLibrary/packages.config diff --git a/ErgometerLibrary/ChatMessage.cs b/ErgometerLibrary/ChatMessage.cs new file mode 100644 index 0000000..1b19465 --- /dev/null +++ b/ErgometerLibrary/ChatMessage.cs @@ -0,0 +1,21 @@ +namespace ErgometerLibrary +{ + public class ChatMessage + { + public string Message { get; } + public string Name { get; } + public double TimeStamp { get; set;} + + public ChatMessage(string name, string message) + { + Name = name; + Message = message; + TimeStamp = Helper.Now; + } + + public override string ToString() + { + return $"[{Name}] <{TimeStamp}> - {Message}"; + } + } +} \ No newline at end of file diff --git a/ErgometerLibrary/ErgometerLibrary.csproj b/ErgometerLibrary/ErgometerLibrary.csproj index 74739fe..f53e6dc 100644 --- a/ErgometerLibrary/ErgometerLibrary.csproj +++ b/ErgometerLibrary/ErgometerLibrary.csproj @@ -30,6 +30,10 @@ 4 + + ..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll + True + @@ -40,12 +44,18 @@ + + + + + +