Пример #1
0
        public async Task <IMusicGenreGetResponse> GetMusicGenreAsync(IMusicGenreGetRequest request)
        {
            if (WebBrowserNavigator.WebBrowser.Url?.AbsoluteUri != ChunithmNetUrl.MusicGenre)
            {
                await WebBrowserNavigator.NavigateAsync(ChunithmNetUrl.MusicGenre);
            }

            {
                var documente      = WebBrowserNavigator.WebBrowser.Document;
                var musicGenreForm = documente.GetElementById("music_genre");
                var genre          = musicGenreForm.GetElementsByTagName("select").OfType <HtmlElement>().FirstOrDefault();
                genre.SetAttribute("value", request.GenreCode.ToString());
            }

            var   musicGenre = WebBrowserNavigator.InvokeScriptAsync("formSubmitAddParam", new[] { "music_genre", ToDifficultyParam(request.Difficulty) });
            await musicGenre;

            var response = new MusicGenreGetResponse(WebBrowserNavigator.WebBrowser);

            if (response.Success)
            {
                var musicGenreParser = new MusicGenreParser();
                response.MusicGenre = musicGenreParser.Parse(WebBrowserNavigator.WebBrowser.DocumentText);
            }
            return(response);
        }
Пример #2
0
        public async Task <IMusicGenreGetResponse> GetMusicGenreAsync(IMusicGenreGetRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            if (WebBrowserNavigator.WebBrowser.Address != ChunithmNetUrl.MusicGenre)
            {
                await WebBrowserNavigator.LoadAsync(ChunithmNetUrl.MusicGenre);
            }

            await WebBrowserNavigator.EvaluatePageMoveScriptAsync($@"
var genreSelecter  = document.getElementsByName('genre')[0];
genreSelecter.value = { request.GenreCode };
formSubmitAddParam('music_genre','{ ToDifficultyParam(request.Difficulty) }');
");

            var   responseAsync = MusicGenreGetResponse.CreateResponseAsync(WebBrowserNavigator.WebBrowser);
            await responseAsync;
            var   response = responseAsync.Result;

            if (response.Success)
            {
                var musicGenreParser = new MusicGenreParser();
                response.MusicGenre = musicGenreParser.Parse(response.DocumentText);
            }
            return(response);
        }
Пример #3
0
        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");
        }