From fe4fbc6838f1facac8200c069c7420ab0dadad10 Mon Sep 17 00:00:00 2001 From: Thad House Date: Tue, 30 Nov 2021 11:49:02 -0800 Subject: [PATCH 1/5] Add method to explicitly specify assemblies to load as plugins --- .../AssemblyTypeReference.cs | 2 +- .../Discovery/AssemblyExtensionDiscovery.cs | 2 +- .../PluginSet.cs | 70 +++++++++++++++++-- 3 files changed, 68 insertions(+), 6 deletions(-) diff --git a/src/Microsoft.Performance.SDK.Runtime/AssemblyTypeReference.cs b/src/Microsoft.Performance.SDK.Runtime/AssemblyTypeReference.cs index 98c778d0..e10f9552 100644 --- a/src/Microsoft.Performance.SDK.Runtime/AssemblyTypeReference.cs +++ b/src/Microsoft.Performance.SDK.Runtime/AssemblyTypeReference.cs @@ -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; diff --git a/src/Microsoft.Performance.SDK.Runtime/Discovery/AssemblyExtensionDiscovery.cs b/src/Microsoft.Performance.SDK.Runtime/Discovery/AssemblyExtensionDiscovery.cs index a971def6..5a161970 100644 --- a/src/Microsoft.Performance.SDK.Runtime/Discovery/AssemblyExtensionDiscovery.cs +++ b/src/Microsoft.Performance.SDK.Runtime/Discovery/AssemblyExtensionDiscovery.cs @@ -359,7 +359,7 @@ public bool ProcessAssemblies( return allLoaded; } - private bool ProcessAssembly( + public bool ProcessAssembly( Assembly assembly, out ErrorInfo error) { diff --git a/src/Microsoft.Performance.Toolkit.Engine/PluginSet.cs b/src/Microsoft.Performance.Toolkit.Engine/PluginSet.cs index fdacde78..5681653b 100644 --- a/src/Microsoft.Performance.Toolkit.Engine/PluginSet.cs +++ b/src/Microsoft.Performance.Toolkit.Engine/PluginSet.cs @@ -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; @@ -258,6 +259,49 @@ public static PluginSet Load( public static PluginSet Load( IEnumerable extensionDirectories, IAssemblyLoader assemblyLoader) + { + return Load(extensionDirectories, assemblyLoader, null); + } + /// + /// Creates a new , loading all plugins found + /// in the given directories, using the given loading function, and + /// any extra direct assemblies specified + /// + /// + /// The directories to search for plugins. + /// + /// + /// The loader to use to load plugin assemblies. This parameter may be + /// null. If this parameter is null, then the default + /// loader will be used. + /// + /// The default loader provides no isolation. + /// + /// + /// + /// A list of extra assemblies to attemt to directly load plugins from. + /// This parameter may be null or empty. + /// + /// + /// A new instance of the 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.) + /// + /// + /// is null. + /// + /// + /// is empty. + /// + /// + /// One or more directory paths in + /// is invalid or does not exist. + /// + public static PluginSet Load( + IEnumerable extensionDirectories, + IAssemblyLoader assemblyLoader, + IEnumerable extraAssemblies) { Guard.NotNull(extensionDirectories, nameof(extensionDirectories)); Guard.Any(extensionDirectories, nameof(extensionDirectories)); @@ -307,13 +351,31 @@ public static PluginSet Load( var reflector = new DataExtensionReflector(assemblyDiscovery, repo); + var creationErrors = new List(); + 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(); + 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); From e0724d63f841514fc56438cfe4c01f4ad8faba24 Mon Sep 17 00:00:00 2001 From: Thad House <87844845+thhous-msft@users.noreply.github.com> Date: Tue, 30 Nov 2021 12:29:09 -0800 Subject: [PATCH 2/5] Update src/Microsoft.Performance.Toolkit.Engine/PluginSet.cs Co-authored-by: Nick Banks --- src/Microsoft.Performance.Toolkit.Engine/PluginSet.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.Performance.Toolkit.Engine/PluginSet.cs b/src/Microsoft.Performance.Toolkit.Engine/PluginSet.cs index 5681653b..4c1bfffd 100644 --- a/src/Microsoft.Performance.Toolkit.Engine/PluginSet.cs +++ b/src/Microsoft.Performance.Toolkit.Engine/PluginSet.cs @@ -279,7 +279,7 @@ public static PluginSet Load( /// /// /// - /// A list of extra assemblies to attemt to directly load plugins from. + /// A list of extra assemblies to attempt to directly load plugins from. /// This parameter may be null or empty. /// /// From 9e1e1a5971529754b49ffe4f1e8c55f93ada95b4 Mon Sep 17 00:00:00 2001 From: Thad House Date: Wed, 1 Dec 2021 10:05:19 -0800 Subject: [PATCH 3/5] Revert "Update src/Microsoft.Performance.Toolkit.Engine/PluginSet.cs" This reverts commit e0724d63f841514fc56438cfe4c01f4ad8faba24. --- src/Microsoft.Performance.Toolkit.Engine/PluginSet.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.Performance.Toolkit.Engine/PluginSet.cs b/src/Microsoft.Performance.Toolkit.Engine/PluginSet.cs index 4c1bfffd..5681653b 100644 --- a/src/Microsoft.Performance.Toolkit.Engine/PluginSet.cs +++ b/src/Microsoft.Performance.Toolkit.Engine/PluginSet.cs @@ -279,7 +279,7 @@ public static PluginSet Load( /// /// /// - /// A list of extra assemblies to attempt to directly load plugins from. + /// A list of extra assemblies to attemt to directly load plugins from. /// This parameter may be null or empty. /// /// From 659d9cbf3cfad51a07922d9e52d4a66f983a05af Mon Sep 17 00:00:00 2001 From: Thad House Date: Wed, 1 Dec 2021 10:05:25 -0800 Subject: [PATCH 4/5] Revert "Add method to explicitly specify assemblies to load as plugins" This reverts commit fe4fbc6838f1facac8200c069c7420ab0dadad10. --- .../AssemblyTypeReference.cs | 2 +- .../Discovery/AssemblyExtensionDiscovery.cs | 2 +- .../PluginSet.cs | 70 ++----------------- 3 files changed, 6 insertions(+), 68 deletions(-) diff --git a/src/Microsoft.Performance.SDK.Runtime/AssemblyTypeReference.cs b/src/Microsoft.Performance.SDK.Runtime/AssemblyTypeReference.cs index e10f9552..98c778d0 100644 --- a/src/Microsoft.Performance.SDK.Runtime/AssemblyTypeReference.cs +++ b/src/Microsoft.Performance.SDK.Runtime/AssemblyTypeReference.cs @@ -47,7 +47,7 @@ protected internal AssemblyTypeReference(Type type) this.type = type; - if (!this.Type.Assembly.IsDynamic && !string.IsNullOrWhiteSpace(this.Type.Assembly.Location)) + if (!this.Type.Assembly.IsDynamic) { this.assemblyPath = this.Type.Assembly.Location; this.version = FileVersionInfo.GetVersionInfo(this.AssemblyPath).FileVersion; diff --git a/src/Microsoft.Performance.SDK.Runtime/Discovery/AssemblyExtensionDiscovery.cs b/src/Microsoft.Performance.SDK.Runtime/Discovery/AssemblyExtensionDiscovery.cs index 5a161970..a971def6 100644 --- a/src/Microsoft.Performance.SDK.Runtime/Discovery/AssemblyExtensionDiscovery.cs +++ b/src/Microsoft.Performance.SDK.Runtime/Discovery/AssemblyExtensionDiscovery.cs @@ -359,7 +359,7 @@ public bool ProcessAssemblies( return allLoaded; } - public bool ProcessAssembly( + private bool ProcessAssembly( Assembly assembly, out ErrorInfo error) { diff --git a/src/Microsoft.Performance.Toolkit.Engine/PluginSet.cs b/src/Microsoft.Performance.Toolkit.Engine/PluginSet.cs index 5681653b..fdacde78 100644 --- a/src/Microsoft.Performance.Toolkit.Engine/PluginSet.cs +++ b/src/Microsoft.Performance.Toolkit.Engine/PluginSet.cs @@ -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; @@ -259,49 +258,6 @@ public static PluginSet Load( public static PluginSet Load( IEnumerable extensionDirectories, IAssemblyLoader assemblyLoader) - { - return Load(extensionDirectories, assemblyLoader, null); - } - /// - /// Creates a new , loading all plugins found - /// in the given directories, using the given loading function, and - /// any extra direct assemblies specified - /// - /// - /// The directories to search for plugins. - /// - /// - /// The loader to use to load plugin assemblies. This parameter may be - /// null. If this parameter is null, then the default - /// loader will be used. - /// - /// The default loader provides no isolation. - /// - /// - /// - /// A list of extra assemblies to attemt to directly load plugins from. - /// This parameter may be null or empty. - /// - /// - /// A new instance of the 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.) - /// - /// - /// is null. - /// - /// - /// is empty. - /// - /// - /// One or more directory paths in - /// is invalid or does not exist. - /// - public static PluginSet Load( - IEnumerable extensionDirectories, - IAssemblyLoader assemblyLoader, - IEnumerable extraAssemblies) { Guard.NotNull(extensionDirectories, nameof(extensionDirectories)); Guard.Any(extensionDirectories, nameof(extensionDirectories)); @@ -351,32 +307,14 @@ public static PluginSet Load( var reflector = new DataExtensionReflector(assemblyDiscovery, repo); - var creationErrors = new List(); - 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(); + extensionRoot = new ExtensionRoot(catalog, repo); return new PluginSet( From 3d02c21308df88a455d136bee8bdffa7a7d93dcf Mon Sep 17 00:00:00 2001 From: Thad House Date: Wed, 1 Dec 2021 10:06:39 -0800 Subject: [PATCH 5/5] Only change assemblytypereference --- .../AssemblyTypeReference.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.Performance.SDK.Runtime/AssemblyTypeReference.cs b/src/Microsoft.Performance.SDK.Runtime/AssemblyTypeReference.cs index 98c778d0..b04310b8 100644 --- a/src/Microsoft.Performance.SDK.Runtime/AssemblyTypeReference.cs +++ b/src/Microsoft.Performance.SDK.Runtime/AssemblyTypeReference.cs @@ -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; @@ -63,7 +63,7 @@ protected internal AssemblyTypeReference(Type type) /// /// Initializes a new instance of using - /// 's , + /// 's , /// , and /// . ///