Codemaru 1.0.0.0
QR 코드, 모바일 랜딩 페이지, vCard 연락처 저장과 명함 디자인을 한 화면에서 제공하는 디지털 명함 서비스입니다.
로딩중...
검색중...
일치하는것 없음
Codemaru.Services.Certificates.WinAcmeService 클래스 참조sealed

더 자세히 ...

Codemaru.Services.Certificates.WinAcmeService에 대한 상속 다이어그램 :
Codemaru.Services.Certificates.WinAcmeService에 대한 협력 다이어그램:

Public 멤버 함수

 WinAcmeService (IProcessRunner processRunner)
async Task< WinAcmeTaskInfoGetRenewalTaskAsync (CancellationToken cancellationToken)
Task< ProcessExecutionResultRunRenewAsync (CertificateMonitorOptions options, bool force, CancellationToken cancellationToken)

Private 멤버 함수

async Task< WinAcmeTaskInfoGetTaskDetailAsync (string taskName, string taskPath, string state, CancellationToken cancellationToken)
Task< ProcessExecutionResultRunPowerShellAsync (string command, TimeSpan timeout, int maxOutputChars, CancellationToken cancellationToken)

정적 Private 멤버 함수

static string EscapePowerShellSingleQuotedString (string value)
static string NormalizeTaskPath (string taskPath)
static string GetString (JsonElement root, string propertyName)

Private 속성

readonly IProcessRunner _processRunner

정적 Private 속성

const string PowerShellPath = @"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe"

상세한 설명

win-acme 갱신 작업 상태 조회와 갱신 명령 실행을 담당합니다.

WinAcmeService.cs 파일의 17 번째 라인에서 정의되었습니다.

생성자 & 소멸자 문서화

◆ WinAcmeService()

Codemaru.Services.Certificates.WinAcmeService.WinAcmeService ( IProcessRunner processRunner)
inline

WinAcmeService 클래스의 새 인스턴스를 초기화합니다.

매개변수
processRunner외부 프로세스 실행 서비스입니다.
예외
ArgumentNullException필수 입력 인자 중 하나가 null인 경우 발생합니다.

WinAcmeService.cs 파일의 62 번째 라인에서 정의되었습니다.

63 {
64 _processRunner = processRunner ?? throw new ArgumentNullException(nameof(processRunner));
65 }

다음을 참조함 : _processRunner.

멤버 함수 문서화

◆ EscapePowerShellSingleQuotedString()

string Codemaru.Services.Certificates.WinAcmeService.EscapePowerShellSingleQuotedString ( string value)
inlinestaticprivate

Escape Power Shell Single Quoted String 작업을 수행합니다.

매개변수
value적용할 값입니다.
반환값
Escape Power Shell Single Quoted String 작업에서 생성한 string 결과입니다.

WinAcmeService.cs 파일의 443 번째 라인에서 정의되었습니다.

444 {
445 return value.Replace("'", "''", StringComparison.Ordinal);
446 }

다음에 의해서 참조됨 : GetTaskDetailAsync().

이 함수를 호출하는 함수들에 대한 그래프입니다.:

◆ GetRenewalTaskAsync()

async Task< WinAcmeTaskInfo > Codemaru.Services.Certificates.WinAcmeService.GetRenewalTaskAsync ( CancellationToken cancellationToken)
inline

Renewal Task Async 값을 가져옵니다.

매개변수
cancellationToken취소 요청을 감시하는 토큰입니다.
반환값
Get Renewal Task Async 작업에서 생성한 Task<WinAcmeTaskInfo> 결과입니다.

Codemaru.Services.Certificates.IWinAcmeService를 구현.

WinAcmeService.cs 파일의 91 번째 라인에서 정의되었습니다.

