1
0
mirror of https://github.com/ZetaKebab/MpcNET.git synced 2025-01-14 22:18:43 +00:00

First command for test app implemented

This commit is contained in:
Gabriel 2016-12-05 09:46:44 +01:00
parent 71367cea59
commit 7561d2a04f

View File

@ -1,12 +1,20 @@
using System; using System;
using System.Net; using System.Net;
using System.Threading.Tasks;
using LibMpc; using LibMpc;
using System.Collections.Generic;
namespace LibMpcApp namespace LibMpcApp
{ {
/// <summary>
/// Simple console app to test commands and parsed responses.
/// </summary>
public class Program public class Program
{ {
private static readonly Dictionary<int, Func<object, IMpcCommand>> _commands = new Dictionary<int, Func<object, IMpcCommand>>
{
{ 1, input => new Commands.Reflection.TagTypes() }
};
public static void Main(string[] args) public static void Main(string[] args)
{ {
var mpc = new Mpc(new IPEndPoint(IPAddress.Loopback, 6600)); var mpc = new Mpc(new IPEndPoint(IPAddress.Loopback, 6600));
@ -27,16 +35,31 @@ namespace LibMpcApp
private static void StartReadCommands(Mpc mpc) private static void StartReadCommands(Mpc mpc)
{ {
while(true) int userInput = 0;
while ((userInput = DisplayMenu()) != 99)
{ {
Console.Write("Command: "); Func<object, IMpcCommand> command;
var command = Console.ReadLine(); 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);
}
} }
} }