-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Finished up plugin loading and removed application started event
- Loading branch information
1 parent
5bf4311
commit 695fd86
Showing
8 changed files
with
66 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ | |
Copier.sln.DotSettings.user | ||
/Client/bin/* | ||
CopierPluginBase/obj/* | ||
CopierPluginBase/bin* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace Copier.Client | ||
{ | ||
public interface IPluginLoader | ||
{ | ||
void Subscribe(IPreCopyEventBroadcaster pre, IPostCopyEventBroadcaster post); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,49 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Reflection; | ||
using CopierPluginBase; | ||
|
||
namespace Copier.Client | ||
{ | ||
public class PluginLoader | ||
public class PluginLoader : IPluginLoader | ||
{ | ||
public void Load() | ||
private readonly List<Type> _preCopyListeners = new List<Type>(); | ||
private readonly List<Type> _postCopyListeners = new List<Type>(); | ||
|
||
public PluginLoader() | ||
{ | ||
var pluginDirectory = Path.Combine(Directory.GetCurrentDirectory(), "plugins"); | ||
var files = Directory.GetFiles(pluginDirectory, "*.dll"); | ||
foreach (var file in files) | ||
var assemblyFiles = Directory.GetFiles(pluginDirectory, "*.dll"); | ||
|
||
foreach (var assemblyFile in assemblyFiles) | ||
{ | ||
var pluginAssembly = Assembly.LoadFile(file); | ||
var existingTypes = pluginAssembly.GetTypes(); | ||
var pluginAssembly = Assembly.LoadFile(assemblyFile); | ||
|
||
var preCopyType = existingTypes | ||
.FirstOrDefault(a => a.Name == "PreCopyEventListener")?.GetType(); | ||
if (preCopyType != null) | ||
{ | ||
var preCopyObject = Activator.CreateInstance(preCopyType); | ||
} | ||
var postCopyListenerTypes = pluginAssembly | ||
.GetTypes().Where(a => a.IsClass && a.IsSubclassOf(typeof(IPostCopyEventListener))); | ||
_postCopyListeners.AddRange(postCopyListenerTypes); | ||
|
||
var postCopyType = existingTypes | ||
.FirstOrDefault(a => a.Name == "PostCopyEventListener")?.GetType(); | ||
|
||
if (postCopyType != null) | ||
{ | ||
var preCopyObject = Activator.CreateInstance(preCopyType); | ||
} | ||
var preCopyListenerTypes = pluginAssembly | ||
.GetTypes().Where(a => a.IsClass && a.IsSubclassOf(typeof(IPreCopyEventListener))); | ||
_preCopyListeners.AddRange(preCopyListenerTypes); | ||
} | ||
} | ||
|
||
public void Subscribe(IPreCopyEventBroadcaster pre, IPostCopyEventBroadcaster post) | ||
{ | ||
_preCopyListeners.ForEach(a => | ||
{ | ||
var listenerObject = (IPreCopyEventListener) Activator.CreateInstance(a); | ||
pre.PreCopyEvent += listenerObject.OnPreCopy; | ||
}); | ||
|
||
_postCopyListeners.ForEach(a => | ||
{ | ||
var listenerObject = (IPostCopyEventListener) Activator.CreateInstance(a); | ||
post.PostCopy += listenerObject.OnPostCopy; | ||
}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters