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)
|
|
|
|
|
{
|
2016-12-02 14:41:52 +00:00
|
|
|
|
Console.WriteLine("Connected to MPD.");
|
2016-12-02 14:19:18 +00:00
|
|
|
|
StartReadCommands(mpc);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2016-12-02 14:41:52 +00:00
|
|
|
|
Console.WriteLine("Could not connect to MPD.");
|
2016-12-02 14:19:18 +00:00
|
|
|
|
}
|
2016-12-02 14:41:52 +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-02 14:41:52 +00:00
|
|
|
|
{
|
2016-12-05 08:46:44 +00:00
|
|
|
|
Func<object, IMpcCommand> command;
|
|
|
|
|
var response = new object();
|
2016-12-02 14:41:52 +00:00
|
|
|
|
|
2016-12-05 08:46:44 +00:00
|
|
|
|
if (_commands.TryGetValue(userInput, out command))
|
2016-12-02 14:41:52 +00:00
|
|
|
|
{
|
2016-12-05 08:46:44 +00:00
|
|
|
|
response = mpc.SendAsync(command(null)).GetAwaiter().GetResult();
|
2016-12-02 14:41:52 +00:00
|
|
|
|
}
|
2016-12-05 08:46:44 +00:00
|
|
|
|
|
|
|
|
|
Console.WriteLine("Response: ");
|
|
|
|
|
Console.WriteLine(response);
|
2016-12-02 14:41:52 +00:00
|
|
|
|
}
|
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
|
|
|
|
}
|
|
|
|
|
}
|