본문 바로가기

전체 글351

[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.
[MFC] Log 생성. #include #include // for PathIsDirectory() #include // for std::put_time #include // for std::time_t and std::tm #include CString logfileDirectory = CurPath + "\\log"; if (!PathIsDirectory(logfileDirectory)) { CreateDirectory(logfileDirectory, NULL); } // get current date and time std::time_t now = std::time(nullptr); std::tm now_tm = *std::localtime(&now); std::stringstream ss1, ss2; ss1 2023. 1. 12.
[MFC] 현재 실행중인 프로그램 경로 구하기 #define MAX_PATH = 200 CString curPath; char szBuf[MAX_PATH]; ZeroMemory(szBuf, _countof(szBuf)); GetModuleFileName(NULL, szBuf, MAX_PATH); char *pBuf = strrchr(szBuf, '\\'); if(pBuf) { *pBuf = '\0'; curPath.Format("%s", szBuf); } 2023. 1. 12.
[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.
[MFC] Exception handle, try catch, event viewer try { int i; i++; AfxThrowUserException(); } catch (CException* ce) { CString strExceptionMessage; TCHAR szMsg[1024]; memset(szMsg, 0x00, sizeof(szMsg)); if (ce->GetErrorMessage(szMsg, 1024)) { CString strErrorMessage = szMsg; strExceptionMessage.Format( //_T("Url - %s\n") _T("Error Code - %d\n") _T("Error Message - %s\n") _T("Error Line - %d\n") _T("test") , GetLastError() , strErrorMessage , _.. 2022. 11. 4.
[MFC] DPI Scale Windows SDK 8.1 미만 코드. 그 이상으로 필요시 https://learn.microsoft.com/ko-kr/windows/win32/api/winuser/nf-winuser-getdpiforwindow 해당 함수 사용. GetDpiForWindow function (winuser.h) - Win32 apps Returns the dots per inch (dpi) value for the specified window. learn.microsoft.com void CTestDlg::InitializeDPIScale(HWND hwnd) { CDC* pDC = GetDC(); m_fDPIScaleX = GetDeviceCaps(pDC->GetSafeHdc(), LOGPIXELSX) / 96.0.. 2022. 9. 21.
[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.
[인터파크/Yes24] 취켓팅 보호되어 있는 글 입니다. 2022. 6. 16.
[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.