mirror of
https://github.com/DrMboga/WotBlitzStatisticsBlazor.git
synced 2026-10-21 10:27:18 +02:00
Dictionaries updater factory
This commit is contained in:
1 parent
cdf7ec5130
commit
32f7245d85
11 files changed
+279
-21
No files matched your search
@@ -0,0 +1,13 @@
|
||||
using System.Threading.Tasks;
|
||||
using WotBlitzStatisticsPro.Common.Model;
|
||||
|
||||
namespace WotBlitzStatisticsPro.Logic.Dictionaries
|
||||
{
|
||||
public class AchievementsDictionaryUpdater : IDictionaryUpdater
|
||||
{
|
||||
public Task<UpdateDictionariesResponseItem> Update()
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
using WotBlitzStatisticsPro.Common.Model;
|
||||
|
||||
namespace WotBlitzStatisticsPro.Logic.Dictionaries
|
||||
{
|
||||
/// <summary>
|
||||
/// Dictionaries updater factory method.
|
||||
/// </summary>
|
||||
/// <param name="dictionaryType">Dictionary type for resolving service.</param>
|
||||
/// <returns>Updater service.</returns>
|
||||
public delegate IDictionaryUpdater DictionariesUpdaterResolver(DictionaryType dictionaryType);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
using System.Threading.Tasks;
|
||||
using WotBlitzStatisticsPro.Common.Model;
|
||||
|
||||
namespace WotBlitzStatisticsPro.Logic.Dictionaries
|
||||
{
|
||||
public interface IDictionaryUpdater
|
||||
{
|
||||
Task<UpdateDictionariesResponseItem> Update();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using WotBlitzStatisticsPro.Common.Model;
|
||||
using WotBlitzStatisticsPro.WgApiClient;
|
||||
|
||||
namespace WotBlitzStatisticsPro.Logic.Dictionaries
|
||||
{
|
||||
public class StaticDictionariesUpdater : IDictionaryUpdater
|
||||
{
|
||||
private readonly IWargamingDictionariesApiClient _wargamingDictionariesApiClient;
|
||||
|
||||
public StaticDictionariesUpdater(IWargamingDictionariesApiClient wargamingDictionariesApiClient)
|
||||
{
|
||||
_wargamingDictionariesApiClient = wargamingDictionariesApiClient;
|
||||
}
|
||||
public async Task<UpdateDictionariesResponseItem> Update()
|
||||
{
|
||||
var defaultRealmType = RealmType.Eu;
|
||||
foreach (var requestLanguage in (RequestLanguage[]) Enum.GetValues(typeof(RequestLanguage)))
|
||||
{
|
||||
var (WotEncyclopediaInfoResponse, WotClanMembersDictionaryResponse) =
|
||||
await _wargamingDictionariesApiClient.GetStaticDictionariesAsync(defaultRealmType, requestLanguage);
|
||||
// ToDo: map
|
||||
// ToDo: add to dictionary
|
||||
}
|
||||
|
||||
// ToDo: Save dictionary to Mongo
|
||||
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using System.Threading.Tasks;
|
||||
using WotBlitzStatisticsPro.Common.Model;
|
||||
|
||||
namespace WotBlitzStatisticsPro.Logic.Dictionaries
|
||||
{
|
||||
public class VehiclesDictionaryUpdater : IDictionaryUpdater
|
||||
{
|
||||
public Task<UpdateDictionariesResponseItem> Update()
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,29 +1,34 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using WotBlitzStatisticsPro.Common.Model;
|
||||
using WotBlitzStatisticsPro.Logic.Dictionaries;
|
||||
|
||||
namespace WotBlitzStatisticsPro.Logic
|
||||
{
|
||||
public class WargamingDictionaries: IWargamingDictionaries
|
||||
{
|
||||
public Task<UpdateDictionariesResponseItem[]> UpdateDictionaries(UpdateDictionariesRequest updateDictionariesRequest)
|
||||
private readonly DictionariesUpdaterResolver _dictionaryUpdaterFactoryMethod;
|
||||
|
||||
public WargamingDictionaries(DictionariesUpdaterResolver dictionaryUpdaterFactoryMethod)
|
||||
{
|
||||
_dictionaryUpdaterFactoryMethod = dictionaryUpdaterFactoryMethod;
|
||||
}
|
||||
|
||||
public async Task<UpdateDictionariesResponseItem[]> UpdateDictionaries(UpdateDictionariesRequest updateDictionariesRequest)
|
||||
{
|
||||
var response = new List<UpdateDictionariesResponseItem>();
|
||||
// ToDo: Make factory
|
||||
if ((updateDictionariesRequest.DictionaryTypes & DictionaryType.StaticDictionaries) != 0)
|
||||
|
||||
foreach (var dictionaryType in (DictionaryType[])Enum.GetValues(typeof(DictionaryType)))
|
||||
{
|
||||
// Update static
|
||||
}
|
||||
if ((updateDictionariesRequest.DictionaryTypes & DictionaryType.Achievements) != 0)
|
||||
{
|
||||
// Update achievements
|
||||
}
|
||||
if ((updateDictionariesRequest.DictionaryTypes & DictionaryType.Vehicles) != 0)
|
||||
{
|
||||
// Update vehicles
|
||||
if ((updateDictionariesRequest.DictionaryTypes & dictionaryType) != 0)
|
||||
{
|
||||
var dictionaryUpdater = _dictionaryUpdaterFactoryMethod(dictionaryType);
|
||||
response.Add(await dictionaryUpdater.Update());
|
||||
}
|
||||
}
|
||||
|
||||
return Task.FromResult(response.ToArray());
|
||||
return response.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,17 +1,47 @@
|
||||
using AutoMapper;
|
||||
using System.Collections.Generic;
|
||||
using AutoMapper;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using WotBlitzStatisticsPro.Common.Model;
|
||||
using WotBlitzStatisticsPro.Logic.Dictionaries;
|
||||
using WotBlitzStatisticsPro.WgApiClient;
|
||||
|
||||
namespace WotBlitzStatisticsPro.Logic
|
||||
{
|
||||
public static class WotBlitzStatisticsLogicInstaller
|
||||
{
|
||||
|
||||
|
||||
public static void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
ConfigureDictionariesFactory(services);
|
||||
services.AddAutoMapper(typeof(WotBlitzStatisticsLogicInstaller));
|
||||
services.AddHttpClient<IWargamingApiClient, WargamingApiClient>();
|
||||
services.AddHttpClient<IWargamingDictionariesApiClient, WargamingApiClient>();
|
||||
services.AddTransient<IWargamingSearch, WargamingSearch>();
|
||||
services.AddTransient<IWargamingDictionaries, WargamingDictionaries>();
|
||||
}
|
||||
|
||||
private static void ConfigureDictionariesFactory(IServiceCollection services)
|
||||
{
|
||||
services.AddTransient<StaticDictionariesUpdater>();
|
||||
services.AddTransient<AchievementsDictionaryUpdater>();
|
||||
services.AddTransient<VehiclesDictionaryUpdater>();
|
||||
|
||||
services.AddTransient<DictionariesUpdaterResolver>(serviceProvider => dictionaryType =>
|
||||
{
|
||||
switch (dictionaryType)
|
||||
{
|
||||
case DictionaryType.StaticDictionaries:
|
||||
return serviceProvider.GetService<StaticDictionariesUpdater>();
|
||||
case DictionaryType.Achievements:
|
||||
return serviceProvider.GetService<AchievementsDictionaryUpdater>();
|
||||
case DictionaryType.Vehicles:
|
||||
return serviceProvider.GetService<VehiclesDictionaryUpdater>();
|
||||
default:
|
||||
throw new KeyNotFoundException(
|
||||
$"Unable to find service for dictionary type '{dictionaryType}'");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using System.Threading.Tasks;
|
||||
using WotBlitzStatisticsPro.Common.Model;
|
||||
using WotBlitzStatisticsPro.WgApiClient.Model;
|
||||
|
||||
namespace WotBlitzStatisticsPro.WgApiClient
|
||||
{
|
||||
public interface IWargamingDictionariesApiClient
|
||||
{
|
||||
Task<(
|
||||
WotEncyclopediaInfoResponse,
|
||||
WotClanMembersDictionaryResponse)> GetStaticDictionariesAsync(
|
||||
RealmType realmType = RealmType.Ru,
|
||||
RequestLanguage language = RequestLanguage.En);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
using System.Collections.Generic;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace WotBlitzStatisticsPro.WgApiClient.Model
|
||||
{
|
||||
public class WotClanMembersDictionaryResponse
|
||||
{
|
||||
/// <summary>
|
||||
/// Clan roles list
|
||||
/// </summary>
|
||||
[JsonProperty("clans_roles")]
|
||||
public Dictionary<string, string> ClanRoles { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Clan settings list
|
||||
/// </summary>
|
||||
[JsonProperty("settings")]
|
||||
public Dictionary<string, string> Settings { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace WotBlitzStatisticsPro.WgApiClient.Model
|
||||
{
|
||||
public class WotEncyclopediaInfoResponse
|
||||
{
|
||||
///<summary>
|
||||
/// Game client version
|
||||
///</summary>
|
||||
[JsonProperty("game_version")]
|
||||
public string GameVersion { get; set; }
|
||||
|
||||
///<summary>
|
||||
/// List of supported languages
|
||||
///</summary>
|
||||
[JsonProperty("languages")]
|
||||
public Dictionary<string, string> Languages { get; set; }
|
||||
|
||||
///<summary>
|
||||
/// Encyclopedia last update time
|
||||
///</summary>
|
||||
[JsonProperty("tanks_updated_at")]
|
||||
public int? TanksUpdatedAt { get; set; }
|
||||
|
||||
///<summary>
|
||||
/// Cru clan role
|
||||
///</summary>
|
||||
[JsonProperty("vehicle_crew_roles")]
|
||||
public Dictionary<string, string> VehicleCrewRoles { get; set; }
|
||||
|
||||
///<summary>
|
||||
/// Vehicle nations dictionary
|
||||
///</summary>
|
||||
[JsonProperty("vehicle_nations")]
|
||||
public Dictionary<string, string> VehicleNations { get; set; }
|
||||
|
||||
///<summary>
|
||||
/// Vehicle types dictionary
|
||||
///</summary>
|
||||
[JsonProperty("vehicle_types")]
|
||||
public Dictionary<string, string> VehicleTypes { get; set; }
|
||||
|
||||
///<summary>
|
||||
/// Achievements sections
|
||||
///</summary>
|
||||
[JsonProperty("achievement_sections")]
|
||||
public Dictionary<string, WotEncyclopediaInfoAchievementSection> AchievementSections { get; set; }
|
||||
|
||||
}
|
||||
|
||||
public class WotEncyclopediaInfoAchievementSection
|
||||
{
|
||||
|
||||
///<summary>
|
||||
/// Achievements section name
|
||||
///</summary>
|
||||
[JsonProperty("name")]
|
||||
public string Name { get; set; }
|
||||
|
||||
///<summary>
|
||||
/// Achievement section order
|
||||
///</summary>
|
||||
[JsonProperty("order")]
|
||||
public long? Order { get; set; }
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -7,15 +7,18 @@ using WotBlitzStatisticsPro.WgApiClient.Model;
|
||||
|
||||
namespace WotBlitzStatisticsPro.WgApiClient
|
||||
{
|
||||
public class WargamingApiClient : WagramingApiClientBase, IWargamingApiClient
|
||||
{
|
||||
public class WargamingApiClient : WagramingApiClientBase,
|
||||
IWargamingApiClient,
|
||||
IWargamingDictionariesApiClient
|
||||
{
|
||||
public WargamingApiClient(
|
||||
HttpClient httpClient,
|
||||
IWargamingApiSettings wargamingApiSettings) : base(httpClient, wargamingApiSettings)
|
||||
{
|
||||
}
|
||||
|
||||
public async Task<List<WotAccountListResponse>> FindAccounts(string nickName,
|
||||
#region Search methods
|
||||
public async Task<List<WotAccountListResponse>> FindAccounts(string nickName,
|
||||
RealmType realmType = RealmType.Ru,
|
||||
RequestLanguage language = RequestLanguage.En)
|
||||
{
|
||||
@@ -37,8 +40,40 @@ namespace WotBlitzStatisticsPro.WgApiClient
|
||||
$"search={searchString}").ConfigureAwait(false);
|
||||
|
||||
}
|
||||
#endregion
|
||||
|
||||
public async Task<AccountInfo> GetPlayerAccountInfo(long accountId,
|
||||
#region Encyclopedia methods
|
||||
|
||||
public async Task<(
|
||||
WotEncyclopediaInfoResponse,
|
||||
WotClanMembersDictionaryResponse)> GetStaticDictionariesAsync(
|
||||
RealmType realmType = RealmType.Ru,
|
||||
RequestLanguage language = RequestLanguage.En)
|
||||
{
|
||||
var encyclopedia = await GetFromBlitzApi<WotEncyclopediaInfoResponse>(
|
||||
realmType,
|
||||
language,
|
||||
"encyclopedia/info/"
|
||||
).ConfigureAwait(false);
|
||||
|
||||
|
||||
var clanGlossaryResponse = await GetFromBlitzApi<WotClanMembersDictionaryResponse>(
|
||||
realmType,
|
||||
language,
|
||||
"clans/glossary/");
|
||||
|
||||
return (encyclopedia, clanGlossaryResponse);
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public async Task<AccountInfo> GetPlayerAccountInfo(long accountId,
|
||||
RealmType realmType = RealmType.Ru,
|
||||
RequestLanguage language = RequestLanguage.En)
|
||||
{
|
||||
@@ -83,7 +118,10 @@ namespace WotBlitzStatisticsPro.WgApiClient
|
||||
return null;
|
||||
}
|
||||
|
||||
// https://api.wotblitz.ru/wotb/encyclopedia/achievements/?application_id=adc1387489cf9fc8d9a1d85dbd27763d
|
||||
// https://api.wotblitz.ru/wotb/encyclopedia/achievements/?application_id=adc1387489cf9fc8d9a1d85dbd27763d
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user