private async Task<AccountInfoResponse> SaveAccountAndTankInformation(AccountAndTanksContextRow accountAndTanksInfo)
        {
            var contextData = new AccountInformationPipelineContextData
            {
                AccountInfo = accountAndTanksInfo.AccountInfo,
                AccountInfoHistory = accountAndTanksInfo.AccountInfoHistory,
                Tanks = accountAndTanksInfo.Tanks,
                TanksHistory = accountAndTanksInfo.TanksHistory
            };

            var context = new OperationContext(new AccountRequest(contextData.AccountInfo?.AccountId ?? -1, RealmType.Ru, RequestLanguage.En));
            context.AddOrReplace(contextData);
            var pipeline = new Pipeline<IOperationContext>(_operationFactory);

            pipeline
                .AddOperation<CalculateStatisticsOperation>()
                .AddOperation<SaveAccountAndTanksOperation>()
                .AddOperation<BuildAccountInfoResponseOperation>()
                ;

            var firstOperation = pipeline.Build();
            if (firstOperation != null)
            {
                await firstOperation
                    .Invoke(context, null)
                    .ConfigureAwait(false);
            }
            return contextData?.Response ?? new AccountInfoResponse();
        }
Ejemplo n.º 2
0
        private async Task <AccountInfoResponse> GatherAndSaveAccountInformation(string accountFileName, string tanksFileName)
        {
            var contextData = new AccountInformationPipelineContextData();

            await SetAccountInfo(accountFileName, contextData);
            await SetTanksInfo(tanksFileName, contextData);

            var context = new OperationContext(new AccountRequest(contextData.AccountInfo?.AccountId ?? -1, Realm, RequestLanguage.En));

            context.AddOrReplace(contextData);
            var pipeline = new Pipeline <IOperationContext>(_operationFactory);

            pipeline
            .AddOperation <CalculateStatisticsOperation>()
            .AddOperation <SaveAccountAndTanksOperation>()
            .AddOperation <BuildAccountInfoResponseOperation>()
            ;

            var firstOperation = pipeline.Build();

            if (firstOperation != null)
            {
                await firstOperation
                .Invoke(context, null)
                .ConfigureAwait(false);
            }
            return(contextData?.Response ?? new AccountInfoResponse());
        }
Ejemplo n.º 3
0
        private async Task SetTanksInfo(string tanksInfoFileName, AccountInformationPipelineContextData contextData)
        {
            List <WotAccountTanksStatistics> tanksInfo = null;

            using (var r = new StreamReader(tanksInfoFileName))
            {
                var json = await r.ReadToEndAsync();

                var tanks = JsonConvert.DeserializeObject <ResponseBody <Dictionary <string, List <WotAccountTanksStatistics> > > >(json);
                tanksInfo = tanks.Data?.Values.FirstOrDefault();
            }


            if (tanksInfo == null)
            {
                throw new ApplicationException($"Can not read tanks info from '{tanksInfoFileName}'");
            }

            contextData.Tanks        = new List <TankInfo>();
            contextData.TanksHistory = new Dictionary <long, TankInfoHistory>();

            tanksInfo.OrderByDescending(t => t.LastBattleTime).ToList().ForEach(tank =>
            {
                var tankInfo = new TankInfo(tank.AccountId, tank.TankId);
                _mapper.Map(tank, tankInfo);
                contextData.Tanks.Add(tankInfo);
                var stat = new TankInfoHistory(tank.AccountId, tank.TankId, tank.LastBattleTime);
                _mapper.Map(tank.All, stat);
                contextData.TanksHistory[stat.TankId] = stat;
            });
        }
        public void Init()
        {
            InitDataAccessors();
            _operation = new ReadAccountInfoFromDbOperation(
                WargamingDataAccessorMock.Object);

            _contextData = new AccountInformationPipelineContextData();
        }
        public void Init()
        {
            _operation = new CheckLastBattleDateOperation(
                (new Mock <ILogger <CheckLastBattleDateOperation> >()).Object);

            _contextData = new AccountInformationPipelineContextData();
            FillAccountAndTanks(_contextData);
        }
        public void Init()
        {
            InitDataAccessors();
            _operation = new CalculateStatisticsOperation(
                DictionariesDataAccessorMock.Object);

            _contextData = new AccountInformationPipelineContextData();
            FillAccountAndTanks(_contextData);
            FillExpectedTanksWn7();
        }
        public void Init()
        {
            InitDataAccessors();
            _operation = new SaveAccountAndTanksOperation(
                WargamingDataAccessorMock.Object,
                (new Mock <ILogger <SaveAccountAndTanksOperation> >()).Object);

            _contextData = new AccountInformationPipelineContextData();
            FillAccountAndTanks(_contextData);
        }
