public async Task Execute(StatisticsCollectorOperationContext operationContext)
        {
            operationContext.OperationStateMessage = string.Empty;
            foreach (var accountInfo in operationContext.Accounts)
            {
                var accountInfoFromWg = await _wargamingApiClient.GetAccountInfoAllStatisticsAsync(
                    accountInfo.CurrentAccountInfo.AccountId,
                    accountInfo.CurrentAccountInfo.AccessToken);

                accountInfo.WargamingAccountInfo       = accountInfoFromWg;
                operationContext.OperationStateMessage = $"Got account info from WG for account {accountInfo.CurrentAccountInfo.AccountId}; ";
            }
        }
Пример #2
0
        public async Task <AccountInfoDto> GetAccountInfo(long accountId)
        {
            // For simplicity I have put the whole logic of getting and calculating account information here.
            // This method need to be refactored. It should be separated by small steps, and each step should be tied into the pipe,
            // And here shold be called just one method of that piped operation. Same operation is implemented here https://github.com/DrMboga/WotBlitzStatician
            await LoadDictionaries();

            var accountInfoMapper = new AccountInfoToDtoMapper();
            var accountStatistics = await _wargamingApiClient.GetAccountInfoAllStatisticsAsync(accountId, null);

            if (accountStatistics?.AccountInfoStatistics == null ||
                accountStatistics.AccountInfoStatistics.Count == 0 ||
                accountStatistics.AccountInfoStatistics.Single().Battles == 0)
            {
                throw new ArgumentException("This player haven't played World Of Tanks Blitz yet");
            }

            // Getting Clan info step
            accountStatistics.AccountClanInfo = await _wargamingApiClient.GetAccountClanInfoAsync(accountId);

            // Getting Achevements step
            var accountInfoAchievements = await _wargamingApiClient.GetAccountAchievementsAsync(accountId);

            // Getting player's tanks list step
            var tanks = await _wargamingApiClient.GetTanksStatisticsAsync(accountId, null);

            // Calculating middle tier step
            accountStatistics.AccountInfoStatistics.Single().CalculateMiddleTier(
                tanks,
                _wargamingDictionaries.VehicleEncyclopedia.GetTanksTires());

            // Calculating Wn7 effectivity parameter
            accountStatistics.AccountInfoStatistics.Single().CalculateWn7();

            // Mapping result to the viewmodel dto
            var returningAccount = accountInfoMapper.Map(accountStatistics);

            // Getting meaningful achievements for the view
            returningAccount.Achievements = MapMeaningfulAchievements(accountInfoAchievements);

            // Getting top 3 tanks
            returningAccount.TopTanks = GetTopTanks(tanks, 3);

            return(returningAccount);
        }