Skip to content

Commit fc44c8c

Browse files
committed
Merge branch 'chore/modernize_code'
2 parents 363a989 + 4368fb9 commit fc44c8c

File tree

136 files changed

+2983
-8394
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

136 files changed

+2983
-8394
lines changed

src/Directory.Build.props

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<Project>
2+
<PropertyGroup>
3+
<LangVersion>latestMajor</LangVersion>
4+
</PropertyGroup>
5+
<ItemGroup>
6+
<PackageReference Include="IsExternalInit" Version="1.0.1">
7+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
8+
<PrivateAssets>all</PrivateAssets>
9+
</PackageReference>
10+
</ItemGroup>
11+
</Project>

src/InEngine.Commands/AlwaysFail.cs

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,19 @@
22
using InEngine.Core;
33
using InEngine.Core.Exceptions;
44

5-
namespace InEngine.Commands
5+
namespace InEngine.Commands;
6+
7+
/// <summary>
8+
/// Dummy command for testing and sample code.
9+
/// </summary>
10+
public class AlwaysFail : AbstractCommand
611
{
7-
/// <summary>
8-
/// Dummy command for testing and sample code.
9-
/// </summary>
10-
public class AlwaysFail : AbstractCommand
11-
{
12-
public override void Run()
13-
{
14-
throw new CommandFailedException("This command always fails.");
15-
}
12+
public override void Run() => throw new CommandFailedException("This command always fails.");
1613

17-
public override void Failed(Exception exception)
18-
{
19-
Error(exception.Message);
20-
if (exception.InnerException != null)
21-
Error(exception.InnerException.Message);
22-
}
14+
public override void Failed(Exception exception)
15+
{
16+
Error(exception.Message);
17+
if (exception.InnerException != null)
18+
Error(exception.InnerException.Message);
2319
}
24-
}
20+
}
Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
using InEngine.Core;
22

3-
namespace InEngine.Commands
3+
namespace InEngine.Commands;
4+
5+
/// <summary>
6+
/// Dummy command for testing and sample code.
7+
/// </summary>
8+
public class AlwaysSucceed : AbstractCommand
49
{
5-
/// <summary>
6-
/// Dummy command for testing and sample code.
7-
/// </summary>
8-
public class AlwaysSucceed : AbstractCommand
9-
{
10-
public override void Run()
11-
{
12-
Info("This command always succeeds.");
13-
}
14-
}
15-
}
10+
public override void Run() => Info("This command always succeeds.");
11+
}
Lines changed: 29 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,40 @@
1-
using System;
2-
using System.Collections.Generic;
1+
using System.Collections.Generic;
32
using CommandLine;
43
using InEngine.Core;
54
using InEngine.Core.Commands;
65
using InEngine.Core.Scheduling;
76

