[성현모] CPMeta 기능 수정

This commit is contained in:
SHM
2026-02-12 10:59:13 +09:00
parent 4bfcf64720
commit 3626030124
3 changed files with 61 additions and 27 deletions

View File

@ -21,37 +21,61 @@ namespace CPMeta
public static async Task<string> HealthCheck(string host) public static async Task<string> HealthCheck(string host)
{ {
Guid guid = Guid.NewGuid();
string url = $"https://{host}:{Port}/CPMeta/Health/health"; string url = $"https://{host}:{Port}/CPMeta/Health/health";
var res = await RestAPI.GetAsync<string>(url); var res = await RestAPI.GetAsync<string>(url, guid);
Console.ForegroundColor = ConsoleColor.Blue;
Console.WriteLine($"Response: {res} (Trace Guid:{guid})");
Console.ForegroundColor = ConsoleColor.White;
return res; return res;
} }
public static async Task<Response_SetWbmsMeta> SetWbmsMetaAsync(string host, Request_SetWbmsMeta request) public static async Task<Response_SetWbmsMeta> SetWbmsMetaAsync(string host, Request_SetWbmsMeta request)
{ {
Guid guid = Guid.NewGuid();
string url = $"https://{host}:{Port}/CPMeta/SetWbmsMeta"; string url = $"https://{host}:{Port}/CPMeta/SetWbmsMeta";
Response_SetWbmsMeta res = await RestAPI.PostAsync<Request_SetWbmsMeta,Response_SetWbmsMeta>(url, request); Response_SetWbmsMeta res = await RestAPI.PostAsync<Request_SetWbmsMeta,Response_SetWbmsMeta>(url, request, guid);
Console.ForegroundColor = ConsoleColor.Blue;
Console.WriteLine($"Response: {JsonConvert.SerializeObject(res, Formatting.Indented)} (Trace Guid:{guid})");
Console.ForegroundColor = ConsoleColor.White;
return res; return res;
} }
public static async Task<Response_GetWbmsMeta> GetWbmsMetaByProductId(string host, string productID, int shardID = 1) public static async Task<Response_GetWbmsMeta> GetWbmsMetaByProductId(string host, string productID, int shardID = 1)
{ {
Guid guid = Guid.NewGuid();
string url = $"https://{host}:{Port}/CPMeta/GetWbmsMetaByProductID?"; string url = $"https://{host}:{Port}/CPMeta/GetWbmsMetaByProductID?";
url += $"ProductID={productID}&"; url += $"ProductID={productID}&";
url += $"ShardID={shardID}"; url += $"ShardID={shardID}";
Response_GetWbmsMeta res = await RestAPI.GetAsync<Response_GetWbmsMeta>(url); Response_GetWbmsMeta res = await RestAPI.GetAsync<Response_GetWbmsMeta>(url, guid);
Console.ForegroundColor = ConsoleColor.Blue;
Console.WriteLine($"Response: {JsonConvert.SerializeObject(res, Formatting.Indented)} (Trace Guid: {guid})");
Console.ForegroundColor = ConsoleColor.White;
return res; return res;
} }
public static async Task<Response_GetWbmsMeta> GetWbmsMetaByMacAddress(string host, string macAddress, int shardID = 1) public static async Task<Response_GetWbmsMeta> GetWbmsMetaByMacAddress(string host, string macAddress, int shardID = 1)
{ {
Guid guid = Guid.NewGuid();
string url = $"https://{host}:{Port}/CPMeta/GetWbmsMetaByMacAddress?"; string url = $"https://{host}:{Port}/CPMeta/GetWbmsMetaByMacAddress?";
url += $"MacAddress={macAddress}&"; url += $"MacAddress={macAddress}&";
url += $"ShardID={shardID}"; url += $"ShardID={shardID}";
Response_GetWbmsMeta res = await RestAPI.GetAsync<Response_GetWbmsMeta>(url); Response_GetWbmsMeta res = await RestAPI.GetAsync<Response_GetWbmsMeta>(url, guid);
Console.ForegroundColor = ConsoleColor.DarkYellow;
Console.WriteLine($"Response: {JsonConvert.SerializeObject(res, Formatting.Indented)} (Trace Guid: {guid})");
Console.ForegroundColor = ConsoleColor.White;
return res; return res;
} }
} }

