コード例 #1
0
        public Home()
        {
            InitializeComponent();
            #region 获取歌曲
            new Thread(a =>
            {
                Song[] getSongs = new Song[0];
                try
                {
                    getSongs = Song.GetHotMusic(1, 20);
                }
                catch (Exception ex)
                {
                    var reslut = Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                    {
                        Frame.Navigate(typeof(Fail), new Error {
                            ErrorCode = ex.Message, ReTryPage = typeof(Home)
                        });
                    });
                    while (true)
                    {
                        if (reslut.Status == AsyncStatus.Completed)
                        {
                            return;
                        }
                    }
                }

                foreach (Song songTemp in getSongs)
                {
                    Invoke(new Action(delegate
                    {
                        songs.Add(songTemp);
                    }));
                }

                getSongs = null;
            })
            {
                IsBackground = true
            }.Start();
            #endregion

            #region 获取 Banners
            new Thread(a =>
            {
                Banner[] getBanners = new Banner[0];
                try
                {
                    getBanners = Banner.GetBanners();
                }
                catch (Exception ex)
                {
                    var reslut = Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                    {
                        Frame.Navigate(typeof(Fail), new Error {
                            ErrorCode = ex.Message, ReTryPage = typeof(Home)
                        });
                    });
                    while (true)
                    {
                        if (reslut.Status == AsyncStatus.Completed)
                        {
                            return;
                        }
                    }
                }

                foreach (Banner bannerTemp in getBanners)
                {
                    Invoke(new Action(delegate
                    {
                        banners.Add(bannerTemp);
                    }));
                }

                getBanners = null;
            })
            {
                IsBackground = true
            }.Start();
            #endregion

            #region 获取歌手
            new Thread(a =>
            {
                Vocal[] getVocals = new Vocal[0];
                try
                {
                    getVocals = Vocal.GetVocalList("Id", "", 1, 20, "Watch", "desc");
                }
                catch (Exception ex)
                {
                    var reslut = Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                    {
                        Frame.Navigate(typeof(Fail), new Error {
                            ErrorCode = ex.Message, ReTryPage = typeof(Home)
                        });
                    });
                    while (true)
                    {
                        if (reslut.Status == AsyncStatus.Completed)
                        {
                            return;
                        }
                    }
                }

                foreach (Vocal vocalTemp in getVocals)
                {
                    Invoke(new Action(delegate
                    {
                        vocals.Add(vocalTemp);
                    }));
                }
            })
            {
                IsBackground = true
            }.Start();
            #endregion

            #region 获取歌单
            new Thread(a =>
            {
                SongListList[] getSongLists = new SongListList[0];
                try
                {
                    getSongLists = SongListList.GetSongListList("Id", "", 1, 20, "CreateTime", "desc");
                }
                catch (Exception ex)
                {
                    var reslut = Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                    {
                        Frame.Navigate(typeof(Fail), new Error {
                            ErrorCode = ex.Message, ReTryPage = typeof(Home)
                        });
                    });
                    while (true)
                    {
                        if (reslut.Status == AsyncStatus.Completed)
                        {
                            return;
                        }
                    }
                }

                foreach (SongListList songListTemp in getSongLists)
                {
                    Invoke(new Action(delegate
                    {
                        songLists.Add(songListTemp);
                    }));
                }
            })
            {
                IsBackground = true
            }.Start();
            #endregion
        }
コード例 #2
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            songListId           = (string)e.Parameter;
            LoadingRing.IsActive = true;
            if (songListId != null)
            {
                Log.WriteLine("[GUI]跳转到歌单: " + songListId, Level.Info);
                new Thread(a =>
                {
                    Song[] getSongs = null;
                    try
                    {
                        songListList = SongListList.GetSongListList("Id", songListId, 1, 1, "Id", "dasc");
                        getSongs     = Modules.SongList.GetSongListSong(songListId);
                    }
                    catch (Exception ex)
                    {
                        Invoke(new Action(delegate
                        {
                            Frame.Navigate(typeof(Fail), new Error {
                                ErrorCode = ex.Message, CanBackHome = true, ReTryPage = typeof(VTuber), ReTryArgs = songListId
                            });
                        }));
                    }

                    if (getSongs != null)
                    {
                        Invoke(new Action(delegate
                        {
                            songs.Clear();
                            for (int i = 0; i != getSongs.Length; i++)
                            {
                                songs.Add(getSongs[i]);
                            }
                        }));
                    }

                    if (songListList != null)
                    {
                        Invoke(new Action(delegate
                        {
                            LoadingRing.IsActive             = false;
                            SongListName.Text                = songListList[0].Name;
                            intro.Text                       = songListList[0].introduce;
                            SongListCreator.Text             = songListList[0].CreatorRealName;
                            SongListCreatorImage.DisplayName = songListList[0].CreatorRealName;
                            BitmapImage bitmapImage          = new BitmapImage(new Uri(songListList[0].CoverImg));
                            SongListImage.Source             = (bitmapImage);
                            bitmapImage                      = null;
                            getSongs = null;
                            GC.Collect();
                        }));
                    }

                    songListList = null;
                }).Start();
            }
            else
            {
                Log.WriteLine("[GUI]跳转到歌单: 本地我喜欢歌单", Level.Info);
            }
        }
