Exemplo n.º 1
0
            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);
            }
Exemplo n.º 2
0
            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);
            }