[성현모] CPMeta 기능 수정
This commit is contained in:
@ -21,37 +21,61 @@ namespace CPMeta
|
||||
|
||||
public static async Task<string> HealthCheck(string host)
|
||||
{
|
||||
Guid guid = Guid.NewGuid();
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
public static async Task<Response_SetWbmsMeta> SetWbmsMetaAsync(string host, Request_SetWbmsMeta request)
|
||||
{
|
||||
Guid guid = Guid.NewGuid();
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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?";
|
||||
url += $"ProductID={productID}&";
|
||||
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;
|
||||
}
|
||||
|
||||
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?";
|
||||
url += $"MacAddress={macAddress}&";
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -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<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
|
||||
{
|
||||
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);
|
||||
resContentStr = await response.Content.ReadAsStringAsync();
|
||||
|
||||
var resContentStr = await response.Content.ReadAsStringAsync();
|
||||
return JsonConvert.DeserializeObject<RESPONSE>(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<RESPONSE> GetAsync<RESPONSE>(string Url)
|
||||
public static async Task<RESPONSE> GetAsync<RESPONSE>(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);
|
||||
resContentStr = await response.Content.ReadAsStringAsync();
|
||||
|
||||
var resContentStr = await response.Content.ReadAsStringAsync();
|
||||
return JsonConvert.DeserializeObject<RESPONSE>(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);
|
||||
|
||||
@ -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,7 +20,14 @@ namespace PlayGround.NetFramework
|
||||
//Get
|
||||
Task.Run(async () =>
|
||||
{
|
||||
var res2 = await CPMeta.CPMeta.GetWbmsMetaByProductId(host, ProductId);
|
||||
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();
|
||||
|
||||
Reference in New Issue
Block a user