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);
        }
        public void MusicLevelParser_Test1()
        {
            var musicLevel = new MusicLevelParser().Parse(TestUtility.LoadResource("MusicLevel/html_test_case_1.html"));

            Assert.IsNotNull(musicLevel, "パースチェック");

            Assert.AreEqual(41, musicLevel.MusicCount, "楽曲数");
            Assert.AreEqual(39, musicLevel.ClearCount, "クリア 楽曲数");
            Assert.AreEqual(39, musicLevel.SCount, "S 楽曲数");
            Assert.AreEqual(39, musicLevel.SsCount, "SS 楽曲数");
            Assert.AreEqual(39, musicLevel.SssCount, "SSS 楽曲数");
            Assert.AreEqual(39, musicLevel.FullComboCount, "フルコンボ 楽曲数");
            Assert.AreEqual(39, musicLevel.AllJusticeCount, "AJ 楽曲数");
            Assert.AreEqual(0, musicLevel.FullChainGoldCount, "フルチェイン(金) 楽曲数");
            Assert.AreEqual(0, musicLevel.FullChainPlatinumCount, "フルチェイン 楽曲数");

            var units = musicLevel.Units;

            Assert.AreEqual(3, units.Length, "件数チェック");
            {
                var unit = units[0];
                Assert.IsNotNull(unit);
                Assert.AreEqual(531, unit.Id, "ID");
                Assert.AreEqual("ホーリーナイト", unit.Name, "楽曲名");
                Assert.AreEqual(Difficulty.Master, unit.Difficulty, "難易度");
                Assert.AreEqual(10.7, unit.Level, "レベル");
                Assert.AreEqual(1009974, unit.Score, "スコア");
                Assert.AreEqual(Rank.SSS, unit.Rank, "ランク");
                Assert.AreEqual(true, unit.IsClear, "クリア");
                Assert.AreEqual(ComboStatus.AllJustice, unit.ComboStatus, "コンボランプ");
                Assert.AreEqual(ChainStatus.None, unit.ChainStatus, "チェインランプ");
            }
            {
                var unit = units[1];
                Assert.IsNotNull(unit);
                Assert.AreEqual(138, unit.Id, "ID");
                Assert.AreEqual("conflict", unit.Name, "楽曲名");
                Assert.AreEqual(Difficulty.Expert, unit.Difficulty, "難易度");
                Assert.AreEqual(10.7, unit.Level, "レベル");
                Assert.AreEqual(1010000, unit.Score, "スコア");
                Assert.AreEqual(Rank.SSS, unit.Rank, "ランク");
                Assert.AreEqual(true, unit.IsClear, "クリア");
                Assert.AreEqual(ComboStatus.AllJustice, unit.ComboStatus, "コンボランプ");
                Assert.AreEqual(ChainStatus.None, unit.ChainStatus, "チェインランプ");
            }
            {
                var unit = units[2];
                Assert.IsNotNull(unit);
                Assert.AreEqual(692, unit.Id, "ID");
                Assert.AreEqual("足立オウフwwww", unit.Name, "楽曲名");
                Assert.AreEqual(Difficulty.Expert, unit.Difficulty, "難易度");
                Assert.AreEqual(10.7, unit.Level, "レベル");
                Assert.AreEqual(0, unit.Score, "スコア");
                Assert.AreEqual(Rank.None, unit.Rank, "ランク");
                Assert.AreEqual(false, unit.IsClear, "クリア");
                Assert.AreEqual(ComboStatus.None, unit.ComboStatus, "コンボランプ");
                Assert.AreEqual(ChainStatus.None, unit.ChainStatus, "チェインランプ");
            }
        }
Beispiel #4
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");
        }
        public void MusicLevelParser_Test2()
        {
            var musicLevel = new MusicLevelParser().Parse(TestUtility.LoadResource("MusicLevel/html_test_case_2.html"));

            Assert.IsNotNull(musicLevel, "パースチェック");

            Assert.AreEqual(219, musicLevel.MusicCount, "楽曲数");
            Assert.AreEqual(215, musicLevel.ClearCount, "クリア 楽曲数");
            Assert.AreEqual(215, musicLevel.SCount, "S 楽曲数");
            Assert.AreEqual(215, musicLevel.SsCount, "SS 楽曲数");
            Assert.AreEqual(215, musicLevel.SssCount, "SSS 楽曲数");
            Assert.AreEqual(208, musicLevel.FullComboCount, "フルコンボ 楽曲数");
            Assert.AreEqual(192, musicLevel.AllJusticeCount, "AJ 楽曲数");
            Assert.AreEqual(2, musicLevel.FullChainGoldCount, "フルチェイン(金) 楽曲数");
            Assert.AreEqual(2, musicLevel.FullChainPlatinumCount, "フルチェイン 楽曲数");

            var units = musicLevel.Units;

            Assert.AreEqual(2, units.Length, "件数チェック");
            {
                var unit = units[0];
                Assert.IsNotNull(unit);
                Assert.AreEqual(354, unit.Id, "ID");
                Assert.AreEqual("ラブリー☆えんじぇる!!", unit.Name, "楽曲名");
                Assert.AreEqual(Difficulty.Master, unit.Difficulty, "難易度");
                Assert.AreEqual(12.0, unit.Level, "レベル");
                Assert.AreEqual(1009957, unit.Score, "スコア");
                Assert.AreEqual(Rank.SSS, unit.Rank, "ランク");
                Assert.AreEqual(true, unit.IsClear, "クリア");
                Assert.AreEqual(ComboStatus.AllJustice, unit.ComboStatus, "コンボランプ");
                Assert.AreEqual(ChainStatus.FullChainPlatinum, unit.ChainStatus, "チェインランプ");
            }
            {
                var unit = units[1];
                Assert.IsNotNull(unit);
                Assert.AreEqual(626, unit.Id, "ID");
                Assert.AreEqual("アンノウン・マザーグース", unit.Name, "楽曲名");
                Assert.AreEqual(Difficulty.Master, unit.Difficulty, "難易度");
                Assert.AreEqual(12.0, unit.Level, "レベル");
                Assert.AreEqual(1009614, unit.Score, "スコア");
                Assert.AreEqual(Rank.SSS, unit.Rank, "ランク");
                Assert.AreEqual(true, unit.IsClear, "クリア");
                Assert.AreEqual(ComboStatus.FullCombo, unit.ComboStatus, "コンボランプ");
                Assert.AreEqual(ChainStatus.None, unit.ChainStatus, "チェインランプ");
            }
        }
        public void MusicLevelParser_Error_Test1()
        {
            var musicLevel = new MusicLevelParser().Parse(TestUtility.LoadResource("Common/error_page.html"));

            Assert.IsNull(musicLevel);
        }