async void chimneyMpdServer_OnLsInfo(object sender, ResponseEventArgs e)
{
string response = string.Empty;
bool suc = true;
//
// Get the uri from arguments, if empty uri is empty
//
string uri = (e.arguments.Count > 0) ? e.arguments.First<string>(): string.Empty;
//
// Get the Directories with RelativePath of uri
//
var directories = await Dbconnection.QueryAsync<Directory>("SELECT DirectoryId FROM Directories WHERE RelativePath = \"" + uri + "\"");
foreach (Directory dir in directories)
{
//
// Get the sub directories for the the uri directories
//
var subDirectories = await Dbconnection.QueryAsync<Directory>("SELECT * FROM Directories WHERE ParentDirectoryId = " + dir.DirectoryId);
foreach (Directory subdir in subDirectories)
{
response += subdir.ToReponseString();
}
//
// Get all files in the current uri
//
var files = await Dbconnection.QueryAsync<File>("SELECT * FROM Files WHERE Files.DirectoryId = " + dir.DirectoryId + " AND Type = \"File\"");
foreach (File file in files)
{
response += file.ToResponseString();
}
}
if (suc) chimneyMpdServer.AppendResponse(response, e.id, e.position);
else
{
string errorfile = (e.arguments.Count > 0) ? e.arguments.First<string>() : string.Empty;
chimneyMpdServer.ErrorResponse(MPDKeyWords.Response.ACK + " [50@0] {listall} could not find path:" + " \"" + errorfile + "\"", e.id, e.position);
}
}