본문 바로가기

C#83

[C#] 음력 변환 KoreanLunisolarCalendar KoreanLunisolarCalendar 클래스 (System.Globalization) 시간을 월, 일 및 연도로 구분해서 표시합니다. 연도는 그레고리오력을 사용하여 계산되고 일 및 월은 음양력을 사용하여 계산됩니다. learn.microsoft.com // See https://aka.ms/new-console-template for more information using System.Globalization; Console.WriteLine("Hello, World!"); // KoreanLunisolarCalendar 클래스의 인스턴스를 생성합니다. var koreanLunisolarCalendar = new KoreanLunisolarCalendar.. 2023. 10. 27.
[C#] Secrets.json 사용 static void Main(string[] args) { var config = new ConfigurationBuilder() .AddUserSecrets() .Build(); Console.WriteLine("Hello, World!"); Console.WriteLine($"Hello, {config["Test"]}"); } 2023. 10. 24.
[C#] Worker 프로젝트에서 appsettings.json 불러오기, Serilog 사용하여 로컬 파일 로그 저장. appsettins.json 파일 { "Logging": { "LogLevel": { "Default": "Debug", "System": "Information", "Microsoft": "Information" } }, "Test": { "ApiUrl": "https://test.com", "Time": "0400" }, "Prod": { "ApiUrl": "https://prod.com", "Time": "0400" }, "slackUrl": "https://hooks.slack.com/services/123123324" } Program.cs using Serilog; using Serilog.Events; IHost host = Host.CreateDefaultBuilder(args) .Conf.. 2023. 10. 24.
[C#] Web API NET 7 Background Service 추가 초기 설정. 1. Program.cs public class Program { public static void Main(string[] args) { var builder = WebApplication.CreateBuilder(args); // Add services to the container. builder.Services.AddControllers(); // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle builder.Services.AddEndpointsApiExplorer(); builder.Services.AddSwaggerGen(); // 0. json 환경 변수 파일 읽기. builder.Co.. 2023. 2. 16.
[C#] PublishSingleFile 프로젝트를 런타임 설치 없이 실행하고 싶을 때. 정성태님 블로그 : https://www.sysnet.pe.kr/2/0/13159?pageno=0 .NET Framework: 2066. C# - PublishSingleFile과 관련된 옵션 .NET Framework: 2066. C# - PublishSingleFile과 관련된 옵션 [링크 복사], [링크+제목 복사] 조회: 51 글쓴 사람 정성태 (techsharer at outlook.com) 홈페이지 첨부 파일 부모글 보이기/감추기 C# - PublishSingleFile과 관 www.sysnet.pe.kr Exe net6.0 enable enable true win-x64 embedded true 2022. 11. 11.
[C#] WPF에서 Windows.Graphics.Capture 사용하여 디스플레이, 프로그램 Screen Capture 사용, NET Framework, NET6 모두 사용. windows 7, 8.1에선 Bitblt 방식으로 디스플레이 또는 프로그램 좌표를 통해 캡쳐를 진행했다. 그러나 windows10 sdk에(windrt) Windows.Graphics.Capture 를 이용하여 캡쳐가 가능하다. 해당 링크는 마이크로소프트 깃허브에 있는 Sample 프로젝트 링크이다. - Windows.UI.Composition-Win32-Samples/dotnet/WPF/ScreenCapture at master · microsoft/Windows.UI.Composition-Win32-Samples (github.com) GitHub - microsoft/Windows.UI.Composition-Win32-Samples: Windows.UI.Composition Win32 Sample.. 2022. 8. 19.
[C#] HttpClient Download With Progress public class HttpClientDownloadWithProgress : IDisposable { private string _downloadUrl; private string _destinationFilePath; private bool disposedValue; private readonly HttpClient _httpClient = new HttpClient { Timeout = TimeSpan.FromDays(1) }; public string DownloadUrl { get => _downloadUrl; set => _downloadUrl = value; } public string DestinationFilePath { get => _destinationFilePath; set =>.. 2022. 6. 29.
[C#] EF Core 간단 사용. 본인이 편하기 위해 작성. 1. Model, Data 폴더 생성. - Model 클래스 작성. - Data 클래스 생성. 2. select 후 insert ot update 실행. 2022. 5. 26.
[C#] .NET 6 - Worker Service Environment.Exit .NET 6에선 더 이상 Environment.Exit 가 더 이상 먹히지 않는다. 프로그램이 종료됐을 때 슬랙 알림을 보내려고 했는데 알림이 오지 않았다. 참고 링크 : .NET 일반 호스트 | Microsoft Docs .NET 일반 호스트 앱 시작 및 수명 관리를 담당하는 .NET 제네릭 호스트에 대해 알아봅니다. docs.microsoft.com 2022. 4. 27.
[C#] string.Create String.Create(Int32, TState, SpanAction) 메서드 (System) | Microsoft Docs String.Create(Int32, TState, SpanAction) 메서드 (System) 특정 길이의 새 문자열을 만든 다음 지정된 콜백을 사용하여 문자열을 초기화합니다.Creates a new string with a specific length and initializes it after creation by using the specified callback. docs.microsoft.com Byte 배열을 Hex(16진수) 문자열로 변환하는 방법 - 📌 자유게시판 - 닷넷데브 (dotnetdev.kr) Byte 배열을 Hex(16진수) 문자열로 변환하는 방법 호오.. 2022. 2. 23.
[C#] FormBorderStyle None 사용시 아이콘, Resize, Move, taskbar click to minimize 1. FormBorderStyle None. 2. 버튼 아이콘 설정. 3. 위에 패널 or label 더블 클릭시 폼 최대화. 4. 위에 패널 or label 마우스 클릭후 폼 이동. 5. form padding으로 폼 Resize. 6. 작업표시줄에서 아이콘 클릭시 폼 최소화, 원상태 복귀. 2. 아이콘 - 환경설정 버튼 : font Wingdings, 16.2pt, style=Bold, text = R - 최소화, 최대화, 닫기 : font Webdings, 13.8pt, style=Bold, text = 0, 1(최대화시 원상 복귀 2), r C#: 아이콘 폰트를 사용해보자. (webdings, wingdings) (tistory.com) C#: 아이콘 폰트를 사용해보자. (webdings, win.. 2022. 2. 18.
[C#] System.Text.Json.JsonSerializer.Serialize 할 때 한글이 유니코드 형식으로 출력 될 때 internal class Program { static void Main(string[] args) { TextEncoderSettings encoderSettings = new(); encoderSettings.AllowRange(UnicodeRanges.All); JsonSerializerOptions settings = new() { WriteIndented = true, //Encoder = System.Text.Encodings.Web.JavaScriptEncoder.Create(encoderSettings), AllowTrailingCommas = true }; if (args.Length == 0) { Console.WriteLine($"{nameof(args)}가 비어있습니다. 파일 경로.. 2022. 2. 11.
[C#] .NET 6 - NativeMemory 사용 static unsafe void Test1() { int* age = (int*)System.Runtime.InteropServices.NativeMemory.Alloc(sizeof(int)); int* ages = (int*)NativeMemory.Alloc(2, sizeof(int)); try { *age = 28; Console.WriteLine($"{*age}"); ages[0] = 29; ages[1] = 30; for (int i = 0; i < 2; i++) { Console.WriteLine($"{i} : {ages[i]}"); } } finally { NativeMemory.Free(age); NativeMemory.Free(ages); } } NativeMemory Class (Sys.. 2022. 1. 12.
[C#] HttpClient download file example [C#] Webview2 runtime 설치 여부 및 설치 (tistory.com) [C#] Webview2 runtime 설치 여부 및 설치 해당 코드는 .NET 5, .NET Framework로 바꿔서 사용해도 됨. using Microsoft.Win32; using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using Sy.. jcoder1.tistory.com 기존엔 WebClient를 이용했지만 ms에서 HttpClient 사용 권장 public static async Task InstallWebview2RuntimeAsync() { // 윈도우가 아니면.. 2022. 1. 11.
[C#] .NET 6 HttpClient - The SSL connection could not be established, see inner exception - 에러 내용 System.Net.Http.Exception Fail StackTrace: at System.Net.Http.ConnectHelper.EstablishSslConnectionAsync(SslClientAuthenticationOptions sslOptions, HttpRequestMessage request, Boolean async, Stream stream, CancellationToken cancellationToken) at System.Net.Http.HttpConnectionPool.ConnectAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken) at System.Net.Htt.. 2021. 12. 14.
[C#] WPF Resource에서 이미지 파일(BitmapImage) 코드로 가져오기 public MainWindow() { InitializeComponent(); SetImage(); } private void SetImage() { var streamResource = Application.GetResourceStream(LoadBitmapFromResource("/Resources/chromaKey_001.jpg")); var bitmapImage = new BitmapImage(); bitmapImage.BeginInit(); bitmapImage.CacheOption = BitmapCacheOption.OnLoad; bitmapImage.StreamSource = streamResource.Stream; bitmapImage.EndInit(); img_box.Source = b.. 2021. 12. 7.
[C#] OpenCV Cam ChromaKey - 캠 크로마키 [C#] WPF - OpenCV, Cam 출력 (tistory.com) [C#] WPF - OpenCV, Cam 출력 소스 : CsharpFramework/CameraCapture at main · tjdskaqks/CsharpFramework · GitHub tjdskaqks/CsharpFramework Contribute to tjdskaqks/CsharpFramework development by creating an account on GitHub. gi.. jcoder1.tistory.com 기존 코드에서 수정된 건 별로 없다. private void _dispatcherTimer_Tick(object sender, EventArgs e) 부분 수정 // 타이머 동작 private void _d.. 2021. 12. 2.
[C# ] 요소수 중점 유통 주유소 재고현황 API 조회 데이터 상세 | 공공데이터포털 (data.go.kr) 공공데이터활용지원센터_요소수 중점 유통 주유소 재고현황_20211120 전국의 중점 유통 주유소의 요소수 재고 현황은 매일 2회 업데이트 됩니다. (12시 기준 재고현황 : 14시, 18시 기준 재고현황 : 20시) * 현재 버전 11월20일 12시 기준 업데이트 완료 www.data.go.kr 해당 페이지에서 활용신청 후 마이페이지에서 들어가면 아래처럼 일반 인증키가 나온다. Header와 Query에서 인증을 두번 해야한다. System.Net.Http.HttpClient httpClient = new(); httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(.. 2021. 11. 20.
[C#] 건강보험심사평가원_병원평가정보서비스 Rest Api 사용 건강보험심사평가원_병원평가정보서비스 | 공공데이터포털 (data.go.kr) 건강보험심사평가원_병원평가정보서비스 건강보험심사평가원에서 제공하는 암호화된 요양기관 기호, 평가항목 등을 기준으로 요양기관의 평가항목별 병원평가결과를 조회하는 서비스 www.data.go.kr 활용신청 후 인증 키를 볼 수 있다. 미리보기 버튼 클릭하면 아래처럼 xml 데이터를 볼 수 있다. 1. 리스트뷰의 아이템을 클릭하면 해당 주소를 웹뷰2 구글 지도로 표시. 2. Get을 전체 리스트를 다 받아올 때까지 반복 조회. - 위에 보이는 totalCount가 numOfRows보다 작을 때까지 반복. - numOfRows가 한페이지당 결과 수인데 totalCount가 작다면 데이터가 끝. using System.Xml; using.. 2021. 11. 13.
[C#] ffmpeg 를 process 실행시 인코딩 예상 시간 구하기 using System; using System.Diagnostics; using System.Threading.Tasks; using System.Text.Json; using System.Text.Json.Serialization; using System.IO; using System.Text; using System.Runtime.InteropServices.ComTypes; using System.Collections.Generic; using System.Linq; using System.Collections.Concurrent; namespace VideoEncoding_console { class Program { static async Task Main(string[] args) { Con.. 2021. 11. 3.