Skip to content

Commit 9380111

Browse files
committed
Merge branch '3.4-dev'
2 parents be51482 + dcffd98 commit 9380111

35 files changed

+331
-166
lines changed
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
using System;
2+
using InEngine.Core;
23
using InEngine.Core.Exceptions;
34

4-
namespace InEngine.Core.Commands
5+
namespace InEngine.Commands
56
{
67
/// <summary>
78
/// Dummy command for testing and sample code.

src/InEngine.Core/Commands/AlwaysSucceed.cs renamed to src/InEngine.Commands/AlwaysSucceed.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
namespace InEngine.Core.Commands
1+
using InEngine.Core;
2+
3+
namespace InEngine.Commands
24
{
35
/// <summary>
46
/// Dummy command for testing and sample code.

src/InEngine.Commands/Options.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
using CommandLine;
2-
using InEngine.Commands.Sample;
2+
using CommandLine.Text;
33
using InEngine.Core;
44

55
namespace InEngine.Commands
66
{
77
public class Options : IOptions
88
{
9-
[VerbOption("sample:minimal")]
10-
public Minimal Minimal { get; set; }
9+
[VerbOption("fail", HelpText = "Always fail. Useful for end-to-end testing.")]
10+
public AlwaysFail AlwaysFail { get; set; }
1111

12+
[VerbOption("succeed", HelpText = "A null operation command. Literally does nothing.")]
13+
public AlwaysSucceed Null { get; set; }
14+
15+
[HelpVerbOption]
1216
public string GetUsage(string verb)
1317
{
14-
return "\tsample:minimal \t\tA minimal implementation of a command.";
18+
return HelpText.AutoBuild(this, verb);
1519
}
1620
}
1721
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ public class MoreOptions : IOptions
1313
[VerbOption("sample:say-hello", HelpText = "A sample command to say \"hello\".")]
1414
public SayHello SayHello { get; set; }
1515

16+
[VerbOption("sample:minimal")]
17+
public Minimal Minimal { get; set; }
18+
19+
[HelpVerbOption]
1620
public string GetUsage(string verb)
1721
{
1822
return HelpText.AutoBuild(this, verb);

src/InEngine.Core.Test/Queue/Commands/ConsumeTest.cs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
using System.Collections.Generic;
2-
using System.Linq;
3-
using BeekmanLabs.UnitTesting;
4-
using InEngine.Core.Commands;
5-
using InEngine.Core.Exceptions;
6-
using InEngine.Core.Queue.Commands;
1+
using BeekmanLabs.UnitTesting;
2+
using InEngine.Commands;
3+
using InEngine.Core.Queuing.Commands;
74
using Moq;
85
using NUnit.Framework;
96
using Quartz;
@@ -52,7 +49,6 @@ public void ShouldConsumeSecondaryQueueBasedOnJobContextData()
5249
var jobExecutionConext = new Mock<IJobExecutionContext>();
5350
var jobDataMap = new JobDataMap { { "useSecondaryQueue", true } };
5451
jobExecutionConext.SetupGet(p => p.JobDetail.JobDataMap).Returns(jobDataMap);
55-
Subject.JobExecutionContext = jobExecutionConext.Object;
5652

5753
Subject.Run();
5854
}

src/InEngine.Core.Test/Queue/Commands/PublishTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
using System;
2-
using System.Collections.Generic;
32
using System.Linq;
43
using BeekmanLabs.UnitTesting;
4+
using InEngine.Commands;
55
using InEngine.Core.Commands;
66
using InEngine.Core.Exceptions;
7-
using InEngine.Core.Queue.Commands;
7+
using InEngine.Core.Queuing.Commands;
88
using NUnit.Framework;
99

1010
namespace InEngine.Core.Test.Queue.Commands

src/InEngine.Core.Test/appsettings.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
{
22
"InEngine": {
3+
"Plugins": [
4+
"InEngine.Commands"
5+
],
36
"Queue": {
7+
"UseCompression": false,
8+
"PrimaryQueueConsumers": 16,
9+
"SecondaryQueueConsumers": 4,
410
"QueueName": "InEngine:Queue",
511
"RedisHost": "localhost",
612
"RedisPort": 6379,

src/InEngine.Core/AbstractCommand.cs

Lines changed: 11 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,19 @@
11
using System;
2+
using System.Linq;
23
using InEngine.Core.IO;
4+
using InEngine.Core.Scheduling;
35
using Konsole;
4-
using NLog;
56
using Quartz;
67

78
namespace InEngine.Core
89
{
910
abstract public class AbstractCommand : ICommand, IFailed, IJob, IWrite
1011
{
11-
public IJobExecutionContext JobExecutionContext { get; set; }
12-
public ILogger Logger { get; internal set; }
12+
public Write Write { get; set; }
1313
public ProgressBar ProgressBar { get; internal set; }
14-
string _name;
15-
public string Name
16-
{
17-
get { return _name; }
18-
set
19-
{
20-
_name = value;
21-
Logger = LogManager.GetLogger(_name);
22-
}
23-
}
14+
public string Name { get; set; }
2415
public string SchedulerGroup { get; set; }
2516
public string ScheduleId { get; set; }
26-
public Write Write { get; set; }
2717

2818
protected AbstractCommand()
2919
{
@@ -56,7 +46,13 @@ public void UpdateProgress(int tick)
5646
#region Scheduling
5747
public void Execute(IJobExecutionContext context)
5848
{
59-
JobExecutionContext = context;
49+
var properties = GetType().GetProperties();
50+
context.MergedJobDataMap.ToList().ForEach(x => {
51+
var property = properties.FirstOrDefault(y => y.Name == x.Key);
52+
if (property != null)
53+
property.SetValue(this, x.Value);
54+
});
55+
6056
try
6157
{
6258
Run();
@@ -67,33 +63,6 @@ public void Execute(IJobExecutionContext context)
6763
}
6864
}
6965

70-
public JobBuilder MakeJobBuilder()
71-
{
72-
return JobBuilder
73-
.Create(GetType())
74-
.WithIdentity($"{Name}:job:{ScheduleId}", SchedulerGroup);
75-
}
76-
77-
public TriggerBuilder MakeTriggerBuilder()
78-
{
79-
return TriggerBuilder
80-
.Create()
81-
.WithIdentity($"{Name}:trigger:{ScheduleId}", SchedulerGroup);
82-
}
83-
84-
public T GetJobContextData<T>(string key)
85-
{
86-
if (JobExecutionContext == null || JobExecutionContext.MergedJobDataMap == null)
87-
return default(T);
88-
var objectVal = JobExecutionContext.MergedJobDataMap.Get(key);
89-
return objectVal == null ? default(T) : (T)objectVal;
90-
}
91-
92-
public void AddJobContextData<T>(string key, T val)
93-
{
94-
JobExecutionContext.MergedJobDataMap.Add(key, val);
95-
}
96-
9766
#endregion
9867

9968
#region Console output

src/InEngine.Core/Commands/Echo.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using System;
2-
using CommandLine;
1+
using CommandLine;
32

43
namespace InEngine.Core.Commands
54
{

src/InEngine.Core/Commands/Options.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,16 @@ namespace InEngine.Core.Commands
55
{
66
public class Options : IOptions
77
{
8-
[VerbOption("fail", HelpText = "Always fail. Useful for end-to-end testing.")]
9-
public AlwaysFail AlwaysFail { get; set; }
10-
118
[VerbOption("echo", HelpText= "Echo some text to the console. Useful for end-to-end testing.")]
129
public Echo Echo { get; set; }
1310

14-
[VerbOption("succeed", HelpText = "A null operation command. Literally does nothing.")]
15-
public AlwaysSucceed Null { get; set; }
11+
[VerbOption("proc", HelpText = "Launch an arbitrary process.")]
12+
public SystemProcess SystemProcess { get; set; }
1613

14+
[HelpVerbOption]
1715
public string GetUsage(string verb)
1816
{
19-
return null;
17+
return HelpText.AutoBuild(this, verb);
2018
}
2119
}
2220
}

0 commit comments

Comments
 (0)