Esempio n. 1
0
        public async Task <ILoginResponse> LoginAsync(ILoginRequest request)
        {
            if (!IsLoggedIn())
            {
                await GetToken();
            }

            var loginContent = new FormUrlEncodedContent(new Dictionary <string, string>()
            {
                { "segaId", request.SegaId },
                { "password", request.Password },
                { "token", token },
            });

            var   postLogin = client.PostAsync(ChunithmNetUrl.CreateUrl("submit"), loginContent);
            await postLogin;

            var   getAimeList = client.GetAsync(ChunithmNetUrl.CreateUrl("aimeList"));
            await getAimeList;

            var response = new LoginResponse(getAimeList.Result);

            if (response.Success)
            {
                var aimeListParser = new AimeListParser();
                response.AimeList = aimeListParser.Parse(response.DocumentText);
                if (response.AimeList == null)
                {
                    response.OnInvalidAimeList();
                }
            }

            return(response);
        }
        public async Task <ILoginResponse> LoginAsync(ILoginRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

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

            await WebBrowserNavigator.EvaluatePageMoveScriptAsync($@"
var inputs = document.getElementsByTagName('input');
var inputName = inputs[0];
var inputPassword = inputs[1];
inputName.value = '{request.SegaId}';
inputPassword.value = '{request.Password}';
formSubmit('sega_login');
");

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

            if (response.Success)
            {
                var aimeListParser = new AimeListParser();
                response.AimeList = aimeListParser.Parse(response.DocumentText);
            }

            return(response);
        }
        public async Task <ILoginResponse> LoginAsync(ILoginRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            if (WebBrowserNavigator.WebBrowser.Url?.AbsoluteUri != ChunithmNetUrl.Top)
            {
                await WebBrowserNavigator.NavigateAsync(ChunithmNetUrl.Top);
            }

            {
                var document      = WebBrowserNavigator.WebBrowser.Document;
                var inputs        = document.GetElementsByTagName("input");
                var segaIdInput   = inputs.GetElementsByName("segaId").OfType <HtmlElement>().FirstOrDefault();
                var passwordInput = inputs.GetElementsByName("password").OfType <HtmlElement>().FirstOrDefault();
                segaIdInput.SetAttribute("value", request.SegaId);
                passwordInput.SetAttribute("value", request.Password);
            }

            var   login = WebBrowserNavigator.InvokeScriptAsync("formSubmit", new[] { "sega_login" });
            await login;

            var response = new LoginResponse(WebBrowserNavigator.WebBrowser);

            if (response.Success)
            {
                var aimeListParser = new AimeListParser();
                response.AimeList = aimeListParser.Parse(WebBrowserNavigator.WebBrowser.DocumentText);
            }
            return(response);
        }
Esempio n. 4
0
        public void AimeListParser_Test1()
        {
            var aimeList = new AimeListParser().Parse(TestUtility.LoadResource("AimeList/html_test_case_1.html"));

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

            var units = aimeList.Units;

            Assert.AreEqual(1, units.Length, "件数チェック");
            {
                var unit = units[0];
                Assert.AreEqual(0, unit.RebornCount, "転生数");
                Assert.AreEqual(9, unit.Level, "ユーザーレベル");
                Assert.AreEqual("********", unit.Name, "ユーザー名");
                Assert.AreEqual(15.37, unit.NowRating, "現在レーティング");
                Assert.AreEqual(15.49, unit.MaxRating, "最大レーティング");
            }
        }
Esempio n. 5
0
        public void AimeListParser_Error_Test1()
        {
            var aimeList = new AimeListParser().Parse(TestUtility.LoadResource("Common/error_page.html"));

            Assert.IsNull(aimeList);
        }