From 5c5048f3628be0b6210e19838bfd3f6bb7aa3d7f Mon Sep 17 00:00:00 2001 From: Kenneth van Ewijk Date: Fri, 9 Oct 2015 12:10:53 +0200 Subject: [PATCH] Added Request --- ErgometerLibrary/NetCommand.cs | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/ErgometerLibrary/NetCommand.cs b/ErgometerLibrary/NetCommand.cs index bd96b5f..0b30861 100644 --- a/ErgometerLibrary/NetCommand.cs +++ b/ErgometerLibrary/NetCommand.cs @@ -8,8 +8,8 @@ namespace ErgometerLibrary { public class NetCommand { - public enum CommandType { LOGIN, DATA, CHAT, LOGOUT, SESSION, VALUESET, USER, RESPONSE, REQUEST }; - public enum RequestType { USERS} + public enum CommandType { LOGIN, DATA, CHAT, LOGOUT, SESSION, VALUESET, USER, RESPONSE, REQUEST } + public enum RequestType { USERS } public enum ResponseType { LOGINOK, LOGINWRONG, ERROR, NOTLOGGEDIN } public enum ValueType { TIME, POWER, ENERGY, DISTANCE } @@ -44,6 +44,15 @@ namespace ErgometerLibrary Response = response; } + //REQUEST + public NetCommand(RequestType request, int session) + { + Type = CommandType.REQUEST; + Session = session; + Timestamp = Helper.Now; + Request = request; + } + //STANDARD public NetCommand(CommandType commandtype, int session) { @@ -138,11 +147,27 @@ namespace ErgometerLibrary return ParseValue(session, args); case 8: return ParseUsers(session, args); + case 9: + return ParseRequest(session, args); default: throw new FormatException("Error in NetCommand: " + comType + " is not a valid command type."); } } + private static NetCommand ParseRequest(int session, string[] args) + { + if (args.Length != 1) + throw new MissingFieldException("Error in NetCommand: Request is missing arguments"); + + switch (args[0]) + { + case "users": + return new NetCommand(ResponseType.LOGINOK, session); + default: + throw new FormatException("Error in NetCommand: Request type not recognised"); + } + } + private static NetCommand ParseUsers(int session, string[] args) { if (args.Length < 2) @@ -287,6 +312,9 @@ namespace ErgometerLibrary command += "»" + keys.Key + "|" + keys.Value; } break; + case CommandType.REQUEST: + command += "9»ses" + Session + "»" + Request.ToString().ToLower(); + break; default: throw new FormatException("Error in NetCommand: Cannot find type of command");