92 {
93 string command = """
94$task = Get-ScheduledTask -ErrorAction SilentlyContinue |
95 Where-Object {
96 $_.TaskName -like '*win-acme*' -or
97 $_.TaskPath -like '*win-acme*' -or
98 $_.Description -like '*win-acme*'
99 } |
100 Select-Object -First 1 TaskName, TaskPath, State
101
102if ($null -eq $task) {
103 return
104}
105
106$task | ConvertTo-Json -Compress
107""";
108
109 ProcessExecutionResult result = await RunPowerShellAsync(
110 command,
111 TimeSpan.FromSeconds(20),
112 4000,
113 cancellationToken).ConfigureAwait(false);
114
115 if (!result.IsSuccess)
116 {
117 return new WinAcmeTaskInfo
118 {
119 IsSuccess = false,
120 Message = $"Failed to query scheduled task. {result.Message} {result.Error}".Trim()
121 };
122 }
123
124 if (string.IsNullOrWhiteSpace(result.Output))
125 {
126 return new WinAcmeTaskInfo
127 {
128 IsSuccess = false,
129 Message = "win-acme scheduled task was not found."
130 };
131 }
132
133 try
134 {
135 using JsonDocument document = JsonDocument.Parse(result.Output);
136 JsonElement root = document.RootElement;
137 string taskName = GetString(root, "TaskName");
138 string taskPath = NormalizeTaskPath(GetString(root, "TaskPath"));
139 string state = GetString(root, "State");
140
141 return await GetTaskDetailAsync(taskName, taskPath, state, cancellationToken).ConfigureAwait(false);
142 }
143 catch (Exception ex)
144 {
145 return new WinAcmeTaskInfo
146 {
147 IsSuccess = false,
148 Message = $"Failed to parse scheduled task information. {ex.Message}"
149 };
150 }
151 }

다음을 참조함 : GetString(), GetTaskDetailAsync(), Codemaru.Models.Certificates.ProcessExecutionResult.IsSuccess, NormalizeTaskPath(), Codemaru.Models.Certificates.ProcessExecutionResult.Output, RunPowerShellAsync().

이 함수 내부에서 호출하는 함수들에 대한 그래프입니다.:

◆ GetString()

string Codemaru.Services.Certificates.WinAcmeService.GetString ( JsonElement root,
string propertyName )
inlinestaticprivate

String 값을 가져옵니다.

매개변수
rootroot에 사용할 JsonElement 값입니다.
propertyNameproperty Name에 사용할 string 값입니다.
반환값
Get String 작업에서 생성한 string 결과입니다.

WinAcmeService.cs 파일의 514 번째 라인에서 정의되었습니다.

515 {
516 return root.TryGetProperty(propertyName, out JsonElement element)
517 ? element.ToString()
518 : string.Empty;
519 }

다음에 의해서 참조됨 : GetRenewalTaskAsync(), GetTaskDetailAsync().

이 함수를 호출하는 함수들에 대한 그래프입니다.:

◆ GetTaskDetailAsync()

async Task< WinAcmeTaskInfo > Codemaru.Services.Certificates.WinAcmeService.GetTaskDetailAsync ( string taskName,
string taskPath,
string state,
CancellationToken cancellationToken )
inlineprivate

Task Detail Async 값을 가져옵니다.

매개변수
taskNametask Name에 사용할 string 값입니다.
taskPathtask Path에 사용할 string 값입니다.
statestate에 사용할 string 값입니다.
cancellationToken취소 요청을 감시하는 토큰입니다.
반환값
Get Task Detail Async 작업에서 생성한 Task<WinAcmeTaskInfo> 결과입니다.

WinAcmeService.cs 파일의 255 번째 라인에서 정의되었습니다.

