public async Task <string> DoLogin(string name, string pass) { if (name.Length == 0 || pass.Length == 0) { return(AppResources.ErrorMsgNamePassEmpty); } string uid = null; bool isSuccess = false; try { IsBusy = true; if (!String.IsNullOrEmpty(Uid) && !string.IsNullOrEmpty(_formHash)) { await new S1WebClient().Logout(_formHash); } S1WebClient.ResetCookie(); var user = await new S1WebClient().Login(name, pass); uid = user.Member_uid; if (uid != null) { Uid = uid; LoginStatus = name; isSuccess = true; return(null); } return(AppResources.ErrorMsgUnknown); } catch (Exception ex) { var mainpage = IoC.Get <MainPageViewModel>(); var userEx = (ex as S1UserException); if ((ex is System.Net.WebException && DeviceNetworkInformation.IsNetworkAvailable) || (userEx != null && userEx.ErrorType == UserErrorTypes.InvalidData)) { ServerViewModel.Current.CheckServerStatus(mainpage); } return(S1Nyan.Utils.Util.ErrorMsg.GetExceptionMessage(ex)); } finally { IsBusy = false; _eventAggregator.Publish(new UserMessage(Messages.LoginStatusChanged, isSuccess)); } }
private async void DoTest() { client = new S1WebClient(); int fid = 2; //client.Headers[HttpRequestHeader.Referer] = "http://192.168.0.113:8080/phpwind/read.php?tid=1"; //client.AddPostParam("replytouser", "asdf"); //client.AddPostParam("cyid", "1"); //client.AddPostParam("iscontinue", "0"); //client.AddPostParam("atc_desc1", ""); //client.AddPostParam("_hexie", "36c309f2"); client.AddPostParam("atc_title", "12345"); client.AddPostParam("verify", verify); client.AddPostParam("atc_usesign", "1"); client.AddPostParam("atc_convert", "1"); client.AddPostParam("atc_autourl", "1"); client.AddPostParam("stylepath", "wind"); client.AddPostParam(stepKey, 2); client.AddPostParam("action", "reply"); client.AddPostParam("fid", fid); client.AddPostParam("tid", "1"); client.AddPostParam("ajax", "1"); client.AddPostParam("atc_content", "[s:13] test from client @" + DateTime.Now.ToShortTimeString() + deviceInfo); Result = await client.PostDataTaskAsync(new Uri(postFormatString + fid)); //Result = await client.PostMultipartTaskAsync(new Uri(postUrl)); string error = ""; var match = resultPattern.Match(Result); if (match.Success) { error = match.Groups["data"].Value; } if (error.Length < 200) { Debug.WriteLine(error); } if (OnUpdateView != null) { OnUpdateView(Result + ConvertExtendedASCII(error)); } }
public async void TestServer() { Status = "Connecting"; try{ client = new S1WebClient(); var result = await client.DownloadStringTaskAsync(Addr + path); Status = "Wrong Data"; if (result.Length > 0) { var root = new HtmlDoc(result).RootElement; var serverDownTitle = ServerListViewModel.ServerDownTitle; if (serverDownTitle != null && root.FindFirst("title").InnerHtml.Contains(serverDownTitle)) { Status = "Server Down"; if (NotifySuccess != null) { NotifySuccess(); } } else { if (NotifySuccess != null) { NotifySuccess(); } Status = "Success"; } } } catch (TaskCanceledException) { Status = "Cancled"; } catch (Exception) { Status = "Failed"; } }
public async Task <string> DoLogin(string name, string pass) { if (name.Length == 0 || pass.Length == 0) { return(AppResources.ErrorMsgNamePassEmpty); } string uid = null; bool isSuccess = false; try { IsBusy = true; if (!String.IsNullOrEmpty(Uid) && !string.IsNullOrEmpty(_formHash)) { await new S1WebClient().Logout(_formHash); } S1WebClient.ResetCookie(); var user = await new S1WebClient().Login(name, pass); uid = user.Member_uid; if (uid != null) { Uid = uid; LoginStatus = name; isSuccess = true; return(null); } return(AppResources.ErrorMsgUnknown); } catch (Exception ex) { return(S1Nyan.Utils.Util.ErrorMsg.GetExceptionMessage(ex)); } finally { IsBusy = false; _eventAggregator.Publish(new UserMessage(Messages.LoginStatusChanged, isSuccess)); } }
private async void DoLogin() { client = new S1WebClient(); client.AddPostParam(stepKey, 2); client.AddPostParam(loginTypeKey, loginType); client.AddPostParam(userKey, testUser); client.AddPostParam(passKey, testPass); client.AddPostParam(cktimeKey, cktime); Result = await client.PostDataTaskAsync(new Uri(loginUrl)); foreach (Cookie c in client.Cookies) { if (c.Name.Contains("uid")) { Uid = c.Value; } } if (OnUpdateView != null) { OnUpdateView(Result); } }