diff --git a/Projects/DLL/SystemX.Core.dll b/Projects/DLL/SystemX.Core.dll index f540533..6dd3b48 100644 Binary files a/Projects/DLL/SystemX.Core.dll and b/Projects/DLL/SystemX.Core.dll differ diff --git a/Projects/HubX/Config/log4net.config b/Projects/HubX/Config/log4net.config index 0ab5109..e5b8ab4 100644 --- a/Projects/HubX/Config/log4net.config +++ b/Projects/HubX/Config/log4net.config @@ -46,6 +46,10 @@ + + + + diff --git a/Projects/HubX/DBPatch/sqlScripts/dacpac/HubX.DB.dacpac b/Projects/HubX/DBPatch/sqlScripts/dacpac/HubX.DB.dacpac index 6243de0..0d07919 100644 Binary files a/Projects/HubX/DBPatch/sqlScripts/dacpac/HubX.DB.dacpac and b/Projects/HubX/DBPatch/sqlScripts/dacpac/HubX.DB.dacpac differ diff --git a/Projects/HubX/HubX.Library/Enums/EnumResult.cs b/Projects/HubX/HubX.Library/Enums/EnumResult.cs new file mode 100644 index 0000000..46c876f --- /dev/null +++ b/Projects/HubX/HubX.Library/Enums/EnumResult.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HubX.Library.Enums +{ + public enum EnumResult + { + Success = 1, + Failed = 2, + } +} diff --git a/Projects/HubX/HubX.Library/Http/Packet/Packet.cs b/Projects/HubX/HubX.Library/Http/Packet/Packet.cs index 8d271e5..d9aa443 100644 --- a/Projects/HubX/HubX.Library/Http/Packet/Packet.cs +++ b/Projects/HubX/HubX.Library/Http/Packet/Packet.cs @@ -1,4 +1,5 @@ using DB.HubXDB; +using HubX.Library.Enums; using System; using System.Collections.Generic; using System.Linq; @@ -9,17 +10,18 @@ namespace HubX.Library.Http.Packet { public class Request_InsertUniqueKey { - public string Identity { get; set; } + public string Identity { get; set; } = string.Empty; - public string? Data1 { get; set; } - public string? Data2 { get; set; } - public string? Data3 { get; set; } - public string? Data4 { get; set; } - public string? Data5 { get; set; } + public string? Data1 { get; set; } = string.Empty; + public string? Data2 { get; set; } = string.Empty; + public string? Data3 { get; set; } = string.Empty; + public string? Data4 { get; set; } = string.Empty; + public string? Data5 { get; set; } = string.Empty; } public class Response_InsertUniqueKy { - + public string? Identity { get; set; } = string.Empty; + public string? Result { get; set; } = EnumResult.Success.ToString(); } } diff --git a/Projects/HubX/HubX.Library/Socket/Packet/PacketHandler.cs b/Projects/HubX/HubX.Library/Socket/Packet/PacketHandler.cs index e9370cd..069591e 100644 --- a/Projects/HubX/HubX.Library/Socket/Packet/PacketHandler.cs +++ b/Projects/HubX/HubX.Library/Socket/Packet/PacketHandler.cs @@ -1,4 +1,5 @@ -using DB.HubXDB; +using Azure.Core; +using DB.HubXDB; using HubX.Library.Http.Packet; using HubX.Library.Socket.Object; using HubX.Library.Socket.Session; @@ -15,16 +16,19 @@ namespace HubX.Library.Socket.Packet public class PacketHandler { - public static void C2S_INSERT_UniqueKeyHandler(PacketSession session, ArraySegment buffer) + public static async void C2S_INSERT_UniqueKeyHandler(PacketSession session, ArraySegment buffer) { var recvData = Encoding.UTF8.GetString(buffer); + //json으로 요청인지 확인 + bool isJsonRequest = true; + //convert to object var jsonObject = recvData.ToObject(); + //json 요청 아닐때 변환 if (jsonObject == null) { var recvDataList = recvData.Split(","); - jsonObject = new C2S_INSERT_UniqueKey { Identity = recvDataList[0], @@ -34,8 +38,10 @@ namespace HubX.Library.Socket.Packet Data4 = recvDataList[4], Data5 = recvDataList[5], }; + isJsonRequest = false; } - + + string result = string.Empty; //insert DB if(jsonObject != null) { @@ -47,14 +53,23 @@ namespace HubX.Library.Socket.Packet request.Data4 = jsonObject.Data4; request.Data5 = jsonObject.Data5; - SystemX.Core.Communication.Http http = new (); - var res = http.PostJsonAsync("https://127.0.0.1:9000/UniqueKey/InsertUniqueKey", request); + SystemX.Core.Communication.Http http = new(); + var res = await http.PostJsonAsync("https://127.0.0.1:9000/UniqueKey/InsertUniqueKey", request); + result = res.ToJson(); + + //json 요청이 아니면 변환 + if (isJsonRequest == false) + { + result = $"{res.Identity},{res.Result}"; + } } ClientSession clientSession = session as ClientSession; Client client = clientSession.Client; if (client == null) - return; + return; + + client.Session.Send(Encoding.UTF8.GetBytes(result) ,EnumMessageId.S2C_INSERT_UniqueKey); } } } diff --git a/Projects/HubX/HubX.Library/Socket/Packet/ServerPacketManager.cs b/Projects/HubX/HubX.Library/Socket/Packet/ServerPacketManager.cs index 79b7da6..6617da8 100644 --- a/Projects/HubX/HubX.Library/Socket/Packet/ServerPacketManager.cs +++ b/Projects/HubX/HubX.Library/Socket/Packet/ServerPacketManager.cs @@ -49,9 +49,6 @@ namespace HubX.Library.Socket.Packet void MakePacket(PacketSession session, ArraySegment buffer, ushort id) where T : new() { - // T pkt = new T(); - //pkt.MergeFrom(buffer.Array, buffer.Offset + 4, buffer.Count - 4); - if (CustomHandler != null) { CustomHandler.Invoke(session, buffer, id); diff --git a/Projects/HubX/HubX.Library/Socket/Session/ClientSession.cs b/Projects/HubX/HubX.Library/Socket/Session/ClientSession.cs index e11dad6..c51d555 100644 --- a/Projects/HubX/HubX.Library/Socket/Session/ClientSession.cs +++ b/Projects/HubX/HubX.Library/Socket/Session/ClientSession.cs @@ -16,21 +16,21 @@ namespace HubX.Library.Socket.Session public Client Client { get; set; } public int SessionId { get; set; } - public void Send(IMessage packet) + public void Send(ArraySegment packet, EnumMessageId resonseMessageId) { - //string msgName = packet.Descriptor.Name.Replace("_", string.Empty); - //EnumMessageId msgId = (EnumMessageId)Enum.Parse(typeof(EnumMessageId), msgName); - //ushort size = (ushort)packet.CalculateSize(); - //byte[] sendBuffer = new byte[size + 4]; - //Array.Copy(BitConverter.GetBytes((ushort)(size + 4)), 0, sendBuffer, 0, sizeof(ushort)); - //Array.Copy(BitConverter.GetBytes((ushort)msgId), 0, sendBuffer, 2, sizeof(ushort)); - //Array.Copy(packet.ToByteArray(), 0, sendBuffer, 4, size); - //Send(new ArraySegment(sendBuffer)); + Log4net.WriteLine($"Send:{Encoding.UTF8.GetString(packet)}", LogType.SOCKET); + + ushort size = (ushort)packet.Count; + byte[] sendBuffer = new byte[size + 4]; + Array.Copy(BitConverter.GetBytes((ushort)(size + 4)), 0, sendBuffer, 0, sizeof(ushort)); + Array.Copy(BitConverter.GetBytes((ushort)resonseMessageId), 0, sendBuffer, 2, sizeof(ushort)); + Array.Copy(packet.ToArray(), 0, sendBuffer, 4, size); + Send(new ArraySegment(sendBuffer)); } public override void OnConnected(EndPoint endPoint) { - Log4net.WriteLine($"OnConnected : {endPoint}", LogType.SOCKET); + Log4net.WriteLine($"OnConnected:{endPoint}", LogType.SOCKET); Client = ObjectManager.Instance.Add(); { Client.Session = this; @@ -39,13 +39,13 @@ namespace HubX.Library.Socket.Session public override void OnRecvPacket(ArraySegment buffer) { - Log4net.WriteLine($"OnRecvPacket : {Encoding.UTF8.GetString(buffer)}", LogType.SOCKET); + Log4net.WriteLine($"OnRecvPacket:{Encoding.UTF8.GetString(buffer)}", LogType.SOCKET); PacketManager.Instance.OnRecvPacket(this, buffer); } public override void OnDisconnected(EndPoint endPoint) { - Log4net.WriteLine($"OnDisconnected : {endPoint}", LogType.SOCKET); + Log4net.WriteLine($"OnDisconnected:{endPoint}", LogType.SOCKET); } public override void OnSend(int numOfBytes) diff --git a/Projects/HubX/HubX.Server/Controllers/UniqueKeyController.cs b/Projects/HubX/HubX.Server/Controllers/UniqueKeyController.cs index 9cd0cec..fc88648 100644 --- a/Projects/HubX/HubX.Server/Controllers/UniqueKeyController.cs +++ b/Projects/HubX/HubX.Server/Controllers/UniqueKeyController.cs @@ -19,7 +19,11 @@ namespace HubX.Server.Controllers [HttpPost] public async Task InsertUniqueKey(Request_InsertUniqueKey request) { + var guid = Guid.NewGuid(); + Log4net.WriteLine($"[Requeust]({guid}) UniqueKey/InsertUniqueKey::{request.ToJson()}", LogType.CONTROLLER); + Response_InsertUniqueKy res = await _uniqueKeyService.Request_InsertUniqueKey(request); + Log4net.WriteLine($"[Response]({guid}) UniqueKey/InsertUniqueKey::{res.ToJson()}", LogType.CONTROLLER); return Results.Ok(res); } diff --git a/Projects/HubX/HubX.Server/Services/UniqueKeyService.cs b/Projects/HubX/HubX.Server/Services/UniqueKeyService.cs index a7bddf5..54e2002 100644 --- a/Projects/HubX/HubX.Server/Services/UniqueKeyService.cs +++ b/Projects/HubX/HubX.Server/Services/UniqueKeyService.cs @@ -1,4 +1,5 @@ using DB.HubXDB; +using HubX.Library.Enums; using HubX.Library.Http.Packet; using SystemX.Core.DB; @@ -17,36 +18,43 @@ namespace HubX.Server.Services { Response_InsertUniqueKy response = new Response_InsertUniqueKy(); - var storage = new TStorage + if (request != null) { - CIdentity = request.Identity, - CData1 = request.Data1, - CData2 = request.Data2, - CData3 = request.Data3, - CData4 = request.Data4, - CData5 = request.Data5, + response.Identity = request.Identity; - CDateTime = DateTime.Now - }; - - - bool transactionResult = true; - bool isExist = false; - var context = _efCoreService.GetDBContext(); - - if (context != null) - { - using (var transaction = await context.CreateTransactionAsync()) + var storage = new TStorage { - await context.AddAsync(storage); - transactionResult = await context.CloseTransactionAsync(transaction); - } - } + CIdentity = request.Identity, + CData1 = request.Data1, + CData2 = request.Data2, + CData3 = request.Data3, + CData4 = request.Data4, + CData5 = request.Data5, - //db error - if (transactionResult == false) - { - + CDateTime = DateTime.Now + }; + + bool transactionResult = true; + var context = _efCoreService.GetDBContext(); + if (context != null) + { + using (var transaction = await context.CreateTransactionAsync()) + { + await context.AddAsync(storage); + transactionResult = await context.CloseTransactionAsync(transaction); + } + } + + //db error + if (transactionResult == false) + { + response.Result = EnumResult.Failed.ToString(); + Log4net.WriteLine($"Transaction Error", LogType.Error); + } + else + { + Log4net.WriteLine($"Transaction Success", LogType.DB); + } } return response; diff --git a/Projects/SystemX.Core/SystemX.Core/Communication/Socket/Session.cs b/Projects/SystemX.Core/SystemX.Core/Communication/Socket/Session.cs index d4edf48..4013e0c 100644 --- a/Projects/SystemX.Core/SystemX.Core/Communication/Socket/Session.cs +++ b/Projects/SystemX.Core/SystemX.Core/Communication/Socket/Session.cs @@ -72,8 +72,6 @@ namespace SystemX.Core.Communication public void Start(Socket socket) { - Log4net.WriteLine("Session Start"); - _socket = socket; _recvArgs.Completed += new EventHandler(OnRecvCompleted); diff --git a/Projects/SystemX.Core/SystemX.Core/Log4net/Log4net.cs b/Projects/SystemX.Core/SystemX.Core/Log4net/Log4net.cs index 34bb330..dd165c3 100644 --- a/Projects/SystemX.Core/SystemX.Core/Log4net/Log4net.cs +++ b/Projects/SystemX.Core/SystemX.Core/Log4net/Log4net.cs @@ -23,6 +23,7 @@ public enum LogType HTTP = 20, SOCKET = 21, + CONTROLLER = 22, } #endregion @@ -32,12 +33,14 @@ public static class Log4netCustomLevel public static readonly log4net.Core.Level DB = new log4net.Core.Level(10010, LogType.DB.ToString()); public static readonly log4net.Core.Level HTTP = new log4net.Core.Level(10020, LogType.HTTP.ToString()); public static readonly log4net.Core.Level SOCKET = new log4net.Core.Level(10021, LogType.SOCKET.ToString()); + public static readonly log4net.Core.Level CONTROLLER = new log4net.Core.Level(10022, LogType.CONTROLLER.ToString()); public static void SetCustomLevel(ILoggerRepository repo) { repo.LevelMap.Add(DB); repo.LevelMap.Add(HTTP); repo.LevelMap.Add(SOCKET); + repo.LevelMap.Add(CONTROLLER); } } #endregion @@ -56,9 +59,11 @@ public static class Log4net { string log4netConfigPath = @"../Config/log4net.config"; - if (File.Exists(log4netConfigPath) == false) + if (File.Exists(log4netConfigPath) == true) { - Console.WriteLine($"create log4netConfig: {log4netConfigPath}"); + File.Delete(log4netConfigPath); + + Console.WriteLine($"Create log4netConfig: {log4netConfigPath}"); File.WriteAllText(log4netConfigPath, Config); } @@ -152,6 +157,15 @@ public static class Log4net } break; } + case LogType.CONTROLLER: + { + Type? t = MethodBase.GetCurrentMethod()?.DeclaringType; + if (t != null) + { + Manager?.Logger.Log(t, Log4netCustomLevel.CONTROLLER, log, null); + } + break; + } } } @@ -210,6 +224,10 @@ public static class Log4net + + + +