public static async Task PartialLoading(LoadDelegate load, AddAudioItem addItem, Int32 loadCount, CancellationToken token) { Int32 currentCount = 20; Int32 currentOffset = 0; do { if (currentCount + currentOffset > loadCount) { currentCount = loadCount - currentOffset + 1; } VKList <VKAudio> list = await load(currentOffset, currentCount, token); if (list != null && list.Items != null) { foreach (var item in list.Items) { token.ThrowIfCancellationRequested(); await addItem(item); } } else { break; } currentOffset += currentCount; currentCount *= 2; } while (currentOffset < loadCount); }
public static async Task PartialLoading(LoadDelegate load, AddAudioItem addItem, Int32 loadCount, CancellationToken token) { Int32 currentCount = 20; Int32 currentOffset = 0; do { if (currentCount + currentOffset > loadCount) currentCount = loadCount - currentOffset + 1; VKList<VKAudio> list = await load(currentOffset, currentCount, token); if (list != null && list.Items != null) { foreach (var item in list.Items) { token.ThrowIfCancellationRequested(); await addItem(item); } } else { break; } currentOffset += currentCount; currentCount *= 2; } while (currentOffset < loadCount); }
public async Task GetListAsync(AddAudioItem addItem, CancellationToken token) { Int32 count = await VKApi.Audio.GetCountAsync(VKSession.Instance.UserId, token); await AudioProviderHelper.PartialLoading((o, c, t) => VKApi.Audio.GetAsync(VKSession.Instance.UserId, offset: o, count: c, token: token), addItem, count, token); }
private static async Task LoadAudios(Int64 groupId, AddAudioItem addItem, CancellationToken token) { Int32 count = await VKApi.Audio.GetCountAsync(-groupId, token); await AudioProviderHelper.PartialLoading((o, c, t) => VKApi.Audio.GetAsync(-groupId, token: token), addItem, count, token); }
public async Task GetListAsync(AddAudioItem addItem, CancellationToken token) { Debug.Assert(State.Content != null); await AudioProviderHelper.PartialLoading(async (o, c, t) => await VKApi.Audio.GetRecommendationsAsync(State.Content.Id, State.Content.OwnerId, offset: o, count: c, token: t), addItem, 400, token); }
public async Task GetListAsync(AddAudioItem addItem, CancellationToken token) { Debug.Assert(this.friend != null); Int32 count = await VKApi.Audio.GetCountAsync(this.friend.Id, token); Int64?albumId = this.album != null ? this.album.Id : (Int64?)null; await AudioProviderHelper.PartialLoading((o, c, t) => VKApi.Audio.GetAsync(this.friend.Id, albumId, offset: o, count: c, token: t), addItem, count, token); }
public async Task GetListAsync(AddAudioItem addItem, CancellationToken token) { await AudioProviderHelper.PartialLoading(async (o, c, t) => await VKApi.Audio.SearchAsync( State.Query, State.AutoComplete, State.OnlyWithLyrics, State.OnlyByArtist, State.ChosenSort, false, o, c, t), addItem, 300, token); }
private async Task LoadAudiosFromWall(AddAudioItem addItem, long ownerId, CancellationToken token) { int offset = 0; const int maxCount = 100; int allCount; int curCount = 0; Func <VKList <VKPost>, IEnumerable <VKAudio> > audioFilter = list => list.Items .Where(x => x.Attachments != null) .SelectMany(x => x.Attachments) .Where(x => x.Type == "audio") .Select(x => x.Audio) .Where(x => !String.IsNullOrWhiteSpace(x.Url)); var lHead = await WallAPI.GetAsync(ownerId, count : maxCount, offset : offset, token : token); if (lHead == null) { return; } foreach (var item in audioFilter(lHead)) { token.ThrowIfCancellationRequested(); await addItem(item); } curCount += maxCount; allCount = Convert.ToInt32(lHead.Count); while (curCount < allCount) { offset = curCount; var lCurr = await WallAPI.GetAsync(ownerId, count : maxCount, offset : offset, token : token); if (lCurr == null) { break; } foreach (var item in audioFilter(lCurr)) { token.ThrowIfCancellationRequested(); await addItem(item); } curCount += maxCount; token.ThrowIfCancellationRequested(); } }
public async Task GetListAsync(AddAudioItem addItem, CancellationToken token) { Debug.Assert(this.album != null); var list = await VKApi.Audio.GetAsync(ownerId : this.album.OwnerId, albumId : this.album.Id, token : token); if (list != null) { foreach (var item in list.Items) { token.ThrowIfCancellationRequested(); await addItem(item); } } }
public async Task GetListAsync(AddAudioItem addItem, CancellationToken token) { Debug.Assert(this.group != null); switch (group.Type) { case VKGroupTypeEnum.Page: await LoadAudiosFromWall(addItem, -group.Id, token); break; case VKGroupTypeEnum.Group: await LoadAudios(this.group.Id, addItem, token); break; case VKGroupTypeEnum.Event: await LoadAudios(this.group.Id, addItem, token); break; } }
public async Task LoadListAsync(AddAudioItem addItem, CancellationToken token) { Contract.Requires(AudioProvider != null); await AudioProvider.GetListAsync(addItem, token); }
public async Task GetListAsync(AddAudioItem addItem, CancellationToken token) { await AudioProviderHelper.PartialLoading(async (o, c, t) => await VKApi.Audio.GetPopularAsync(State.Genre, State.OnlyEng, o, c, t), addItem, 400, token); }