8-
namespace InEngine.Commands
7+
namespace InEngine.Commands;
8+
9+
public class CommandsPlugin : AbstractPlugin
910
{
10-
public class CommandsPlugin : AbstractPlugin
11-
{
12-
[VerbOption("fail", HelpText = "Always fail. Useful for end-to-end testing.")]
13-
public AlwaysFail AlwaysFail { get; set; }
11+
[VerbOption("fail", HelpText = "Always fail. Useful for end-to-end testing.")]
12+
public AlwaysFail AlwaysFail { get; set; }
1413

15-
[VerbOption("succeed", HelpText = "A null operation command. Literally does nothing.")]
16-
public AlwaysSucceed Null { get; set; }
14+
[VerbOption("succeed", HelpText = "A null operation command. Literally does nothing.")]
15+
public AlwaysSucceed Null { get; set; }
1716

18-
public override void Schedule(ISchedule schedule)
19-
{
20-
schedule.Command(new Echo { VerbatimText = "Core Echo command." })
21-
.EverySecond()
22-
.Before(x => Console.WriteLine("Before"))
23-
.After(x => Console.WriteLine("After"))
24-
.PingBefore("http://www.google.com")
25-
.PingAfter("http://www.google.com")
26-
.WriteOutputTo("AlwaysSucceedWrite.log")
27-
.AppendOutputTo("AlwaysSucceedAppend.log")
28-
.EmailOutputTo("example@inengine.net");
17+
public override void Schedule(ISchedule schedule)
18+
{
19+
schedule.Command(new Echo { VerbatimText = "Core Echo command." })
20+
.EveryMinute()
21+
.Before(x => x.Line($"Before {x.Name}"))
22+
.After(x => x.Line($"After {x.Name}"))
23+
.PingBefore("https://www.google.com")
24+
.PingAfter("https://www.google.com")
25+
.WriteOutputTo("AlwaysSucceedWrite.log")
26+
.AppendOutputTo("AlwaysSucceedAppend.log")
27+
.EmailOutputTo("example@inengine.net");
2928

30-
schedule.Command(new[] {
31-
new Echo { VerbatimText = "Chain Link 1" },
32-
new Echo { VerbatimText = "Chain Link 2" },
33-
}).EverySecond();
29+
schedule.Command(new AbstractCommand[] {
30+
new Echo { VerbatimText = "Chain Link 1" },
31+
new Echo { VerbatimText = "Chain Link 2" },
32+
}).EveryFiveMinutes();
3433

35-
schedule.Command(new List<AbstractCommand> {
36-
new Echo { VerbatimText = "Chain Link A" },
37-
new AlwaysFail(),
38-
new Echo { VerbatimText = "Chain Link C" },
39-
}).EverySecond();
40-
}
34+
schedule.Command(new List<AbstractCommand> {
35+
new Echo { VerbatimText = "Chain Link A" },
36+
new AlwaysFail(),
37+
new Echo { VerbatimText = "Chain Link C" },
38+
}).EveryFifteenMinutes();
4139
}
42-
}
40+
}

src/InEngine.Commands/InEngine.Commands.csproj

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<TargetFrameworks>net47;net462;net461</TargetFrameworks>
3+
<TargetFramework>net6.0</TargetFramework>
4+
<PackageVersion>5.0.0</PackageVersion>
45
</PropertyGroup>
56
<PropertyGroup>
67
<Version>4.0.0</Version>
7-
<FileVersion>4.0.0</FileVersion>
8+
<FileVersion>5.0.0</FileVersion>
89
<Authors>Ethan Hann</Authors>
910
<Description>Plugin-based queuing and scheduling command server.</Description>
10-
<Copyright>Copyright © 2017 Ethan Hann</Copyright>
11+
<Copyright>Copyright © 2022 Ethan Hann</Copyright>
1112
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
1213
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
1314
</PropertyGroup>
Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
using InEngine.Core;
1+
using System.Threading.Tasks;
2+
using InEngine.Core;
23

3-
namespace InEngine.Commands.Sample
4+
namespace InEngine.Commands.Sample;
5+
6+
using System;
7+
8+
/*
9+
* At a minimum, a command must implement the AbstractCommand interface.
10+
*
11+
* A command result must be returned from the Run method.
12+
* The command result has an optional message. This is especially helpful
13+
* when the command does not finish successfully.
14+
*/
15+
public class Minimal : AbstractCommand
416
{
5-
/*
6-
* At a minimum, a command must implement the AbstractCommand interface.
7-
*
8-
* A command result must be returned from the Run method.
9-
* The command result has an optional message. This is especially helpful
10-
* when the command does not finish successfully.
11-
*/
12-
public class Minimal : AbstractCommand
13-
{
14-
public override void Run()
15-
{
16-
}
17-
}
17+
public override void Run() => Line("This is an example of a minimal command.");
1818
}
Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
using System.Threading;
22
using InEngine.Core;
33

