mirror of
https://github.com/DrMboga/WotBlitzStatisticsBlazor.git
synced 2026-10-24 11:50:05 +02:00
Some errors fix
This commit is contained in:
1 parent
7ec01f0c58
commit
ccc5c768b3
7 files changed
+119
-74
No files matched your search
@@ -16,17 +16,17 @@ namespace WotBlitzStatisticsPro.Common.Model
|
|||||||
///<summary>
|
///<summary>
|
||||||
/// Account creation date
|
/// Account creation date
|
||||||
///</summary>
|
///</summary>
|
||||||
public DateTime CreatedAt { get; set; }
|
public DateTime CreatedAt { get; set; } = new DateTime(1970, 1, 1);
|
||||||
|
|
||||||
///<summary>
|
///<summary>
|
||||||
/// Last battle time
|
/// Last battle time
|
||||||
///</summary>
|
///</summary>
|
||||||
public DateTime LastBattleTime { get; set; }
|
public DateTime LastBattleTime { get; set; } = new DateTime(1970, 1, 1);
|
||||||
|
|
||||||
///<summary>
|
///<summary>
|
||||||
/// Player's nick
|
/// Player's nick
|
||||||
///</summary>
|
///</summary>
|
||||||
public string? Nickname { get; set; }
|
public string? Nickname { get; set; }
|
||||||
|
|
||||||
///<summary>
|
///<summary>
|
||||||
/// Battles count
|
/// Battles count
|
||||||
|
|||||||
@@ -7,6 +7,6 @@ namespace WotBlitzStatisticsPro.Logic.Dictionaries
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="dictionaryType">Dictionary type for resolving service.</param>
|
/// <param name="dictionaryType">Dictionary type for resolving service.</param>
|
||||||
/// <returns>Updater service.</returns>
|
/// <returns>Updater service.</returns>
|
||||||
public delegate IDictionaryUpdater DictionariesUpdaterResolver(DictionaryType dictionaryType);
|
public delegate IDictionaryUpdater? DictionariesUpdaterResolver(DictionaryType dictionaryType);
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
using System.Collections.Generic;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using AutoMapper;
|
using AutoMapper;
|
||||||
using WotBlitzStatisticsPro.Common.Dictionaries;
|
using WotBlitzStatisticsPro.Common.Dictionaries;
|
||||||
using WotBlitzStatisticsPro.DataAccess.Model;
|
using WotBlitzStatisticsPro.DataAccess.Model;
|
||||||
@@ -26,9 +27,9 @@ namespace WotBlitzStatisticsPro.Logic.Mappers
|
|||||||
.ForMember(d => d.NormalImage,
|
.ForMember(d => d.NormalImage,
|
||||||
o => o.MapFrom(s => s.Images == null ? string.Empty : s.Images["normal"]))
|
o => o.MapFrom(s => s.Images == null ? string.Empty : s.Images["normal"]))
|
||||||
.ForMember(d => d.PriceCredit,
|
.ForMember(d => d.PriceCredit,
|
||||||
o => o.MapFrom(s => s.Cost == null ? string.Empty : s.Cost["price_credit"]))
|
o => o.MapFrom(s => s.Cost == null ? decimal.Zero : Convert.ToDecimal(s.Cost["price_credit"])))
|
||||||
.ForMember(d => d.PriceGold,
|
.ForMember(d => d.PriceGold,
|
||||||
o => o.MapFrom(s => s.Cost == null ? string.Empty : s.Cost["price_gold"]))
|
o => o.MapFrom(s => s.Cost == null ? decimal.Zero : Convert.ToDecimal(s.Cost["price_gold"])))
|
||||||
.ForMember(d => d.NexTanksInTree,
|
.ForMember(d => d.NexTanksInTree,
|
||||||
o =>
|
o =>
|
||||||
o.MapFrom(s => s.NextTanks))
|
o.MapFrom(s => s.NextTanks))
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
using WotBlitzStatisticsPro.Common.Model;
|
using WotBlitzStatisticsPro.Common.Model;
|
||||||
using WotBlitzStatisticsPro.Logic.AccountInformationPipeline;
|
using WotBlitzStatisticsPro.Logic.AccountInformationPipeline;
|
||||||
using WotBlitzStatisticsPro.Logic.AccountInformationPipeline.OperationContext;
|
using WotBlitzStatisticsPro.Logic.AccountInformationPipeline.OperationContext;
|
||||||
@@ -11,31 +12,45 @@ namespace WotBlitzStatisticsPro.Logic
|
|||||||
public class WargamingAccounts: IWargamingAccounts
|
public class WargamingAccounts: IWargamingAccounts
|
||||||
{
|
{
|
||||||
private readonly IOperationFactory _operationFactory;
|
private readonly IOperationFactory _operationFactory;
|
||||||
|
private readonly ILogger<WargamingAccounts> _logger;
|
||||||
|
|
||||||
public WargamingAccounts(IOperationFactory operationFactory)
|
public WargamingAccounts(IOperationFactory operationFactory, ILogger<WargamingAccounts> logger)
|
||||||
{
|
{
|
||||||
_operationFactory = operationFactory;
|
_operationFactory = operationFactory;
|
||||||
|
_logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<AccountInfoResponse> GatherAccountInformation(RealmType realm, long accountId, RequestLanguage requestLanguage)
|
public async Task<AccountInfoResponse> GatherAccountInformation(RealmType realm, long accountId,
|
||||||
|
RequestLanguage requestLanguage)
|
||||||
{
|
{
|
||||||
var contextData = new AccountInformationPipelineContextData();
|
var contextData = new AccountInformationPipelineContextData();
|
||||||
var context = new OperationContext(new AccountRequest(accountId, realm, requestLanguage));
|
try
|
||||||
context.AddOrReplace(contextData);
|
|
||||||
var pipeline = new Pipeline<IOperationContext>(_operationFactory);
|
|
||||||
|
|
||||||
pipeline.AddOperation<GetAccountInfoOperation>()
|
|
||||||
.AddOperation<GetTanksInfoOperation>()
|
|
||||||
.AddOperation<CalculateStatisticsOperation>()
|
|
||||||
.AddOperation<BuildAccountInfoResponseOperation>()
|
|
||||||
;
|
|
||||||
|
|
||||||
var firstOperation = pipeline.Build();
|
|
||||||
if (firstOperation != null)
|
|
||||||
{
|
{
|
||||||
await firstOperation
|
|
||||||
.Invoke(context, null)
|
var context = new OperationContext(new AccountRequest(accountId, realm, requestLanguage));
|
||||||
.ConfigureAwait(false);
|
context.AddOrReplace(contextData);
|
||||||
|
var pipeline = new Pipeline<IOperationContext>(_operationFactory);
|
||||||
|
|
||||||
|
pipeline.AddOperation<GetAccountInfoOperation>()
|
||||||
|
.AddOperation<GetTanksInfoOperation>()
|
||||||
|
.AddOperation<CalculateStatisticsOperation>()
|
||||||
|
.AddOperation<BuildAccountInfoResponseOperation>()
|
||||||
|
;
|
||||||
|
|
||||||
|
var firstOperation = pipeline.Build();
|
||||||
|
if (firstOperation != null)
|
||||||
|
{
|
||||||
|
await firstOperation
|
||||||
|
.Invoke(context, null)
|
||||||
|
.ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
_logger.LogError(e, "GatherAccountInformation error");
|
||||||
|
|
||||||
|
throw;
|
||||||
}
|
}
|
||||||
|
|
||||||
return contextData?.Response ?? new AccountInfoResponse();
|
return contextData?.Response ?? new AccountInfoResponse();
|
||||||
@@ -44,55 +59,71 @@ namespace WotBlitzStatisticsPro.Logic
|
|||||||
public async Task<AccountInfoResponse> GatherAndSaveAccountInformation(RealmType realm, long accountId, RequestLanguage requestLanguage)
|
public async Task<AccountInfoResponse> GatherAndSaveAccountInformation(RealmType realm, long accountId, RequestLanguage requestLanguage)
|
||||||
{
|
{
|
||||||
var contextData = new AccountInformationPipelineContextData();
|
var contextData = new AccountInformationPipelineContextData();
|
||||||
var context = new OperationContext(new AccountRequest(accountId, realm, requestLanguage));
|
try
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
var context = new OperationContext(new AccountRequest(accountId, realm, requestLanguage));
|
||||||
|
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();
|
return contextData?.Response ?? new AccountInfoResponse();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<AccountInfoHistoryResponse> GetAccountInfoHistory(RealmType realm, long accountId, DateTime startDate, RequestLanguage requestLanguage)
|
public async Task<AccountInfoHistoryResponse> GetAccountInfoHistory(RealmType realm, long accountId, DateTime startDate, RequestLanguage requestLanguage)
|
||||||
{
|
{
|
||||||
var contextData = new AccountHistoryInformationPipelineContextData(startDate);
|
var contextData = new AccountHistoryInformationPipelineContextData(startDate);
|
||||||
var context = new OperationContext(new AccountRequest(accountId, realm, requestLanguage));
|
try
|
||||||
context.AddOrReplace(contextData);
|
|
||||||
var pipeline = new Pipeline<IOperationContext>(_operationFactory);
|
|
||||||
|
|
||||||
pipeline.AddOperation<ReadAccountInfoFromDbOperation>()
|
|
||||||
.AddOperation<ReadAccountInfoHistoryFromDbOperation>()
|
|
||||||
.AddOperation<CheckIfHistoryIsEmptyOperation>()
|
|
||||||
.AddOperation<FillOverallStatisticsOperation>()
|
|
||||||
.AddOperation<FillPeriodStatisticsOperation>()
|
|
||||||
.AddOperation<FillPeriodDifferenceOperation>()
|
|
||||||
.AddOperation<FillStatisticsDifferenceOperation>()
|
|
||||||
.AddOperation<FillAccountInfoHistoryResponse>()
|
|
||||||
;
|
|
||||||
|
|
||||||
var firstOperation = pipeline.Build();
|
|
||||||
if (firstOperation != null)
|
|
||||||
{
|
{
|
||||||
await firstOperation
|
var context = new OperationContext(new AccountRequest(accountId, realm, requestLanguage));
|
||||||
.Invoke(context, null)
|
context.AddOrReplace(contextData);
|
||||||
.ConfigureAwait(false);
|
var pipeline = new Pipeline<IOperationContext>(_operationFactory);
|
||||||
}
|
|
||||||
|
|
||||||
|
pipeline.AddOperation<ReadAccountInfoFromDbOperation>()
|
||||||
|
.AddOperation<ReadAccountInfoHistoryFromDbOperation>()
|
||||||
|
.AddOperation<CheckIfHistoryIsEmptyOperation>()
|
||||||
|
.AddOperation<FillOverallStatisticsOperation>()
|
||||||
|
.AddOperation<FillPeriodStatisticsOperation>()
|
||||||
|
.AddOperation<FillPeriodDifferenceOperation>()
|
||||||
|
.AddOperation<FillStatisticsDifferenceOperation>()
|
||||||
|
.AddOperation<FillAccountInfoHistoryResponse>()
|
||||||
|
;
|
||||||
|
|
||||||
|
var firstOperation = pipeline.Build();
|
||||||
|
if (firstOperation != null)
|
||||||
|
{
|
||||||
|
await firstOperation
|
||||||
|
.Invoke(context, null)
|
||||||
|
.ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
_logger.LogError(e, "GetAccountInfoHistory error");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
return contextData?.Response ?? new AccountInfoHistoryResponse();
|
return contextData?.Response ?? new AccountInfoHistoryResponse();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
using WotBlitzStatisticsPro.Common.Model;
|
using WotBlitzStatisticsPro.Common.Model;
|
||||||
using WotBlitzStatisticsPro.Logic.Dictionaries;
|
using WotBlitzStatisticsPro.Logic.Dictionaries;
|
||||||
|
|
||||||
@@ -9,27 +10,37 @@ namespace WotBlitzStatisticsPro.Logic
|
|||||||
public class WargamingDictionaries: IWargamingDictionaries
|
public class WargamingDictionaries: IWargamingDictionaries
|
||||||
{
|
{
|
||||||
private readonly DictionariesUpdaterResolver _dictionaryUpdaterFactoryMethod;
|
private readonly DictionariesUpdaterResolver _dictionaryUpdaterFactoryMethod;
|
||||||
|
private readonly ILogger<WargamingDictionaries> _logger;
|
||||||
|
|
||||||
public WargamingDictionaries(DictionariesUpdaterResolver dictionaryUpdaterFactoryMethod)
|
public WargamingDictionaries(DictionariesUpdaterResolver dictionaryUpdaterFactoryMethod, ILogger<WargamingDictionaries> logger)
|
||||||
{
|
{
|
||||||
_dictionaryUpdaterFactoryMethod = dictionaryUpdaterFactoryMethod;
|
_dictionaryUpdaterFactoryMethod = dictionaryUpdaterFactoryMethod;
|
||||||
|
_logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<UpdateDictionariesResponseItem[]> UpdateDictionaries(UpdateDictionariesRequest updateDictionariesRequest)
|
public async Task<UpdateDictionariesResponseItem[]> UpdateDictionaries(UpdateDictionariesRequest updateDictionariesRequest)
|
||||||
{
|
{
|
||||||
var response = new List<UpdateDictionariesResponseItem>();
|
var response = new List<UpdateDictionariesResponseItem>();
|
||||||
|
|
||||||
foreach (var dictionaryType in (DictionaryType[])Enum.GetValues(typeof(DictionaryType)))
|
try
|
||||||
{
|
{
|
||||||
if ((updateDictionariesRequest.DictionaryTypes & dictionaryType) != 0)
|
foreach (var dictionaryType in (DictionaryType[]) Enum.GetValues(typeof(DictionaryType)))
|
||||||
{
|
{
|
||||||
var dictionaryUpdater = _dictionaryUpdaterFactoryMethod(dictionaryType);
|
if ((updateDictionariesRequest.DictionaryTypes & dictionaryType) != 0)
|
||||||
if (dictionaryUpdater != null)
|
|
||||||
{
|
{
|
||||||
response.Add(await dictionaryUpdater.Update());
|
var dictionaryUpdater = _dictionaryUpdaterFactoryMethod(dictionaryType);
|
||||||
|
if (dictionaryUpdater != null)
|
||||||
|
{
|
||||||
|
response.Add(await dictionaryUpdater.Update());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
_logger.LogError(e, "UpdateDictionaries error");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
|
||||||
return response.ToArray();
|
return response.ToArray();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ namespace WotBlitzStatisticsPro.Logic
|
|||||||
DictionaryType.StaticDictionaries => serviceProvider.GetService<StaticDictionariesUpdater>()!,
|
DictionaryType.StaticDictionaries => serviceProvider.GetService<StaticDictionariesUpdater>()!,
|
||||||
DictionaryType.Achievements => serviceProvider.GetService<AchievementsDictionaryUpdater>()!,
|
DictionaryType.Achievements => serviceProvider.GetService<AchievementsDictionaryUpdater>()!,
|
||||||
DictionaryType.Vehicles => serviceProvider.GetService<VehiclesDictionaryUpdater>()!,
|
DictionaryType.Vehicles => serviceProvider.GetService<VehiclesDictionaryUpdater>()!,
|
||||||
_ => throw new ApplicationException($"Unknown dictionary type '{dictionaryType}'")
|
_ => null
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
using Moq;
|
using Moq;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using WotBlitzStatisticsPro.Common.Model;
|
using WotBlitzStatisticsPro.Common.Model;
|
||||||
@@ -40,7 +41,8 @@ namespace WotBlitzStatisticsPro.Tests.DictionariesTests
|
|||||||
|
|
||||||
var services = serviceProvider.BuildServiceProvider();
|
var services = serviceProvider.BuildServiceProvider();
|
||||||
|
|
||||||
_wargamingDictionaries = new WargamingDictionaries(services.GetService<DictionariesUpdaterResolver>());
|
_wargamingDictionaries = new WargamingDictionaries(services.GetService<DictionariesUpdaterResolver>(),
|
||||||
|
(new Mock<ILogger<WargamingDictionaries>>()).Object);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
|
|||||||
Reference in new issue
Block a user