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 3 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
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ protected internal AssemblyTypeReference(Type type)

/// <summary>
/// Initializes a new instance of <see cref="AssemblyTypeReference{TDerived}"/> using
/// <paramref name="other"/>'s <see cref="AssemblyTypeReference{TDerived}.Type"/>,
/// <paramref name="other"/>'s <see cref="AssemblyTypeReference{TDerived}.Type"/>,
mslukebo marked this conversation as resolved.
Show resolved Hide resolved
/// <see cref="AssemblyTypeReference{TDerived}.AssemblyPath"/>, and
/// <see cref="AssemblyTypeReference{TDerived}.Version"/>.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ public bool ProcessAssemblies(
return allLoaded;
}

public bool ProcessAssembly(
private bool ProcessAssembly(
Assembly assembly,
out ErrorInfo error)
{
Expand Down
70 changes: 4 additions & 66 deletions src/Microsoft.Performance.Toolkit.Engine/PluginSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
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 @@ -259,49 +258,6 @@ 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 attempt to directly load plugins from.
/// 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 @@ -351,32 +307,14 @@ public static PluginSet Load(

var reflector = new DataExtensionReflector(assemblyDiscovery, repo);

var creationErrors = new List<ErrorInfo>();

assemblyDiscovery.ProcessAssemblies(extensionDirectoriesFullPaths, out var discoveryError);

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

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();

var creationErrors = discoveryError != null && discoveryError != ErrorInfo.None
? new[] { discoveryError, }
: Array.Empty<ErrorInfo>();

extensionRoot = new ExtensionRoot(catalog, repo);

return new PluginSet(
Expand Down