private static async Task <MethodResult> SignUp1(Account.Model account) { MethodResult methodResult = new MethodResult(); try { using (var client = new HttpClient()) { var csrfRetryResults = await RetryAction(GetCsrfAction, "GetCsrfAction", account, client, 5); if (csrfRetryResults.Success) { var verifyAgeRetryResults = await RetryAction(AgeVerifyAction, "AgeVerifyAction", account, client, 5); if (verifyAgeRetryResults.Success) { var startSolveCaptchaRetryResults = await RetryCaptchaAction(StartSolveCaptchaAction, "StartSolveCaptchaAction", account, 5); if (startSolveCaptchaRetryResults.Success) { var getSolvedCaptchaRetryResults = await RetryCaptchaAction(GetSolvedCaptchaAction, "GetSolvedCaptchaAction", account, 15); if (getSolvedCaptchaRetryResults.Success) { var profileSettingsRetryResults = await RetryAction(ProfileSettingsAction, "ProfileSettingsAction", account, client, 5); methodResult.Success = profileSettingsRetryResults.Success; } } } } } } catch (Exception ex) { methodResult.Error = ex; methodResult.Success = false; } return(methodResult); }
private static async Task <MethodResult> RetryAction(Func <Model, HttpClient, Task <MethodResult> > action, string actionName, Account.Model account, HttpClient client, int tryCount) { int tries = 1; MethodResult methodResult = new MethodResult(); account.AddLog(LoggerTypes.Debug, $"Starting {actionName}"); while (tries < tryCount) { methodResult = await action(account, client); var tryMsg = " Try #" + tries; if (methodResult.Success) { account.AddLog(LoggerTypes.Success, actionName + tryMsg); } else { tries++; account.AddLog(LoggerTypes.Exception, actionName + tryMsg, "", methodResult.Error); } OnEventRefreshAccount(account); if (account.EventLog.Count > 30) { account.EventLog.RemoveAt(0); } if (methodResult.Error != null && methodResult.Error.Message.Equals("Account Already Exists")) { break; } if (methodResult.Success) { break; } } return(methodResult); }
private static async Task <MethodResult> RetryCaptchaAction(Func <Model, Task <MethodResult> > action, string actionName, Account.Model account, int tryCount) { int tries = 1; MethodResult methodResult = new MethodResult(); account.AddLog(LoggerTypes.Debug, $"Starting {actionName}"); while (tries < tryCount) { methodResult = await action(account); var tryMsg = " Try #" + tries; if (methodResult.Success) { account.AddLog(LoggerTypes.Success, actionName + tryMsg); } else { tries++; account.AddLog(LoggerTypes.Exception, actionName + tryMsg, "", methodResult.Error); } OnEventRefreshAccount(account); if (account.EventLog.Count > 30) { account.EventLog.RemoveAt(0); } bool noneRecoverableError = methodResult.Error != null && (methodResult.Error.Message.Equals("ERROR_KEY_DOES_NOT_EXIST") || methodResult.Error.Message.Equals("ERROR_ZERO_BALANCE")); if (noneRecoverableError) { break; } if (methodResult.Success) { break; } } return(methodResult); }