/// <summary>
        /// Send a predefined command to the MPD server.
        /// Returns a
        /// </summary>
        /// <typeparam name="T">result type T depending on the command</typeparam>
        /// <param name="command">MpcCoreCommand</param>
        /// <returns>Task with result<T></returns>
        public async Task <IMpdResponse> SendAsync <T>(IMpcCoreCommand <T> command)
        {
            var connected = await CheckConnectionAsync();

            _writer.WriteLine(command.Command);
            _writer.Flush();

            return((command.Command.StartsWith("readpicture") || command.Command.StartsWith("albumart"))
                                ? await ReadBinaryResponseAsync()
                                : await ReadResponseAsync());
        }
Exemple #2
0
        public async Task <IMpcCoreResponse <T> > SendAsync <T>(IMpcCoreCommand <T> command)
        {
            if (command == null)
            {
                return(new MpcCoreResponse <T>(command, new MpcCoreResponseStatus
                {
                    HasError = true,
                    ErrorMessage = "Command is null or empty"
                }));
            }

            IMpdResponse response = null;

            try {
                response = await _connection.SendAsync(command);
            }
            catch (Exception exception)
            {
                try
                {
                    await _connection.DisconnectAsync();
                }
                catch (Exception)
                {
                    // TODO handle exception correctly
                }

                return(new MpcCoreResponse <T>(command, new MpcCoreResponseStatus
                {
                    HasError = true,
                    ErrorMessage = $"An exception occured: {exception.Message} in {exception.Source}"
                }));
            }

            return(await new MpcCoreResponse <T>(command, response).CreateResult());
        }
Exemple #3
0
 public MpcCoreResponse(IMpcCoreCommand <T> command, IMpcCoreResponseStatus status)
 {
     Command = command;
     Status  = status;
 }
Exemple #4
0
 public MpcCoreResponse(IMpcCoreCommand <T> command, IMpdResponse response)
 {
     _response = response;
     Command   = command;
 }