示例#1
0
 private Task <NicoliveVideoResponse> GetLiveSearchResponseOnCurrentOption(uint from, uint length)
 {
     return(SearchProvider.LiveSearchAsync(
                SearchOption.Keyword,
                SearchOption.IsTagSearch,
                from: from,
                length: length,
                provider: SearchOption.Provider,
                sort: SearchOption.Sort,
                order: SearchOption.Order,
                mode: SearchOption.Mode
                ));
 }
        async Task <IEnumerable <LiveInfoListItemViewModel> > IIncrementalSource <LiveInfoListItemViewModel> .GetPagedItemsAsync(int pageIndex, int pageSize, CancellationToken ct)
        {
            Query.UsePage(pageIndex);

            var res = await SearchProvider.LiveSearchAsync(Query);

            ct.ThrowIfCancellationRequested();

            using (res.Data)
            {
                List <LiveInfoListItemViewModel> items = new();
                foreach (var item in res.Data.SearchResultItems)
                {
                    if (!SearchedVideoIdsHash.Contains(item.LiveId))
                    {
                        SearchedVideoIdsHash.Add(item.LiveId);
                        _nicoLiveCacheRepository.AddOrUpdate(new NicoLive()
                        {
                            LiveId        = item.LiveId,
                            BroadcasterId = item.ProviderName,
                            Title         = item.Title,
                        });

                        var liveInfoVM = new LiveInfoListItemViewModel(item.LiveId);
                        liveInfoVM.Setup(item);

                        if (_reservation.IsSuccess)
                        {
                            var reserve = _reservation?.Data?.Items.FirstOrDefault(reservation => item.LiveId == reservation.LiveId);
                            if (reserve != null)
                            {
                                liveInfoVM.SetReservation(reserve);
                            }
                        }

                        items.Add(liveInfoVM);
                    }
                    else
                    {
                        continue;
                    }

                    ct.ThrowIfCancellationRequested();
                }

                return(items);
            }
        }
示例#3
0
        public SearchSummaryPageViewModel(
            SearchProvider searchProvider,
            Services.PageManager pageManager
            )
            : base(pageManager)
        {
            RelatedVideoTags = new ObservableCollection <string>();

            KeywordSearchResultItems = this.ObserveProperty(x => x.Keyword)
                                       .Where(x => !string.IsNullOrWhiteSpace(x))
                                       .SelectMany(async(x, i, cancelToken) =>
            {
                RelatedVideoTags.Clear();
                var res = await SearchProvider.GetKeywordSearch(x, 0, 10);

                if (res.IsOK)
                {
                    KeywordSearchItemsTotalCount = (int)res.GetTotalCount();

                    if (res.Tags != null)
                    {
                        foreach (var tag in res.Tags.TagItems)
                        {
                            RelatedVideoTags.Add(tag.Name);
                        }
                    }

                    return(res.VideoInfoItems?.AsEnumerable() ?? Enumerable.Empty <Mntone.Nico2.Searches.Video.VideoInfo>());
                }
                else
                {
                    return(Enumerable.Empty <Mntone.Nico2.Searches.Video.VideoInfo>());
                }
            })
                                       .SelectMany(x => x)
                                       .Select(x =>
            {
                var vm = new VideoInfoControlViewModel(x.Video.Id);
                vm.SetTitle(x.Video.Title);
                vm.SetThumbnailImage(x.Video.ThumbnailUrl.OriginalString);
                return(vm);
            })
                                       .ToReadOnlyReactiveCollection(onReset: this.ObserveProperty(x => x.Keyword).ToUnit())
                                       .AddTo(_CompositeDisposable);
            HasKeywordSearchResultItems = KeywordSearchResultItems
                                          .ObserveProperty(x => x.Count)
                                          .Select(x => x > 0)
                                          .ToReadOnlyReactiveProperty()
                                          .AddTo(_CompositeDisposable);

            RelatedLiveTags       = new ObservableCollection <string>();
            LiveSearchResultItems = this.ObserveProperty(x => x.Keyword)
                                    .Where(x => !string.IsNullOrWhiteSpace(x))
                                    .SelectMany(async(x, i, cancelToken) =>
            {
                RelatedLiveTags.Clear();
                var res = await SearchProvider.LiveSearchAsync(x, false, length: 10);
                if (res.IsStatusOK)
                {
                    if (res.Tags != null)
                    {
                        foreach (var tag in res.Tags.Tag)
                        {
                            RelatedLiveTags.Add(tag.Name);
                        }
                    }

                    LiveSearchItemsTotalCount = res.TotalCount.FilteredCount;
                    return(res.VideoInfo?.AsEnumerable() ?? Enumerable.Empty <Mntone.Nico2.Searches.Live.VideoInfo>());
                }
                else
                {
                    return(Enumerable.Empty <Mntone.Nico2.Searches.Live.VideoInfo>());
                }
            })
                                    .SelectMany(x => x)
                                    .Select(x =>
            {
                var liveInfoVM = new LiveInfoListItemViewModel(x.Video.Id);
                liveInfoVM.Setup(x);
                return(liveInfoVM);
            })
                                    .ToReadOnlyReactiveCollection(onReset: this.ObserveProperty(x => x.Keyword).ToUnit());
            HasLiveSearchResultItems = LiveSearchResultItems
                                       .ObserveProperty(x => x.Count)
                                       .Select(x => x > 0)
                                       .ToReadOnlyReactiveProperty()
                                       .AddTo(_CompositeDisposable);
            SearchProvider = searchProvider;
        }