From c95c09fa2c9918d387997c626ea716eb8a99ac63 Mon Sep 17 00:00:00 2001 From: glucaci Date: Fri, 2 Dec 2016 15:19:18 +0100 Subject: [PATCH 1/5] Console app for test created. --- .gitignore | 12 +++++-- LibMpc.sln | 50 ++++++++++++++++------------ LibMpcApp/LibMpcApp.xproj | 21 ++++++++++++ LibMpcApp/Program.cs | 30 +++++++++++++++++ LibMpcApp/Properties/AssemblyInfo.cs | 19 +++++++++++ LibMpcApp/project.json | 20 +++++++++++ 6 files changed, 128 insertions(+), 24 deletions(-) create mode 100644 LibMpcApp/LibMpcApp.xproj create mode 100644 LibMpcApp/Program.cs create mode 100644 LibMpcApp/Properties/AssemblyInfo.cs create mode 100644 LibMpcApp/project.json diff --git a/.gitignore b/.gitignore index 0d0d052..d776c3a 100644 --- a/.gitignore +++ b/.gitignore @@ -3,7 +3,15 @@ ################################################################################ /.vs + +/LibMpc/bin +/LibMpc/obj /LibMpc/LibMpc.xproj.user -/LibMpc/obj/Debug/netstandard1.6 -/LibMpc/bin/Debug/netstandard1.6 /LibMpc/project.lock.json + +/LibMpcApp/bin +/LibMpcApp/obj +/LibMpcApp/LibMpcApp.xproj.user +/LibMpcApp/project.lock.json + +/LibMpc.sln.DotSettings.user diff --git a/LibMpc.sln b/LibMpc.sln index 36a5f13..6d8fd00 100644 --- a/LibMpc.sln +++ b/LibMpc.sln @@ -1,22 +1,28 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 14 -VisualStudioVersion = 14.0.25420.1 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "LibMpc", "LibMpc\LibMpc.xproj", "{8994C820-7BA9-4BB8-B9EA-C608B07C4A11}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {8994C820-7BA9-4BB8-B9EA-C608B07C4A11}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {8994C820-7BA9-4BB8-B9EA-C608B07C4A11}.Debug|Any CPU.Build.0 = Debug|Any CPU - {8994C820-7BA9-4BB8-B9EA-C608B07C4A11}.Release|Any CPU.ActiveCfg = Release|Any CPU - {8994C820-7BA9-4BB8-B9EA-C608B07C4A11}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 14 +VisualStudioVersion = 14.0.25420.1 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "LibMpc", "LibMpc\LibMpc.xproj", "{8994C820-7BA9-4BB8-B9EA-C608B07C4A11}" +EndProject +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "LibMpcApp", "LibMpcApp\LibMpcApp.xproj", "{FF176AD5-D6DA-41EE-B27D-1DBEF0CE462F}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {8994C820-7BA9-4BB8-B9EA-C608B07C4A11}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8994C820-7BA9-4BB8-B9EA-C608B07C4A11}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8994C820-7BA9-4BB8-B9EA-C608B07C4A11}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8994C820-7BA9-4BB8-B9EA-C608B07C4A11}.Release|Any CPU.Build.0 = Release|Any CPU + {FF176AD5-D6DA-41EE-B27D-1DBEF0CE462F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FF176AD5-D6DA-41EE-B27D-1DBEF0CE462F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FF176AD5-D6DA-41EE-B27D-1DBEF0CE462F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FF176AD5-D6DA-41EE-B27D-1DBEF0CE462F}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/LibMpcApp/LibMpcApp.xproj b/LibMpcApp/LibMpcApp.xproj new file mode 100644 index 0000000..b0a483b --- /dev/null +++ b/LibMpcApp/LibMpcApp.xproj @@ -0,0 +1,21 @@ + + + + 14.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + + + + ff176ad5-d6da-41ee-b27d-1dbef0ce462f + LibMpcApp + .\obj + .\bin\ + v4.5.2 + + + + 2.0 + + + diff --git a/LibMpcApp/Program.cs b/LibMpcApp/Program.cs new file mode 100644 index 0000000..eba6300 --- /dev/null +++ b/LibMpcApp/Program.cs @@ -0,0 +1,30 @@ +using System; +using System.Net; +using System.Threading.Tasks; +using LibMpc; + +namespace LibMpcApp +{ + public class Program + { + public static void Main(string[] args) + { + var mpc = new Mpc(new IPEndPoint(IPAddress.Loopback, 6600)); + + var connected = mpc.ConnectAsync().GetAwaiter().GetResult(); + if (connected) + { + StartReadCommands(mpc); + } + else + { + Console.WriteLine("Could not connect to MPD"); + } + } + + private static void StartReadCommands(Mpc mpc) + { + + } + } +} diff --git a/LibMpcApp/Properties/AssemblyInfo.cs b/LibMpcApp/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..c72cd92 --- /dev/null +++ b/LibMpcApp/Properties/AssemblyInfo.cs @@ -0,0 +1,19 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Windows User")] +[assembly: AssemblyProduct("LibMpcApp")] +[assembly: AssemblyTrademark("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("ff176ad5-d6da-41ee-b27d-1dbef0ce462f")] diff --git a/LibMpcApp/project.json b/LibMpcApp/project.json new file mode 100644 index 0000000..b24b498 --- /dev/null +++ b/LibMpcApp/project.json @@ -0,0 +1,20 @@ +{ + "version": "1.0.0-*", + "buildOptions": { + "emitEntryPoint": true + }, + + "dependencies": { + "LibMpc": "1.0.0-*", + "Microsoft.NETCore.App": { + "type": "platform", + "version": "1.0.1" + } + }, + + "frameworks": { + "netcoreapp1.0": { + "imports": "dnxcore50" + } + } +} From 483f6740e0a331df2270e820ce9716004dacd5fa Mon Sep 17 00:00:00 2001 From: Gabriel Date: Fri, 2 Dec 2016 15:41:19 +0100 Subject: [PATCH 2/5] Mpc Disconnect implemented. --- LibMpc/Mpc.cs | 13 +++++++++++++ LibMpc/MpcConnection.cs | 8 ++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/LibMpc/Mpc.cs b/LibMpc/Mpc.cs index 751113c..21236ec 100644 --- a/LibMpc/Mpc.cs +++ b/LibMpc/Mpc.cs @@ -39,6 +39,19 @@ namespace LibMpc return _connection.IsConnected; } + public async Task DisconnectAsync() + { + if (_connection == null) + { + return; + } + + if (_connection.IsConnected) + { + await _connection?.DisconnectAsync(); + } + } + #region Admin Commands /// /// Disables an MPD output. diff --git a/LibMpc/MpcConnection.cs b/LibMpc/MpcConnection.cs index 804aa0d..5210fa1 100644 --- a/LibMpc/MpcConnection.cs +++ b/LibMpc/MpcConnection.cs @@ -63,7 +63,7 @@ namespace LibMpc var firstLine = _reader.ReadLine(); if (!firstLine.StartsWith(FIRST_LINE_PREFIX)) { - await Disconnect(); + await DisconnectAsync(); throw new InvalidDataException("Response of mpd does not start with \"" + FIRST_LINE_PREFIX + "\"." ); } _version = firstLine.Substring(FIRST_LINE_PREFIX.Length); @@ -74,7 +74,7 @@ namespace LibMpc await ReadResponseAsync(); } - private Task Disconnect() + public Task DisconnectAsync() { if (_tcpClient == null) { @@ -113,7 +113,7 @@ namespace LibMpc } catch (Exception) { - try { await Disconnect(); } catch (Exception) { } + try { await DisconnectAsync(); } catch (Exception) { } return null; // TODO: Create Null Object for MpdResponse } } @@ -161,7 +161,7 @@ namespace LibMpc } catch (Exception) { - try { await Disconnect(); } catch (Exception) { } + try { await DisconnectAsync(); } catch (Exception) { } throw; } } From 6b72534a7a273716a001189960a3c534152d2cc6 Mon Sep 17 00:00:00 2001 From: Gabriel Date: Fri, 2 Dec 2016 15:41:52 +0100 Subject: [PATCH 3/5] Connect and disconnect from mpd in test app implemented. --- LibMpcApp/Program.cs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/LibMpcApp/Program.cs b/LibMpcApp/Program.cs index eba6300..4cdf2b2 100644 --- a/LibMpcApp/Program.cs +++ b/LibMpcApp/Program.cs @@ -14,17 +14,29 @@ namespace LibMpcApp var connected = mpc.ConnectAsync().GetAwaiter().GetResult(); if (connected) { + Console.WriteLine("Connected to MPD."); StartReadCommands(mpc); } else { - Console.WriteLine("Could not connect to MPD"); + Console.WriteLine("Could not connect to MPD."); } + + mpc.DisconnectAsync().GetAwaiter().GetResult(); } private static void StartReadCommands(Mpc mpc) { - + while(true) + { + Console.Write("Command: "); + var command = Console.ReadLine(); + + if (string.IsNullOrEmpty(command)) + { + break; + } + } } } } From 71367cea5920a891b4c6660b2fd61d50ab6fc43d Mon Sep 17 00:00:00 2001 From: Gabriel Date: Mon, 5 Dec 2016 09:45:20 +0100 Subject: [PATCH 4/5] Send Mpc command to execute. --- LibMpc/Mpc.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/LibMpc/Mpc.cs b/LibMpc/Mpc.cs index 21236ec..a56e0b8 100644 --- a/LibMpc/Mpc.cs +++ b/LibMpc/Mpc.cs @@ -52,6 +52,16 @@ namespace LibMpc } } + // TODO: create response type + public async Task SendAsync(IMpcCommand command) + { + var mpdResponse = await _connection.Exec(command.Value); + var respose = command.ParseResponse(mpdResponse); + + return respose; + } + + #region Admin Commands /// /// Disables an MPD output. From 7561d2a04f2c36c0feae077f5b010ddb1f4a280b Mon Sep 17 00:00:00 2001 From: Gabriel Date: Mon, 5 Dec 2016 09:46:44 +0100 Subject: [PATCH 5/5] First command for test app implemented --- LibMpcApp/Program.cs | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/LibMpcApp/Program.cs b/LibMpcApp/Program.cs index 4cdf2b2..7a54497 100644 --- a/LibMpcApp/Program.cs +++ b/LibMpcApp/Program.cs @@ -1,12 +1,20 @@ using System; using System.Net; -using System.Threading.Tasks; using LibMpc; +using System.Collections.Generic; namespace LibMpcApp { + /// + /// Simple console app to test commands and parsed responses. + /// public class Program { + private static readonly Dictionary> _commands = new Dictionary> + { + { 1, input => new Commands.Reflection.TagTypes() } + }; + public static void Main(string[] args) { var mpc = new Mpc(new IPEndPoint(IPAddress.Loopback, 6600)); @@ -27,16 +35,31 @@ namespace LibMpcApp private static void StartReadCommands(Mpc mpc) { - while(true) + int userInput = 0; + while ((userInput = DisplayMenu()) != 99) { - Console.Write("Command: "); - var command = Console.ReadLine(); + Func command; + var response = new object(); - if (string.IsNullOrEmpty(command)) + if (_commands.TryGetValue(userInput, out command)) { - break; + response = mpc.SendAsync(command(null)).GetAwaiter().GetResult(); } + + Console.WriteLine("Response: "); + Console.WriteLine(response); } } + + 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); + } } }