feat: create window client app
This commit is contained in:
27
Client/Infrastructure/Factories/EntityFactory.cs
Normal file
27
Client/Infrastructure/Factories/EntityFactory.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Client.Domain.Entities;
|
||||
using Client.Domain.Factories;
|
||||
using Client.Infrastructure.Parsers.Converters;
|
||||
|
||||
namespace Client.Infrastructure.Factories
|
||||
{
|
||||
public class EntityFactory<T> : EntityFactoryInterface<T> where T : EntityInterface
|
||||
{
|
||||
public T? Create(string data)
|
||||
{
|
||||
return JsonConvert.DeserializeObject<T>(data, settings);
|
||||
}
|
||||
|
||||
public void Update(T entity, string data)
|
||||
{
|
||||
JsonConvert.PopulateObject(data, entity, settings);
|
||||
}
|
||||
|
||||
private JsonSerializerSettings settings = new JsonSerializerSettings { Converters = { new BooleanConverter() } };
|
||||
}
|
||||
}
|
44
Client/Infrastructure/Factories/EntityHandlerFactory.cs
Normal file
44
Client/Infrastructure/Factories/EntityHandlerFactory.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Client.Domain.Entities;
|
||||
using Client.Domain.Enums;
|
||||
using Client.Domain.Factories;
|
||||
using Client.Domain.Service;
|
||||
|
||||
namespace Client.Infrastructure.Factories
|
||||
{
|
||||
public class EntityHandlerFactory : EntityHandlerFactoryInterface
|
||||
{
|
||||
private readonly IServiceProvider serviceProvider;
|
||||
|
||||
public HandlerInterface GetHandler(MessageTypeEnum type)
|
||||
{
|
||||
HandlerInterface? result = null;
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case MessageTypeEnum.Hero:
|
||||
result = (HandlerInterface?)serviceProvider.GetService(typeof(EntityHandler<Hero>));
|
||||
break;
|
||||
case MessageTypeEnum.Drop:
|
||||
result = (HandlerInterface?)serviceProvider.GetService(typeof(EntityHandler<Drop>));
|
||||
break;
|
||||
}
|
||||
|
||||
if (result == null)
|
||||
{
|
||||
throw new ArgumentException("Handler not found " + type.ToString());
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public EntityHandlerFactory(IServiceProvider serviceProvider)
|
||||
{
|
||||
this.serviceProvider = serviceProvider;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user