File tree Expand file tree Collapse file tree 13 files changed +3221
-34
lines changed Expand file tree Collapse file tree 13 files changed +3221
-34
lines changed Original file line number Diff line number Diff line change
1
+ using Quartz ;
2
+
3
+ namespace InEngine . Core
4
+ {
5
+ public interface IJobs : IPluginType
6
+ {
7
+ void Schedule ( IScheduler scheduler ) ;
8
+ }
9
+ }
Original file line number Diff line number Diff line change 1
1
namespace InEngine . Core
2
2
{
3
- public interface IOptions
3
+ public interface IOptions : IPluginType
4
4
{
5
5
string GetUsage ( string verb ) ;
6
6
}
Original file line number Diff line number Diff line change
1
+ namespace InEngine . Core
2
+ {
3
+ public interface IPluginType
4
+ { }
5
+ }
Original file line number Diff line number Diff line change 90
90
<Compile Include =" IOptions.cs" />
91
91
<Compile Include =" Queue\Options.cs" />
92
92
<Compile Include =" Plugin.cs" />
93
+ <Compile Include =" IJobs.cs" />
94
+ <Compile Include =" IPluginType.cs" />
93
95
</ItemGroup >
94
96
<ItemGroup >
95
97
<None Include =" packages.config" />
Original file line number Diff line number Diff line change 1
1
using System ;
2
2
using System . Collections . Generic ;
3
+ using System . IO ;
3
4
using System . Linq ;
4
5
using System . Reflection ;
6
+ using NLog ;
5
7
6
8
namespace InEngine . Core
7
9
{
8
10
public class Plugin
9
11
{
10
- public Assembly Assembly { get ; set ; }
11
- public string Name { get { return Assembly . GetName ( ) . Name ; } }
12
+ public Assembly Assembly { get ; set ; }
13
+ public string Name { get { return Assembly . GetName ( ) . Name ; } }
12
14
13
15
public Plugin ( Assembly assembly )
14
16
{
15
17
Assembly = assembly ;
16
18
}
17
19
18
- public List < IOptions > MakeOptions ( )
20
+ public List < T > Make < T > ( ) where T : class , IPluginType
19
21
{
20
22
return Assembly
21
23
. GetTypes ( )
22
- . Where ( x => x . IsClass && typeof ( IOptions ) . IsAssignableFrom ( x ) )
23
- . Select ( x => Assembly . CreateInstance ( x . FullName ) as IOptions )
24
+ . Where ( x => x . IsClass && typeof ( T ) . IsAssignableFrom ( x ) )
25
+ . Select ( x => Assembly . CreateInstance ( x . FullName ) as T )
24
26
. ToList ( ) ;
25
27
}
28
+
29
+ public static List < Plugin > Discover < T > ( ) where T : IPluginType
30
+ {
31
+ var discoveredAssemblies = Directory
32
+ . GetFiles ( "." , "*.dll" )
33
+ . Select ( x => Assembly . LoadFrom ( x ) ) ;
34
+ var pluginList = new List < Plugin > ( ) ;
35
+ foreach ( var assembly in discoveredAssemblies )
36
+ {
37
+ try
38
+ {
39
+ if ( assembly . GetTypes ( ) . Any ( y => y . IsClass && typeof ( T ) . IsAssignableFrom ( y ) ) )
40
+ pluginList . Add ( new Plugin ( assembly ) ) ;
41
+ }
42
+ catch ( Exception exception )
43
+ {
44
+ LogManager . GetCurrentClassLogger ( ) . Error ( exception , "Error discovering plugins" ) ;
45
+ }
46
+ }
47
+ return pluginList ;
48
+ }
26
49
}
27
50
}
Original file line number Diff line number Diff line change 4
4
5
5
namespace InEngine . Core . Queue
6
6
{
7
- public static class Jobs
7
+ public class Jobs : IJobs
8
8
{
9
- public static void Schedule ( IScheduler scheduler )
9
+ public void Schedule ( IScheduler scheduler )
10
10
{
11
11
var consume = new Consume ( ) ;
12
12
var jobDetails = JobBuilder
Original file line number Diff line number Diff line change 4
4
<package id =" Common.Logging" version =" 3.4.1" targetFramework =" net462" />
5
5
<package id =" Common.Logging.Core" version =" 3.4.1" targetFramework =" net462" />
6
6
<package id =" Goblinfactory.Konsole.ProgressBar.Core" version =" 1.0.2" targetFramework =" net462" />
7
- <package id =" Microsoft.CSharp" version =" 4.0.1 " targetFramework =" net462" />
7
+ <package id =" Microsoft.CSharp" version =" 4.4.0 " targetFramework =" net462" />
8
8
<package id =" Microsoft.Diagnostics.Tracing.EventSource.Redist" version =" 1.1.28" targetFramework =" net462" />
9
9
<package id =" Newtonsoft.Json" version =" 10.0.3" targetFramework =" net462" />
10
10
<package id =" NLog" version =" 4.4.12" targetFramework =" net462" />
Original file line number Diff line number Diff line change 1
1
using System ;
2
- using System . Collections . Generic ;
3
- using System . IO ;
4
2
using System . Linq ;
5
3
using System . Reflection ;
6
4
using CommandLine ;
@@ -21,7 +19,7 @@ public ArgumentInterpreter()
21
19
22
20
public void Interpret ( string [ ] args )
23
21
{
24
- var plugins = FindPlugins ( ) ;
22
+ var plugins = Plugin . Discover < IOptions > ( ) ;
25
23
if ( ! args . Any ( ) )
26
24
{
27
25
Console . WriteLine ( "Available plugins... " ) ;
@@ -41,7 +39,7 @@ public void Interpret(string[] args)
41
39
if ( plugin == null )
42
40
ExitWithFailure ( "Plugin does not exist: " + options . PluginName ) ;
43
41
44
- var pluginOptionList = plugin . MakeOptions ( ) ;
42
+ var pluginOptionList = plugin . Make < IOptions > ( ) ;
45
43
46
44
var pluginArgs = args . Skip ( 1 ) . ToArray ( ) ;
47
45
if ( ! pluginArgs . ToList ( ) . Any ( ) ) {
@@ -90,16 +88,6 @@ protected string MakeErrorMessage(string message = null)
90
88
return $ "✘ { message } ";
91
89
}
92
90
93
- public List < Plugin > FindPlugins ( )
94
- {
95
- return Directory
96
- . GetFiles ( "." , "*.dll" )
97
- . Select ( x => Assembly . LoadFrom ( x ) )
98
- . Where ( x => x . GetTypes ( ) . Any ( y => y . IsClass && typeof ( IOptions ) . IsAssignableFrom ( y ) ) )
99
- . Select ( x => new Plugin ( x ) )
100
- . ToList ( ) ;
101
- }
102
-
103
91
public void InterpretPluginArguments ( string [ ] pluginArgs , IOptions pluginOptions )
104
92
{
105
93
var isSuccessful = Parser
Original file line number Diff line number Diff line change 28
28
</PropertyGroup >
29
29
<ItemGroup >
30
30
<Reference Include =" System" />
31
- <Reference Include =" Common.Logging.Core" >
32
- <HintPath >..\packages\Common.Logging.Core.3.3.1\lib\net40\Common.Logging.Core.dll</HintPath >
33
- </Reference >
34
- <Reference Include =" Common.Logging" >
35
- <HintPath >..\packages\Common.Logging.3.3.1\lib\net40\Common.Logging.dll</HintPath >
36
- </Reference >
37
31
<Reference Include =" Quartz" >
38
32
<HintPath >..\packages\Quartz.2.6.1\lib\net40\Quartz.dll</HintPath >
39
33
</Reference >
40
34
<Reference Include =" System.Configuration" />
41
35
<Reference Include =" System.ServiceProcess" />
42
36
<Reference Include =" System.Configuration.Install" />
37
+ <Reference Include =" Microsoft.CSharp" />
38
+ <Reference Include =" Common.Logging.Core" >
39
+ <HintPath >..\packages\Common.Logging.Core.3.4.1\lib\net40\Common.Logging.Core.dll</HintPath >
40
+ </Reference >
41
+ <Reference Include =" Common.Logging" >
42
+ <HintPath >..\packages\Common.Logging.3.4.1\lib\net40\Common.Logging.dll</HintPath >
43
+ </Reference >
44
+ <Reference Include =" NLog" >
45
+ <HintPath >..\packages\NLog.4.4.12\lib\net45\NLog.dll</HintPath >
46
+ </Reference >
43
47
</ItemGroup >
44
48
<ItemGroup >
45
49
<Compile Include =" Program.cs" />
51
55
<ItemGroup >
52
56
<None Include =" packages.config" />
53
57
<None Include =" job_scheduling_data_2_0.xsd" />
58
+ <None Include =" NLog.xsd" />
59
+ <None Include =" NLog.config" />
54
60
</ItemGroup >
55
61
<ItemGroup >
56
62
<ProjectReference Include =" ..\InEngine.Core\InEngine.Core.csproj" >
Original file line number Diff line number Diff line change 1
- using InEngine . Commands . Sample ;
2
- using QueueJobs = InEngine . Core . Queue . Jobs ;
1
+ using System ;
2
+ using InEngine . Core ;
3
3
using Quartz ;
4
+ using NLog ;
5
+
4
6
5
7
namespace InEngineScheduler
6
8
{
7
9
public static class Jobs
8
10
{
9
11
public static void Schedule ( IScheduler scheduler )
10
12
{
11
- QueueJobs . Schedule ( scheduler ) ;
13
+ var logger = LogManager . GetCurrentClassLogger ( ) ;
14
+ Plugin . Discover < IJobs > ( ) . ForEach ( x => {
15
+ logger . Info ( $ "Registering jobs from plugin: { x . Name } ") ;
16
+ x . Make < IJobs > ( ) . ForEach ( y => y . Schedule ( scheduler ) ) ;
17
+ } ) ;
12
18
}
13
19
}
14
20
}
You can’t perform that action at this time.
0 commit comments