/// <summary> /// Gets the offline red heart songs. /// </summary> /// <param name="maxSize">The maximum amount of returned songs.</param> /// <param name="excludedSids">The excluded SIDs of songs.</param> /// <returns> /// The offline red heart songs. /// </returns> public async Task <Song[]> GetOfflineRedHeartSongs(int maxSize, IEnumerable <string> excludedSids) { var uri = ServerConnection.CreateGetPlayListUri(-3, type: ReportType.CurrentChannelChanged, sid: null, start: null, formats: null, kbps: null, playedTime: null, mode: "offline", excludedSids: excludedSids, max: maxSize); var jsonContent = await ServerConnection.Get(uri, ServerConnection.SetSessionInfoToRequest); return(ServerRequests.ParseGetPlayListResult(jsonContent)); }
/// <summary> /// Send a report to server. /// </summary> /// <param name="type">The type of report.</param> /// <param name="channelId">The channel ID.</param> /// <param name="sid">The SID of current song.</param> /// <param name="start">The start song code.</param> /// <returns></returns> private async Task Report(ReportType type, int channelId, string sid, string start) { var changeCurrentSong = !(type == ReportType.Like || type == ReportType.CancelLike); if (changeCurrentSong) { CurrentSong = null; } var uri = ServerConnection.CreateGetPlayListUri(channelId, type: type, sid: sid, start: start, formats: null, kbps: null, playedTime: null, mode: null, excludedSids: null, max: null); var jsonContent = await ServerConnection.Get(uri, ServerConnection.SetSessionInfoToRequest); var newPlayList = ServerRequests.ParseGetPlayListResult(jsonContent); if (newPlayList.Length == 0) { if (type != ReportType.CurrentSongEnded) { throw new NoAvailableSongsException(); } if (_pendingSongs.Count == 0) { await Report(ReportType.PlayListEmpty, channelId, sid, start); return; } } if (channelId == AsyncExpectedChannelId) { if (newPlayList.Length != 0) { if (_pendingSongs == null) { _pendingSongs = new Queue <Song>(); } _pendingSongs.Clear(); foreach (var song in newPlayList) { _pendingSongs.Enqueue(song); } } if (changeCurrentSong) { CurrentSong = _pendingSongs.Dequeue(); } } else { // TODO: throw exception or not? } }