public SongsFilesDetailsResponse(SongsFilesDetailsResponse request) { FileName = request.FileName; ErrorCode = request.ErrorCode; FailReason = request.FailReason; AlbumsPlayed = new DisplayAlbum[request.AlbumsPlayed.Length]; for (int i = 0; i < request.AlbumsPlayed.Length; i++) { AlbumsPlayed[i] = new DisplayAlbum(request.AlbumsPlayed[i]); } }
public SongsFilesDetailsResponse GetAllAlbumsPlayedFromFile(string key) { SongsFilesDetailsResponse resp = new SongsFilesDetailsResponse { FileName = key, ErrorCode = (int)SongsFilesResponseCode.Success }; string fullPath = FileUtilities.GetFullSongsDetailsFilePath(key, _uploaderSettings.UploadFilesDirectory); if (System.IO.File.Exists(fullPath)) { List <AlbumPlayed> albums = new List <AlbumPlayed>(); if (fullPath.ToLower().EndsWith(".txt")) { albums = SongFileParser.GetAlbumsPlayedFromFile(fullPath); } else if (fullPath.ToLower().EndsWith(".csv")) { albums = SongFileParserCsv.GetAlbumsPlayedFromFile(fullPath); } else if (fullPath.ToLower().EndsWith(".json")) { albums = SongFileParserJson.GetAlbumsPlayedFromFile(fullPath); } if (albums == null || !albums.Any()) { resp.ErrorCode = (int)SongsFilesResponseCode.NoSongsInFile; resp.FailReason = "No songs in file."; } else { resp.AlbumsPlayed = new DisplayAlbum[albums.Count]; for (int i = 0; i < albums.Count; i++) { resp.AlbumsPlayed[i] = new DisplayAlbum { Date = albums[i].Date, Location = albums[i].Location, Artist = albums[i].Artist, Album = albums[i].Album, ImagePath = albums[i].ImagePath, PlayerLink = albums[i].PlayerLink, UserName = albums[i].UserName, Id = albums[i].Id.ToString() } } ; } } else { resp.ErrorCode = (int)SongsFilesResponseCode.InvalidFile; resp.FailReason = "No such file exists."; } return(resp); }