feat: add chat messages
This commit is contained in:
parent
42d594bbbb
commit
340e91b325
@ -10,6 +10,7 @@ using Client.Infrastructure.Transports;
|
||||
using Client.Domain.Entities;
|
||||
using Client.Domain.Service;
|
||||
using BaseApp = System.Windows.Application;
|
||||
using Client.Domain.ValueObjects;
|
||||
|
||||
namespace Client
|
||||
{
|
||||
@ -38,10 +39,14 @@ namespace Client
|
||||
.AddSingleton(typeof(EntityHandlerFactoryInterface), typeof(EntityHandlerFactory))
|
||||
.AddSingleton(typeof(MessageParserInterface), typeof(JsonMessageParser))
|
||||
.AddSingleton(typeof(TransportInterface), x => new NamedPipeTransport("PipeL2Bot"))
|
||||
|
||||
.AddTransient(typeof(EntityFactoryInterface<Hero>), typeof(EntityFactory<Hero>))
|
||||
.AddTransient(typeof(EntityFactoryInterface<Drop>), typeof(EntityFactory<Drop>))
|
||||
.AddTransient(typeof(EntityFactoryInterface<ChatMessage>), typeof(EntityFactory<ChatMessage>))
|
||||
|
||||
.AddSingleton<EntityHandler<Hero>>()
|
||||
.AddSingleton<EntityHandler<Drop>>();
|
||||
.AddSingleton<EntityHandler<Drop>>()
|
||||
.AddSingleton<ChatMessageHandler>();
|
||||
})
|
||||
.Build();
|
||||
}
|
||||
|
@ -53,8 +53,6 @@ namespace Client
|
||||
try
|
||||
{
|
||||
var message = messageParser.Parse(args);
|
||||
Debug.WriteLine(message);
|
||||
|
||||
try
|
||||
{
|
||||
var handler = entityHandlerFactory.GetHandler(message.Type);
|
||||
|
26
Client/Domain/Enums/ChatChannelEnum.cs
Normal file
26
Client/Domain/Enums/ChatChannelEnum.cs
Normal file
@ -0,0 +1,26 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Client.Domain.Enums
|
||||
{
|
||||
public enum ChatChannelEnum
|
||||
{
|
||||
All,
|
||||
Shout,
|
||||
Tell,
|
||||
Party,
|
||||
Clan,
|
||||
Gm,
|
||||
PetitionPlayer,
|
||||
PetitionGm,
|
||||
Trade,
|
||||
Alliance,
|
||||
Announcement,
|
||||
PartyroomCommander = 15,
|
||||
PartyroomAll,
|
||||
HeroVoice
|
||||
}
|
||||
}
|
14
Client/Domain/Factories/ChatMessageFactoryInterface.cs
Normal file
14
Client/Domain/Factories/ChatMessageFactoryInterface.cs
Normal file
@ -0,0 +1,14 @@
|
||||
using Client.Domain.ValueObjects;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Client.Domain.Factories
|
||||
{
|
||||
public interface ChatMessageFactoryInterface
|
||||
{
|
||||
ChatMessage Create(string data);
|
||||
}
|
||||
}
|
@ -7,7 +7,7 @@ using Client.Domain.Entities;
|
||||
|
||||
namespace Client.Domain.Factories
|
||||
{
|
||||
public interface EntityFactoryInterface<T>
|
||||
public interface EntityFactoryInterface<T> where T: class
|
||||
{
|
||||
public T? Create(string data);
|
||||
public void Update(T entity, string data);
|
||||
|
37
Client/Domain/Service/ChatMessageHandler.cs
Normal file
37
Client/Domain/Service/ChatMessageHandler.cs
Normal file
@ -0,0 +1,37 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Client.Domain.DTO;
|
||||
using Client.Domain.Entities;
|
||||
using Client.Domain.Enums;
|
||||
using Client.Domain.Factories;
|
||||
using Client.Domain.ValueObjects;
|
||||
|
||||
namespace Client.Domain.Service
|
||||
{
|
||||
public class ChatMessageHandler : HandlerInterface
|
||||
{
|
||||
public void Update(MessageOperationEnum operation, string content)
|
||||
{
|
||||
var message = factory.Create(content);
|
||||
if (operation == MessageOperationEnum.Create)
|
||||
{
|
||||
if (message == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(message));
|
||||
}
|
||||
messages.Add(message);
|
||||
}
|
||||
}
|
||||
|
||||
public ChatMessageHandler(EntityFactoryInterface<ChatMessage> factory)
|
||||
{
|
||||
this.factory = factory;
|
||||
}
|
||||
|
||||
private readonly EntityFactoryInterface<ChatMessage> factory;
|
||||
private List<ChatMessage> messages = new List<ChatMessage>();
|
||||
}
|
||||
}
|
@ -10,7 +10,7 @@ using Client.Domain.Factories;
|
||||
|
||||
namespace Client.Domain.Service
|
||||
{
|
||||
public class EntityHandler<T> : HandlerInterface where T : EntityInterface
|
||||
public class EntityHandler<T> : HandlerInterface where T : class, EntityInterface
|
||||
{
|
||||
public void Update(MessageOperationEnum operation, string content)
|
||||
{
|
||||
|
25
Client/Domain/ValueObjects/ChatMessage.cs
Normal file
25
Client/Domain/ValueObjects/ChatMessage.cs
Normal file
@ -0,0 +1,25 @@
|
||||
using Client.Domain.Enums;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Client.Domain.ValueObjects
|
||||
{
|
||||
public class ChatMessage
|
||||
{
|
||||
public uint ObjectId { get; set; }
|
||||
public ChatChannelEnum Channel { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string Text { get; set; }
|
||||
|
||||
public ChatMessage(uint objectId, ChatChannelEnum channel, string name, string text)
|
||||
{
|
||||
ObjectId = objectId;
|
||||
Channel = channel;
|
||||
Name = name;
|
||||
Text = text;
|
||||
}
|
||||
}
|
||||
}
|
@ -10,7 +10,7 @@ using Client.Infrastructure.Parsers.Converters;
|
||||
|
||||
namespace Client.Infrastructure.Factories
|
||||
{
|
||||
public class EntityFactory<T> : EntityFactoryInterface<T> where T : EntityInterface
|
||||
public class EntityFactory<T> : EntityFactoryInterface<T> where T : class
|
||||
{
|
||||
public T? Create(string data)
|
||||
{
|
||||
|
@ -7,6 +7,7 @@ using Client.Domain.Entities;
|
||||
using Client.Domain.Enums;
|
||||
using Client.Domain.Factories;
|
||||
using Client.Domain.Service;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace Client.Infrastructure.Factories
|
||||
{
|
||||
@ -21,10 +22,13 @@ namespace Client.Infrastructure.Factories
|
||||
switch (type)
|
||||
{
|
||||
case MessageTypeEnum.Hero:
|
||||
result = (HandlerInterface?)serviceProvider.GetService(typeof(EntityHandler<Hero>));
|
||||
result = serviceProvider.GetService<EntityHandler<Hero>>();
|
||||
break;
|
||||
case MessageTypeEnum.Drop:
|
||||
result = (HandlerInterface?)serviceProvider.GetService(typeof(EntityHandler<Drop>));
|
||||
result = serviceProvider.GetService<EntityHandler<Drop>>();
|
||||
break;
|
||||
case MessageTypeEnum.Chat:
|
||||
result = serviceProvider.GetService<ChatMessageHandler>();
|
||||
break;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user