Libmpc.Mpc.Outputs C# (CSharp) Method

Outputs() public method

Lists all outputs of the MPD.
public Outputs ( ) : MpdOutput[]
return MpdOutput[]
        public MpdOutput[] Outputs()
        {
            MpdResponse response = this.getConnection().Exec("outputs");
              if (response.Message.Count % 3 != 0)
            throw new InvalidMpdResponseException();

              MpdOutput[] ret = new MpdOutput[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;
        }