2020-11-17 11:01:35 +01:00
|
|
|
using System;
|
|
|
|
|
using System.Threading.Tasks;
|
2020-07-19 13:04:31 +02:00
|
|
|
using WotBlitzStatisticsPro.Common.Model;
|
|
|
|
|
using WotBlitzStatisticsPro.Logic.AccountInformationPipeline;
|
|
|
|
|
using WotBlitzStatisticsPro.Logic.AccountInformationPipeline.Operations;
|
|
|
|
|
using WotBlitzStatisticsPro.Logic.Pipeline;
|
|
|
|
|
|
|
|
|
|
namespace WotBlitzStatisticsPro.Logic
|
|
|
|
|
{
|
|
|
|
|
public class WargamingAccounts: IWargamingAccounts
|
|
|
|
|
{
|
|
|
|
|
private readonly IOperationFactory _operationFactory;
|
|
|
|
|
|
|
|
|
|
public WargamingAccounts(IOperationFactory operationFactory)
|
|
|
|
|
{
|
|
|
|
|
_operationFactory = operationFactory;
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-30 19:30:36 +02:00
|
|
|
public async Task<AccountInfoResponse> GatherAccountInformation(RealmType realm, long accountId, RequestLanguage requestLanguage)
|
2020-07-19 13:04:31 +02:00
|
|
|
{
|
|
|
|
|
var context = new AccountInformationPipelineContext(accountId, realm, requestLanguage);
|
|
|
|
|
var pipeline = new Pipeline<AccountInformationPipelineContext>(_operationFactory);
|
|
|
|
|
|
|
|
|
|
pipeline.AddOperation<GetAccountInfoOperation>()
|
|
|
|
|
.AddOperation<GetTanksInfoOperation>()
|
2020-09-22 17:54:35 +02:00
|
|
|
.AddOperation<CalculateStatisticsOperation>()
|
2020-09-30 19:30:36 +02:00
|
|
|
.AddOperation<BuildAccountInfoResponseOperation>()
|
2020-07-19 13:04:31 +02:00
|
|
|
;
|
|
|
|
|
|
|
|
|
|
await pipeline.Build()
|
|
|
|
|
.Invoke(context, null)
|
|
|
|
|
.ConfigureAwait(false);
|
|
|
|
|
|
2020-10-25 19:05:08 +01:00
|
|
|
return context.Response;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<AccountInfoResponse> GatherAndSaveAccountInformation(RealmType realm, long accountId, RequestLanguage requestLanguage)
|
|
|
|
|
{
|
|
|
|
|
var context = new AccountInformationPipelineContext(accountId, realm, requestLanguage);
|
|
|
|
|
var pipeline = new Pipeline<AccountInformationPipelineContext>(_operationFactory);
|
|
|
|
|
|
|
|
|
|
pipeline.AddOperation<GetAccountInfoOperation>()
|
2020-11-01 14:10:57 +01:00
|
|
|
.AddOperation<ReadAccountInfoFromDbOperation>()
|
2020-11-05 14:57:40 +01:00
|
|
|
.AddOperation<CheckLastBattleDateOperation>()
|
2020-10-25 19:05:08 +01:00
|
|
|
.AddOperation<GetTanksInfoOperation>()
|
|
|
|
|
.AddOperation<CalculateStatisticsOperation>()
|
2020-11-06 19:23:20 +01:00
|
|
|
.AddOperation<SaveAccountAndTanksOperation>()
|
2020-10-25 19:05:08 +01:00
|
|
|
.AddOperation<BuildAccountInfoResponseOperation>()
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
await pipeline.Build()
|
|
|
|
|
.Invoke(context, null)
|
|
|
|
|
.ConfigureAwait(false);
|
2020-07-19 13:04:31 +02:00
|
|
|
|
2020-09-30 19:30:36 +02:00
|
|
|
return context.Response;
|
2020-07-19 13:04:31 +02:00
|
|
|
}
|
2020-11-17 11:01:35 +01:00
|
|
|
|
|
|
|
|
public async Task<AccountInfoHistoryResponse> GetAccountInfoHistory(RealmType realm, long accountId, DateTime startDate, RequestLanguage requestLanguage)
|
|
|
|
|
{
|
|
|
|
|
var context = new HistoryInformationPipelineContext(accountId, realm, requestLanguage);
|
|
|
|
|
var pipeline = new Pipeline<HistoryInformationPipelineContext>(_operationFactory);
|
|
|
|
|
|
|
|
|
|
//pipeline.AddOperation<ReadAccountInfoFromDbOperation>()
|
|
|
|
|
|
|
|
|
|
// ToDo:
|
|
|
|
|
// 1. First read account info from DB operation
|
|
|
|
|
// 2. Read account history from DB at the startDate !Array SortedByDate! operation
|
|
|
|
|
// 3. Fill the OverallAccountStatistics
|
|
|
|
|
// PeriodAccountStatistics
|
|
|
|
|
// PeriodDifference
|
|
|
|
|
// StatisticsHistory
|
|
|
|
|
|
|
|
|
|
await pipeline.Build()
|
|
|
|
|
.Invoke(context, null)
|
|
|
|
|
.ConfigureAwait(false);
|
|
|
|
|
|
|
|
|
|
return context.Response;
|
|
|
|
|
}
|
2020-07-19 13:04:31 +02:00
|
|
|
}
|
|
|
|
|
}
|