1
0
mirror of https://github.com/ZetaKebab/MpcNET.git synced 2025-07-02 00:57:38 +00:00

Line pattern extended. New commands in test app.

This commit is contained in:
glucaci
2016-12-06 18:18:06 +01:00
parent 53325604e8
commit 4a176e8f45
4 changed files with 10 additions and 91 deletions

View File

@ -62,94 +62,7 @@ namespace LibMpc
/*
#region Admin Commands
/// <summary>
/// Disables an MPD output.
/// </summary>
/// <param name="id">The id of the output.</param>
/// <returns>If the action was successful.</returns>
public async Task<bool> DisableOutputAsync(int id)
{
var mpdResponse = await _connection.Exec("disableoutput", new string[] { id.ToString() });
return !mpdResponse.IsError;
}
/// <summary>
/// Enables an MPD output.
/// </summary>
/// <param name="id">The id of the output.</param>
/// <returns>If the action was successful.</returns>
public async Task<bool> EnableOutputAsync(int id)
{
var mpdResponse = await _connection.Exec("enableoutput", new string[] { id.ToString() });
return !mpdResponse.IsError;
}
/// <summary>
/// Lists all outputs of the MPD.
/// </summary>
/// <returns>The list of all MPD outputs.</returns>
public async Task<MpdOutput[]> OutputsAsync()
{
MpdResponse response = await _connection.SendAsync("outputs");
if (response.Message.Count % 3 != 0)
throw new InvalidMpdResponseException();
MpdOutput[] ret = new MpdcountsOutput[response.Message.Count / 3];
for (int i = 0; i < ret.Length; i++)
{
int id;
string name;
int enabled;
KeyValuePair<string, string> idLine = response[i * 3];
if (idLine.Key == null)
throw new InvalidMpdResponseException("Invalid form of line " + (i * 3));
if (!idLine.Key.Equals("outputid"))
throw new InvalidMpdResponseException("Key of line " + (i * 3) + " is not 'outputid'");
if (!int.TryParse(idLine.Value, out id))
throw new InvalidMpdResponseException("Value of line " + (i * 3) + " is not a number");
KeyValuePair<string, string> nameLine = response[i * 3 + 1];
if (nameLine.Key == null)
throw new InvalidMpdResponseException("Invalid form of line " + (i * 3 + 1));
if (!nameLine.Key.Equals("outputname"))
throw new InvalidMpdResponseException("Key of line " + (i * 3 + 1) + " is not 'outputname'");
name = nameLine.Value;
KeyValuePair<string, string> enabledLine = response[i * 3 + 2];
if (enabledLine.Key == null)
throw new InvalidMpdResponseException("Invalid form of line " + (i * 3 + 2));
if (!enabledLine.Key.Equals("outputenabled"))
throw new InvalidMpdResponseException("Key of line " + (i * 3 + 2) + " is not 'outputenabled'");
if (!int.TryParse(enabledLine.Value, out enabled))
throw new InvalidMpdResponseException("Value of line " + (i * 3 + 2) + " is not a number");
ret[i] = new MpdOutput(id, name, enabled > 0);
}
return ret;
}
/// <summary>
/// Returns the list of tag types the MPD supports.
/// </summary>
/// <returns>The list of tag types the MPD supports.</returns>
public async Task<string[]> TagTypesAsync()
{
MpdResponse response = await _connection.SendAsync("tagtypes");
string[] ret = new string[response.Message.Count];
for (int i = 0; i < ret.Length; i++)
{
KeyValuePair<string, string> line = response[i];
if (!line.Key.Equals("tagtype"))
throw new InvalidMpdResponseException("Key of line " + (i) + " is not 'tagtype'");
ret[i] = line.Value;
}
return ret;
}
/// <summary>
/// Starts an update of the MPD database.
/// </summary>