Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow loading assemblies without an assembly location #178

Merged
merged 6 commits into from
Dec 2, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ protected internal AssemblyTypeReference(Type type)

this.type = type;

if (!this.Type.Assembly.IsDynamic)
if (!this.Type.Assembly.IsDynamic && !string.IsNullOrWhiteSpace(this.Type.Assembly.Location))
{
this.assemblyPath = this.Type.Assembly.Location;
this.version = FileVersionInfo.GetVersionInfo(this.AssemblyPath).FileVersion;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ public bool ProcessAssemblies(
return allLoaded;
}

private bool ProcessAssembly(
public bool ProcessAssembly(
Assembly assembly,
out ErrorInfo error)
{
Expand Down
70 changes: 66 additions & 4 deletions src/Microsoft.Performance.Toolkit.Engine/PluginSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using Microsoft.Performance.SDK;
using Microsoft.Performance.SDK.Extensibility;
using Microsoft.Performance.SDK.Runtime;
Expand Down Expand Up @@ -258,6 +259,49 @@ public static PluginSet Load(
public static PluginSet Load(
IEnumerable<string> extensionDirectories,
IAssemblyLoader assemblyLoader)
{
return Load(extensionDirectories, assemblyLoader, null);
}
/// <summary>
/// Creates a new <see cref="PluginSet"/>, loading all plugins found
/// in the given directories, using the given loading function, and
/// any extra direct assemblies specified
/// </summary>
/// <param name="extensionDirectories">
/// The directories to search for plugins.
/// </param>
/// <param name="assemblyLoader">
/// The loader to use to load plugin assemblies. This parameter may be
/// <c>null</c>. If this parameter is <c>null</c>, then the default
/// loader will be used.
/// <remarks>
/// The default loader provides no isolation.
/// </remarks>
/// </param>
/// <param name="extraAssemblies">
/// A list of extra assemblies to attemt to directly load plugins from.
thhous-msft marked this conversation as resolved.
Show resolved Hide resolved
/// This parameter may be <c>null</c> or <c>empty</c>.
/// </param>
/// <returns>
/// A new instance of the <see cref="PluginSet"/> class containing all
/// of the successfully discovered plugins. The returned instance will
/// also contain a collection of non-fatal errors that occurred when
/// creating this data set (e.g. a plugin failed to load.)
/// </returns>
/// <exception cref="System.ArgumentNullException">
/// <paramref name="extensionDirectories"/> is <c>null</c>.
/// </exception>
/// <exception cref="System.ArgumentException">
/// <paramref name="extensionDirectories"/> is empty.
/// </exception>
/// <exception cref="InvalidExtensionDirectoryException">
/// One or more directory paths in <paramref name="extensionDirectories"/>
/// is invalid or does not exist.
/// </exception>
public static PluginSet Load(
IEnumerable<string> extensionDirectories,
IAssemblyLoader assemblyLoader,
IEnumerable<Assembly> extraAssemblies)
{
Guard.NotNull(extensionDirectories, nameof(extensionDirectories));
Guard.Any(extensionDirectories, nameof(extensionDirectories));
Expand Down Expand Up @@ -307,13 +351,31 @@ public static PluginSet Load(

var reflector = new DataExtensionReflector(assemblyDiscovery, repo);

var creationErrors = new List<ErrorInfo>();

assemblyDiscovery.ProcessAssemblies(extensionDirectoriesFullPaths, out var discoveryError);

repo.FinalizeDataExtensions();
if (discoveryError != null && discoveryError != ErrorInfo.None)
{
creationErrors.Add(discoveryError);
}

var creationErrors = discoveryError != null && discoveryError != ErrorInfo.None
? new[] { discoveryError, }
: Array.Empty<ErrorInfo>();
if (extraAssemblies != null)
{
foreach (var assembly in extraAssemblies)
{
if (assembly != null)
{
assemblyDiscovery.ProcessAssembly(assembly, out discoveryError);
if (discoveryError != null && discoveryError != ErrorInfo.None)
{
creationErrors.Add(discoveryError);
}
}
}
}

repo.FinalizeDataExtensions();

extensionRoot = new ExtensionRoot(catalog, repo);

Expand Down