1
0
mirror of https://github.com/ZetaKebab/MpcNET.git synced 2024-09-16 05:30:09 +00:00
MpcNET/LibMpcApp/Program.cs

66 lines
1.9 KiB
C#
Raw Normal View History

2016-12-02 14:19:18 +00:00
using System;
using System.Net;
using LibMpc;
2016-12-05 08:46:44 +00:00
using System.Collections.Generic;
2016-12-02 14:19:18 +00:00
namespace LibMpcApp
{
2016-12-05 08:46:44 +00:00
/// <summary>
/// Simple console app to test commands and parsed responses.
/// </summary>
2016-12-02 14:19:18 +00:00
public class Program
{
2016-12-05 08:46:44 +00:00
private static readonly Dictionary<int, Func<object, IMpcCommand>> _commands = new Dictionary<int, Func<object, IMpcCommand>>
{
{ 1, input => new Commands.Reflection.TagTypes() }
};
2016-12-02 14:19:18 +00:00
public static void Main(string[] args)
{
var mpc = new Mpc(new IPEndPoint(IPAddress.Loopback, 6600));
var connected = mpc.ConnectAsync().GetAwaiter().GetResult();
if (connected)
{
Console.WriteLine("Connected to MPD.");
2016-12-02 14:19:18 +00:00
StartReadCommands(mpc);
}
else
{
Console.WriteLine("Could not connect to MPD.");
2016-12-02 14:19:18 +00:00
}
mpc.DisconnectAsync().GetAwaiter().GetResult();
2016-12-02 14:19:18 +00:00
}
private static void StartReadCommands(Mpc mpc)
{
2016-12-05 08:46:44 +00:00
int userInput = 0;
while ((userInput = DisplayMenu()) != 99)
{
2016-12-05 08:46:44 +00:00
Func<object, IMpcCommand> command;
var response = new object();
2016-12-05 08:46:44 +00:00
if (_commands.TryGetValue(userInput, out command))
{
2016-12-05 08:46:44 +00:00
response = mpc.SendAsync(command(null)).GetAwaiter().GetResult();
}
2016-12-05 08:46:44 +00:00
Console.WriteLine("Response: ");
Console.WriteLine(response);
}
2016-12-02 14:19:18 +00:00
}
2016-12-05 08:46:44 +00:00
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);
}
2016-12-02 14:19:18 +00:00
}
}