Ejemplo n.º 8
0
        public void Init()
        {
            InitAutoMapper();
            InitWgApiClient();
            _operation = new GetAccountInfoOperation(
                WargamingApiClient,
                Mapper,
                (new Mock <ILogger <GetAccountInfoOperation> >()).Object);

            _contextData = new AccountInformationPipelineContextData();
        }
        protected void FillAccountAndTanks(AccountInformationPipelineContextData contextData)
        {
            var mappedAccountInfoHistory = File.ReadAllText(GetFixturePath("MappedAccountHistory.json"));
            var mappedTanks        = File.ReadAllText(GetFixturePath("MappedTanks.json"));
            var mappedTanksHistory = File.ReadAllText(GetFixturePath("MappedTanksHistory.json"));

            contextData.AccountInfo        = GetAccountInfoFromFixture();
            contextData.AccountInfoHistory =
                JsonConvert.DeserializeObject <AccountInfoHistory>(mappedAccountInfoHistory);
            contextData.Tanks        = JsonConvert.DeserializeObject <List <TankInfo> >(mappedTanks);
            contextData.TanksHistory =
                JsonConvert.DeserializeObject <Dictionary <long, TankInfoHistory> >(mappedTanksHistory);
        }
Ejemplo n.º 10
0
        public async Task <AccountInfoResponse> GatherAndSaveAccountInformation(
            RealmType realm,
            long accountId,
            RequestLanguage requestLanguage,
            string wargamingToken)
        {
            var contextData = new AccountInformationPipelineContextData();

            try
            {
                var context = new OperationContext(new AccountRequest(accountId, realm, requestLanguage, wargamingToken));
                context.AddOrReplace(contextData);
                var pipeline = new Pipeline <IOperationContext>(_operationFactory);

                pipeline.AddOperation <GetAccountInfoOperation>()
                .AddOperation <ReadAccountInfoFromDbOperation>()
                .AddOperation <CheckLastBattleDateOperation>()
                .AddOperation <GetTanksInfoOperation>()
                .AddOperation <CalculateStatisticsOperation>()
                .AddOperation <SaveAccountAndTanksOperation>()
                .AddOperation <BuildAccountInfoResponseOperation>()
                ;

                var firstOperation = pipeline.Build();
                if (firstOperation != null)
                {
                    await firstOperation
                    .Invoke(context, null)
                    .ConfigureAwait(false);
                }
            }
            catch (Exception e)
            {
                _logger.LogError(e, "GatherAndSaveAccountInformation error");

                throw;
            }
            return(contextData?.Response ?? new AccountInfoResponse());
        }
Ejemplo n.º 11
0
        private async Task SetAccountInfo(string accountInfoFileName, AccountInformationPipelineContextData contextData)
        {
            WotAccountInfo accountInfo = null;

            using (var r = new StreamReader(accountInfoFileName))
            {
                var json = await r.ReadToEndAsync();

                var account = JsonConvert.DeserializeObject <ResponseBody <Dictionary <string, WotAccountInfo> > >(json);
                accountInfo = account.Data?.Values.FirstOrDefault();
            }

            if (accountInfo == null)
            {
                throw new ApplicationException($"Can not read account info from '{accountInfoFileName}'");
            }

            // Store info to AccountInfo and in AccountInfoHistory
            contextData.AccountInfo       = _mapper.Map <WotAccountInfo, AccountInfo>(accountInfo);
            contextData.AccountInfo.Realm = Realm;

            contextData.AccountInfoHistory = new AccountInfoHistory(contextData.AccountInfo.AccountId, contextData.AccountInfo.LastBattleTime);
            _mapper.Map(accountInfo.Statistics?.All, contextData.AccountInfoHistory);
        }