2020-05-29 23:03:32 +02:00
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2020-05-23 10:44:04 +02:00
|
|
|
using System.Threading.Tasks;
|
2020-12-27 17:20:57 +01:00
|
|
|
using Microsoft.Extensions.Logging;
|
2020-05-21 17:53:01 +02:00
|
|
|
using WotBlitzStatisticsPro.Common.Model;
|
2020-05-29 23:03:32 +02:00
|
|
|
using WotBlitzStatisticsPro.Logic.Dictionaries;
|
2020-05-21 17:53:01 +02:00
|
|
|
|
2020-05-23 11:43:14 +02:00
|
|
|
namespace WotBlitzStatisticsPro.Logic
|
2020-05-21 17:53:01 +02:00
|
|
|
{
|
|
|
|
|
public class WargamingDictionaries: IWargamingDictionaries
|
|
|
|
|
{
|
2020-05-29 23:03:32 +02:00
|
|
|
private readonly DictionariesUpdaterResolver _dictionaryUpdaterFactoryMethod;
|
2020-12-27 17:20:57 +01:00
|
|
|
private readonly ILogger<WargamingDictionaries> _logger;
|
2020-05-29 23:03:32 +02:00
|
|
|
|
2020-12-27 17:20:57 +01:00
|
|
|
public WargamingDictionaries(DictionariesUpdaterResolver dictionaryUpdaterFactoryMethod, ILogger<WargamingDictionaries> logger)
|
2020-05-29 23:03:32 +02:00
|
|
|
{
|
|
|
|
|
_dictionaryUpdaterFactoryMethod = dictionaryUpdaterFactoryMethod;
|
2020-12-27 17:20:57 +01:00
|
|
|
_logger = logger;
|
2020-05-29 23:03:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<UpdateDictionariesResponseItem[]> UpdateDictionaries(UpdateDictionariesRequest updateDictionariesRequest)
|
2020-05-21 17:53:01 +02:00
|
|
|
{
|
2020-05-23 10:44:04 +02:00
|
|
|
var response = new List<UpdateDictionariesResponseItem>();
|
2020-05-29 23:03:32 +02:00
|
|
|
|
2020-12-27 17:20:57 +01:00
|
|
|
try
|
2020-05-21 17:53:01 +02:00
|
|
|
{
|
2020-12-27 17:20:57 +01:00
|
|
|
foreach (var dictionaryType in (DictionaryType[]) Enum.GetValues(typeof(DictionaryType)))
|
2020-05-29 23:03:32 +02:00
|
|
|
{
|
2020-12-27 17:20:57 +01:00
|
|
|
if ((updateDictionariesRequest.DictionaryTypes & dictionaryType) != 0)
|
2020-05-31 15:43:39 +02:00
|
|
|
{
|
2020-12-27 17:20:57 +01:00
|
|
|
var dictionaryUpdater = _dictionaryUpdaterFactoryMethod(dictionaryType);
|
|
|
|
|
if (dictionaryUpdater != null)
|
|
|
|
|
{
|
|
|
|
|
response.Add(await dictionaryUpdater.Update());
|
|
|
|
|
}
|
2020-05-31 15:43:39 +02:00
|
|
|
}
|
2020-05-29 23:03:32 +02:00
|
|
|
}
|
2020-05-21 17:53:01 +02:00
|
|
|
}
|
2020-12-27 17:20:57 +01:00
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(e, "UpdateDictionaries error");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
2020-05-23 10:44:04 +02:00
|
|
|
|
2020-05-29 23:03:32 +02:00
|
|
|
return response.ToArray();
|
2020-05-21 17:53:01 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|