public async Task <IMusicLevelGetResponse> GetMusicLevelAsync(IMusicLevelGetRequest request) { if (WebBrowserNavigator.WebBrowser.Url?.AbsoluteUri != ChunithmNetUrl.MusicLevel) { await WebBrowserNavigator.NavigateAsync(ChunithmNetUrl.MusicLevel); } { var document = WebBrowserNavigator.WebBrowser.Document; var content = document.GetElementById("inner"); var form = content.GetElementsByTagName("form").OfType <HtmlElement>().FirstOrDefault(); var select = form.GetElementsByTagName("select").OfType <HtmlElement>().FirstOrDefault(); select.SetAttribute("value", request.Level.ToString()); var raiseEvent = RaiseEventAsync(); select.RaiseEvent("onChange"); await raiseEvent; } var response = new MusicLevelGetResponse(WebBrowserNavigator.WebBrowser); if (response.Success) { var musicLevelParser = new MusicLevelParser(); response.MusicLevel = musicLevelParser.Parse(WebBrowserNavigator.WebBrowser.DocumentText); } return(response); }
public async Task <IMusicLevelGetResponse> GetMusicLevelAsync(IMusicLevelGetRequest request) { if (request == null) { throw new ArgumentNullException(nameof(request)); } if (WebBrowserNavigator.WebBrowser.Address != ChunithmNetUrl.MusicLevel) { await WebBrowserNavigator.LoadAsync(ChunithmNetUrl.MusicLevel); } await WebBrowserNavigator.EvaluatePageMoveScriptAsync($@" var levelSelecter = document.getElementsByName('level')[0]; levelSelecter.value = {request.Level}; changeSelecter(levelSelecter); "); var responseAsync = MusicLevelGetResponse.CreateResponseAsync(WebBrowserNavigator.WebBrowser); await responseAsync; var response = responseAsync.Result; if (response.Success) { var musicLevelParser = new MusicLevelParser(); response.MusicLevel = musicLevelParser.Parse(response.DocumentText); } return(response); }
private async void 楽曲更新ToolStripMenuItem_Click(object sender, EventArgs e) { var maxLevel = 14; var loadNum = maxLevel + 1; Console.WriteLine($"楽曲の取得中... (1/{loadNum})"); var musicGenre = chunithmNetBackgroundConnector.GetMusicGenreAsync(Utility.GENRE_ALL_CODE, Difficulty.Master); await musicGenre; if (!musicGenre.Result.Success) { Console.WriteLine("!! Failed !!"); Console.WriteLine("Error Code : " + musicGenre.Result.ErrorCode); Console.WriteLine(musicGenre.Result.ErrorMessage); return; } var musicGenreDocument = musicGenre.Result.DocumentText; var musicLevelDocuments = new List <string>(); for (var i = 1; i <= maxLevel; i++) { Console.WriteLine($"楽曲の取得中... ({i + 1}/{loadNum})"); var musicLevel = chunithmNetBackgroundConnector.GetMusicLevelAsync(i); await musicLevel; if (!musicLevel.Result.Success) { Console.WriteLine("!! Failed !!"); Console.WriteLine("Error Code : " + musicLevel.Result.ErrorCode); Console.WriteLine(musicLevel.Result.ErrorMessage); return; } musicLevelDocuments.Add(musicLevel.Result.DocumentText); } Console.WriteLine("Success"); Console.WriteLine("楽曲テーブルを生成します..."); var musicDataTable = new MusicDataTable(); var musicGenreParser = new MusicGenreParser(); var musicLevelParser = new MusicLevelParser(); musicDataTable.Add(musicGenreParser.Parse(musicGenreDocument)); foreach (var musicLevel in musicLevelDocuments) { musicDataTable.Add(musicLevelParser.Parse(musicLevel)); } var tableUpdate = dataManagerConnector.UpdateTableAsync(musicDataTable.MusicDatas); await tableUpdate; Console.WriteLine("Success"); }