From 4a176e8f45656f3148cb74080d6b3ecb355c7260 Mon Sep 17 00:00:00 2001 From: glucaci Date: Tue, 6 Dec 2016 18:18:06 +0100 Subject: [PATCH] Line pattern extended. New commands in test app. --- LibMpc/Commands/Commands.Database.cs | 1 + LibMpc/Message/MpdMessage.cs | 2 +- LibMpc/Mpc.cs | 87 ---------------------------- LibMpcApp/Program.cs | 11 +++- 4 files changed, 10 insertions(+), 91 deletions(-) diff --git a/LibMpc/Commands/Commands.Database.cs b/LibMpc/Commands/Commands.Database.cs index a35195c..9862681 100644 --- a/LibMpc/Commands/Commands.Database.cs +++ b/LibMpc/Commands/Commands.Database.cs @@ -76,6 +76,7 @@ namespace LibMpc public class Update : IMpcCommand { + // TODO: Extend command: < update [URI] > public string Value => "update"; public IReadOnlyDictionary> FormatResponse(IReadOnlyDictionary> response) diff --git a/LibMpc/Message/MpdMessage.cs b/LibMpc/Message/MpdMessage.cs index e7061f4..767c16a 100644 --- a/LibMpc/Message/MpdMessage.cs +++ b/LibMpc/Message/MpdMessage.cs @@ -13,7 +13,7 @@ namespace LibMpc public class MpdMessage : IMpdMessage { - private readonly Regex _linePattern = new Regex("^(?[A-Za-z]*):[ ]{0,1}(?.*)$"); + private readonly Regex _linePattern = new Regex("^(?[A-Za-z_]*):[ ]{0,1}(?.*)$"); private readonly IList _rawResponse; public MpdMessage(IMpcCommand command, bool connected, IReadOnlyCollection response) diff --git a/LibMpc/Mpc.cs b/LibMpc/Mpc.cs index 8772d4d..cbcbc50 100644 --- a/LibMpc/Mpc.cs +++ b/LibMpc/Mpc.cs @@ -62,94 +62,7 @@ namespace LibMpc /* #region Admin Commands - /// - /// Disables an MPD output. - /// - /// The id of the output. - /// If the action was successful. - public async Task DisableOutputAsync(int id) - { - var mpdResponse = await _connection.Exec("disableoutput", new string[] { id.ToString() }); - return !mpdResponse.IsError; - } - - /// - /// Enables an MPD output. - /// - /// The id of the output. - /// If the action was successful. - public async Task EnableOutputAsync(int id) - { - var mpdResponse = await _connection.Exec("enableoutput", new string[] { id.ToString() }); - return !mpdResponse.IsError; - } - /// - /// Lists all outputs of the MPD. - /// - /// The list of all MPD outputs. - public async Task 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 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 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 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; - } - /// - /// Returns the list of tag types the MPD supports. - /// - /// The list of tag types the MPD supports. - public async Task TagTypesAsync() - { - MpdResponse response = await _connection.SendAsync("tagtypes"); - - string[] ret = new string[response.Message.Count]; - - for (int i = 0; i < ret.Length; i++) - { - KeyValuePair line = response[i]; - if (!line.Key.Equals("tagtype")) - throw new InvalidMpdResponseException("Key of line " + (i) + " is not 'tagtype'"); - ret[i] = line.Value; - } - - return ret; - } /// /// Starts an update of the MPD database. /// diff --git a/LibMpcApp/Program.cs b/LibMpcApp/Program.cs index cb43c88..688f0fa 100644 --- a/LibMpcApp/Program.cs +++ b/LibMpcApp/Program.cs @@ -49,6 +49,10 @@ namespace LibMpcApp case 24: response = mpc.SendAsync(new Commands.Reflection.TagTypes()).GetAwaiter().GetResult(); break; + + case 313: + response = mpc.SendAsync(new Commands.Database.Update()).GetAwaiter().GetResult(); + break; } Console.WriteLine("Response: "); @@ -61,17 +65,18 @@ namespace LibMpcApp Console.WriteLine(); Console.WriteLine("Commands: "); - // Ouput Console.WriteLine(); Console.WriteLine("11. disableoutput 0"); Console.WriteLine("12. enableoutput 0"); Console.WriteLine("13. outputs"); - // Reflection Console.WriteLine(); + Console.WriteLine("Reflection"); Console.WriteLine("24. tagtypes"); - // Database + Console.WriteLine(); + Console.WriteLine("Database"); + Console.WriteLine("313. update"); Console.WriteLine(); Console.WriteLine("99. Exit");