mirror of
https://github.com/DrMboga/WotBlitzStatisticsBlazor.git
synced 2026-10-21 02:17:20 +02:00
Operations pipeline start
This commit is contained in:
1 parent
6c10c6c654
commit
7ffbeb6b17
19 files changed
+432
-5
No files matched your search
@@ -11,7 +11,74 @@ Detailed player & tank statistics and history for [World of Tanks: Blitz](ht
|
||||
- Frontent - Blazor WebAssembly (coming soon)
|
||||
|
||||
### Local MongoDB Installation for debugging ([Docker desktop for Windows](https://www.docker.com/products/docker-desktop))
|
||||
(Coming soon)
|
||||
For the developing and debugging purposes, you have to istall MongoDB locally on your dev machine and run it as a service. Alternatively, if you have istalled [Docker desktop for Windows](https://www.docker.com/products/docker-desktop), you can deploy MongoDB inside the container. To do so, create an empty folder and make 2 files there: ```docker-compose.yml``` and ```.env```. Second one will contain sensitive data.
|
||||
|
||||
<details>
|
||||
<summary>Example for docker-compose.yml with mongo-express shell:</summary>
|
||||
|
||||
```yml
|
||||
version: "3"
|
||||
services:
|
||||
mongo:
|
||||
image: mongo
|
||||
restart: always
|
||||
container_name: "mein-mongo"
|
||||
ports:
|
||||
- "27017:27017"
|
||||
environment:
|
||||
MONGO_INITDB_ROOT_USERNAME: "${DB_USERNAME}"
|
||||
MONGO_INITDB_ROOT_PASSWORD: "${DB_PASSWORD}"
|
||||
volumes:
|
||||
- "mongodblvolume:/data/db"
|
||||
mongo-express:
|
||||
image: mongo-express
|
||||
container_name: "mein-mongo-express"
|
||||
restart: always
|
||||
ports:
|
||||
- 8081:8081
|
||||
environment:
|
||||
ME_CONFIG_MONGODB_ADMINUSERNAME: "${DB_USERNAME}"
|
||||
ME_CONFIG_MONGODB_ADMINPASSWORD: "${DB_PASSWORD}"
|
||||
volumes:
|
||||
mongodblvolume:
|
||||
```
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary>Example of .env file</summary>
|
||||
|
||||
```
|
||||
DB_USERNAME=root
|
||||
DB_PASSWORD=P@SSW0RT!
|
||||
```
|
||||
</details>
|
||||
<br>
|
||||
To install docker, use shell command:
|
||||
|
||||
```bash
|
||||
docker-compose up -d
|
||||
```
|
||||
|
||||
That's all. You can use mongo shell like this:
|
||||
|
||||
```bash
|
||||
docker exec -it mein-mongo bash
|
||||
mongo --username root --password --authenticationDatabase admin
|
||||
use your_database_name
|
||||
db.someSampleCollection.insert({})
|
||||
```
|
||||
|
||||
Or you can use mongo-express by this address: http://localhost:8081/
|
||||
|
||||
To use this mongo instance in application, use this connection string in ```appsettings.json```:
|
||||
|
||||
```json
|
||||
{
|
||||
"Mongo": {
|
||||
"ConnectionString": "mongodb://root:P@SSW0RT!@localhost:27017/?authSource=admin"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Hosting solution (k8s)
|
||||
(Coming soon)
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace WotBlitzStatisticsPro.DataAccess
|
||||
{
|
||||
public interface IWargamingAccountDataAccessor
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
using MongoDB.Bson.Serialization.Attributes;
|
||||
using WotBlitzStatisticsPro.Common.Model;
|
||||
|
||||
namespace WotBlitzStatisticsPro.DataAccess.Model.Accounts
|
||||
{
|
||||
/// <summary>
|
||||
/// Account information
|
||||
/// </summary>
|
||||
public class AccountInfo
|
||||
{
|
||||
///<summary>
|
||||
/// Player account identifier
|
||||
///</summary>
|
||||
[BsonId]
|
||||
public long AccountId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Player region
|
||||
/// </summary>
|
||||
public RealmType Realm { get; set; }
|
||||
|
||||
///<summary>
|
||||
/// Account creation date
|
||||
///</summary>
|
||||
public int CreatedAt { get; set; }
|
||||
|
||||
///<summary>
|
||||
/// Last battle time
|
||||
///</summary>
|
||||
public int LastBattleTime { get; set; }
|
||||
|
||||
///<summary>
|
||||
/// Player's nick
|
||||
///</summary>
|
||||
public string Nickname { get; set; }
|
||||
|
||||
///<summary>
|
||||
/// Player information update date
|
||||
///</summary>
|
||||
public int? UpdatedAt { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
using System.Runtime.Serialization.Formatters;
|
||||
using MongoDB.Driver;
|
||||
using WotBlitzStatisticsPro.Common;
|
||||
using WotBlitzStatisticsPro.DataAccess.Model.Accounts;
|
||||
|
||||
namespace WotBlitzStatisticsPro.DataAccess
|
||||
{
|
||||
public class WargamingAccountDataAccessor : IWargamingAccountDataAccessor
|
||||
{
|
||||
private const string AccountInfoCollectionName = "account-info";
|
||||
|
||||
|
||||
private readonly IMongoDatabase _database;
|
||||
|
||||
public WargamingAccountDataAccessor(IMongoSettings mongoSettings)
|
||||
{
|
||||
var client = new MongoClient(mongoSettings.ConnectionString);
|
||||
_database = client.GetDatabase(mongoSettings.DatabaseName);
|
||||
|
||||
CreateAccountIndexesIfNotExists();
|
||||
}
|
||||
|
||||
private void CreateAccountIndexesIfNotExists()
|
||||
{
|
||||
var accountInfoBuilder = Builders<AccountInfo>.IndexKeys;
|
||||
var accountInfoRealmIndexModel = new CreateIndexModel<AccountInfo>(accountInfoBuilder.Ascending(a => a.Realm));
|
||||
var accountInfoLastBattleTimeIndexModel = new CreateIndexModel<AccountInfo>(accountInfoBuilder.Descending(a => a.LastBattleTime));
|
||||
_database.GetCollection<AccountInfo>(AccountInfoCollectionName).Indexes
|
||||
.CreateMany(new[] {accountInfoRealmIndexModel, accountInfoLastBattleTimeIndexModel});
|
||||
|
||||
|
||||
/*
|
||||
|
||||
// Multiple keys
|
||||
var indexDefinition = Builders<FooDocument>.IndexKeys.Combine(
|
||||
Builders<FooDocument>.IndexKeys.Ascending(f => f.Key1),
|
||||
Builders<FooDocument>.IndexKeys.Ascending(f => f.Key2));
|
||||
|
||||
await collection.Indexes.CreateOneAsync(indexDefinition);
|
||||
*/
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ namespace WotBlitzStatisticsPro.DataAccess
|
||||
public static void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
services.AddTransient<IDictionariesDataAccessor, DictionariesDataAccessor>();
|
||||
services.AddTransient<IWargamingAccountDataAccessor, WargamingAccountDataAccessor>();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -10,10 +10,13 @@ namespace WotBlitzStatisticsPro.GraphQl.Mutation
|
||||
public class WotBlitzStatisticsMutation
|
||||
{
|
||||
private readonly IWargamingDictionaries _wargamingDictionaries;
|
||||
private readonly IWargamingAccounts _wargamingAccounts;
|
||||
|
||||
public WotBlitzStatisticsMutation(IWargamingDictionaries wargamingDictionaries)
|
||||
public WotBlitzStatisticsMutation(IWargamingDictionaries wargamingDictionaries,
|
||||
IWargamingAccounts wargamingAccounts)
|
||||
{
|
||||
_wargamingDictionaries = wargamingDictionaries;
|
||||
_wargamingAccounts = wargamingAccounts;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -26,5 +29,17 @@ namespace WotBlitzStatisticsPro.GraphQl.Mutation
|
||||
{
|
||||
return _wargamingDictionaries.UpdateDictionaries(updateDictionariesRequest);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gathers all account information
|
||||
/// </summary>
|
||||
/// <param name="realmType">Account region</param>
|
||||
/// <param name="accountId">AccountId</param>
|
||||
/// <param name="requestLanguage">Request language</param>
|
||||
/// <returns></returns>
|
||||
public Task<bool> GatherAccountInformation(RealmType realmType, long accountId, RequestLanguage requestLanguage)
|
||||
{
|
||||
return _wargamingAccounts.GatherAccountInformation(realmType, accountId, requestLanguage);
|
||||
}
|
||||
}
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
using WotBlitzStatisticsPro.Common.Model;
|
||||
|
||||
namespace WotBlitzStatisticsPro.Logic.AccountInformationPipeline
|
||||
{
|
||||
public class AccountInformationPipelineContext
|
||||
{
|
||||
public AccountInformationPipelineContext(
|
||||
long accountId,
|
||||
RealmType realmType,
|
||||
RequestLanguage requestLanguage)
|
||||
{
|
||||
AccountId = accountId;
|
||||
RealmType = realmType;
|
||||
RequestLanguage = requestLanguage;
|
||||
}
|
||||
|
||||
|
||||
public long AccountId { get; }
|
||||
public RealmType RealmType { get; }
|
||||
public RequestLanguage RequestLanguage { get; }
|
||||
|
||||
}
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using WotBlitzStatisticsPro.Logic.Pipeline;
|
||||
|
||||
namespace WotBlitzStatisticsPro.Logic.AccountInformationPipeline.Operations
|
||||
{
|
||||
public class GetAccountInfoOperation: IOperation<AccountInformationPipelineContext>
|
||||
{
|
||||
public Task Invoke(AccountInformationPipelineContext context, Func<AccountInformationPipelineContext, Task> next)
|
||||
{
|
||||
return next.Invoke(context);
|
||||
}
|
||||
}
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using WotBlitzStatisticsPro.Logic.Pipeline;
|
||||
|
||||
namespace WotBlitzStatisticsPro.Logic.AccountInformationPipeline.Operations
|
||||
{
|
||||
public class GetTanksInfoOperation: IOperation<AccountInformationPipelineContext>
|
||||
{
|
||||
public Task Invoke(AccountInformationPipelineContext context, Func<AccountInformationPipelineContext, Task> next)
|
||||
{
|
||||
return next.Invoke(context);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
using System.Threading.Tasks;
|
||||
using WotBlitzStatisticsPro.Common.Model;
|
||||
|
||||
namespace WotBlitzStatisticsPro.Logic
|
||||
{
|
||||
public interface IWargamingAccounts
|
||||
{
|
||||
Task<bool> GatherAccountInformation(RealmType realm, long accountId, RequestLanguage requestLanguage);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WotBlitzStatisticsPro.Logic.Pipeline
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents pipeline single operation
|
||||
/// </summary>
|
||||
public interface IOperation<TContext>
|
||||
{
|
||||
/// <summary>
|
||||
/// Invokes the pipeline operation
|
||||
/// </summary>
|
||||
/// <param name="context">Pipeline context</param>
|
||||
/// <param name="next">Next operation</param>
|
||||
Task Invoke(TContext context, Func<TContext, Task> next);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
|
||||
namespace WotBlitzStatisticsPro.Logic.Pipeline
|
||||
{
|
||||
/// <summary>
|
||||
/// Factory creates the operation instances.
|
||||
/// </summary>
|
||||
public interface IOperationFactory
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates new operation instance
|
||||
/// </summary>
|
||||
/// <typeparam name="TContext"></typeparam>
|
||||
/// <param name="operationType"></param>
|
||||
/// <returns></returns>
|
||||
IOperation<TContext> Create<TContext>(Type operationType);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
namespace WotBlitzStatisticsPro.Logic.Pipeline
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents operation pipeline
|
||||
/// </summary>
|
||||
public interface IPipeline<TContext>
|
||||
{
|
||||
/// <summary>
|
||||
/// Builds the pipeline.
|
||||
/// </summary>
|
||||
/// <returns>First operation in pipeline.</returns>
|
||||
IOperation<TContext> Build();
|
||||
|
||||
/// <summary>
|
||||
/// Adds operation type to the pipeline
|
||||
/// </summary>
|
||||
/// <typeparam name="TOperation">Operation type</typeparam>
|
||||
/// <returns>Pipeline instance</returns>
|
||||
IPipeline<TContext> AddOperation<TOperation>() where TOperation : IOperation<TContext>;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WotBlitzStatisticsPro.Logic.Pipeline
|
||||
{
|
||||
public class OperationMediator<TContext>: IOperation<TContext>
|
||||
{
|
||||
private readonly IOperation<TContext> _current;
|
||||
private readonly IOperation<TContext> _next;
|
||||
|
||||
public OperationMediator(IOperation<TContext> current, IOperation<TContext> next)
|
||||
{
|
||||
_current = current ?? throw new ArgumentNullException(nameof(current));
|
||||
_next = next;
|
||||
}
|
||||
|
||||
public Task Invoke(TContext context, Func<TContext, Task> next)
|
||||
{
|
||||
return _current.Invoke(context, c => _next == null ? Task.CompletedTask : _next.Invoke(c, null));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace WotBlitzStatisticsPro.Logic.Pipeline
|
||||
{
|
||||
public class Pipeline<TContext>: IPipeline<TContext>
|
||||
{
|
||||
private readonly IOperationFactory _operationFactory;
|
||||
private readonly List<Type> _operations = new List<Type>();
|
||||
|
||||
public Pipeline(IOperationFactory operationFactory)
|
||||
{
|
||||
_operationFactory = operationFactory;
|
||||
}
|
||||
|
||||
public IOperation<TContext> Build()
|
||||
{
|
||||
var allOperationTypes = _operations.ToArray();
|
||||
var lastOperationType = allOperationTypes.LastOrDefault();
|
||||
if (lastOperationType == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
var nextOperation = new OperationMediator<TContext>(_operationFactory.Create<TContext>(lastOperationType), null);
|
||||
|
||||
for (int i = allOperationTypes.Length - 2; i >= 0; i--)
|
||||
{
|
||||
nextOperation = new OperationMediator<TContext>(_operationFactory.Create<TContext>(allOperationTypes[i]), nextOperation);
|
||||
}
|
||||
|
||||
return nextOperation;
|
||||
}
|
||||
|
||||
public IPipeline<TContext> AddOperation<TOperation>() where TOperation : IOperation<TContext>
|
||||
{
|
||||
_operations.Add(typeof(TOperation));
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using System;
|
||||
|
||||
namespace WotBlitzStatisticsPro.Logic.Pipeline
|
||||
{
|
||||
public class ServiceProviderOperationFactory: IOperationFactory
|
||||
{
|
||||
private readonly IServiceProvider _serviceProvider;
|
||||
|
||||
public ServiceProviderOperationFactory(IServiceProvider serviceProvider)
|
||||
{
|
||||
_serviceProvider = serviceProvider;
|
||||
}
|
||||
|
||||
public IOperation<TContext> Create<TContext>(Type operationType)
|
||||
{
|
||||
return _serviceProvider.GetService(operationType) as IOperation<TContext>;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
using System.Threading.Tasks;
|
||||
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;
|
||||
}
|
||||
|
||||
public async Task<bool> GatherAccountInformation(RealmType realm, long accountId, RequestLanguage requestLanguage)
|
||||
{
|
||||
var context = new AccountInformationPipelineContext(accountId, realm, requestLanguage);
|
||||
var pipeline = new Pipeline<AccountInformationPipelineContext>(_operationFactory);
|
||||
|
||||
pipeline.AddOperation<GetAccountInfoOperation>()
|
||||
.AddOperation<GetTanksInfoOperation>()
|
||||
;
|
||||
// ToDo: add other operations
|
||||
|
||||
await pipeline.Build()
|
||||
.Invoke(context, null)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
// ToDo: return context response
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,9 @@ using AutoMapper;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using WotBlitzStatisticsPro.Common.Model;
|
||||
using WotBlitzStatisticsPro.DataAccess;
|
||||
using WotBlitzStatisticsPro.Logic.AccountInformationPipeline.Operations;
|
||||
using WotBlitzStatisticsPro.Logic.Dictionaries;
|
||||
using WotBlitzStatisticsPro.Logic.Pipeline;
|
||||
using WotBlitzStatisticsPro.WgApiClient;
|
||||
|
||||
[assembly: InternalsVisibleTo("WotBlitzStatisticsPro.Tests")]
|
||||
@@ -17,12 +19,14 @@ namespace WotBlitzStatisticsPro.Logic
|
||||
public static void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
ConfigureDictionariesFactory(services);
|
||||
ConfigureOperationsFactory(services);
|
||||
WotBlitzStatisticsDataAccessInstaller.ConfigureServices(services);
|
||||
services.AddAutoMapper(typeof(WotBlitzStatisticsLogicInstaller));
|
||||
services.AddHttpClient<IWargamingApiClient, WargamingApiClient>();
|
||||
services.AddHttpClient<IWargamingDictionariesApiClient, WargamingApiClient>();
|
||||
services.AddTransient<IWargamingSearch, WargamingSearch>();
|
||||
services.AddTransient<IWargamingDictionaries, WargamingDictionaries>();
|
||||
services.AddTransient<IWargamingAccounts, WargamingAccounts>();
|
||||
}
|
||||
|
||||
private static void ConfigureDictionariesFactory(IServiceCollection services)
|
||||
@@ -31,10 +35,10 @@ namespace WotBlitzStatisticsPro.Logic
|
||||
services.AddTransient<AchievementsDictionaryUpdater>();
|
||||
services.AddTransient<VehiclesDictionaryUpdater>();
|
||||
|
||||
RegisterFactoryMethod(services);
|
||||
RegisterDictionariesFactoryMethod(services);
|
||||
}
|
||||
|
||||
internal static void RegisterFactoryMethod(IServiceCollection services)
|
||||
internal static void RegisterDictionariesFactoryMethod(IServiceCollection services)
|
||||
{
|
||||
services.AddTransient<DictionariesUpdaterResolver>(serviceProvider => dictionaryType =>
|
||||
{
|
||||
@@ -51,5 +55,14 @@ namespace WotBlitzStatisticsPro.Logic
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static void ConfigureOperationsFactory(IServiceCollection services)
|
||||
{
|
||||
services.AddTransient<GetAccountInfoOperation>();
|
||||
services.AddTransient<GetTanksInfoOperation>();
|
||||
|
||||
services.AddTransient<IOperationFactory>(serviceProvider =>
|
||||
new ServiceProviderOperationFactory(serviceProvider));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -36,7 +36,7 @@ namespace WotBlitzStatisticsPro.Tests.DictionariesTests
|
||||
serviceProvider.AddSingleton(_achievementsDictionaryUpdaterMock.Object);
|
||||
serviceProvider.AddSingleton(_vehiclesDictionaryUpdaterMock.Object);
|
||||
|
||||
WotBlitzStatisticsLogicInstaller.RegisterFactoryMethod(serviceProvider);
|
||||
WotBlitzStatisticsLogicInstaller.RegisterDictionariesFactoryMethod(serviceProvider);
|
||||
|
||||
var services = serviceProvider.BuildServiceProvider();
|
||||
|
||||
|
||||
Reference in new issue
Block a user