diff --git a/Client/App.xaml.cs b/Client/App.xaml.cs index 69ae0db..2d09695 100644 --- a/Client/App.xaml.cs +++ b/Client/App.xaml.cs @@ -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), typeof(EntityFactory)) .AddTransient(typeof(EntityFactoryInterface), typeof(EntityFactory)) + .AddTransient(typeof(EntityFactoryInterface), typeof(EntityFactory)) + .AddSingleton>() - .AddSingleton>(); + .AddSingleton>() + .AddSingleton(); }) .Build(); } diff --git a/Client/Application.cs b/Client/Application.cs index 134162e..41c6299 100644 --- a/Client/Application.cs +++ b/Client/Application.cs @@ -53,8 +53,6 @@ namespace Client try { var message = messageParser.Parse(args); - Debug.WriteLine(message); - try { var handler = entityHandlerFactory.GetHandler(message.Type); diff --git a/Client/Domain/Enums/ChatChannelEnum.cs b/Client/Domain/Enums/ChatChannelEnum.cs new file mode 100644 index 0000000..1bf7493 --- /dev/null +++ b/Client/Domain/Enums/ChatChannelEnum.cs @@ -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 + } +} diff --git a/Client/Domain/Factories/ChatMessageFactoryInterface.cs b/Client/Domain/Factories/ChatMessageFactoryInterface.cs new file mode 100644 index 0000000..f203284 --- /dev/null +++ b/Client/Domain/Factories/ChatMessageFactoryInterface.cs @@ -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); + } +} diff --git a/Client/Domain/Factories/EntityFactoryInterface.cs b/Client/Domain/Factories/EntityFactoryInterface.cs index e236453..c07a21e 100644 --- a/Client/Domain/Factories/EntityFactoryInterface.cs +++ b/Client/Domain/Factories/EntityFactoryInterface.cs @@ -7,8 +7,8 @@ using Client.Domain.Entities; namespace Client.Domain.Factories { - public interface EntityFactoryInterface - { + public interface EntityFactoryInterface where T: class + { public T? Create(string data); public void Update(T entity, string data); } diff --git a/Client/Domain/Service/ChatMessageHandler.cs b/Client/Domain/Service/ChatMessageHandler.cs new file mode 100644 index 0000000..53a843c --- /dev/null +++ b/Client/Domain/Service/ChatMessageHandler.cs @@ -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 factory) + { + this.factory = factory; + } + + private readonly EntityFactoryInterface factory; + private List messages = new List(); + } +} diff --git a/Client/Domain/Service/EntityHandler.cs b/Client/Domain/Service/EntityHandler.cs index b3dd3de..a79fc61 100644 --- a/Client/Domain/Service/EntityHandler.cs +++ b/Client/Domain/Service/EntityHandler.cs @@ -10,7 +10,7 @@ using Client.Domain.Factories; namespace Client.Domain.Service { - public class EntityHandler : HandlerInterface where T : EntityInterface + public class EntityHandler : HandlerInterface where T : class, EntityInterface { public void Update(MessageOperationEnum operation, string content) { diff --git a/Client/Domain/ValueObjects/ChatMessage.cs b/Client/Domain/ValueObjects/ChatMessage.cs new file mode 100644 index 0000000..a469630 --- /dev/null +++ b/Client/Domain/ValueObjects/ChatMessage.cs @@ -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; + } + } +} diff --git a/Client/Infrastructure/Factories/EntityFactory.cs b/Client/Infrastructure/Factories/EntityFactory.cs index ed90dfd..d376a03 100644 --- a/Client/Infrastructure/Factories/EntityFactory.cs +++ b/Client/Infrastructure/Factories/EntityFactory.cs @@ -10,7 +10,7 @@ using Client.Infrastructure.Parsers.Converters; namespace Client.Infrastructure.Factories { - public class EntityFactory : EntityFactoryInterface where T : EntityInterface + public class EntityFactory : EntityFactoryInterface where T : class { public T? Create(string data) { diff --git a/Client/Infrastructure/Factories/EntityHandlerFactory.cs b/Client/Infrastructure/Factories/EntityHandlerFactory.cs index 5577663..bbd58b7 100644 --- a/Client/Infrastructure/Factories/EntityHandlerFactory.cs +++ b/Client/Infrastructure/Factories/EntityHandlerFactory.cs @@ -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)); + result = serviceProvider.GetService>(); break; case MessageTypeEnum.Drop: - result = (HandlerInterface?)serviceProvider.GetService(typeof(EntityHandler)); + result = serviceProvider.GetService>(); + break; + case MessageTypeEnum.Chat: + result = serviceProvider.GetService(); break; }