4-
namespace InEngine.Commands.Sample
4+
namespace InEngine.Commands.Sample;
5+
6+
public class Pause : AbstractCommand
57
{
6-
public class Pause : AbstractCommand
7-
{
8-
public override void Run()
9-
{
10-
Thread.Sleep(3000);
11-
}
12-
}
13-
}
8+
public override void Run() => Thread.Sleep(3000);
9+
}
Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
using CommandLine;
22
using InEngine.Core;
33

4-
namespace InEngine.Commands.Sample
4+
namespace InEngine.Commands.Sample;
5+
6+
public class SampleCommandsPlugin : AbstractPlugin
57
{
6-
public class SampleCommandsPlugin : AbstractPlugin
7-
{
8-
[VerbOption("sample:pause", HelpText = "Pause for a few seconds.")]
9-
public Pause Pause { get; set; }
8+
[VerbOption("sample:pause", HelpText = "Pause for a few seconds.")]
9+
public Pause Pause { get; set; }
1010

11-
[VerbOption("sample:show-progress", HelpText = "A sample command to demonstrate the progress bar.")]
12-
public ShowProgress ShowProgress { get; set; }
11+
[VerbOption("sample:show-progress", HelpText = "A sample command to demonstrate the progress bar.")]
12+
public ShowProgress ShowProgress { get; set; }
1313

14-
[VerbOption("sample:say-hello", HelpText = "A sample command to say \"hello\".")]
15-
public SayHello SayHello { get; set; }
14+
[VerbOption("sample:say-hello", HelpText = "A sample command to say \"hello\".")]
15+
public SayHello SayHello { get; set; }
1616

17-
[VerbOption("sample:minimal", HelpText = "A minimal implementation of a command - does nothing.")]
18-
public Minimal Minimal { get; set; }
19-
}
20-
}
17+
[VerbOption("sample:minimal", HelpText = "A minimal implementation of a command - does nothing.")]
18+
public Minimal Minimal { get; set; }
19+
}
Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
using InEngine.Core;
2-
using System;
32

4-
namespace InEngine.Commands.Sample
3+
namespace InEngine.Commands.Sample;
4+
5+
public class SayHello : AbstractCommand
56
{
6-
public class SayHello : AbstractCommand
7-
{
8-
public override void Run()
9-
{
10-
Console.WriteLine("hello");
11-
}
12-
}
13-
}
7+
public override void Run() => Line("hello");
8+
}
Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
using InEngine.Core;
2+
using System.Threading.Tasks;
23

3-
namespace InEngine.Commands.Sample
4+
namespace InEngine.Commands.Sample;
5+
6+
/*
7+
* The AbstractCommand class adds functionality, including a logger and a
8+
* progress bar.
9+
*/
10+
public class ShowProgress : AbstractCommand
411
{
512
/*
6-
* The AbstractCommand class adds functionality, including a logger and a
7-
* progress bar.
13+
* Note that the override keyword is necessary in the Run method
14+
* signature as the base class method is virtual.
815
*/
9-
public class ShowProgress : AbstractCommand
16+
public override async Task RunAsync()
1017
{
11-
/*
12-
* Note that the override keyword is necessary in the Run method
13-
* signature as the base class method is virtual.
14-
*/
15-
public override void Run()
16-
{
17-
// Define the ticks (aka steps) for the command...
18-
var maxTicks = 100000;
19-
SetProgressBarMaxTicks(maxTicks);
18+
// Define the ticks (aka steps) for the command...
19+
const int maxTicks = 100000;
20+
SetProgressBarMaxTicks(maxTicks);
2021

21-
// Do some work...
22-
for (var i = 0; i <= maxTicks;i++)
23-
{
24-
// Update the command's progress
25-
UpdateProgress(i);
26-
}
22+
// Do some work...
23+
for (var i = 0; i <= maxTicks;i++)
24+
{
25+
// Update the command's progress
26+
await Task.Run(() => UpdateProgress(i));
2727
}
2828
}
29-
}
29+
}

0 commit comments

Comments
 (0)