[성현모] VPKI Http Service Core dll적용
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.Http.Json;
|
||||
@ -14,7 +15,7 @@ namespace SystemX.Core.Communication
|
||||
/// </summary>
|
||||
/// <param name="url">https://127.0.0.1:443</param>
|
||||
/// <param name="timeOutSeconds">Range 5~30 secconds</param>
|
||||
public virtual async Task<RESPONSE?> PostJsonAsync<REQUEST, RESPONSE>(string url, REQUEST request, short timeOutSeconds = 5) where REQUEST : class where RESPONSE : class
|
||||
public virtual async Task<RESPONSE?> PostJsonAsync<REQUEST, RESPONSE>(string url, REQUEST request, string bearerToken = "", short timeOutSeconds = 5) where REQUEST : class where RESPONSE : class
|
||||
{
|
||||
RESPONSE? response = default(RESPONSE);
|
||||
Guid guid = Guid.NewGuid();
|
||||
@ -25,6 +26,9 @@ namespace SystemX.Core.Communication
|
||||
httpClient.Timeout = new TimeSpan(0, 0, timeOutSec);
|
||||
httpClient.BaseAddress = new Uri($"{url}");
|
||||
|
||||
if(string.IsNullOrEmpty(bearerToken) == false)
|
||||
httpClient.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", $"{bearerToken}");
|
||||
|
||||
int retry = 0;
|
||||
while (true)
|
||||
{
|
||||
@ -59,7 +63,7 @@ namespace SystemX.Core.Communication
|
||||
/// </summary>
|
||||
/// <param name="url">https://127.0.0.1:443</param>
|
||||
/// <param name="timeOutSeconds">Range 5~30 secconds</param>
|
||||
public virtual async Task<RESPONSE?> GetJsonAsync<RESPONSE>(string url, short timeOutSeconds = 10) where RESPONSE : class
|
||||
public virtual async Task<RESPONSE?> GetJsonAsync<RESPONSE>(string url, string bearerToken = "", short timeOutSeconds = 10) where RESPONSE : class
|
||||
{
|
||||
RESPONSE? response = default(RESPONSE);
|
||||
Guid guid = Guid.NewGuid();
|
||||
@ -72,6 +76,9 @@ namespace SystemX.Core.Communication
|
||||
httpClient.Timeout = new TimeSpan(0, 0, timeOutSec);
|
||||
httpClient.BaseAddress = new Uri($"{url}");
|
||||
|
||||
if (string.IsNullOrEmpty(bearerToken) == false)
|
||||
httpClient.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", $"{bearerToken}");
|
||||
|
||||
Log4net.WriteLine($"[GET] Request({guid})::{url}", LogType.HTTP);
|
||||
|
||||
DateTime requestTime = DateTime.Now;
|
||||
@ -88,6 +95,7 @@ namespace SystemX.Core.Communication
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
protected HttpClientHandler GetClientHandler()
|
||||
{
|
||||
HttpClientHandler clientHandler = new HttpClientHandler();
|
||||
|
||||
@ -12,14 +12,6 @@ namespace SystemX.Core.DB
|
||||
{
|
||||
public static class DBTransaction
|
||||
{
|
||||
/// <summary>
|
||||
/// Get SqlServer Connection String
|
||||
/// </summary>
|
||||
public static string ConvertToConnectionString(this DataBase dbConfig)
|
||||
{
|
||||
return $"server={dbConfig.IP},{dbConfig.Port}; user id={dbConfig.UserID}; password={dbConfig.Password}; database={dbConfig.DBName}; TrustServerCertificate=true;";
|
||||
}
|
||||
|
||||
public static IEnumerable<TEntity>? GetEntity<TEntity>(this DbContext dbContext) where TEntity : class
|
||||
{
|
||||
IEnumerable<TEntity>? entity = default;
|
||||
|
||||
@ -16,6 +16,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="CsvHelper" Version="33.0.1" />
|
||||
<PackageReference Include="log4net" Version="3.0.4" />
|
||||
<PackageReference Include="Microsoft.Data.SqlClient" Version="6.0.1" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.15" />
|
||||
|
||||
28
Projects/SystemX.Core/SystemX.Core/Utils/CsvUtils.cs
Normal file
28
Projects/SystemX.Core/SystemX.Core/Utils/CsvUtils.cs
Normal file
@ -0,0 +1,28 @@
|
||||
using CsvHelper.Configuration;
|
||||
using CsvHelper;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using static System.Runtime.InteropServices.JavaScript.JSType;
|
||||
|
||||
public static class CsvUtils
|
||||
{
|
||||
public static async Task<byte[]> ExportToCsvByteArray<T>(this IEnumerable<T> data) where T : class
|
||||
{
|
||||
using var memoryStream = new MemoryStream();
|
||||
using var streamWriter = new StreamWriter(memoryStream, Encoding.UTF8);
|
||||
using var csvWriter = new CsvWriter(streamWriter, new CsvConfiguration(CultureInfo.InvariantCulture));
|
||||
|
||||
await csvWriter.WriteRecordsAsync(data);
|
||||
await streamWriter.FlushAsync();
|
||||
|
||||
memoryStream.Position = 0;
|
||||
|
||||
return memoryStream.ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
18
Projects/SystemX.Core/SystemX.Core/Utils/DBUtils.cs
Normal file
18
Projects/SystemX.Core/SystemX.Core/Utils/DBUtils.cs
Normal file
@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using SystemX.Core.Config.Model;
|
||||
|
||||
public static class DBUtils
|
||||
{
|
||||
/// <summary>
|
||||
/// Get SqlServer Connection String
|
||||
/// </summary>
|
||||
public static string ConvertToConnectionString(this DataBase dbConfig)
|
||||
{
|
||||
return $"server={dbConfig.IP},{dbConfig.Port}; user id={dbConfig.UserID}; password={dbConfig.Password}; database={dbConfig.DBName};";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user