protected override void MyWorker_DoWork(object sender, DoWorkEventArgs e) { SingleBetData bet = (SingleBetData)e.Argument; if (bet == null) { return; } int myBetCount = 0; while (bet.MaxBet > myBetCount) { var rezult = _singleBetting.StartBetting(bet); ProcessResult(rezult, bet); OnSendResult?.Invoke(this, rezult); if (myWorker.CancellationPending) { e.Cancel = true; return; } myBetCount++; } e.Result = bet; }
public BetResultData StartBetting(MultipleBetData data) { if (data == null) { return(null); } PlaceAutomatedBetsResponse rezBet = DiceWebAPI.PlaceAutomatedBets(data.Session, data.AutoSettings); var rezult = new BetResultData { Session = data.Session }; if (rezBet.Success) { if (rezBet.TotalPayOut == 0) //запуск одиночных ставок { decimal baseBet; if (rezBet.BetCount > 1) { baseBet = rezBet.PayIns[rezBet.BetCount - 1] <= rezBet.PayIns[rezBet.BetCount - 2] ? 2 * rezBet.PayIns[rezBet.BetCount - 1] : 2 * rezBet.PayIns[rezBet.BetCount - 2]; } else { baseBet = 2 * rezBet.PayIns[rezBet.BetCount - 1]; } //сформировать исходные данные для одиночных ставок SingleBetData singlData = data.GetSingleData(); singlData.PayIn = baseBet; BetResultData singleResult = singleBetting.StartBetting(singlData); rezult.BetCount = rezBet.BetCount + singleResult.BetCount; rezult.Percent = singleResult.Percent; rezult.Profit = rezBet.TotalPayOut + singleResult.Profit; rezult.Balance = data.Session[data.Currency].Balance; } else //получен профит { rezult.BetCount = rezBet.BetCount; rezult.Percent = 0; rezult.Profit = rezBet.TotalPayOut + rezBet.TotalPayIn; rezult.Balance = data.Session[data.Currency].Balance; } } else { if (rezBet.InsufficientFunds) { OnFinishMoney?.Invoke(this, data); } else { Thread.Sleep(30000); } } return(rezult); }