@@ -36,18 +36,17 @@ private async Task ExecuteJob(IJobExecutionContext context)
3636 JsonSerializer . Deserialize < Dictionary < string , string > > ( strHeaders . Trim ( ) ) ;
3737
3838 var strAction = data . GetString ( HttpJobKeys . PropertyRequestAction ) ;
39- HttpAction action ;
4039 if ( strAction == null )
4140 {
4241 logger . LogWarning ( "[{runInstanceId}]. Cannot run HttpJob. No http action specified." ,
4342 context . FireInstanceId ) ;
4443 throw new JobExecutionException ( "No http action specified" ) ;
4544 }
46- action = Enum . Parse < HttpAction > ( strAction ) ;
45+ var action = Enum . Parse < HttpAction > ( strAction ) ;
4746
4847 logger . LogDebug ( "[{runInstanceId}]. Creating HttpClient..." , context . FireInstanceId ) ;
4948 HttpClient httpClient ;
50- if ( data . TryGetBoolean ( HttpJobKeys . PropertyIgnoreVerifySsl , out var IgnoreVerifySsl ) && IgnoreVerifySsl )
49+ if ( data . TryGetBoolean ( HttpJobKeys . PropertyIgnoreVerifySsl , out var ignoreVerifySsl ) && ignoreVerifySsl )
5150 {
5251 httpClient = httpClientFactory . CreateClient ( Constants . HttpClientIgnoreVerifySsl ) ;
5352 logger . LogInformation ( "[{runInstanceId}]. Created ignore SSL validation HttpClient." ,
@@ -63,14 +62,7 @@ private async Task ExecuteJob(IJobExecutionContext context)
6362 // configure time out. Default 100 secs
6463 if ( timeoutInSec . HasValue )
6564 {
66- if ( timeoutInSec > 0 )
67- {
68- httpClient . Timeout = TimeSpan . FromSeconds ( timeoutInSec . Value ) ;
69- }
70- else
71- {
72- httpClient . Timeout = Timeout . InfiniteTimeSpan ;
73- }
65+ httpClient . Timeout = timeoutInSec > 0 ? TimeSpan . FromSeconds ( timeoutInSec . Value ) : Timeout . InfiniteTimeSpan ;
7466 }
7567
7668 if ( headers != null )
@@ -90,24 +82,17 @@ private async Task ExecuteJob(IJobExecutionContext context)
9082 var response = new HttpResponseMessage ( ) ;
9183 logger . LogInformation ( "[{runInstanceId}]. Sending '{action}' request to specified url '{url}'." ,
9284 context . FireInstanceId , action , url ) ;
93- switch ( action )
85+ response = action switch
9486 {
95- case HttpAction . Get :
96- response = await httpClient . GetAsync ( url , context . CancellationToken ) ;
97- break ;
98- case HttpAction . Post :
99- response = await httpClient . PostAsync ( url , reqParam , context . CancellationToken ) ;
100- break ;
101- case HttpAction . Put :
102- response = await httpClient . PutAsync ( url , reqParam , context . CancellationToken ) ;
103- break ;
104- case HttpAction . Delete :
105- response = await httpClient . DeleteAsync ( url , context . CancellationToken ) ;
106- break ;
107- }
87+ HttpAction . Get => await httpClient . GetAsync ( url , context . CancellationToken ) ,
88+ HttpAction . Post => await httpClient . PostAsync ( url , reqParam , context . CancellationToken ) ,
89+ HttpAction . Put => await httpClient . PutAsync ( url , reqParam , context . CancellationToken ) ,
90+ HttpAction . Delete => await httpClient . DeleteAsync ( url , context . CancellationToken ) ,
91+ _ => response
92+ } ;
10893
10994 var result = await response . Content . ReadAsStringAsync ( context . CancellationToken ) ;
110- logger . LogInformation ( "[{runInstanceId}]. Response tatus code '{code}'." ,
95+ logger . LogInformation ( "[{runInstanceId}]. Response status code '{code}'." ,
11196 context . FireInstanceId , response . StatusCode ) ;
11297 context . Result = result ;
11398 context . SetIsSuccess ( response . IsSuccessStatusCode ) ;
@@ -133,7 +118,6 @@ public async Task Execute(IJobExecutionContext context)
133118 context . CancellationToken . Register ( ( ) =>
134119 {
135120 // We received a cancellation message, cancel the TaskCompletionSource.Task
136- // ReSharper disable once InvertIf
137121 taskCompletionSource . TrySetCanceled ( ) ;
138122 } ) ;
139123 var completedTask = await Task . WhenAny ( ExecuteJob ( context ) , taskCompletionSource . Task ) ;
0 commit comments