Skip to content

Commit f0b0340

Browse files
committed
code cleanups
1 parent 1153ec3 commit f0b0340

File tree

6 files changed

+11
-32
lines changed

6 files changed

+11
-32
lines changed

demos/MainDemo/src/Syrna.QuartzAdmin.MainDemo.Jobs/AutoJob.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ public async Task Execute(IJobExecutionContext context)
3838
context.CancellationToken.Register(() =>
3939
{
4040
// We received a cancellation message, cancel the TaskCompletionSource.Task
41-
// ReSharper disable once InvertIf
4241
taskCompletionSource.TrySetCanceled();
4342
});
4443
var completedTask = await Task.WhenAny(ExecuteJob(context), taskCompletionSource.Task);

demos/MainDemo/src/Syrna.QuartzAdmin.MainDemo.Jobs/AutoJob1.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ public async Task Execute(IJobExecutionContext context)
2626
context.CancellationToken.Register(() =>
2727
{
2828
// We received a cancellation message, cancel the TaskCompletionSource.Task
29-
// ReSharper disable once InvertIf
3029
taskCompletionSource.TrySetCanceled();
3130
});
3231
var completedTask = await Task.WhenAny(ExecuteJob(context), taskCompletionSource.Task);

demos/MainDemo/src/Syrna.QuartzAdmin.MainDemo.Jobs/AutoJob2.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ public async Task Execute(IJobExecutionContext context)
4242
context.CancellationToken.Register(() =>
4343
{
4444
// We received a cancellation message, cancel the TaskCompletionSource.Task
45-
// ReSharper disable once InvertIf
4645
taskCompletionSource.TrySetCanceled();
4746
});
4847
var completedTask = await Task.WhenAny(ExecuteJob(context), taskCompletionSource.Task);

demos/MainDemo/src/Syrna.QuartzAdmin.MainDemo.Jobs/HelloJob.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ public async Task Execute(IJobExecutionContext context)
4141
context.CancellationToken.Register(() =>
4242
{
4343
// We received a cancellation message, cancel the TaskCompletionSource.Task
44-
// ReSharper disable once InvertIf
4544
taskCompletionSource.TrySetCanceled();
4645
});
4746
var completedTask = await Task.WhenAny(ExecuteJob(context), taskCompletionSource.Task);

demos/MainDemo/src/Syrna.QuartzAdmin.MainDemo.Jobs/HttpJob.cs

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -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);

demos/MainDemo/src/Syrna.QuartzAdmin.MainDemo.Jobs/LongJob.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ public async Task Execute(IJobExecutionContext context)
5454
context.CancellationToken.Register(() =>
5555
{
5656
// We received a cancellation message, cancel the TaskCompletionSource.Task
57-
// ReSharper disable once InvertIf
5857
taskCompletionSource.TrySetCanceled();
5958
});
6059
var completedTask = await Task.WhenAny(ExecuteJob(context), taskCompletionSource.Task);

0 commit comments

Comments
 (0)