[성현모] CPMeta 라이브러리, 예제 추가
This commit is contained in:
44
Projects/NetStandard/CPMeta/CPMeta.cs
Normal file
44
Projects/NetStandard/CPMeta/CPMeta.cs
Normal file
@ -0,0 +1,44 @@
|
||||
using CPMeta.Models;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CPMeta
|
||||
{
|
||||
public class CPMeta
|
||||
{
|
||||
public static int Port { get; set; } = 9000;
|
||||
|
||||
public static async Task<Response_SetWbmsMeta> SetWbmsMetaAsync(string host, Request_SetWbmsMeta request)
|
||||
{
|
||||
string url = $"https://{host}:{Port}/CPMeta/SetWbmsMeta";
|
||||
|
||||
Response_SetWbmsMeta res = await RestAPI.PostAsync<Request_SetWbmsMeta,Response_SetWbmsMeta>(url, request);
|
||||
return res;
|
||||
}
|
||||
|
||||
public static async Task<Response_GetWbmsMeta> GetWbmsMetaByProductId(string host, string productID, int shardID = 1)
|
||||
{
|
||||
string url = $"https://{host}:{Port}/CPMeta/GetWbmsMetaByProductID?";
|
||||
url += $"ProductID={productID}&";
|
||||
url += $"ShardID={shardID}";
|
||||
|
||||
Response_GetWbmsMeta res = await RestAPI.GetAsync<Response_GetWbmsMeta>(url);
|
||||
return res;
|
||||
}
|
||||
|
||||
public static async Task<Response_GetWbmsMeta> GetWbmsMetaByMacAddress(string host, string macAddress, int shardID = 1)
|
||||
{
|
||||
string url = $"https://{host}:{Port}/CPMeta/GetWbmsMetaByMacAddress?";
|
||||
url += $"MacAddress={macAddress}&";
|
||||
url += $"ShardID={shardID}";
|
||||
|
||||
Response_GetWbmsMeta res = await RestAPI.GetAsync<Response_GetWbmsMeta>(url);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Projects/NetStandard/CPMeta/CPMeta.csproj
Normal file
11
Projects/NetStandard/CPMeta/CPMeta.csproj
Normal file
@ -0,0 +1,11 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.4" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
59
Projects/NetStandard/CPMeta/Models/Wbms.cs
Normal file
59
Projects/NetStandard/CPMeta/Models/Wbms.cs
Normal file
@ -0,0 +1,59 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace CPMeta.Models
|
||||
{
|
||||
public class Request_SetWbmsMeta
|
||||
{
|
||||
//pk
|
||||
public string ProductID { get; set; } = string.Empty;
|
||||
//uk
|
||||
public string MacAddress1 { get; set; } = string.Empty;
|
||||
public string MacAddress2 { get; set; } = string.Empty;
|
||||
|
||||
//value
|
||||
public string Type { get; set; } = string.Empty;
|
||||
public string ProductNo { get; set; } = string.Empty;
|
||||
public string SpareValue { get; set; } = string.Empty;
|
||||
|
||||
public int ShardID { get; set; } = 1;
|
||||
}
|
||||
|
||||
public class Response_SetWbmsMeta
|
||||
{
|
||||
public string ProductID { get; set; } = string.Empty;
|
||||
public string Result { get; set; } = string.Empty;
|
||||
public string Message { get; set; } = string.Empty;
|
||||
}
|
||||
|
||||
public class Request_GetWbmsMetaByProductID
|
||||
{
|
||||
public string ProductID { get; set; } = string.Empty;
|
||||
public int ShardID { get; set; } = 1;
|
||||
}
|
||||
public class Request_GetWbmsMetaByMacAddress
|
||||
{
|
||||
public string MacAddress { get; set; } = string.Empty;
|
||||
public int ShardID { get; set; } = 1;
|
||||
}
|
||||
|
||||
public class Response_GetWbmsMeta
|
||||
{
|
||||
public List<tWbms> Wbms { get; set; }
|
||||
public string Result { get; set; } = string.Empty;
|
||||
public string Message { get; set; } = string.Empty;
|
||||
}
|
||||
|
||||
public class tWbms
|
||||
{
|
||||
public string cProductID { get; set; } = null;
|
||||
|
||||
public string cMacAddress1 { get; set; }
|
||||
public string cMacAddress2 { get; set; }
|
||||
public string cType { get; set; }
|
||||
public string cProductNo { get; set; }
|
||||
public string cSpareValue { get; set; }
|
||||
public DateTime cDateTime { get; set; }
|
||||
}
|
||||
}
|
||||
67
Projects/NetStandard/CPMeta/RestAPI.cs
Normal file
67
Projects/NetStandard/CPMeta/RestAPI.cs
Normal file
@ -0,0 +1,67 @@
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CPMeta
|
||||
{
|
||||
public class RestAPI
|
||||
{
|
||||
public static async Task<RESPONSE> PostAsync<REQUEST,RESPONSE>(string Url, REQUEST body) where REQUEST : class where RESPONSE : class
|
||||
{
|
||||
try
|
||||
{
|
||||
ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;
|
||||
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
|
||||
|
||||
if (body != null)
|
||||
{
|
||||
var jsonBody = JsonConvert.SerializeObject(body);
|
||||
var contents = new StringContent(jsonBody, Encoding.UTF8, "application/json");
|
||||
|
||||
HttpClient client = new HttpClient();
|
||||
client.Timeout = TimeSpan.FromMilliseconds(3000);
|
||||
|
||||
var response = await client.PostAsync(Url, contents);
|
||||
|
||||
var resContentStr = await response.Content.ReadAsStringAsync();
|
||||
return JsonConvert.DeserializeObject<RESPONSE>(resContentStr);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine("PostAsync Error");
|
||||
}
|
||||
|
||||
return default(RESPONSE);
|
||||
}
|
||||
|
||||
public static async Task<RESPONSE> GetAsync<RESPONSE>(string Url)
|
||||
{
|
||||
try
|
||||
{
|
||||
ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;
|
||||
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
|
||||
|
||||
HttpClient client = new HttpClient();
|
||||
client.Timeout = TimeSpan.FromMilliseconds(3000);
|
||||
|
||||
var response = await client.GetAsync(Url);
|
||||
|
||||
var resContentStr = await response.Content.ReadAsStringAsync();
|
||||
return JsonConvert.DeserializeObject<RESPONSE>(resContentStr);
|
||||
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
Console.WriteLine("GetAsync Error");
|
||||
}
|
||||
|
||||
return default(RESPONSE);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user