Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ScriptCs.sln.DotSettings
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateInstanceFields/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="_" Suffix="" Style="aaBb" /&gt;</s:String></wpf:ResourceDictionary>
1 change: 0 additions & 1 deletion src/ScriptCs.Contracts/IAppDomainAssemblyResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ namespace ScriptCs.Contracts
{
public interface IAppDomainAssemblyResolver
{
void AddAssemblyPaths(IEnumerable<string> assemblyPaths);
void Initialize();
}
}
2 changes: 1 addition & 1 deletion src/ScriptCs.Core/AppDomainAssemblyResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class AppDomainAssemblyResolver : IAppDomainAssemblyResolver
private readonly IFileSystem _fileSystem;
private readonly IAssemblyResolver _resolver;
private readonly IAssemblyUtility _assemblyUtility;
private IDictionary<string, AssemblyInfo> _assemblyInfoMap;
private readonly IDictionary<string, AssemblyInfo> _assemblyInfoMap;

public AppDomainAssemblyResolver(
ILog logger,
Expand Down
6 changes: 2 additions & 4 deletions src/ScriptCs.Core/AssemblyResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,15 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection.Emit;
using Common.Logging;

using ScriptCs.Contracts;

namespace ScriptCs
{
public class AssemblyResolver : IAssemblyResolver
{
private readonly Dictionary<string, List<string>> _assemblyPathCache = new Dictionary<string, List<string>>();

private readonly IFileSystem _fileSystem;

private readonly IPackageAssemblyResolver _packageAssemblyResolver;
Expand Down Expand Up @@ -62,7 +60,7 @@ public IEnumerable<string> GetAssemblyPaths(string path, bool binariesOnly = fal
return assemblies;
}

public IEnumerable<string> GetBinAssemblyPaths(string path)
private IEnumerable<string> GetBinAssemblyPaths(string path)
{
var binFolder = Path.Combine(path, _fileSystem.BinFolder);
if (!_fileSystem.DirectoryExists(binFolder))
Expand Down
39 changes: 19 additions & 20 deletions src/ScriptCs.Hosting/ModuleLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using Common.Logging;
using ScriptCs.Contracts;

Expand All @@ -23,8 +21,8 @@ public class ModuleLoader : IModuleLoader

[ImportingConstructor]
public ModuleLoader(IAssemblyResolver resolver, ILog logger, IFileSystem fileSystem, IAssemblyUtility assemblyUtility) :
this(resolver, logger, null, null, fileSystem, assemblyUtility )
{
this(resolver, logger, null, null, fileSystem, assemblyUtility)
{
}

public ModuleLoader(IAssemblyResolver resolver, ILog logger, Action<Assembly, AggregateCatalog> addToCatalog, Func<CompositionContainer, IEnumerable<Lazy<IModule, IModuleMetadata>>> getLazyModules, IFileSystem fileSystem, IAssemblyUtility assemblyUtility)
Expand All @@ -41,7 +39,7 @@ public ModuleLoader(IAssemblyResolver resolver, ILog logger, Action<Assembly, Ag
var assemblyCatalog = new AssemblyCatalog(assembly);
catalog.Catalogs.Add(assemblyCatalog);
}
catch(Exception exception)
catch (Exception exception)
{
logger.DebugFormat("Module Loader exception: {0}", exception.Message);
}
Expand All @@ -52,11 +50,9 @@ public ModuleLoader(IAssemblyResolver resolver, ILog logger, Action<Assembly, Ag

if (getLazyModules == null)
{
getLazyModules = (container) =>
{
return container.GetExports<IModule, IModuleMetadata>();
};
getLazyModules = container => container.GetExports<IModule, IModuleMetadata>();
}

_getLazyModules = getLazyModules;
_fileSystem = fileSystem;
_assemblyUtility = assemblyUtility;
Expand All @@ -78,13 +74,17 @@ public void Load(IModuleConfiguration config, string[] modulePackagesPaths, stri
InitializeModules(config, extension, moduleNames, lazyModules);
}

private void InitializeModules(IModuleConfiguration config, string extension, string[] moduleNames,
private void InitializeModules(
IModuleConfiguration config,
string extension,
IEnumerable<string> moduleNames,
IEnumerable<Lazy<IModule, IModuleMetadata>> lazyModules)
{
var modules = lazyModules
.Where(m => moduleNames.Contains(m.Metadata.Name) ||
(extension != null && m.Metadata.Extensions != null &&
(m.Metadata.Extensions.Split(',').Contains(extension))) || m.Metadata.Autoload == true)
(m.Metadata.Extensions.Split(',').Contains(extension))) ||
m.Metadata.Autoload)
.Select(m => m.Value);

_logger.Debug("Initializing modules");
Expand All @@ -98,7 +98,7 @@ private void InitializeModules(IModuleConfiguration config, string extension, st
_logger.Debug("Modules initialized");
}

private AggregateCatalog CreateAggregateCatalog(List<string> paths)
private AggregateCatalog CreateAggregateCatalog(IEnumerable<string> paths)
{
var catalog = new AggregateCatalog();
foreach (var path in paths)
Expand Down Expand Up @@ -127,27 +127,24 @@ private AggregateCatalog CreateAggregateCatalog(List<string> paths)
return catalog;
}

private void AddPaths(string[] modulePackagesPaths, string hostBin, List<string> paths)
private void AddPaths(IEnumerable<string> modulePackagesPaths, string hostBin, List<string> paths)
{
foreach (var modulePackagesPath in modulePackagesPaths)
foreach (var modulePaths in modulePackagesPaths
.Select(modulePackagesPath => _resolver.GetAssemblyPaths(modulePackagesPath, true)))
{
var modulePaths = _resolver.GetAssemblyPaths(modulePackagesPath, true);
paths.AddRange(modulePaths);
}

if (hostBin != null)
{
var assemblyPaths = _fileSystem.EnumerateBinaries(hostBin, SearchOption.TopDirectoryOnly);
foreach (var path in assemblyPaths)
{
paths.Add(path);
}
paths.AddRange(assemblyPaths);
}
}

private IEnumerable<Lazy<IModule, IModuleMetadata>> GetLazyModules(CompositionContainer container)
{
IEnumerable<Lazy<IModule, IModuleMetadata>> lazyModules = null;
IEnumerable<Lazy<IModule, IModuleMetadata>> lazyModules;

try
{
Expand All @@ -166,8 +163,10 @@ private IEnumerable<Lazy<IModule, IModuleMetadata>> GetLazyModules(CompositionCo
{
_logger.DebugFormat("Module Loader exception: {0}", exception.Message);
}

lazyModules = Enumerable.Empty<Lazy<IModule, IModuleMetadata>>();
}

return lazyModules;
}
}
Expand Down
2 changes: 1 addition & 1 deletion test/ScriptCs.Core.Tests/AssemblyResolverTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public void ShouldOnlyReturnBinariesWhenFlagIsSet(
AssemblyResolver resolver)
{
const string WorkingDirectory = @"C:\";

var binFolder = Path.Combine(WorkingDirectory, "bin");

assemblyUtilityMock.Setup(a => a.IsManagedAssembly(It.IsAny<string>())).Returns(true);
Expand Down