コード例 #3
0
        private void Pivot_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            pivot = (Pivot)sender;
            switch (pivot.SelectedIndex)
            {
                #region 歌曲搜索
            case 0:
                Log.WriteLine("[UI]搜索音乐: " + searchText, Level.Info);
                SongProgressRing.IsActive = true;
                new Thread(a =>
                {
                    Song[] songsArray = new Song[0];
                    try
                    {
                        songsArray = Song.GetMusicList("OriginName", searchText, 1, 200, "OriginName", "dasc");
                    }
                    catch (Exception ex)
                    {
                        Invoke(new Action(delegate {
                            SongProgressRing.IsActive = false;
                            Frame.Navigate(typeof(Fail), new Error {
                                ErrorCode = ex.Message, CanBackHome = true, ReTryPage = typeof(Search), ReTryArgs = searchText
                            });
                        }));
                    }

                    Invoke(new Action(delegate { SongProgressRing.IsActive = false; }));
                    if (songsArray.Length != 0)
                    {
                        Invoke(new Action(delegate
                        {
                            songs.Clear();
                            for (int i = 0; i != songsArray.Length; i++)
                            {
                                songs.Add(songsArray[i]);
                            }
                        }));
                    }
                    else
                    {
                        Invoke(new Action(delegate { SongFailText.Text = "找不到内容"; }));
                        Log.WriteLine("[UI]搜索音乐: " + searchText + " 失败", Level.Error);
                    }
                }).Start();
                break;

                #endregion
                #region VTuber 搜索
            case 1:
                Log.WriteLine("[UI]搜索 VTuber: " + searchText, Level.Info);
                VTuberProgressRing.IsActive = true;
                new Thread(a =>
                {
                    Vocal[] vocalsArray = new Vocal[0];
                    try
                    {
                        vocalsArray = Vocal.GetVocalList("OriginalName", searchText, 1, 200, "OriginalName", "desc");
                    }
                    catch (Exception ex)
                    {
                        Invoke(new Action(delegate {
                            Frame.Navigate(typeof(Fail), new Error {
                                ErrorCode = ex.Message, CanBackHome = true, ReTryPage = typeof(Search), ReTryArgs = searchText
                            });
                            VTuberProgressRing.IsActive = false;
                        }));
                    }

                    Invoke(new Action(delegate { VTuberProgressRing.IsActive = false; }));
                    if (vocalsArray.Length != 0)
                    {
                        Invoke(new Action(delegate
                        {
                            vocals.Clear();
                            for (int i = 0; i != vocalsArray.Length; i++)
                            {
                                vocals.Add(vocalsArray[i]);
                            }
                        }));
                    }
                    else
                    {
                        Invoke(new Action(delegate { VTuberFailText.Text = "找不到内容"; }));
                        Log.WriteLine("[UI]搜索 VTuber: " + searchText + " 失败", Level.Error);
                    }
                }).Start();
                break;

                #endregion
                #region 歌单搜索
            case 2:
                Log.WriteLine("[UI]搜索歌单: " + searchText, Level.Info);
                SongListProgressRing.IsActive = true;
                new Thread(a =>
                {
                    SongListList[] songListArray = new SongListList[0];
                    try
                    {
                        songListArray = SongListList.GetSongListList("Name", searchText, 1, 50, "Name", "desc");
                    }
                    catch (Exception ex)
                    {
                        Invoke(new Action(delegate {
                            Frame.Navigate(typeof(Fail), new Error {
                                ErrorCode = ex.Message, CanBackHome = true, ReTryPage = typeof(Search), ReTryArgs = searchText
                            });
                            SongListProgressRing.IsActive = false;
                        }));
                    }

                    Invoke(new Action(delegate { SongListProgressRing.IsActive = false; }));
                    if (songListArray.Length != 0)
                    {
                        Invoke(new Action(delegate
                        {
                            songLists.Clear();
                            for (int i = 0; i != songListArray.Length; i++)
                            {
                                songLists.Add(songListArray[i]);
                            }
                        }));
                    }
                    else
                    {
                        Invoke(new Action(delegate { SongListFailText.Text = "找不到内容"; }));
                        Log.WriteLine("[UI]搜索歌单: " + searchText + " 失败", Level.Error);
                    }
                }).Start();
                break;
                #endregion
            }
        }