protected LogModel GetLog(MethodResult methodResult) { var loggerType = methodResult.Success ? LoggerTypes.Success : LoggerTypes.Exception; var newLog = new LogModel(loggerType, $"{ModuleName} : {methodResult.MethodName + " " + methodResult.Message}", "", methodResult.Error); return(newLog); }
private static async Task <MethodResult <string> > StartSolveCaptchaTask(string captchaKey, string captchaUrl) { var methodResult = new MethodResult <string>(); var postData = $"key={captchaKey}&method=userrecaptcha&googlekey={RecaptchaSiteKey}&proxy=0&proxytype=SOCKS4&pageurl={captchaUrl}"; try { string result = SendRecaptchav2RequestTask(CaptchaIn, postData); if (result.Contains("OK|")) { methodResult.Data = result.Substring(3, result.Length - 3); methodResult.Success = true; } else { methodResult.Message = result; methodResult.Success = false; } } catch (Exception ex) { methodResult.Message = ex + "\n\t" + ex.StackTrace; methodResult.Success = false; } return(methodResult); }
private static async Task <MethodResult <string> > GetSolvedCaptchaTask(string captchaKey, string captchaId) { var methodResult = new MethodResult <string>(); var postData = $"key={captchaKey}&action=get&id={captchaId}"; try { string result = SendRecaptchav2RequestTask(CaptchaOut, postData); while (result.Contains("CAPCHA_NOT_READY")) { await Task.Delay(750); result = SendRecaptchav2RequestTask(CaptchaOut, postData); } if (result.Contains("OK|")) { methodResult.Data = result.Substring(3, result.Length - 3); methodResult.Success = true; } else { methodResult.Message = result; methodResult.Success = false; } } catch (Exception ex) { methodResult.Message = ex + "\n\t" + ex.StackTrace; methodResult.Success = false; } return(methodResult); }
public static async Task <MethodResult <string> > GetCaptchaResponse(string captchaKey, string captchaUrl) { MethodResult <string> startSolveCaptchaTaskResults = await StartSolveCaptchaTask(captchaKey, captchaUrl); if (!startSolveCaptchaTaskResults.Success) { return(startSolveCaptchaTaskResults); } return(await GetSolvedCaptchaTask(captchaKey, startSolveCaptchaTaskResults.Data)); }
private static async Task <MethodResult> RetryAction(Func <string, string, IManager, Task <MethodResult> > action, string captchaKey, string captchaUrl, IManager manager, int tryCount) { var tries = 1; var methodResult = new MethodResult(); while (tries < tryCount) { methodResult = await action(captchaKey, captchaUrl, manager); if (!methodResult.Success) { tries++; } if (methodResult.Success) { break; } await Task.Delay(1000); } return(methodResult); }