Skip to content

Commit 85386f8

Browse files
committed
[R] Expression bodies, usings, null check
1 parent 232fa9c commit 85386f8

14 files changed

+46
-106
lines changed

src/Simplify.Scheduler/Jobs/Crontab/CrontabProcessor.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,7 @@ public CrontabProcessor(string crontabExpression)
5858
/// <summary>
5959
/// Calculates the next occurrences.
6060
/// </summary>
61-
public void CalculateNextOccurrences()
62-
{
63-
CalculateNextOccurrences(TimeProvider.Current.Now);
64-
}
61+
public void CalculateNextOccurrences() => CalculateNextOccurrences(TimeProvider.Current.Now);
6562

6663
/// <summary>
6764
/// Calculates the next occurrences.
@@ -93,9 +90,6 @@ public bool IsMatching(DateTime time)
9390
/// Determines whether current time is matching next occurrence.
9491
/// </summary>
9592
/// <returns></returns>
96-
public bool IsMatching()
97-
{
98-
return IsMatching(TimeProvider.Current.Now);
99-
}
93+
public bool IsMatching() => IsMatching(TimeProvider.Current.Now);
10094
}
10195
}

src/Simplify.Scheduler/Jobs/Crontab/CrontabProcessorFactory.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@ public class CrontabProcessorFactory : ICrontabProcessorFactory
1010
/// </summary>
1111
/// <param name="crontabExpression">The crontab expression.</param>
1212
/// <returns></returns>
13-
public ICrontabProcessor Create(string crontabExpression)
14-
{
15-
return new CrontabProcessor(crontabExpression);
16-
}
13+
public ICrontabProcessor Create(string crontabExpression) => new CrontabProcessor(crontabExpression);
1714
}
1815
}

src/Simplify.Scheduler/Jobs/Crontab/CrontabSchedulerJob.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,7 @@ public override void Start()
9393
/// <summary>
9494
/// Stops and disposes job timer.
9595
/// </summary>
96-
public override void Stop()
97-
{
98-
Dispose();
99-
}
96+
public override void Stop() => Dispose();
10097

10198
/// <summary>
10299
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

src/Simplify.Scheduler/Jobs/SchedulerJobFactory.cs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,7 @@ public SchedulerJobFactory(string appName)
3030
/// <param name="invokeMethodName">Name of the invoke method.</param>
3131
/// <param name="startupArgs">The startup arguments.</param>
3232
/// <returns></returns>
33-
public ISchedulerJob CreateJob<T>(string invokeMethodName,
34-
object? startupArgs)
35-
{
36-
return new SchedulerJob<T>(invokeMethodName, CreateJobArgs(startupArgs));
37-
}
33+
public ISchedulerJob CreateJob<T>(string invokeMethodName, object? startupArgs) => new SchedulerJob<T>(invokeMethodName, CreateJobArgs(startupArgs));
3834

3935
/// <summary>
4036
/// Creates the crontab-based scheduler job.
@@ -66,9 +62,6 @@ private static string FormatConfigurationSectionName<T>(string? configurationSec
6662
return type.Name + "Settings";
6763
}
6864

69-
private IJobArgs CreateJobArgs(object? startupArgs)
70-
{
71-
return new JobArgs(_appName, startupArgs);
72-
}
65+
private IJobArgs CreateJobArgs(object? startupArgs) => new JobArgs(_appName, startupArgs);
7366
}
7467
}

src/Simplify.Scheduler/MultitaskScheduler.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,7 @@ public class MultitaskScheduler : SchedulerJobsHandler
1616
/// <summary>
1717
/// Initializes a new instance of the <see cref="MultitaskScheduler" /> class.
1818
/// </summary>
19-
public MultitaskScheduler()
20-
{
21-
Console.CancelKeyPress += StopJobs;
22-
}
19+
public MultitaskScheduler() => Console.CancelKeyPress += StopJobs;
2320

2421
/// <summary>
2522
/// Gets or sets the current command line processor.

src/Simplify.Scheduler/SchedulerJobsHandler.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -237,16 +237,15 @@ private void Run(object state)
237237

