From 7561d2a04f2c36c0feae077f5b010ddb1f4a280b Mon Sep 17 00:00:00 2001 From: Gabriel Date: Mon, 5 Dec 2016 09:46:44 +0100 Subject: [PATCH] First command for test app implemented --- LibMpcApp/Program.cs | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/LibMpcApp/Program.cs b/LibMpcApp/Program.cs index 4cdf2b2..7a54497 100644 --- a/LibMpcApp/Program.cs +++ b/LibMpcApp/Program.cs @@ -1,12 +1,20 @@ using System; using System.Net; -using System.Threading.Tasks; using LibMpc; +using System.Collections.Generic; namespace LibMpcApp { + /// + /// Simple console app to test commands and parsed responses. + /// public class Program { + private static readonly Dictionary> _commands = new Dictionary> + { + { 1, input => new Commands.Reflection.TagTypes() } + }; + public static void Main(string[] args) { var mpc = new Mpc(new IPEndPoint(IPAddress.Loopback, 6600)); @@ -27,16 +35,31 @@ namespace LibMpcApp private static void StartReadCommands(Mpc mpc) { - while(true) + int userInput = 0; + while ((userInput = DisplayMenu()) != 99) { - Console.Write("Command: "); - var command = Console.ReadLine(); + Func command; + var response = new object(); - if (string.IsNullOrEmpty(command)) + if (_commands.TryGetValue(userInput, out command)) { - break; + response = mpc.SendAsync(command(null)).GetAwaiter().GetResult(); } + + Console.WriteLine("Response: "); + Console.WriteLine(response); } } + + static public int DisplayMenu() + { + Console.WriteLine(); + Console.WriteLine("Commands: "); + Console.WriteLine("1. tagtypes"); + Console.WriteLine("99. Exit"); + Console.WriteLine(); + var result = Console.ReadLine(); + return Convert.ToInt32(result); + } } }