/// <summary> /// Search a text asynchronously. /// </summary> /// <param name="text">text</param> public void SearchAsync(string text, int pagenum) { SearchText = text; long aid = FindAid(text); if (aid >= 0) { HistoryBox.Insert(text); VideoSelected?.Invoke("Av" + aid.ToString(), aid); return; } if (cancellationTokenSource != null) { cancellationTokenSource.Cancel(); } ContentViewer.ScrollToHome(); ContentPanel.Children.Clear(); PagesBox.Visibility = Visibility.Hidden; if (text != null && text.Trim() != string.Empty) { HistoryBox.Insert(text); HistoryBox.Visibility = Visibility.Hidden; TypeBtn.IsChecked = true; cancellationTokenSource = new CancellationTokenSource(); CancellationToken cancellationToken = cancellationTokenSource.Token; LoadingPrompt.Visibility = Visibility.Visible; NoMoreGrid.Visibility = Visibility.Collapsed; ContentViewer.Visibility = Visibility.Collapsed; Task task = new Task(() => { string type = NavType; Json.Value json = GetResult(text, type, pagenum); if (json != null) { Dispatcher.Invoke(new Action(() => { if (cancellationToken.IsCancellationRequested) { return; } ShowResult(json, type); PagesBox.SetPage((int)json["data"]["numPages"], (int)json["data"]["page"], false); PagesBox.Visibility = Visibility.Visible; LoadingPrompt.Visibility = Visibility.Hidden; })); } }); task.Start(); } else { HistoryBox.Visibility = Visibility.Visible; } }
private void ShowFolder(int mediaId, int pagenum, bool init) { if (cancellationTokenSource != null) { cancellationTokenSource.Cancel(); } ContentViewer.ScrollToHome(); ContentPanel.Children.Clear(); MediaId = mediaId; cancellationTokenSource = new CancellationTokenSource(); CancellationToken cancellationToken = cancellationTokenSource.Token; LoadingPrompt.Visibility = Visibility.Visible; PagesBox.Visibility = Visibility.Hidden; Dictionary <string, string> dic = new Dictionary <string, string>(); dic.Add("media_id", mediaId.ToString()); dic.Add("pn", pagenum.ToString()); dic.Add("ps", "20"); dic.Add("keyword", ""); dic.Add("order", "mtime"); dic.Add("type", "0"); dic.Add("tid", "0"); dic.Add("jsonp", "jsonp"); Task task = new Task(() => { IJson json = BiliApi.GetJsonResult("https://api.bilibili.com/medialist/gateway/base/spaceDetail", dic, false); if (cancellationToken.IsCancellationRequested) { return; } if (json.GetValue("code").ToLong() == 0) { Dispatcher.Invoke(new Action(() => { foreach (IJson media in json.GetValue("data").GetValue("medias")) { FavItem favItem = new FavItem(media.GetValue("title").ToString(), media.GetValue("cover").ToString(), media.GetValue("fav_time").ToLong(), media.GetValue("id").ToLong(), false); favItem.PreviewMouseLeftButtonDown += FavItem_PreviewMouseLeftButtonDown; ContentPanel.Children.Add(favItem); } if (init) { PagesBox.SetPage((int)Math.Ceiling((double)json.GetValue("data").GetValue("info").GetValue("media_count").ToLong() / 20), 1, true); } PagesBox.Visibility = Visibility.Visible; })); } Dispatcher.Invoke(new Action(() => { LoadingPrompt.Visibility = Visibility.Hidden; })); }); task.Start(); }
public void LoadAsync(int mid, int page, bool init) { Mid = mid; if (cancellationTokenSource != null) { cancellationTokenSource.Cancel(); } ContentViewer.ScrollToHome(); ContentPanel.Children.Clear(); PagesBox.Visibility = Visibility.Hidden; cancellationTokenSource = new CancellationTokenSource(); CancellationToken cancellationToken = cancellationTokenSource.Token; LoadingPrompt.Visibility = Visibility.Visible; Task task = new Task(() => { Dictionary <string, string> dic = new Dictionary <string, string>(); dic.Add("mid", mid.ToString()); dic.Add("ps", "30"); dic.Add("pn", page.ToString()); try { Json.Value json = BiliApi.GetJsonResult("https://api.bilibili.com/x/space/arc/search", dic, true); Dispatcher.Invoke(new Action(() => { foreach (Json.Value v in json["data"]["list"]["vlist"]) { ResultBox.Video video = new ResultBox.Video(v); ResultVideo resultVideo = new ResultVideo(video); resultVideo.PreviewMouseLeftButtonDown += ResultVideo_PreviewMouseLeftButtonDown; ContentPanel.Children.Add(resultVideo); } if (init) { int pages = (int)Math.Ceiling((double)json["data"]["page"]["count"] / json["data"]["page"]["ps"]); PagesBox.SetPage(pages, 1, true); } PagesBox.Visibility = Visibility.Visible; LoadingPrompt.Visibility = Visibility.Hidden; })); } catch (Exception) { } Dispatcher.Invoke(new Action(() => { LoadingPrompt.Visibility = Visibility.Hidden; })); }, cancellationTokenSource.Token); task.Start(); }
public void LoadAsync(int mid, int page, bool init) { Mid = mid; if (cancellationTokenSource != null) { cancellationTokenSource.Cancel(); } ContentViewer.ScrollToHome(); ContentPanel.Children.Clear(); PagesBox.Visibility = Visibility.Hidden; cancellationTokenSource = new CancellationTokenSource(); CancellationToken cancellationToken = cancellationTokenSource.Token; LoadingPrompt.Visibility = Visibility.Visible; Task task = new Task(() => { Dictionary <string, string> dic = new Dictionary <string, string>(); dic.Add("mid", mid.ToString()); dic.Add("pagesize", "30"); dic.Add("page", page.ToString()); try { IJson json = BiliApi.GetJsonResult("https://space.bilibili.com/ajax/member/getSubmitVideos", dic, true); Dispatcher.Invoke(new Action(() => { foreach (IJson v in json.GetValue("data").GetValue("vlist")) { ResultBox.Video video = new ResultBox.Video(v); ResultVideo resultVideo = new ResultVideo(video); resultVideo.PreviewMouseLeftButtonDown += ResultVideo_PreviewMouseLeftButtonDown; ContentPanel.Children.Add(resultVideo); } if (init) { PagesBox.SetPage((int)json.GetValue("data").GetValue("pages").ToLong(), 1, true); } PagesBox.Visibility = Visibility.Visible; LoadingPrompt.Visibility = Visibility.Hidden; })); } catch (Exception) { } Dispatcher.Invoke(new Action(() => { LoadingPrompt.Visibility = Visibility.Hidden; })); }, cancellationTokenSource.Token); task.Start(); }
/// <summary> /// Search a text asynchronously. /// </summary> /// <param name="text">text</param> public void SearchAsync(string text, int pagenum) { if (cancellationTokenSource != null) { cancellationTokenSource.Cancel(); } ContentViewer.ScrollToHome(); ContentPanel.Children.Clear(); PagesBox.Visibility = Visibility.Hidden; if (text != null && text.Trim() != string.Empty) { HistoryBox.Insert(text); HistoryBox.Visibility = Visibility.Hidden; TypeBtn.IsChecked = true; cancellationTokenSource = new CancellationTokenSource(); CancellationToken cancellationToken = cancellationTokenSource.Token; LoadingPrompt.Visibility = Visibility.Visible; Task task = new Task(() => { string type = NavType; IJson json = GetResult(text, type, pagenum); if (json != null) { Dispatcher.Invoke(new Action(() => { if (cancellationToken.IsCancellationRequested) { return; } ShowResult(json, type); PagesBox.SetPage((int)json.GetValue("data").GetValue("numpages").ToLong(), (int)json.GetValue("data").GetValue("page").ToLong(), false); PagesBox.Visibility = Visibility.Visible; LoadingPrompt.Visibility = Visibility.Hidden; })); } }); task.Start(); } else { HistoryBox.Visibility = Visibility.Visible; } }