private void LoadBeatmapData(int Beatmap) { Threaded.Add(() => { ApiRequestBeatmapDetail bm = ApiBase.Create <ApiRequestBeatmapDetail>(Beatmap.ToString()); this.Beatmap = bm.GetData <Beatmap>(); Dispatcher.Invoke(DispatcherPriority.Normal, new Action(this.DisplayData)); }); }
private void PerformBeatmapSearch() { ThreadPool.QueueUserWorkItem(new WaitCallback((object ob) => { List <string> Filters = new List <string>(); Dispatcher.Invoke(DispatcherPriority.Normal, new Action(() => { this.Overlay.BeginAnimation(Grid.OpacityProperty, new DoubleAnimation() { Duration = new Duration(new TimeSpan(0, 0, 0, 0, 500)), FillBehavior = FillBehavior.HoldEnd, From = 0.0, To = 1.0 }); this.Overlay.Visibility = Visibility.Visible; if (!string.IsNullOrWhiteSpace(this.SearchTitle.Text)) { Filters.Add(string.Format("maps.title.like.{0}", this.SearchTitle.Text)); } if (!string.IsNullOrWhiteSpace(this.SearchCreator.Text)) { Filters.Add(string.Format("metadata.m_creator.like.{0}", this.SearchCreator.Text)); } if (!string.IsNullOrWhiteSpace(this.SearchSource.Text)) { Filters.Add(string.Format("metadata.m_source.like.{0}", this.SearchSource.Text)); } if (!string.IsNullOrWhiteSpace(this.SearchTags.Text)) { Filters.Add(string.Format("metadata.m_tags.like.{0}", this.SearchTags.Text)); } if (this.SearchSizeMin.Value > 0) { Filters.Add(string.Format("maps.size.gteq.{0}", (int)(this.SearchSizeMin.Value * 1024.0 * 1024.0))); } if (this.SearchSizeMax.Value > 0) { Filters.Add(string.Format("maps.size.lteq.{0}", (int)(this.SearchSizeMax.Value * 1024.0 * 1024.0))); } if (this.SearchVersion.Value > 0) { Filters.Add(string.Format("metadata.version.eq.{0}", this.SearchVersion.Value)); } this.SearchResults.Items.Clear(); this.RawSearchResultList.Clear(); })); ApiRequestSearch search = ApiBase.Create <ApiRequestSearch>(Filters.ToArray()); List <Beatmap> data = search.GetData <List <Beatmap> >(); Dispatcher.Invoke(DispatcherPriority.Normal, new Action(() => { DoubleAnimation anim = new DoubleAnimation() { Duration = new Duration(new TimeSpan(0, 0, 0, 0, 500)), FillBehavior = FillBehavior.HoldEnd, From = 1.0, To = 0.0 }; anim.Completed += (object sender, EventArgs e) => { this.Overlay.Visibility = Visibility.Hidden; }; this.Overlay.BeginAnimation(Grid.OpacityProperty, anim); if (data == null) { return; } this.RawSearchResultList.AddRange(data); foreach (Beatmap bm in data) { this.SearchResults.Items.Add(bm); } })); })); }
private static void DownloadQueue() { QueueDownload qitem; while (true) { qitem = Queue.Take(); if (qitem.DownloadType == DownloadType.Beatmap) { ApiRequestBeatmapDownload Download = ApiBase.Create <ApiRequestBeatmapDownload>(qitem.Beatmap.Ranked_ID.ToString()); Download.EOnDownloadUpdate += (long Downloaded) => { if (FileUpdate != null) { FileUpdate(qitem.Beatmap, (int)Downloaded); } }; Download.EOnDownloadComplete += (byte[] Buffer) => { File.WriteAllBytes(string.Format("{0}\\{1}.{2}", Configuration.BeatmapDownloadLocation, Helpers.CleanFileName(qitem.Beatmap.Name), qitem.Beatmap.Type.ToString().ToLower()), Buffer); if (DownloadFinished != null) { DownloadFinished(qitem.Beatmap); } }; Download.SendRequest(); } else if (qitem.DownloadType == DownloadType.MP3) { ApiRequestBeatmapDownloadMP3 MP3Download = ApiBase.Create <ApiRequestBeatmapDownloadMP3>(qitem.Beatmap.Ranked_ID.ToString()); MP3Download.EOnDownloadUpdate += (long Downloaded) => { if (FileUpdate != null) { FileUpdate(qitem.Beatmap, (int)Downloaded); } }; MP3Download.EOnDownloadComplete += (byte[] Buffer) => { File.WriteAllBytes(string.Format("{0}\\{1}.mp3", Configuration.Mp3DownloadLocation, Helpers.CleanFileName(qitem.Beatmap.Title)), Buffer); if (DownloadFinished != null) { DownloadFinished(qitem.Beatmap); } }; MP3Download.EOnContentLength += (long ContentLength) => { qitem.Beatmap.Size = (int)ContentLength; }; MP3Download.SendRequest(); } } }