public IEnumerable <Track> GetTracksByName(string name) { Track[] tracks = new Track[0]; if (!IsLoggedIn()) { return(tracks); } QueryServiceClient query = new QueryServiceClient(); try { QueryResult result = query.Query(name, 0, 150, 0, 0, 0, 0); tracks = result.Tracks .Where(t => t.IsAvailable) .Select(ConvertTrack) .ToArray(); query.Close(); } catch (Exception e) { _logger.Log(e.Message, Category.Exception, Priority.Medium); query.Abort(); } return(tracks); }
public IEnumerable <TrackContainer> GetAlbumsByArtist(string artist) { List <TrackContainer> containers = new List <TrackContainer>(); if (!IsLoggedIn()) { return(containers); } QueryServiceClient query = new QueryServiceClient(); try { var queryResult = query.Query(artist, 0, 0, 0, 0, 0, 10); var result = queryResult.Artists.FirstOrDefault( a => a.Name.Equals(artist, StringComparison.InvariantCultureIgnoreCase)); if (result == null && queryResult.Artists.Any()) { result = queryResult.Artists.FirstOrDefault(); } if (result != null) { var browse = query.ArtistBrowse(result.ID, ArtistBrowsingType.Full); var albumGroups = browse.Tracks.Where(t => t.IsAvailable).GroupBy(t => t.Album.ID); foreach (var albumGroup in albumGroups) { TrackContainer container = new TrackContainer(); container.Owner = new TrackContainerOwner(artist); container.Tracks = albumGroup.Select(SpotifyRadioTrackPlayer.ConvertTrack).ToArray(); var firstOrDefault = container.Tracks.FirstOrDefault(); if (firstOrDefault != null) { container.Name = firstOrDefault.Album; container.Image = container.Image = firstOrDefault.AlbumArt; } containers.Add(container); } } query.Close(); } catch (Exception e) { _logger.Log(e.Message, Category.Exception, Priority.Medium); query.Abort(); } return(containers); }
private T CallQueryService <T>(Func <IQueryService, T> call) { QueryServiceClient client = NewServiceClient(); try { return(call(client)); } finally { try { client.Close(); } catch (Exception) { client.Abort(); } } }
private T CallQueryService <T>(Func <IQueryService, T> call) { QueryServiceClient client = ClientFactory.CreateClient <QueryServiceClient, IQueryService>(); try { return(call(client)); } finally { try { client.Close(); } catch (Exception) { client.Abort(); } } }
public IEnumerable<TrackContainer> GetAlbumsByArtist(string artist) { List<TrackContainer> containers = new List<TrackContainer>(); if (!IsLoggedIn()) { return containers; } QueryServiceClient query = new QueryServiceClient(); try { var queryResult = query.Query(artist, 0, 0, 0, 0, 0, 10); var result = queryResult.Artists.FirstOrDefault( a => a.Name.Equals(artist, StringComparison.InvariantCultureIgnoreCase)); if (result == null && queryResult.Artists.Any()) { result = queryResult.Artists.FirstOrDefault(); } if (result != null) { var browse = query.ArtistBrowse(result.ID, ArtistBrowsingType.Full); var albumGroups = browse.Tracks.Where(t => t.IsAvailable).GroupBy(t => t.Album.ID); foreach (var albumGroup in albumGroups) { TrackContainer container = new TrackContainer(); container.Owner = new TrackContainerOwner(artist); container.Tracks = albumGroup.Select(SpotifyRadioTrackPlayer.ConvertTrack).ToArray(); var firstOrDefault = container.Tracks.FirstOrDefault(); if (firstOrDefault != null) { container.Name = firstOrDefault.Album; container.Image = container.Image = firstOrDefault.AlbumArt; } containers.Add(container); } } query.Close(); } catch (Exception e) { _logger.Log(e.Message, Category.Exception, Priority.Medium); query.Abort(); } return containers; }
public IEnumerable<Track> GetTracksByName(string name) { Track[] tracks = new Track[0]; if (!IsLoggedIn()) { return tracks; } QueryServiceClient query = new QueryServiceClient(); try { QueryResult result = query.Query(name, 0, 150, 0, 0, 0, 0); tracks = result.Tracks .Where(t => t.IsAvailable) .Select(ConvertTrack) .ToArray(); query.Close(); } catch (Exception e) { _logger.Log(e.Message, Category.Exception, Priority.Medium); query.Abort(); } return tracks; }