Skip to content

Commit 8557258

Browse files
committed
[add] null checks
[edit] switch to better exceptions
1 parent 4fa1382 commit 8557258

File tree

4 files changed

+30
-25
lines changed

4 files changed

+30
-25
lines changed

src/Simplify.Scheduler/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Changelog
22

3+
## [1.4.0] - 2024-01-09
4+
5+
### Added
6+
7+
- Null checks
8+
- Switch to better exceptions
9+
310
## [1.3.1] - 2023-08-24
411

512
### Added

src/Simplify.Scheduler/MultitaskScheduler.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.ComponentModel;
23
using System.Reflection;
34
using System.Threading;
45
using Simplify.Scheduler.CommandLine;
@@ -60,7 +61,7 @@ public bool Start(string[]? args = null)
6061
break;
6162

6263
default:
63-
throw new ArgumentOutOfRangeException();
64+
throw new InvalidEnumArgumentException(nameof(commandLineProcessResult));
6465
}
6566

6667
return true;
@@ -69,7 +70,7 @@ public bool Start(string[]? args = null)
6970
/// <summary>
7071
/// Called when scheduler is about to stop, main stopping point
7172
/// </summary>
72-
protected void StopJobs(object sender, ConsoleCancelEventArgs args)
73+
protected void StopJobs(object? sender, ConsoleCancelEventArgs args)
7374
{
7475
StopJobs();
7576

src/Simplify.Scheduler/SchedulerJobsHandler.cs

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.ComponentModel;
34
using System.Linq;
45
using System.Reflection;
56
using System.Threading.Tasks;
@@ -199,8 +200,11 @@ private void InitializeJob(ICrontabSchedulerJob job)
199200
_jobs.Add(job);
200201
}
201202

202-
private void OnCronTimerTick(object state)
203+
private void OnCronTimerTick(object? state)
203204
{
205+
if (state is null)
206+
throw new ArgumentNullException(nameof(state));
207+
204208
var job = (ICrontabSchedulerJob)state;
205209

206210
if (job.CrontabProcessor == null)
@@ -214,8 +218,11 @@ private void OnCronTimerTick(object state)
214218
OnStartWork(state);
215219
}
216220

217-
private void OnStartWork(object state)
221+
private void OnStartWork(object? state)
218222
{
223+
if (state is null)
224+
throw new ArgumentNullException(nameof(state));
225+
219226
var job = (ICrontabSchedulerJob)state;
220227

221228
lock (_workingJobsTasks)
@@ -232,8 +239,11 @@ private void OnStartWork(object state)
232239

233240
#region Execution
234241

235-
private async Task Run(object state)
242+
private async Task Run(object? state)
236243
{
244+
if (state is null)
245+
throw new ArgumentNullException(nameof(state));
246+
237247
var (jobTaskID, job) = (Tuple<long, ICrontabSchedulerJob>)state;
238248

239249
try
@@ -291,26 +301,13 @@ private async Task RunBasicJob(ISchedulerJobRepresentation job)
291301

292302
private Task InvokeJobMethod(ISchedulerJobRepresentation job, object jobObject)
293303
{
294-
object result;
295-
296-
switch (job.InvokeMethodParameterType)
304+
var result = job.InvokeMethodParameterType switch
297305
{
298-
case InvokeMethodParameterType.Parameterless:
299-
result = job.InvokeMethodInfo.Invoke(jobObject, null);
300-
break;
301-
302-
case InvokeMethodParameterType.AppName:
303-
result = job.InvokeMethodInfo.Invoke(jobObject, new object[] { AppName });
304-
break;
305-
306-
case InvokeMethodParameterType.Args:
307-
result = job.InvokeMethodInfo.Invoke(jobObject, new object[] { job.JobArgs });
308-
break;
309-
310-
default:
311-
throw new ArgumentOutOfRangeException();
312-
}
313-
306+
InvokeMethodParameterType.Parameterless => job.InvokeMethodInfo.Invoke(jobObject, null),
307+
InvokeMethodParameterType.AppName => job.InvokeMethodInfo.Invoke(jobObject, new object[] { AppName }),
308+
InvokeMethodParameterType.Args => job.InvokeMethodInfo.Invoke(jobObject, new object[] { job.JobArgs }),
309+
_ => throw new InvalidEnumArgumentException(nameof(job.InvokeMethodParameterType)),
310+
};
314311
if (result is Task task)
315312
return task;
316313

src/Simplify.Scheduler/Simplify.Scheduler.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
99
<GenerateDocumentationFile>true</GenerateDocumentationFile>
1010

11-
<Version>1.3.1</Version>
11+
<Version>1.4</Version>
1212

1313
<Authors>Alexander Krylkov</Authors>
1414
<Product>Simplify</Product>

0 commit comments

Comments
 (0)