260 {
261 if (string.IsNullOrWhiteSpace(taskName))
262 {
263 return new WinAcmeTaskInfo
264 {
265 IsSuccess = false,
266 State = state,
267 Message = "win-acme scheduled task name is empty."
268 };
269 }
270
271 string escapedTaskName = EscapePowerShellSingleQuotedString(taskName);
272 string escapedTaskPath = EscapePowerShellSingleQuotedString(taskPath);
273 string command = $$"""
274$t = Get-ScheduledTask -TaskName '{{escapedTaskName}}' -TaskPath '{{escapedTaskPath}}' -ErrorAction SilentlyContinue
275if ($null -eq $t) {
276 return
277}
278
279$i = $t | Get-ScheduledTaskInfo -ErrorAction SilentlyContinue
280
281$lastRun = '-'
282$nextRun = '-'
283$lastResult = '-'
284
285if ($null -ne $i) {
286 if ($i.LastRunTime -ne [DateTime]::MinValue) {
287 $lastRun = $i.LastRunTime.ToString('yyyy-MM-dd HH:mm:ss')
288 }
289
290 if ($i.NextRunTime -ne [DateTime]::MinValue) {
291 $nextRun = $i.NextRunTime.ToString('yyyy-MM-dd HH:mm:ss')
292 }
293
294 $lastResult = $i.LastTaskResult.ToString()
295}
296
297[PSCustomObject]@{
298 TaskName=$t.TaskName
299 TaskPath=$t.TaskPath
300 State=$t.State.ToString()
301 LastRunTime=$lastRun
302 NextRunTime=$nextRun
303 LastTaskResult=$lastResult
304} | ConvertTo-Json -Compress
305""";
306
307 ProcessExecutionResult result = await RunPowerShellAsync(
308 command,
309 TimeSpan.FromSeconds(20),
310 4000,
311 cancellationToken).ConfigureAwait(false);
312
313 if (!result.IsSuccess || string.IsNullOrWhiteSpace(result.Output))
314 {
315 return new WinAcmeTaskInfo
316 {
317 IsSuccess = true,
318 TaskName = taskName,
319 TaskPath = taskPath,
320 State = state,
321 Message = "win-acme scheduled task was found, but detailed task info could not be loaded."
322 };
323 }
324
325 try
326 {
327 using JsonDocument document = JsonDocument.Parse(result.Output);
328 JsonElement root = document.RootElement;
329
330 return new WinAcmeTaskInfo
331 {
332 IsSuccess = true,
333 TaskName = GetString(root, "TaskName"),
334 TaskPath = NormalizeTaskPath(GetString(root, "TaskPath")),
335 State = GetString(root, "State"),
336 LastRunTime = GetString(root, "LastRunTime"),
337 NextRunTime = GetString(root, "NextRunTime"),
338 LastTaskResult = GetString(root, "LastTaskResult"),
339 Message = "win-acme scheduled task is registered."
340 };
341 }
342 catch (Exception ex)
343 {
344 return new WinAcmeTaskInfo
345 {
346 IsSuccess = false,
347 TaskName = taskName,
348 TaskPath = taskPath,
349 State = state,
350 Message = $"Failed to parse task detail. {ex.Message}"
351 };
352 }
353 }

다음을 참조함 : EscapePowerShellSingleQuotedString(), GetString(), Codemaru.Models.Certificates.ProcessExecutionResult.IsSuccess, NormalizeTaskPath(), Codemaru.Models.Certificates.ProcessExecutionResult.Output, RunPowerShellAsync().

다음에 의해서 참조됨 : GetRenewalTaskAsync().

이 함수 내부에서 호출하는 함수들에 대한 그래프입니다.:
이 함수를 호출하는 함수들에 대한 그래프입니다.:

◆ NormalizeTaskPath()

string Codemaru.Services.Certificates.WinAcmeService.NormalizeTaskPath ( string taskPath)
inlinestaticprivate

Normalize Task Path 작업을 수행합니다.

매개변수
taskPathtask Path에 사용할 string 값입니다.
반환값
Normalize Task Path 작업에서 생성한 string 결과입니다.

WinAcmeService.cs 파일의 472 번째 라인에서 정의되었습니다.

473 {
474 if (string.IsNullOrWhiteSpace(taskPath))
475 {
476 return @"\";
477 }
478
479 return taskPath;
480 }

다음에 의해서 참조됨 : GetRenewalTaskAsync(), GetTaskDetailAsync().

이 함수를 호출하는 함수들에 대한 그래프입니다.:

◆ RunPowerShellAsync()

Task< ProcessExecutionResult > Codemaru.Services.Certificates.WinAcmeService.RunPowerShellAsync ( string command,
TimeSpan timeout,
int maxOutputChars,
CancellationToken cancellationToken )
inlineprivate

Run Power Shell Async 작업을 수행합니다.

매개변수
commandcommand에 사용할 string 값입니다.
timeouttimeout에 사용할 TimeSpan 값입니다.
maxOutputCharsmax Output Chars에 사용할 int 값입니다.
cancellationToken취소 요청을 감시하는 토큰입니다.
반환값
Run Power Shell Async 작업에서 생성한 Task<ProcessExecutionResult> 결과입니다.

WinAcmeService.cs 파일의 403 번째 라인에서 정의되었습니다.

408 {
409 string encodedCommand = Convert.ToBase64String(Encoding.Unicode.GetBytes(command));
410 return _processRunner.RunAsync(
411 PowerShellPath,
412 $"-NoProfile -ExecutionPolicy Bypass -EncodedCommand {encodedCommand}",
413 null,
414 timeout,
415 maxOutputChars,
416 cancellationToken);
417 }

다음을 참조함 : _processRunner, PowerShellPath.

다음에 의해서 참조됨 : GetRenewalTaskAsync(), GetTaskDetailAsync().

이 함수를 호출하는 함수들에 대한 그래프입니다.:

◆ RunRenewAsync()

Task< ProcessExecutionResult > Codemaru.Services.Certificates.WinAcmeService.RunRenewAsync ( CertificateMonitorOptions options,
bool force,
CancellationToken cancellationToken )
inline

Run Renew Async 작업을 수행합니다.

매개변수
options동작을 구성하는 설정입니다.
forceforce에 사용할 bool 값입니다.
cancellationToken취소 요청을 감시하는 토큰입니다.
반환값
Run Renew Async 작업에서 생성한 Task<ProcessExecutionResult> 결과입니다.

Codemaru.Services.Certificates.IWinAcmeService를 구현.

WinAcmeService.cs 파일의 193 번째 라인에서 정의되었습니다.

194 {
195 ArgumentNullException.ThrowIfNull(options);
196
197 string arguments = force ? "--renew --force" : "--renew";
198 return _processRunner.RunAsync(
199 options.WacsPath,
200 arguments,
201 Path.GetDirectoryName(options.WacsPath),
202 TimeSpan.FromMinutes(5),
203 options.MaxCommandOutputChars,
204 cancellationToken);
205 }

다음을 참조함 : _processRunner, Codemaru.Options.CertificateMonitorOptions.MaxCommandOutputChars, Codemaru.Options.CertificateMonitorOptions.WacsPath.

멤버 데이터 문서화

◆ _processRunner

readonly IProcessRunner Codemaru.Services.Certificates.WinAcmeService._processRunner
private

process Runner 값을 보관합니다.

WinAcmeService.cs 파일의 36 번째 라인에서 정의되었습니다.

다음에 의해서 참조됨 : RunPowerShellAsync(), RunRenewAsync(), WinAcmeService().

◆ PowerShellPath

const string Codemaru.Services.Certificates.WinAcmeService.PowerShellPath = @"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe"
staticprivate

Power Shell Path 값을 보관합니다.

WinAcmeService.cs 파일의 27 번째 라인에서 정의되었습니다.

다음에 의해서 참조됨 : RunPowerShellAsync().


이 클래스에 대한 문서화 페이지는 다음의 파일로부터 생성되었습니다.: