public string getLyricSynchron(string artist, string title) { this.artist = artist; this.title = title; try { // Step 1: search title as it is lyricsResult = lyricWiki.getSong(this.artist, this.title); if (isLyric(lyricsResult.lyrics)) { return lyricsResult.lyrics; } //Thread.Sleep(1000); //// Step 2: search with parentheses and other disturbance removed //optimizeString(ref this.artist, ref this.title); //lyricsResult = lyricWiki.getSongResult(this.artist, this.title); //if (isLyric(lyricsResult.lyrics)) //{ // return lyricsResult.lyrics; //} //Thread.Sleep(1000); //// Step 3: search with altered and strings if any //this.artist = LyricUtil.changeAnd_and_and(this.artist); //this.title = LyricUtil.changeAnd_and_and(this.title); //lyricsResult = lyricWiki.getSongResult(this.artist, this.title); //if (isLyric(lyricsResult.lyrics)) //{ // return lyricsResult.lyrics; //} //Thread.Sleep(3000); // final step: return "Not found" if no lyric found return "Not found"; } catch (Exception e) { //System.Windows.Forms.MessageBox.Show(e.ToString()); //System.Windows.Forms.MessageBox.Show(lyricsResult.); Console.Write(e.Message); return ""; } }
private bool SearchForWiki() { DelegateClass del = lyricWiki.getSong; IAsyncResult ar = del.BeginInvoke(this.artist, this.title, null, null); while (noOfTries < 9) { // If the user has aborted stop the search and return (false) if (Abort || lyricSearch.SearchHasEnded) return false; else if (ar.AsyncWaitHandle.WaitOne(0, true)) { lyricsResult = del.EndInvoke(ar); string lyric = lyricsResult.lyrics; Encoding iso8859 = Encoding.GetEncoding("ISO-8859-1"); lyricsResult.lyrics = Encoding.UTF8.GetString(iso8859.GetBytes(lyricsResult.lyrics)); break; } else { // if we don't allow this pause of 2 sec the webservice behaves in a strange maneur Thread.Sleep(2000); } ++noOfTries; } if (lyricsResult != null && IsLyric(lyricsResult.lyrics)) { return true; } else { noOfTries = 0; return false; } }
private bool searchForWiki(string artist, string title) { DelegateClass del = lyricWiki.getSongResult; IAsyncResult ar = del.BeginInvoke(this.artist, this.title, null, null); while (noOfTries < 15) { // If the user has aborted stop the search and return (false) if (Abort) return false; if (ar.AsyncWaitHandle.WaitOne(0, true)) { lyricsResult = del.EndInvoke(ar); break; } else { // if we don't allow this pause of 2 sec the webservice behaves in a strange maneur Thread.Sleep(2000); } ++noOfTries; } if (lyricsResult != null && isLyric(lyricsResult.lyrics)) { return true; } else { noOfTries = 0; return false; } }