[성현모] Socket 응답 추가
This commit is contained in:
Binary file not shown.
@ -46,6 +46,10 @@
|
|||||||
<level value="SOCKET" />
|
<level value="SOCKET" />
|
||||||
<foreColor value="DarkCyan" />
|
<foreColor value="DarkCyan" />
|
||||||
</mapping>
|
</mapping>
|
||||||
|
<mapping>
|
||||||
|
<level value="CONTROLLER" />
|
||||||
|
<foreColor value="DarkGreen" />
|
||||||
|
</mapping>
|
||||||
</appender>
|
</appender>
|
||||||
|
|
||||||
<appender name="file" type="log4net.Appender.RollingFileAppender">
|
<appender name="file" type="log4net.Appender.RollingFileAppender">
|
||||||
|
|||||||
Binary file not shown.
14
Projects/HubX/HubX.Library/Enums/EnumResult.cs
Normal file
14
Projects/HubX/HubX.Library/Enums/EnumResult.cs
Normal file
@ -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,
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,4 +1,5 @@
|
|||||||
using DB.HubXDB;
|
using DB.HubXDB;
|
||||||
|
using HubX.Library.Enums;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@ -9,17 +10,18 @@ namespace HubX.Library.Http.Packet
|
|||||||
{
|
{
|
||||||
public class Request_InsertUniqueKey
|
public class Request_InsertUniqueKey
|
||||||
{
|
{
|
||||||
public string Identity { get; set; }
|
public string Identity { get; set; } = string.Empty;
|
||||||
|
|
||||||
public string? Data1 { get; set; }
|
public string? Data1 { get; set; } = string.Empty;
|
||||||
public string? Data2 { get; set; }
|
public string? Data2 { get; set; } = string.Empty;
|
||||||
public string? Data3 { get; set; }
|
public string? Data3 { get; set; } = string.Empty;
|
||||||
public string? Data4 { get; set; }
|
public string? Data4 { get; set; } = string.Empty;
|
||||||
public string? Data5 { get; set; }
|
public string? Data5 { get; set; } = string.Empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Response_InsertUniqueKy
|
public class Response_InsertUniqueKy
|
||||||
{
|
{
|
||||||
|
public string? Identity { get; set; } = string.Empty;
|
||||||
|
public string? Result { get; set; } = EnumResult.Success.ToString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
using DB.HubXDB;
|
using Azure.Core;
|
||||||
|
using DB.HubXDB;
|
||||||
using HubX.Library.Http.Packet;
|
using HubX.Library.Http.Packet;
|
||||||
using HubX.Library.Socket.Object;
|
using HubX.Library.Socket.Object;
|
||||||
using HubX.Library.Socket.Session;
|
using HubX.Library.Socket.Session;
|
||||||
@ -15,16 +16,19 @@ namespace HubX.Library.Socket.Packet
|
|||||||
|
|
||||||
public class PacketHandler
|
public class PacketHandler
|
||||||
{
|
{
|
||||||
public static void C2S_INSERT_UniqueKeyHandler(PacketSession session, ArraySegment<byte> buffer)
|
public static async void C2S_INSERT_UniqueKeyHandler(PacketSession session, ArraySegment<byte> buffer)
|
||||||
{
|
{
|
||||||
var recvData = Encoding.UTF8.GetString(buffer);
|
var recvData = Encoding.UTF8.GetString(buffer);
|
||||||
|
|
||||||
|
//json으로 요청인지 확인
|
||||||
|
bool isJsonRequest = true;
|
||||||
|
|
||||||
//convert to object
|
//convert to object
|
||||||
var jsonObject = recvData.ToObject<C2S_INSERT_UniqueKey>();
|
var jsonObject = recvData.ToObject<C2S_INSERT_UniqueKey>();
|
||||||
|
//json 요청 아닐때 변환
|
||||||
if (jsonObject == null)
|
if (jsonObject == null)
|
||||||
{
|
{
|
||||||
var recvDataList = recvData.Split(",");
|
var recvDataList = recvData.Split(",");
|
||||||
|
|
||||||
jsonObject = new C2S_INSERT_UniqueKey
|
jsonObject = new C2S_INSERT_UniqueKey
|
||||||
{
|
{
|
||||||
Identity = recvDataList[0],
|
Identity = recvDataList[0],
|
||||||
@ -34,8 +38,10 @@ namespace HubX.Library.Socket.Packet
|
|||||||
Data4 = recvDataList[4],
|
Data4 = recvDataList[4],
|
||||||
Data5 = recvDataList[5],
|
Data5 = recvDataList[5],
|
||||||
};
|
};
|
||||||
|
isJsonRequest = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
string result = string.Empty;
|
||||||
//insert DB
|
//insert DB
|
||||||
if(jsonObject != null)
|
if(jsonObject != null)
|
||||||
{
|
{
|
||||||
@ -47,14 +53,23 @@ namespace HubX.Library.Socket.Packet
|
|||||||
request.Data4 = jsonObject.Data4;
|
request.Data4 = jsonObject.Data4;
|
||||||
request.Data5 = jsonObject.Data5;
|
request.Data5 = jsonObject.Data5;
|
||||||
|
|
||||||
SystemX.Core.Communication.Http http = new ();
|
SystemX.Core.Communication.Http http = new();
|
||||||
var res = http.PostJsonAsync<Request_InsertUniqueKey,Response_InsertUniqueKy>("https://127.0.0.1:9000/UniqueKey/InsertUniqueKey", request);
|
var res = await http.PostJsonAsync<Request_InsertUniqueKey,Response_InsertUniqueKy>("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;
|
ClientSession clientSession = session as ClientSession;
|
||||||
Client client = clientSession.Client;
|
Client client = clientSession.Client;
|
||||||
if (client == null)
|
if (client == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
client.Session.Send(Encoding.UTF8.GetBytes(result) ,EnumMessageId.S2C_INSERT_UniqueKey);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -49,9 +49,6 @@ namespace HubX.Library.Socket.Packet
|
|||||||
|
|
||||||
void MakePacket<T>(PacketSession session, ArraySegment<byte> buffer, ushort id) where T : new()
|
void MakePacket<T>(PacketSession session, ArraySegment<byte> buffer, ushort id) where T : new()
|
||||||
{
|
{
|
||||||
// T pkt = new T();
|
|
||||||
//pkt.MergeFrom(buffer.Array, buffer.Offset + 4, buffer.Count - 4);
|
|
||||||
|
|
||||||
if (CustomHandler != null)
|
if (CustomHandler != null)
|
||||||
{
|
{
|
||||||
CustomHandler.Invoke(session, buffer, id);
|
CustomHandler.Invoke(session, buffer, id);
|
||||||
|
|||||||
@ -16,21 +16,21 @@ namespace HubX.Library.Socket.Session
|
|||||||
public Client Client { get; set; }
|
public Client Client { get; set; }
|
||||||
public int SessionId { get; set; }
|
public int SessionId { get; set; }
|
||||||
|
|
||||||
public void Send(IMessage packet)
|
public void Send(ArraySegment<byte> packet, EnumMessageId resonseMessageId)
|
||||||
{
|
{
|
||||||
//string msgName = packet.Descriptor.Name.Replace("_", string.Empty);
|
Log4net.WriteLine($"Send:{Encoding.UTF8.GetString(packet)}", LogType.SOCKET);
|
||||||
//EnumMessageId msgId = (EnumMessageId)Enum.Parse(typeof(EnumMessageId), msgName);
|
|
||||||
//ushort size = (ushort)packet.CalculateSize();
|
ushort size = (ushort)packet.Count;
|
||||||
//byte[] sendBuffer = new byte[size + 4];
|
byte[] sendBuffer = new byte[size + 4];
|
||||||
//Array.Copy(BitConverter.GetBytes((ushort)(size + 4)), 0, sendBuffer, 0, sizeof(ushort));
|
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(BitConverter.GetBytes((ushort)resonseMessageId), 0, sendBuffer, 2, sizeof(ushort));
|
||||||
//Array.Copy(packet.ToByteArray(), 0, sendBuffer, 4, size);
|
Array.Copy(packet.ToArray(), 0, sendBuffer, 4, size);
|
||||||
//Send(new ArraySegment<byte>(sendBuffer));
|
Send(new ArraySegment<byte>(sendBuffer));
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void OnConnected(EndPoint endPoint)
|
public override void OnConnected(EndPoint endPoint)
|
||||||
{
|
{
|
||||||
Log4net.WriteLine($"OnConnected : {endPoint}", LogType.SOCKET);
|
Log4net.WriteLine($"OnConnected:{endPoint}", LogType.SOCKET);
|
||||||
Client = ObjectManager.Instance.Add<Client>();
|
Client = ObjectManager.Instance.Add<Client>();
|
||||||
{
|
{
|
||||||
Client.Session = this;
|
Client.Session = this;
|
||||||
@ -39,13 +39,13 @@ namespace HubX.Library.Socket.Session
|
|||||||
|
|
||||||
public override void OnRecvPacket(ArraySegment<byte> buffer)
|
public override void OnRecvPacket(ArraySegment<byte> buffer)
|
||||||
{
|
{
|
||||||
Log4net.WriteLine($"OnRecvPacket : {Encoding.UTF8.GetString(buffer)}", LogType.SOCKET);
|
Log4net.WriteLine($"OnRecvPacket:{Encoding.UTF8.GetString(buffer)}", LogType.SOCKET);
|
||||||
PacketManager.Instance.OnRecvPacket(this, buffer);
|
PacketManager.Instance.OnRecvPacket(this, buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void OnDisconnected(EndPoint endPoint)
|
public override void OnDisconnected(EndPoint endPoint)
|
||||||
{
|
{
|
||||||
Log4net.WriteLine($"OnDisconnected : {endPoint}", LogType.SOCKET);
|
Log4net.WriteLine($"OnDisconnected:{endPoint}", LogType.SOCKET);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void OnSend(int numOfBytes)
|
public override void OnSend(int numOfBytes)
|
||||||
|
|||||||
@ -19,7 +19,11 @@ namespace HubX.Server.Controllers
|
|||||||
[HttpPost]
|
[HttpPost]
|
||||||
public async Task<IResult> InsertUniqueKey(Request_InsertUniqueKey request)
|
public async Task<IResult> 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);
|
Response_InsertUniqueKy res = await _uniqueKeyService.Request_InsertUniqueKey(request);
|
||||||
|
Log4net.WriteLine($"[Response]({guid}) UniqueKey/InsertUniqueKey::{res.ToJson()}", LogType.CONTROLLER);
|
||||||
|
|
||||||
return Results.Ok(res);
|
return Results.Ok(res);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
using DB.HubXDB;
|
using DB.HubXDB;
|
||||||
|
using HubX.Library.Enums;
|
||||||
using HubX.Library.Http.Packet;
|
using HubX.Library.Http.Packet;
|
||||||
using SystemX.Core.DB;
|
using SystemX.Core.DB;
|
||||||
|
|
||||||
@ -17,36 +18,43 @@ namespace HubX.Server.Services
|
|||||||
{
|
{
|
||||||
Response_InsertUniqueKy response = new Response_InsertUniqueKy();
|
Response_InsertUniqueKy response = new Response_InsertUniqueKy();
|
||||||
|
|
||||||
var storage = new TStorage
|
if (request != null)
|
||||||
{
|
{
|
||||||
CIdentity = request.Identity,
|
response.Identity = request.Identity;
|
||||||
CData1 = request.Data1,
|
|
||||||
CData2 = request.Data2,
|
|
||||||
CData3 = request.Data3,
|
|
||||||
CData4 = request.Data4,
|
|
||||||
CData5 = request.Data5,
|
|
||||||
|
|
||||||
CDateTime = DateTime.Now
|
var storage = new TStorage
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
bool transactionResult = true;
|
|
||||||
bool isExist = false;
|
|
||||||
var context = _efCoreService.GetDBContext<HubXContext>();
|
|
||||||
|
|
||||||
if (context != null)
|
|
||||||
{
|
|
||||||
using (var transaction = await context.CreateTransactionAsync())
|
|
||||||
{
|
{
|
||||||
await context.AddAsync(storage);
|
CIdentity = request.Identity,
|
||||||
transactionResult = await context.CloseTransactionAsync(transaction);
|
CData1 = request.Data1,
|
||||||
|
CData2 = request.Data2,
|
||||||
|
CData3 = request.Data3,
|
||||||
|
CData4 = request.Data4,
|
||||||
|
CData5 = request.Data5,
|
||||||
|
|
||||||
|
CDateTime = DateTime.Now
|
||||||
|
};
|
||||||
|
|
||||||
|
bool transactionResult = true;
|
||||||
|
var context = _efCoreService.GetDBContext<HubXContext>();
|
||||||
|
if (context != null)
|
||||||
|
{
|
||||||
|
using (var transaction = await context.CreateTransactionAsync())
|
||||||
|
{
|
||||||
|
await context.AddAsync(storage);
|
||||||
|
transactionResult = await context.CloseTransactionAsync(transaction);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
//db error
|
|
||||||
if (transactionResult == false)
|
|
||||||
{
|
|
||||||
|
|
||||||
|
//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;
|
return response;
|
||||||
|
|||||||
@ -72,8 +72,6 @@ namespace SystemX.Core.Communication
|
|||||||
|
|
||||||
public void Start(Socket socket)
|
public void Start(Socket socket)
|
||||||
{
|
{
|
||||||
Log4net.WriteLine("Session Start");
|
|
||||||
|
|
||||||
_socket = socket;
|
_socket = socket;
|
||||||
|
|
||||||
_recvArgs.Completed += new EventHandler<SocketAsyncEventArgs>(OnRecvCompleted);
|
_recvArgs.Completed += new EventHandler<SocketAsyncEventArgs>(OnRecvCompleted);
|
||||||
|
|||||||
@ -23,6 +23,7 @@ public enum LogType
|
|||||||
|
|
||||||
HTTP = 20,
|
HTTP = 20,
|
||||||
SOCKET = 21,
|
SOCKET = 21,
|
||||||
|
CONTROLLER = 22,
|
||||||
}
|
}
|
||||||
#endregion
|
#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 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 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 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)
|
public static void SetCustomLevel(ILoggerRepository repo)
|
||||||
{
|
{
|
||||||
repo.LevelMap.Add(DB);
|
repo.LevelMap.Add(DB);
|
||||||
repo.LevelMap.Add(HTTP);
|
repo.LevelMap.Add(HTTP);
|
||||||
repo.LevelMap.Add(SOCKET);
|
repo.LevelMap.Add(SOCKET);
|
||||||
|
repo.LevelMap.Add(CONTROLLER);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
@ -56,9 +59,11 @@ public static class Log4net
|
|||||||
{
|
{
|
||||||
string log4netConfigPath = @"../Config/log4net.config";
|
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);
|
File.WriteAllText(log4netConfigPath, Config);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -152,6 +157,15 @@ public static class Log4net
|
|||||||
}
|
}
|
||||||
break;
|
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
|
|||||||
<level value=""SOCKET"" />
|
<level value=""SOCKET"" />
|
||||||
<foreColor value=""DarkCyan"" />
|
<foreColor value=""DarkCyan"" />
|
||||||
</mapping>
|
</mapping>
|
||||||
|
<mapping>
|
||||||
|
<level value=""CONTROLLER"" />
|
||||||
|
<foreColor value=""DarkGreen"" />
|
||||||
|
</mapping>
|
||||||
</appender>
|
</appender>
|
||||||
|
|
||||||
<appender name=""file"" type=""log4net.Appender.RollingFileAppender"">
|
<appender name=""file"" type=""log4net.Appender.RollingFileAppender"">
|
||||||
|
|||||||
Reference in New Issue
Block a user