[성현모] CPMeta 라이브러리, 예제 추가

This commit is contained in:
SHM
2025-10-31 11:49:13 +09:00
parent b78e5a23ea
commit 3d5e790057
12 changed files with 378 additions and 0 deletions

View 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;
}
}
}

View 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>

View 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; }
}
}

View 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);
}
}
}

View File

@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.14.36301.6 d17.14
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CPMeta", "CPMeta\CPMeta.csproj", "{0BDB3E8C-2F57-4780-8B6F-3AE3F426A6C3}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PlayGround.NetFramework", "PlayGround.NetFramework\PlayGround.NetFramework.csproj", "{9EFF44BF-88AD-495B-B4FA-313A969666F0}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{0BDB3E8C-2F57-4780-8B6F-3AE3F426A6C3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0BDB3E8C-2F57-4780-8B6F-3AE3F426A6C3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0BDB3E8C-2F57-4780-8B6F-3AE3F426A6C3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0BDB3E8C-2F57-4780-8B6F-3AE3F426A6C3}.Release|Any CPU.Build.0 = Release|Any CPU
{9EFF44BF-88AD-495B-B4FA-313A969666F0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9EFF44BF-88AD-495B-B4FA-313A969666F0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9EFF44BF-88AD-495B-B4FA-313A969666F0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9EFF44BF-88AD-495B-B4FA-313A969666F0}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {9F4B97E1-3EAE-406D-BAD9-69F7D27498B2}
EndGlobalSection
EndGlobal

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8.1" />
</startup>
</configuration>

View File

@ -0,0 +1,63 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{9EFF44BF-88AD-495B-B4FA-313A969666F0}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>PlayGround.NetFramework</RootNamespace>
<AssemblyName>PlayGround.NetFramework</AssemblyName>
<TargetFrameworkVersion>v4.8.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.13.0.4\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\CPMeta\CPMeta.csproj">
<Project>{0bdb3e8c-2f57-4780-8b6f-3ae3f426a6c3}</Project>
<Name>CPMeta</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

View File

@ -0,0 +1,46 @@
using CPMeta;
using CPMeta.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PlayGround.NetFramework
{
internal class Program
{
static void Main(string[] args)
{
//CpMetaSet
CPMeta.CPMeta.Port = 9000;
string ProductId = Guid.NewGuid().ToString();
string Mac1 = Guid.NewGuid().ToString();
string Mac2 = Guid.NewGuid().ToString();
//Set
Task.Run(async() =>
{
Request_SetWbmsMeta req = new Request_SetWbmsMeta();
req.ProductID = ProductId;
req.MacAddress1 = Mac1;
req.MacAddress2 = Mac2;
var res = await CPMeta.CPMeta.SetWbmsMetaAsync("127.0.0.1", req);
}).Wait();
//Get
Task.Run(async() =>
{
var rese2 = await CPMeta.CPMeta.GetWbmsMetaByProductId("127.0.0.1", ProductId);
var rese3 = await CPMeta.CPMeta.GetWbmsMetaByMacAddress("127.0.0.1", Mac1);
var rese4 = await CPMeta.CPMeta.GetWbmsMetaByMacAddress("127.0.0.1", Mac2);
int b = 0;
}).Wait();;
int a = 0;
}
}
}

View File

@ -0,0 +1,33 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// 어셈블리에 대한 일반 정보는 다음 특성 집합을 통해
// 제어됩니다. 어셈블리와 관련된 정보를 수정하려면
// 이러한 특성 값을 변경하세요.
[assembly: AssemblyTitle("PlayGround.NetFramework")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("PlayGround.NetFramework")]
[assembly: AssemblyCopyright("Copyright © 2025")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// ComVisible을 false로 설정하면 이 어셈블리의 형식이 COM 구성 요소에
// 표시되지 않습니다. COM에서 이 어셈블리의 형식에 액세스하려면
// 해당 형식에 대해 ComVisible 특성을 true로 설정하세요.
[assembly: ComVisible(false)]
// 이 프로젝트가 COM에 노출되는 경우 다음 GUID는 typelib의 ID를 나타냅니다.
[assembly: Guid("9eff44bf-88ad-495b-b4fa-313a969666f0")]
// 어셈블리의 버전 정보는 다음 네 가지 값으로 구성됩니다.
//
// 주 버전
// 부 버전
// 빌드 번호
// 수정 버전
//
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Newtonsoft.Json" version="13.0.4" targetFramework="net481" />
</packages>

View File

@ -0,0 +1,13 @@
{
"version": 1,
"isRoot": true,
"tools": {
"dotnet-ef": {
"version": "9.0.10",
"commands": [
"dotnet-ef"
],
"rollForward": false
}
}
}