5
5
using System . IO ;
6
6
using System . Linq ;
7
7
using System . Reflection ;
8
- using System . Runtime . CompilerServices ;
9
- using System . Runtime . InteropServices ;
10
8
using Common . Logging ;
11
9
using ScriptCs . Contracts ;
12
10
@@ -23,8 +21,8 @@ public class ModuleLoader : IModuleLoader
23
21
24
22
[ ImportingConstructor ]
25
23
public ModuleLoader ( IAssemblyResolver resolver , ILog logger , IFileSystem fileSystem , IAssemblyUtility assemblyUtility ) :
26
- this ( resolver , logger , null , null , fileSystem , assemblyUtility )
27
- {
24
+ this ( resolver , logger , null , null , fileSystem , assemblyUtility )
25
+ {
28
26
}
29
27
30
28
public ModuleLoader ( IAssemblyResolver resolver , ILog logger , Action < Assembly , AggregateCatalog > addToCatalog , Func < CompositionContainer , IEnumerable < Lazy < IModule , IModuleMetadata > > > getLazyModules , IFileSystem fileSystem , IAssemblyUtility assemblyUtility )
@@ -41,7 +39,7 @@ public ModuleLoader(IAssemblyResolver resolver, ILog logger, Action<Assembly, Ag
41
39
var assemblyCatalog = new AssemblyCatalog ( assembly ) ;
42
40
catalog . Catalogs . Add ( assemblyCatalog ) ;
43
41
}
44
- catch ( Exception exception )
42
+ catch ( Exception exception )
45
43
{
46
44
logger . DebugFormat ( "Module Loader exception: {0}" , exception . Message ) ;
47
45
}
@@ -52,11 +50,9 @@ public ModuleLoader(IAssemblyResolver resolver, ILog logger, Action<Assembly, Ag
52
50
53
51
if ( getLazyModules == null )
54
52
{
55
- getLazyModules = ( container ) =>
56
- {
57
- return container . GetExports < IModule , IModuleMetadata > ( ) ;
58
- } ;
53
+ getLazyModules = container => container . GetExports < IModule , IModuleMetadata > ( ) ;
59
54
}
55
+
60
56
_getLazyModules = getLazyModules ;
61
57
_fileSystem = fileSystem ;
62
58
_assemblyUtility = assemblyUtility ;
@@ -78,13 +74,17 @@ public void Load(IModuleConfiguration config, string[] modulePackagesPaths, stri
78
74
InitializeModules ( config , extension , moduleNames , lazyModules ) ;
79
75
}
80
76
81
- private void InitializeModules ( IModuleConfiguration config , string extension , string [ ] moduleNames ,
77
+ private void InitializeModules (
78
+ IModuleConfiguration config ,
79
+ string extension ,
80
+ IEnumerable < string > moduleNames ,
82
81
IEnumerable < Lazy < IModule , IModuleMetadata > > lazyModules )
83
82
{
84
83
var modules = lazyModules
85
84
. Where ( m => moduleNames . Contains ( m . Metadata . Name ) ||
86
85
( extension != null && m . Metadata . Extensions != null &&
87
- ( m . Metadata . Extensions . Split ( ',' ) . Contains ( extension ) ) ) || m . Metadata . Autoload == true )
86
+ ( m . Metadata . Extensions . Split ( ',' ) . Contains ( extension ) ) ) ||
87
+ m . Metadata . Autoload )
88
88
. Select ( m => m . Value ) ;
89
89
90
90
_logger . Debug ( "Initializing modules" ) ;
@@ -98,7 +98,7 @@ private void InitializeModules(IModuleConfiguration config, string extension, st
98
98
_logger . Debug ( "Modules initialized" ) ;
99
99
}
100
100
101
- private AggregateCatalog CreateAggregateCatalog ( List < string > paths )
101
+ private AggregateCatalog CreateAggregateCatalog ( IEnumerable < string > paths )
102
102
{
103
103
var catalog = new AggregateCatalog ( ) ;
104
104
foreach ( var path in paths )
@@ -127,27 +127,24 @@ private AggregateCatalog CreateAggregateCatalog(List<string> paths)
127
127
return catalog ;
128
128
}
129
129
130
- private void AddPaths ( string [ ] modulePackagesPaths , string hostBin , List < string > paths )
130
+ private void AddPaths ( IEnumerable < string > modulePackagesPaths , string hostBin , List < string > paths )
131
131
{
132
- foreach ( var modulePackagesPath in modulePackagesPaths )
132
+ foreach ( var modulePaths in modulePackagesPaths
133
+ . Select ( modulePackagesPath => _resolver . GetAssemblyPaths ( modulePackagesPath , true ) ) )
133
134
{
134
- var modulePaths = _resolver . GetAssemblyPaths ( modulePackagesPath , true ) ;
135
135
paths . AddRange ( modulePaths ) ;
136
136
}
137
137
138
138
if ( hostBin != null )
139
139
{
140
140
var assemblyPaths = _fileSystem . EnumerateBinaries ( hostBin , SearchOption . TopDirectoryOnly ) ;
141
- foreach ( var path in assemblyPaths )
142
- {
143
- paths . Add ( path ) ;
144
- }
141
+ paths . AddRange ( assemblyPaths ) ;
145
142
}
146
143
}
147
144
148
145
private IEnumerable < Lazy < IModule , IModuleMetadata > > GetLazyModules ( CompositionContainer container )
149
146
{
150
- IEnumerable < Lazy < IModule , IModuleMetadata > > lazyModules = null ;
147
+ IEnumerable < Lazy < IModule , IModuleMetadata > > lazyModules ;
151
148
152
149
try
153
150
{
@@ -166,8 +163,10 @@ private IEnumerable<Lazy<IModule, IModuleMetadata>> GetLazyModules(CompositionCo
166
163
{
167
164
_logger . DebugFormat ( "Module Loader exception: {0}" , exception . Message ) ;
168
165
}
166
+
169
167
lazyModules = Enumerable . Empty < Lazy < IModule , IModuleMetadata > > ( ) ;
170
168
}
169
+
171
170
return lazyModules ;
172
171
}
173
172
}
0 commit comments