238238
private void RunScoped(ISchedulerJobRepresentation job)
239239
{
240-
using (var scope = DIContainer.Current.BeginLifetimeScope())
241-
{
242-
var jobObject = scope.Resolver.Resolve(job.JobClassType);
240+
using var scope = DIContainer.Current.BeginLifetimeScope();
243241

244-
OnJobStart?.Invoke(job);
242+
var jobObject = scope.Resolver.Resolve(job.JobClassType);
245243

246-
InvokeJobMethod(job, jobObject);
244+
OnJobStart?.Invoke(job);
247245

248-
OnJobFinish?.Invoke(job);
249-
}
246+
InvokeJobMethod(job, jobObject);
247+
248+
OnJobFinish?.Invoke(job);
250249
}
251250

252251
private void RunBasicJob(ISchedulerJobRepresentation job)

src/Simplify.WindowsServices/CommandLine/CommandLineProcessor.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ public virtual ProcessCommandLineResult ProcessCommandLineArguments(string[]? ar
4444

4545
case CommandLineAction.RunAsConsole:
4646
return ProcessCommandLineResult.SkipServiceStart;
47+
48+
case CommandLineAction.UndefinedAction:
49+
break;
50+
51+
default:
52+
throw new ArgumentOutOfRangeException();
4753
}
4854

4955
Console.WriteLine($"Undefined service parameters: '{string.Concat(args)}'");
Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Configuration.Install;
1+
using System;
2+
using System.Configuration.Install;
23
using System.Reflection;
34

45
namespace Simplify.WindowsServices.CommandLine
@@ -12,26 +13,17 @@ public class InstallationController : IInstallationController
1213
/// <summary>
1314
/// Installs the service.
1415
/// </summary>
15-
public virtual void InstallService()
16-
{
17-
ManagedInstallerClass.InstallHelper(new[] { "/LogFile=", "/LogToConsole=true", GetEntryAssemblyLocation() });
18-
}
16+
public virtual void InstallService() => ManagedInstallerClass.InstallHelper(new[] { "/LogFile=", "/LogToConsole=true", GetEntryAssemblyLocation() });
1917

2018
/// <summary>
2119
/// Uninstalls the service.
2220
/// </summary>
23-
public virtual void UninstallService()
24-
{
25-
ManagedInstallerClass.InstallHelper(new[] { "/u", "/LogFile=", "/LogToConsole=true", GetEntryAssemblyLocation() });
26-
}
21+
public virtual void UninstallService() => ManagedInstallerClass.InstallHelper(new[] { "/u", "/LogFile=", "/LogToConsole=true", GetEntryAssemblyLocation() });
2722

2823
/// <summary>
2924
/// Gets the entry assembly location.
3025
/// </summary>
3126
/// <returns></returns>
32-
protected string GetEntryAssemblyLocation()
33-
{
34-
return Assembly.GetEntryAssembly().Location;
35-
}
27+
protected string GetEntryAssemblyLocation() => Assembly.GetEntryAssembly()?.Location ?? throw new InvalidOperationException("Entry assembly location is null");
3628
}
3729
}

src/Simplify.WindowsServices/Jobs/Crontab/CrontabProcessor.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,7 @@ public CrontabProcessor(string crontabExpression)
5858
/// <summary>
5959
/// Calculates the next occurrences.
6060
/// </summary>
61-
public void CalculateNextOccurrences()
62-
{
63-
CalculateNextOccurrences(TimeProvider.Current.Now);
64-
}
61+
public void CalculateNextOccurrences() => CalculateNextOccurrences(TimeProvider.Current.Now);
6562

6663
/// <summary>
6764
/// Calculates the next occurrences.
@@ -93,9 +90,6 @@ public bool IsMatching(DateTime time)
9390
/// Determines whether current time is matching next occurrence.
9491
/// </summary>
9592
/// <returns></returns>
96-
public bool IsMatching()
97-
{
98-
return IsMatching(TimeProvider.Current.Now);
99-
}
93+
public bool IsMatching() => IsMatching(TimeProvider.Current.Now);
10094
}
10195
}

src/Simplify.WindowsServices/Jobs/Crontab/CrontabProcessorFactory.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@ public class CrontabProcessorFactory : ICrontabProcessorFactory
1010
/// </summary>
1111
/// <param name="crontabExpression">The crontab expression.</param>
1212
/// <returns></returns>
13-
public ICrontabProcessor Create(string crontabExpression)
14-
{
15-
return new CrontabProcessor(crontabExpression);
16-
}
13+
public ICrontabProcessor Create(string crontabExpression) => new CrontabProcessor(crontabExpression);
1714
}
1815
}

0 commit comments

Comments
 (0)