Ejemplo n.º 1
0
        public void StartTest()
        {
            try
            {
                var requestUrls = HelperUtils.ReadXmlFromUrl(url);
                WriteLogEvent?.Invoke(string.Format("Get href count: {0}", requestUrls.Count));
                if (requestUrls != null && requestUrls.Any())
                {
                    IEnumerable <Task> tasks = from url in requestUrls select SendRequest(url);

                    var requestTask = tasks.ToArray();
                    Task.WaitAll(requestTask);
                }
                WriteLogEvent?.Invoke("Request done!");
            }
            catch (Exception ex)
            {
                WriteLogEvent?.Invoke(string.Format("Can not open this url:{0}{1}Exception:{2}", url, Environment.NewLine, ex.Message));
            }
        }
Ejemplo n.º 2
0
        public async Task SendRequest(string requestUrl)
        {
            try
            {
                using (HttpClient httpClient = new HttpClient())
                {
                    var response = await httpClient.GetAsync(requestUrl);

                    var result = response.IsSuccessStatusCode;
                    WriteLogEvent?.Invoke(string.Format("Send request url: {0}, Result: {1}, ResponseCode:{2}", requestUrl, response.IsSuccessStatusCode ? "Success" : "Falied", response.StatusCode.ToString()));
                    if (!response.IsSuccessStatusCode)
                    {
                        WriteFaliedUrlEvent?.Invoke(requestUrl);
                    }
                }
            }
            catch (Exception ex)
            {
                WriteLogEvent?.Invoke(string.Format("Send request url: {0}, Result: Failed, Because error has happend:{1}", requestUrl, ex.ToString()));
                WriteFaliedUrlEvent?.Invoke(requestUrl);
            }
        }
Ejemplo n.º 3
0
        public override UserInfo Login(string userName, string pass, string code = "")
        {
            try
            {
                HttpItem cookieItem = new HttpItem()
                {
                    Host      = GetHost(base.Url),
                    URL       = Url + "/ssid1?url=/",
                    Accept    = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
                    Method    = "GET",
                    UserAgent = "Mozilla/5.0(WindowsNT10.0;WOW64)AppleWebKit/537.36(KHTML,likeGecko)Chrome/71.0.3578.98Safari/537.36",
                    Cookie    = "ssid1=8f08f51f9c3a4f47d0a81569d0296baf; random=8135; affid=null",
                };
                var cookieRes = helper.GetHtml(cookieItem);
                var cookie    = cookieRes.Cookie;

                HttpItem loginItem = new HttpItem()
                {
                    Host      = GetHost(Url),
                    URL       = Url + "/web/rest/cashlogin?account=" + userName + "&password="******"application/json,text/plain,*/*",
                    Method    = "Post",
                    UserAgent = "Mozilla/5.0(WindowsNT10.0;WOW64)AppleWebKit/537.36(KHTML,likeGecko)Chrome/71.0.3578.98Safari/537.36",
                    Cookie    = cookie
                };
                var loginRes  = helper.GetHtml(loginItem);
                var obj       = JObject.Parse(loginRes.Html);
                var issuccess = obj["success"].ToString();
                if (issuccess.ToLower() != "true")
                {
                    WriteLogEvent.Invoke("登录失败:" + loginRes.Html); return(null);
                }
                var      agreenPar      = obj["message"].ToString();
                HttpItem agreenHtmlItem = new HttpItem()
                {
                    Host      = GetHost(Url),
                    URL       = Url + "/member/agreement?" + agreenPar,
                    Accept    = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
                    Method    = "GET",
                    UserAgent = "Mozilla/5.0(WindowsNT10.0;WOW64)AppleWebKit/537.36(KHTML,likeGecko)Chrome/71.0.3578.98Safari/537.36",
                    Cookie    = cookie
                };
                var agreeRes = helper.GetHtml(agreenHtmlItem);

                var date      = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
                var timestamp = DateTimeTools.GetTimeStamp(date);

                agreeRes.Cookie = agreeRes.Cookie.Replace("HttpOnly,", "");
                agreeRes.Cookie = agreeRes.Cookie.Replace("HttpOnly", "");
                agreeRes.Cookie = agreeRes.Cookie + "_skin_=blue; defaultLT=SGFT; " + cookie + ";";
                base.Cookie     = agreeRes.Cookie;

                UserInfo userInfo = new UserInfo();
                userInfo.LoginCookie = agreeRes.Cookie;
                var balance = GetMoneyStr();
                userInfo.Money = Convert.ToDecimal(balance);
                userInfo.State = "登陆成功";
                WriteLogEvent.Invoke("会员登录成功");
                return(userInfo);
            }
            catch (Exception ee)
            {
                WriteLogEvent.Invoke("登录失败"); return(null);
            }
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Запуск события записи лога.
 /// </summary>
 /// <param name="message"> Сообщение лога. </param>
 public static void WriteLine(string message)
 {
     WriteLogEvent?.Invoke($@"{DateTime.Now} {message}");
 }