Libmpc.Mpc.AddId C# (CSharp) Method

AddId() public method

Adds a file to the playlist and returns the id.
public AddId ( string filename ) : int
filename string The name and path of the file to add.
return int
        public int AddId(string filename)
        {
            if (filename == null)
            throw new ArgumentNullException("filename");

              filename = EscapeString(filename);
              MpdResponse response = this.getConnection().Exec("add", new string[] { filename });

              if (response.IsError)
            throw new MpdResponseException(response.ErrorCode, response.ErrorMessage);

              if (response.Count != 1)
            throw new InvalidMpdResponseException("Returned more than one line for command addid.");

              string id = response["Id"];
              if (id == null)
            throw new InvalidMpdResponseException("Tag Id missing in response to command addid.");
              int tryId = -1;
              if (!int.TryParse(id, out tryId))
            throw new InvalidMpdResponseException("Tag Id in response to command addid does not contain an number.");

              return tryId;
        }