Improved documentation in several places; renamed 'Support' class in Nuclex.Support.Plugins to 'PluginHelper' to match the established conventions; provided better error messages for the plugin loading methods in the PluginRepository class
git-svn-id: file:///srv/devel/repo-conversion/nusu@88 d2e56fa2-650e-0410-a79f-9358c0239efd
This commit is contained in:
parent
b0026fcdd6
commit
7446b6bc9b
|
@ -36,8 +36,8 @@ namespace Nuclex.Support.Licensing {
|
||||||
/// <para>
|
/// <para>
|
||||||
/// Available storage space is used efficiently and allows for up to four
|
/// Available storage space is used efficiently and allows for up to four
|
||||||
/// 32 bit integers to be stored within the key, that's enough for a full GUID.
|
/// 32 bit integers to be stored within the key, that's enough for a full GUID.
|
||||||
/// The four integers can be modified directly, for example to
|
/// The four integers can be modified directly, for example to store feature
|
||||||
/// store feature lists, checksums or other data within the key.
|
/// lists, checksums or other data within the key.
|
||||||
/// </para>
|
/// </para>
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
public class LicenseKey {
|
public class LicenseKey {
|
||||||
|
|
|
@ -36,7 +36,7 @@ namespace Nuclex.Support.Plugins {
|
||||||
/// <param name="type">Type which will be assessed</param>
|
/// <param name="type">Type which will be assessed</param>
|
||||||
/// <returns>True if the type can be employed</returns>
|
/// <returns>True if the type can be employed</returns>
|
||||||
public virtual bool CanEmploy(Type type) {
|
public virtual bool CanEmploy(Type type) {
|
||||||
return Support.HasDefaultConstructor(type);
|
return PluginHelper.HasDefaultConstructor(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>Employs the specified plugin type</summary>
|
/// <summary>Employs the specified plugin type</summary>
|
||||||
|
|
|
@ -98,7 +98,7 @@ namespace Nuclex.Support.Plugins {
|
||||||
/// <returns>True if the type can be employed</returns>
|
/// <returns>True if the type can be employed</returns>
|
||||||
public override bool CanEmploy(Type type) {
|
public override bool CanEmploy(Type type) {
|
||||||
return
|
return
|
||||||
Support.HasDefaultConstructor(type) &&
|
PluginHelper.HasDefaultConstructor(type) &&
|
||||||
typeof(T).IsAssignableFrom(type);
|
typeof(T).IsAssignableFrom(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -61,7 +61,7 @@ namespace Nuclex.Support.Plugins {
|
||||||
/// <returns>True if the type can be employed</returns>
|
/// <returns>True if the type can be employed</returns>
|
||||||
public override bool CanEmploy(Type type) {
|
public override bool CanEmploy(Type type) {
|
||||||
return
|
return
|
||||||
Support.HasDefaultConstructor(type) &&
|
PluginHelper.HasDefaultConstructor(type) &&
|
||||||
typeof(T).IsAssignableFrom(type);
|
typeof(T).IsAssignableFrom(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,8 +22,8 @@ using System;
|
||||||
|
|
||||||
namespace Nuclex.Support.Plugins {
|
namespace Nuclex.Support.Plugins {
|
||||||
|
|
||||||
/// <summary>Supporting functions for the assembly</summary>
|
/// <summary>Supporting functions for the plugin classes</summary>
|
||||||
internal static class Support {
|
internal static class PluginHelper {
|
||||||
|
|
||||||
/// <summary>Determines whether the given type has a default constructor</summary>
|
/// <summary>Determines whether the given type has a default constructor</summary>
|
||||||
/// <param name="type">Type which is to be checked</param>
|
/// <param name="type">Type which is to be checked</param>
|
||||||
|
|
|
@ -77,20 +77,24 @@ namespace Nuclex.Support.Plugins {
|
||||||
foreach(Type type in assembly.GetTypes()) {
|
foreach(Type type in assembly.GetTypes()) {
|
||||||
|
|
||||||
// We'll ignore abstract and non-public types
|
// We'll ignore abstract and non-public types
|
||||||
if(!type.IsPublic || type.IsAbstract)
|
if(!type.IsPublic || type.IsAbstract) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
// Types that have been tagged with the [NoPlugin] attribute will be ignored
|
// Types that have been tagged with the [NoPlugin] attribute will be ignored
|
||||||
object[] attributes = type.GetCustomAttributes(true);
|
object[] attributes = type.GetCustomAttributes(true);
|
||||||
foreach(object attribute in attributes)
|
for(int index = 0; index < attributes.Length; ++index) {
|
||||||
if(attribute is NoPluginAttribute)
|
if(attributes[index] is NoPluginAttribute) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Type seems to be acceptable, assess and possibly employ it
|
// Type seems to be acceptable, assess and possibly employ it
|
||||||
try {
|
try {
|
||||||
if(this.employer.CanEmploy(type))
|
if(this.employer.CanEmploy(type)) {
|
||||||
this.employer.Employ(type);
|
this.employer.Employ(type);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
catch(Exception exception) {
|
catch(Exception exception) {
|
||||||
System.Console.WriteLine(
|
System.Console.WriteLine(
|
||||||
"Could not employ " + type.ToString() + ": " + exception.Message
|
"Could not employ " + type.ToString() + ": " + exception.Message
|
||||||
|
|
|
@ -65,28 +65,30 @@ namespace Nuclex.Support.Plugins {
|
||||||
// File not found - Most likely a missing dependency of the assembly we
|
// File not found - Most likely a missing dependency of the assembly we
|
||||||
// attempted to load since the assembly itself has been found by the GetFiles() method
|
// attempted to load since the assembly itself has been found by the GetFiles() method
|
||||||
catch(DllNotFoundException exception) {
|
catch(DllNotFoundException exception) {
|
||||||
System.Console.WriteLine(
|
Console.WriteLine(
|
||||||
"Assembly not found, missing dependencies? " + exception.Message
|
"Assembly '" + assemblyFile + "' or one of its dependencies is missing"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
// Unauthorized acccess - Either the assembly is not trusted because it contains
|
// Unauthorized acccess - Either the assembly is not trusted because it contains
|
||||||
// code that imposes a security risk on the system or a user rights problem
|
// code that imposes a security risk on the system or a user rights problem
|
||||||
catch(UnauthorizedAccessException exception) {
|
catch(UnauthorizedAccessException exception) {
|
||||||
System.Console.WriteLine(
|
Console.WriteLine(
|
||||||
"Not authorized, user rights problem? " + exception.Message
|
"Not authorized to load assembly '" + assemblyFile + "', " +
|
||||||
|
"possible rights problem"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
// Bad image format - This exception is often thrown when the assembly we
|
// Bad image format - This exception is often thrown when the assembly we
|
||||||
// attempted to load requires a different version of the .NET framework
|
// attempted to load requires a different version of the .NET framework
|
||||||
catch(BadImageFormatException exception) {
|
catch(BadImageFormatException exception) {
|
||||||
System.Console.WriteLine(
|
Console.WriteLine(
|
||||||
"Not a .NET assembly or wrong runtime version. " + exception.Message
|
"'" + assemblyFile +"' is not a .NET assembly, requires a different version " +
|
||||||
|
"of the .NET Runtime or does not support the current instruction set (x86/x64)"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
// Unknown error - Our last resort is to show a default error message
|
// Unknown error - Our last resort is to show a default error message
|
||||||
catch(Exception exception) {
|
catch(Exception exception) {
|
||||||
System.Console.WriteLine(
|
Console.WriteLine(
|
||||||
"Failed to load plugin. " + exception.Message
|
"Failed to load plugin assembly '" + assemblyFile + "': " + exception.Message
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -102,9 +104,10 @@ namespace Nuclex.Support.Plugins {
|
||||||
this.assemblies.Add(assembly);
|
this.assemblies.Add(assembly);
|
||||||
|
|
||||||
// Trigger event in case any subscribers have been registered
|
// Trigger event in case any subscribers have been registered
|
||||||
if(AssemblyLoaded != null)
|
if(AssemblyLoaded != null) {
|
||||||
AssemblyLoaded(this, new AssemblyLoadEventArgs(assembly));
|
AssemblyLoaded(this, new AssemblyLoadEventArgs(assembly));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>List of all loaded plugin assemblies in the repository</summary>
|
/// <summary>List of all loaded plugin assemblies in the repository</summary>
|
||||||
public List<Assembly> LoadedAssemblies {
|
public List<Assembly> LoadedAssemblies {
|
||||||
|
|
|
@ -120,7 +120,7 @@ namespace Nuclex.Support {
|
||||||
/// <summary>Returns the hash code for the current instance</summary>
|
/// <summary>Returns the hash code for the current instance</summary>
|
||||||
/// <returns>A 32-bit signed integer hash code</returns>
|
/// <returns>A 32-bit signed integer hash code</returns>
|
||||||
public override int GetHashCode() {
|
public override int GetHashCode() {
|
||||||
return ((this.text.GetHashCode() ^ this.offset) ^ this.count);
|
return this.text.GetHashCode() ^ this.offset ^ this.count;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -132,7 +132,9 @@ namespace Nuclex.Support {
|
||||||
/// </returns>
|
/// </returns>
|
||||||
/// <param name="other">The object to be compared with the current instance</param>
|
/// <param name="other">The object to be compared with the current instance</param>
|
||||||
public override bool Equals(object other) {
|
public override bool Equals(object other) {
|
||||||
return ((other is StringSegment) && this.Equals((StringSegment)other));
|
return
|
||||||
|
(other is StringSegment) &&
|
||||||
|
this.Equals((StringSegment)other);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user