From 3626030124708946d172b882bea5385fd042b1b9 Mon Sep 17 00:00:00 2001 From: SHM Date: Thu, 12 Feb 2026 10:59:13 +0900 Subject: [PATCH] =?UTF-8?q?[=EC=84=B1=ED=98=84=EB=AA=A8]=20CPMeta=20?= =?UTF-8?q?=EA=B8=B0=EB=8A=A5=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Projects/NetStandard/CPMeta/CPMeta.cs | 34 +++++++++++++--- Projects/NetStandard/CPMeta/RestAPI.cs | 39 ++++++++++--------- .../PlayGround.NetFramework/Program.cs | 15 +++++-- 3 files changed, 61 insertions(+), 27 deletions(-) diff --git a/Projects/NetStandard/CPMeta/CPMeta.cs b/Projects/NetStandard/CPMeta/CPMeta.cs index 54d9d10..5e99635 100644 --- a/Projects/NetStandard/CPMeta/CPMeta.cs +++ b/Projects/NetStandard/CPMeta/CPMeta.cs @@ -21,37 +21,61 @@ namespace CPMeta public static async Task HealthCheck(string host) { + Guid guid = Guid.NewGuid(); + string url = $"https://{host}:{Port}/CPMeta/Health/health"; - var res = await RestAPI.GetAsync(url); + var res = await RestAPI.GetAsync(url, guid); + + Console.ForegroundColor = ConsoleColor.Blue; + Console.WriteLine($"Response: {res} (Trace Guid:{guid})"); + Console.ForegroundColor = ConsoleColor.White; return res; } public static async Task SetWbmsMetaAsync(string host, Request_SetWbmsMeta request) { - string url = $"https://{host}:{Port}/CPMeta/SetWbmsMeta"; + Guid guid = Guid.NewGuid(); - Response_SetWbmsMeta res = await RestAPI.PostAsync(url, request); + string url = $"https://{host}:{Port}/CPMeta/SetWbmsMeta"; + + Response_SetWbmsMeta res = await RestAPI.PostAsync(url, request, guid); + + Console.ForegroundColor = ConsoleColor.Blue; + Console.WriteLine($"Response: {JsonConvert.SerializeObject(res, Formatting.Indented)} (Trace Guid:{guid})"); + Console.ForegroundColor = ConsoleColor.White; return res; } public static async Task GetWbmsMetaByProductId(string host, string productID, int shardID = 1) { + Guid guid = Guid.NewGuid(); + string url = $"https://{host}:{Port}/CPMeta/GetWbmsMetaByProductID?"; url += $"ProductID={productID}&"; url += $"ShardID={shardID}"; - Response_GetWbmsMeta res = await RestAPI.GetAsync(url); + Response_GetWbmsMeta res = await RestAPI.GetAsync(url, guid); + + Console.ForegroundColor = ConsoleColor.Blue; + Console.WriteLine($"Response: {JsonConvert.SerializeObject(res, Formatting.Indented)} (Trace Guid: {guid})"); + Console.ForegroundColor = ConsoleColor.White; return res; } public static async Task GetWbmsMetaByMacAddress(string host, string macAddress, int shardID = 1) { + Guid guid = Guid.NewGuid(); + string url = $"https://{host}:{Port}/CPMeta/GetWbmsMetaByMacAddress?"; url += $"MacAddress={macAddress}&"; url += $"ShardID={shardID}"; - Response_GetWbmsMeta res = await RestAPI.GetAsync(url); + Response_GetWbmsMeta res = await RestAPI.GetAsync(url, guid); + + Console.ForegroundColor = ConsoleColor.DarkYellow; + Console.WriteLine($"Response: {JsonConvert.SerializeObject(res, Formatting.Indented)} (Trace Guid: {guid})"); + Console.ForegroundColor = ConsoleColor.White; return res; } } diff --git a/Projects/NetStandard/CPMeta/RestAPI.cs b/Projects/NetStandard/CPMeta/RestAPI.cs index 776f06a..8646acd 100644 --- a/Projects/NetStandard/CPMeta/RestAPI.cs +++ b/Projects/NetStandard/CPMeta/RestAPI.cs @@ -11,8 +11,8 @@ namespace CPMeta { public class RestAPI { - private static HttpClient RequestClient = new HttpClient(); - private static HttpClient ResponseClient = new HttpClient(); + private static readonly HttpClient RequestClient = new HttpClient(); + private static readonly HttpClient ResponseClient = new HttpClient(); public static int TimeOut { get; set; } = 3000; @@ -22,54 +22,57 @@ namespace CPMeta ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; RequestClient.Timeout = TimeSpan.FromMilliseconds(TimeOut); + ResponseClient.Timeout = TimeSpan.FromMilliseconds(TimeOut); } - public static async Task PostAsync(string Url, REQUEST body) where REQUEST : class where RESPONSE : class + public static async Task PostAsync(string Url, REQUEST body, Guid guid) where REQUEST : class where RESPONSE : class { try - { + { if (body != null) { - Console.WriteLine($"PostAsync:{Url},{JsonConvert.SerializeObject(body, Formatting.Indented)}"); + string resContentStr = string.Empty; + Console.ForegroundColor = ConsoleColor.DarkYellow; + Console.WriteLine($"PostAsync:{Url},{JsonConvert.SerializeObject(body, Formatting.Indented)} (Trace Guid: {guid})"); + Console.ForegroundColor = ConsoleColor.White; var jsonBody = JsonConvert.SerializeObject(body); var contents = new StringContent(jsonBody, Encoding.UTF8, "application/json"); - //RequestClient.Timeout = TimeSpan.FromMilliseconds(TimeOut); var response = await RequestClient.PostAsync(Url, contents); - - var resContentStr = await response.Content.ReadAsStringAsync(); + resContentStr = await response.Content.ReadAsStringAsync(); + return JsonConvert.DeserializeObject(resContentStr); } } catch (Exception e) { - Console.WriteLine($"TimeOut: {ResponseClient.Timeout}"); - Console.WriteLine("PostAsync Error"); - Console.WriteLine(e.Message); + Console.WriteLine($"TimeOut: {RequestClient.Timeout}"); + Console.WriteLine($"PostAsync Error:{e.Message}"); } return default(RESPONSE); } - public static async Task GetAsync(string Url) + public static async Task GetAsync(string Url, Guid guid) { try { - Console.WriteLine($"GetAsync:{Url}"); + string resContentStr = string.Empty; + Console.ForegroundColor = ConsoleColor.DarkYellow; + Console.WriteLine($"GetAsync:{Url} (Trace Guid: {guid})"); + Console.ForegroundColor = ConsoleColor.White; - //ResponseClient.Timeout = TimeSpan.FromMilliseconds(TimeOut); var response = await ResponseClient.GetAsync(Url); - - var resContentStr = await response.Content.ReadAsStringAsync(); + resContentStr = await response.Content.ReadAsStringAsync(); + return JsonConvert.DeserializeObject(resContentStr); } catch(Exception e) { Console.WriteLine($"TimeOut: {ResponseClient.Timeout}"); - Console.WriteLine("GetAsync Error"); - Console.WriteLine(e.Message); + Console.WriteLine($"GetAsync Error:{e.Message}"); } return default(RESPONSE); diff --git a/Projects/NetStandard/PlayGround.NetFramework/Program.cs b/Projects/NetStandard/PlayGround.NetFramework/Program.cs index c55c979..5accd97 100644 --- a/Projects/NetStandard/PlayGround.NetFramework/Program.cs +++ b/Projects/NetStandard/PlayGround.NetFramework/Program.cs @@ -10,7 +10,7 @@ namespace PlayGround.NetFramework static void Main(string[] args) { //global set - string host = "192.168.0.43"; + string host = "192.168.0.42"; //random value string ProductId = "00010032-87a4-45ca-b627-b975d41e35df"; @@ -20,9 +20,16 @@ namespace PlayGround.NetFramework //Get Task.Run(async () => { - var res2 = await CPMeta.CPMeta.GetWbmsMetaByProductId(host, ProductId); - // var res3 = await CPMeta.CPMeta.GetWbmsMetaByMacAddress(host, Mac1); - // var res4 = await CPMeta.CPMeta.GetWbmsMetaByMacAddress(host, Mac2); + var res2 = await CPMeta.CPMeta.HealthCheck(host); + + // var res2 = await CPMeta.CPMeta.GetWbmsMetaByProductId(host, ProductId); + + Console.ForegroundColor = ConsoleColor.DarkBlue; + Console.WriteLine($"Response: {res2} (Trace Guid:)"); + Console.ForegroundColor = ConsoleColor.White; + + // var res3 = await CPMeta.CPMeta.GetWbmsMetaByMacAddress(host, Mac1); + // var res4 = await CPMeta.CPMeta.GetWbmsMetaByMacAddress(host, Mac2); }).Wait();