mirror of
https://github.com/ZetaKebab/MpcNET.git
synced 2025-01-14 22:18:43 +00:00
Formatting output responsability of command.
Commands: disableoutput, enableoutput, outputs, tagtypes, update implemented.
This commit is contained in:
parent
4a176e8f45
commit
4ffa4bca6c
@ -24,9 +24,9 @@ namespace LibMpc
|
||||
|
||||
public string Value => string.Join(" ", "find", _tag.Value, _searchText);
|
||||
|
||||
public IReadOnlyDictionary<string, IList<string>> FormatResponse(IReadOnlyDictionary<string, IList<string>> response)
|
||||
public IDictionary<string, string> FormatResponse(IList<KeyValuePair<string, string>> response)
|
||||
{
|
||||
return response;
|
||||
return response.ToDefaultDictionary();
|
||||
}
|
||||
}
|
||||
|
||||
@ -41,9 +41,9 @@ namespace LibMpc
|
||||
|
||||
public string Value => string.Join(" ", "list", _tag);
|
||||
|
||||
public IReadOnlyDictionary<string, IList<string>> FormatResponse(IReadOnlyDictionary<string, IList<string>> response)
|
||||
public IDictionary<string, string> FormatResponse(IList<KeyValuePair<string, string>> response)
|
||||
{
|
||||
return response;
|
||||
return response.ToDefaultDictionary();
|
||||
}
|
||||
}
|
||||
|
||||
@ -60,9 +60,9 @@ namespace LibMpc
|
||||
|
||||
public string Value => string.Join(" ", "listall", _path);
|
||||
|
||||
public IReadOnlyDictionary<string, IList<string>> FormatResponse(IReadOnlyDictionary<string, IList<string>> response)
|
||||
public IDictionary<string, string> FormatResponse(IList<KeyValuePair<string, string>> response)
|
||||
{
|
||||
return response;
|
||||
return response.ToDefaultDictionary();
|
||||
}
|
||||
}
|
||||
|
||||
@ -79,9 +79,9 @@ namespace LibMpc
|
||||
// TODO: Extend command: < update [URI] >
|
||||
public string Value => "update";
|
||||
|
||||
public IReadOnlyDictionary<string, IList<string>> FormatResponse(IReadOnlyDictionary<string, IList<string>> response)
|
||||
public IDictionary<string, string> FormatResponse(IList<KeyValuePair<string, string>> response)
|
||||
{
|
||||
return response;
|
||||
return response.ToDefaultDictionary();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -23,9 +23,9 @@ namespace LibMpc
|
||||
|
||||
public string Value => string.Join(" ", "disableoutput", _outputId);
|
||||
|
||||
public IReadOnlyDictionary<string, IList<string>> FormatResponse(IReadOnlyDictionary<string, IList<string>> response)
|
||||
public IDictionary<string, string> FormatResponse(IList<KeyValuePair<string, string>> response)
|
||||
{
|
||||
return response;
|
||||
return response.ToDefaultDictionary();
|
||||
}
|
||||
}
|
||||
|
||||
@ -43,9 +43,9 @@ namespace LibMpc
|
||||
|
||||
public string Value => string.Join(" ", "enableoutput", _outputId);
|
||||
|
||||
public IReadOnlyDictionary<string, IList<string>> FormatResponse(IReadOnlyDictionary<string, IList<string>> response)
|
||||
public IDictionary<string, string> FormatResponse(IList<KeyValuePair<string, string>> response)
|
||||
{
|
||||
return response;
|
||||
return response.ToDefaultDictionary();
|
||||
}
|
||||
}
|
||||
|
||||
@ -54,23 +54,28 @@ namespace LibMpc
|
||||
/// <summary>
|
||||
/// Shows information about all outputs.
|
||||
/// </summary>
|
||||
public class Outputs : IMpcCommand<Dictionary<string, string>>
|
||||
public class Outputs : IMpcCommand<IList<IDictionary<string, string>>>
|
||||
{
|
||||
public string Value => "outputs";
|
||||
public IReadOnlyDictionary<string, IList<Dictionary<string, string>>> FormatResponse(IReadOnlyDictionary<string, IList<string>> response)
|
||||
|
||||
public IDictionary<string, IList<IDictionary<string, string>>> FormatResponse(IList<KeyValuePair<string, string>> response)
|
||||
{
|
||||
var result = new Dictionary<string, IList<Dictionary<string, string>>>
|
||||
var result = new Dictionary<string, IList<IDictionary<string, string>>>
|
||||
{
|
||||
{"outputs", new List<Dictionary<string, string>>()}
|
||||
{ "outputs", new List<IDictionary<string, string>>() }
|
||||
};
|
||||
|
||||
for (var i = 0; i < response["outputid"].Count; i++)
|
||||
for (var i = 0; i < response.Count; i += 3)
|
||||
{
|
||||
var outputId = response[i].Value;
|
||||
var outputName = response[i + 1].Value;
|
||||
var outputEnabled = response[i + 2].Value;
|
||||
|
||||
result["outputs"].Add(new Dictionary<string, string>
|
||||
{
|
||||
{ "id", response["outputid"][i] },
|
||||
{ "name", response["outputname"][i] },
|
||||
{ "enabled", response["outputenabled"][i] }
|
||||
{"id", outputId},
|
||||
{"name", outputName},
|
||||
{"enabled", outputEnabled}
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace LibMpc
|
||||
{
|
||||
@ -13,13 +14,18 @@ namespace LibMpc
|
||||
// TODO: commands
|
||||
// TODO: notcommands
|
||||
|
||||
public class TagTypes : IMpcCommand<string>
|
||||
public class TagTypes : IMpcCommand<IList<string>>
|
||||
{
|
||||
public string Value => "tagtypes";
|
||||
|
||||
public IReadOnlyDictionary<string, IList<string>> FormatResponse(IReadOnlyDictionary<string, IList<string>> response)
|
||||
IDictionary<string, IList<string>> IMpcCommand<IList<string>>.FormatResponse(IList<KeyValuePair<string, string>> response)
|
||||
{
|
||||
return response;
|
||||
var result = new Dictionary<string, IList<string>>
|
||||
{
|
||||
{ "tagtypes", response.Where(item => item.Key.Equals("tagtype")).Select(item => item.Value).ToList() }
|
||||
};
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace LibMpc
|
||||
{
|
||||
@ -6,6 +7,14 @@ namespace LibMpc
|
||||
{
|
||||
string Value { get; }
|
||||
|
||||
IReadOnlyDictionary<string, IList<T>> FormatResponse(IReadOnlyDictionary<string, IList<string>> response);
|
||||
IDictionary<string, T> FormatResponse(IList<KeyValuePair<string, string>> response);
|
||||
}
|
||||
|
||||
internal static class MpdCommandExtensions
|
||||
{
|
||||
public static IDictionary<string, string> ToDefaultDictionary(this IList<KeyValuePair<string, string>> items)
|
||||
{
|
||||
return items.ToDictionary(item => item.Key, item => item.Value);
|
||||
}
|
||||
}
|
||||
}
|
@ -30,9 +30,9 @@ namespace LibMpc
|
||||
public IMpdRequest<T> Request { get; }
|
||||
public IMpdResponse<T> Response { get; }
|
||||
|
||||
private IReadOnlyDictionary<string, IList<string>> GetValuesFromResponse()
|
||||
private IList<KeyValuePair<string, string>> GetValuesFromResponse()
|
||||
{
|
||||
var result = new Dictionary<string, IList<string>>();
|
||||
var result = new List<KeyValuePair<string, string>>();
|
||||
|
||||
foreach (var line in _rawResponse)
|
||||
{
|
||||
@ -45,14 +45,7 @@ namespace LibMpc
|
||||
var mpdValue = match.Result("${value}");
|
||||
if (!string.IsNullOrEmpty(mpdValue))
|
||||
{
|
||||
if (!result.ContainsKey(mpdKey))
|
||||
{
|
||||
result.Add(mpdKey, new List<string>() { mpdValue });
|
||||
}
|
||||
else
|
||||
{
|
||||
result[mpdKey].Add(mpdValue);
|
||||
}
|
||||
result.Add(new KeyValuePair<string, string>(mpdKey, mpdValue));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,19 +6,19 @@ namespace LibMpc
|
||||
public interface IMpdResponse<T>
|
||||
{
|
||||
IMpdResponseState State { get; }
|
||||
IReadOnlyDictionary<string, IList<T>> Body { get; }
|
||||
IDictionary<string, T> Body { get; }
|
||||
}
|
||||
|
||||
public class MpdResponse<T> : IMpdResponse<T>
|
||||
{
|
||||
public MpdResponse(string endLine, IReadOnlyDictionary<string, IList<T>> body, bool connected)
|
||||
public MpdResponse(string endLine, IDictionary<string, T> body, bool connected)
|
||||
{
|
||||
State = new MpdResponseState(endLine, connected);
|
||||
Body = body;
|
||||
}
|
||||
|
||||
public IMpdResponseState State { get; }
|
||||
public IReadOnlyDictionary<string, IList<T>> Body { get; }
|
||||
public IDictionary<string, T> Body { get; }
|
||||
}
|
||||
|
||||
public static class CheckNotNullExtension
|
||||
|
Loading…
Reference in New Issue
Block a user