Пример #1
0
 /// <summary>
 /// Request data to current special url
 /// </summary>
 /// <param name="o">request data</param>
 private void Request(object o)
 {
     //Check login
     if (!LoginList.ContainsKey(modelProvider.CurrentSiteName))
     {
         ($"Please Login Site : { modelProvider.CurrentSiteName } \n{DateTime.Now.ToString()}").showInMessageBox();
         return;
     }
     //Set encoding
     if (netRequestProvider.encoding != modelProvider.Encoding)
     {
         netRequestProvider.encoding = modelProvider.Encoding;
     }
     //Request
     if (IsHttpPost)
     {
         string[] postdata = getPostValue();
         if (postdata == null || postdata.Length < 1)
         {
             developerMessage("Post string error, action not do");
         }
         else
         {
             string poststring = string.Empty;
             poststring = modelProvider.postFormat(postdata);
             requestWith(modelProvider.getUrl(), poststring);
         }
     }
     else
     {
         requestWith(modelProvider.getUrl());
     }
 }
Пример #2
0
        /// <summary>
        /// Request data to login page
        /// </summary>
        /// <param name="o"></param>
        private async void LoginRequest(object o)
        {
            if (isRightUserName(UserName))
            {
                string siteName = SiteName;
                //0.SET MODEL TO LOGIN STATE
                modelProvider.useSite(siteName.ToLower() == "szhxy" ? StoredSiteName.Szhxy : StoredSiteName.Bkjw);
                modelProvider.setLogin();
                netRequestProvider.encoding = modelProvider.Encoding;

                //1.LOGOUT LOGINED USER
                if (LoginList.ContainsKey(siteName))
                {
                    RequestResult = await netRequestProvider.HttpGet(modelProvider.LogoutUrl, "");

                    LoginList.Remove(siteName);
                }

                //2.GET PASSWORD AND SAVE BYTE[] FOR STORE USER DATA
                byte[] tempBytes = null;
                IntPtr p         = System.Runtime.InteropServices.Marshal.SecureStringToBSTR(((o as System.Windows.Controls.PasswordBox).SecurePassword));
                string psw       = System.Runtime.InteropServices.Marshal.PtrToStringBSTR(p);
                if (RememberUser || rememberFailUser)
                {
                    tempBytes = UTF8Encoding.UTF8.GetBytes(psw);
                    if (rememberFailUser)
                    {
                        storeUser(ref tempBytes);
                    }
                }

                //3.COMBINE POST DATA AND SHOW DEVELOPER MESSAGE
                string data = modelProvider.postFormat(UserName, psw);
                developerMessage(modelProvider.getUrl() + "\n" + data);

                //4.REQUEST POST ACTION
                RequestResult = await basicHttpRuquest(new RunHttpRequest(netRequestProvider.HttpPost), modelProvider.LoginUrl, data);

                //5.HAND RESULT BY CHECK LOGIN STATE
                bool loginState = false;
                if (siteName == "Szhxy")
                {
                    modelProvider.usePage(SpecialPage.szhxyCheckLogin);

                    string rule   = modelProvider.getParsingRules();
                    string result = await basicHttpRuquest(new RunHttpRequest(netRequestProvider.HttpGet), modelProvider.getUrl(), string.Empty);

                    loginState = Regex.IsMatch(result, rule);
                }
                else
                {
                    loginState = checkBkjwLogin(RequestResult, UserName);
                }
                if (loginState)
                {
                    Dictionary <string, string> tempList = new Dictionary <string, string>(loginList);
                    tempList.Add(siteName, UserName);
                    LoginList = tempList;
                    if (RememberUser)
                    {
                        storeUser(ref tempBytes);
                    }

                    SetRequest(MenuItems[0]);
                    sendToConsole(UserName + "(" + siteName + ") Login successful!");
                }
            }
        }