View File

@ -11,8 +11,8 @@ namespace CPMeta
{ {
public class RestAPI public class RestAPI
{ {
private static HttpClient RequestClient = new HttpClient(); private static readonly HttpClient RequestClient = new HttpClient();
private static HttpClient ResponseClient = new HttpClient(); private static readonly HttpClient ResponseClient = new HttpClient();
public static int TimeOut { get; set; } = 3000; public static int TimeOut { get; set; } = 3000;
@ -22,54 +22,57 @@ namespace CPMeta
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
RequestClient.Timeout = TimeSpan.FromMilliseconds(TimeOut); RequestClient.Timeout = TimeSpan.FromMilliseconds(TimeOut);
ResponseClient.Timeout = TimeSpan.FromMilliseconds(TimeOut);
} }
public static async Task<RESPONSE> PostAsync<REQUEST,RESPONSE>(string Url, REQUEST body) where REQUEST : class where RESPONSE : class public static async Task<RESPONSE> PostAsync<REQUEST,RESPONSE>(string Url, REQUEST body, Guid guid) where REQUEST : class where RESPONSE : class
{ {
try try
{ {
if (body != null) 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 jsonBody = JsonConvert.SerializeObject(body);
var contents = new StringContent(jsonBody, Encoding.UTF8, "application/json"); var contents = new StringContent(jsonBody, Encoding.UTF8, "application/json");
//RequestClient.Timeout = TimeSpan.FromMilliseconds(TimeOut);
var response = await RequestClient.PostAsync(Url, contents); var response = await RequestClient.PostAsync(Url, contents);
resContentStr = await response.Content.ReadAsStringAsync();
var resContentStr = await response.Content.ReadAsStringAsync();
return JsonConvert.DeserializeObject<RESPONSE>(resContentStr); return JsonConvert.DeserializeObject<RESPONSE>(resContentStr);
} }
} }
catch (Exception e) catch (Exception e)
{ {
Console.WriteLine($"TimeOut: {ResponseClient.Timeout}"); Console.WriteLine($"TimeOut: {RequestClient.Timeout}");
Console.WriteLine("PostAsync Error"); Console.WriteLine($"PostAsync Error:{e.Message}");
Console.WriteLine(e.Message);
} }
return default(RESPONSE); return default(RESPONSE);
} }
public static async Task<RESPONSE> GetAsync<RESPONSE>(string Url) public static async Task<RESPONSE> GetAsync<RESPONSE>(string Url, Guid guid)
{ {
try 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 response = await ResponseClient.GetAsync(Url);
resContentStr = await response.Content.ReadAsStringAsync();
var resContentStr = await response.Content.ReadAsStringAsync();
return JsonConvert.DeserializeObject<RESPONSE>(resContentStr); return JsonConvert.DeserializeObject<RESPONSE>(resContentStr);
} }
catch(Exception e) catch(Exception e)
{ {
Console.WriteLine($"TimeOut: {ResponseClient.Timeout}"); Console.WriteLine($"TimeOut: {ResponseClient.Timeout}");
Console.WriteLine("GetAsync Error"); Console.WriteLine($"GetAsync Error:{e.Message}");
Console.WriteLine(e.Message);
} }
return default(RESPONSE); return default(RESPONSE);

View File

@ -10,7 +10,7 @@ namespace PlayGround.NetFramework
static void Main(string[] args) static void Main(string[] args)
{ {
//global set //global set
string host = "192.168.0.43"; string host = "192.168.0.42";
//random value //random value
string ProductId = "00010032-87a4-45ca-b627-b975d41e35df"; string ProductId = "00010032-87a4-45ca-b627-b975d41e35df";
@ -20,9 +20,16 @@ namespace PlayGround.NetFramework
//Get //Get
Task.Run(async () => Task.Run(async () =>
{ {
var res2 = await CPMeta.CPMeta.GetWbmsMetaByProductId(host, ProductId); var res2 = await CPMeta.CPMeta.HealthCheck(host);
// var res3 = await CPMeta.CPMeta.GetWbmsMetaByMacAddress(host, Mac1);
// var res4 = await CPMeta.CPMeta.GetWbmsMetaByMacAddress(host, Mac2); // 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(); }).Wait();