Moved all contents of the Nuclex.Plugins project into the Nuclex.Support project; added copyright notices to all files imported from Nuclex.Plugins; updated copyright span year in all copyright notices; minor documentation improvements

git-svn-id: file:///srv/devel/repo-conversion/nusu@59 d2e56fa2-650e-0410-a79f-9358c0239efd
This commit is contained in:
Markus Ewald 2008-01-07 18:04:02 +00:00
parent 4829c8f8d5
commit d59753b98d
62 changed files with 622 additions and 58 deletions

View File

@ -84,7 +84,9 @@
<DependentUpon>RingMemoryStream.cs</DependentUpon>
</Compile>
<Compile Include="Source\Collections\TransformingReadOnlyCollection.cs" />
<Compile Include="Source\Collections\TransformingReadOnlyCollection.Interfaces.cs" />
<Compile Include="Source\Collections\TransformingReadOnlyCollection.Interfaces.cs">
<DependentUpon>TransformingReadOnlyCollection.cs</DependentUpon>
</Compile>
<Compile Include="Source\Licensing\LicenseKey.cs" />
<Compile Include="Source\Licensing\LicenseKey.Test.cs">
<DependentUpon>LicenseKey.cs</DependentUpon>
@ -114,6 +116,13 @@
<Compile Include="Source\PathHelper.Test.cs">
<DependentUpon>PathHelper.cs</DependentUpon>
</Compile>
<Compile Include="Source\Plugins\Attributes.cs" />
<Compile Include="Source\Plugins\Employer.cs" />
<Compile Include="Source\Plugins\FactoryEmployer.cs" />
<Compile Include="Source\Plugins\InstanceEmployer.cs" />
<Compile Include="Source\Plugins\PluginHelper.cs" />
<Compile Include="Source\Plugins\PluginHost.cs" />
<Compile Include="Source\Plugins\PluginRepository.cs" />
<Compile Include="Source\Scheduling\AbortedException.cs" />
<Compile Include="Source\Scheduling\IAbortable.cs" />
<Compile Include="Source\Scheduling\Operation.cs" />

View File

@ -1,7 +1,7 @@
#region CPL License
/*
Nuclex Framework
Copyright (C) 2002-2007 Nuclex Development Labs
Copyright (C) 2002-2008 Nuclex Development Labs
This library is free software; you can redistribute it and/or
modify it under the terms of the IBM Common Public License as

View File

@ -1,7 +1,7 @@
#region CPL License
/*
Nuclex Framework
Copyright (C) 2002-2007 Nuclex Development Labs
Copyright (C) 2002-2008 Nuclex Development Labs
This library is free software; you can redistribute it and/or
modify it under the terms of the IBM Common Public License as

View File

@ -1,7 +1,7 @@
#region CPL License
/*
Nuclex Framework
Copyright (C) 2002-2007 Nuclex Development Labs
Copyright (C) 2002-2008 Nuclex Development Labs
This library is free software; you can redistribute it and/or
modify it under the terms of the IBM Common Public License as

View File

@ -1,7 +1,7 @@
#region CPL License
/*
Nuclex Framework
Copyright (C) 2002-2007 Nuclex Development Labs
Copyright (C) 2002-2008 Nuclex Development Labs
This library is free software; you can redistribute it and/or
modify it under the terms of the IBM Common Public License as

View File

@ -1,7 +1,7 @@
#region CPL License
/*
Nuclex Framework
Copyright (C) 2002-2007 Nuclex Development Labs
Copyright (C) 2002-2008 Nuclex Development Labs
This library is free software; you can redistribute it and/or
modify it under the terms of the IBM Common Public License as

View File

@ -1,7 +1,7 @@
#region CPL License
/*
Nuclex Framework
Copyright (C) 2002-2007 Nuclex Development Labs
Copyright (C) 2002-2008 Nuclex Development Labs
This library is free software; you can redistribute it and/or
modify it under the terms of the IBM Common Public License as

View File

@ -1,7 +1,7 @@
#region CPL License
/*
Nuclex Framework
Copyright (C) 2002-2007 Nuclex Development Labs
Copyright (C) 2002-2008 Nuclex Development Labs
This library is free software; you can redistribute it and/or
modify it under the terms of the IBM Common Public License as

View File

@ -1,7 +1,7 @@
#region CPL License
/*
Nuclex Framework
Copyright (C) 2002-2007 Nuclex Development Labs
Copyright (C) 2002-2008 Nuclex Development Labs
This library is free software; you can redistribute it and/or
modify it under the terms of the IBM Common Public License as

View File

@ -1,7 +1,7 @@
#region CPL License
/*
Nuclex Framework
Copyright (C) 2002-2007 Nuclex Development Labs
Copyright (C) 2002-2008 Nuclex Development Labs
This library is free software; you can redistribute it and/or
modify it under the terms of the IBM Common Public License as
@ -196,15 +196,17 @@ namespace Nuclex.Support.Collections {
while(child < this.count) {
if(
bool needsToBeMoved =
((child + 1) < this.count) &&
(this.comparer.Compare(heap[child], this.heap[child + 1]) < 0)
)
(this.comparer.Compare(heap[child], this.heap[child + 1]) < 0);
if(needsToBeMoved)
++child;
this.heap[index] = this.heap[child];
index = child;
child = getLeftChild(index);
}
bubbleUp(index, item);

View File

@ -1,7 +1,7 @@
#region CPL License
/*
Nuclex Framework
Copyright (C) 2002-2007 Nuclex Development Labs
Copyright (C) 2002-2008 Nuclex Development Labs
This library is free software; you can redistribute it and/or
modify it under the terms of the IBM Common Public License as

View File

@ -1,7 +1,7 @@
#region CPL License
/*
Nuclex Framework
Copyright (C) 2002-2007 Nuclex Development Labs
Copyright (C) 2002-2008 Nuclex Development Labs
This library is free software; you can redistribute it and/or
modify it under the terms of the IBM Common Public License as

View File

@ -1,7 +1,7 @@
#region CPL License
/*
Nuclex Framework
Copyright (C) 2002-2007 Nuclex Development Labs
Copyright (C) 2002-2008 Nuclex Development Labs
This library is free software; you can redistribute it and/or
modify it under the terms of the IBM Common Public License as

View File

@ -1,7 +1,7 @@
#region CPL License
/*
Nuclex Framework
Copyright (C) 2002-2007 Nuclex Development Labs
Copyright (C) 2002-2008 Nuclex Development Labs
This library is free software; you can redistribute it and/or
modify it under the terms of the IBM Common Public License as

View File

@ -1,7 +1,7 @@
#region CPL License
/*
Nuclex Framework
Copyright (C) 2002-2007 Nuclex Development Labs
Copyright (C) 2002-2008 Nuclex Development Labs
This library is free software; you can redistribute it and/or
modify it under the terms of the IBM Common Public License as

View File

@ -1,7 +1,7 @@
#region CPL License
/*
Nuclex Framework
Copyright (C) 2002-2007 Nuclex Development Labs
Copyright (C) 2002-2008 Nuclex Development Labs
This library is free software; you can redistribute it and/or
modify it under the terms of the IBM Common Public License as

View File

@ -1,7 +1,7 @@
#region CPL License
/*
Nuclex Framework
Copyright (C) 2002-2007 Nuclex Development Labs
Copyright (C) 2002-2008 Nuclex Development Labs
This library is free software; you can redistribute it and/or
modify it under the terms of the IBM Common Public License as

View File

@ -1,7 +1,7 @@
#region CPL License
/*
Nuclex Framework
Copyright (C) 2002-2007 Nuclex Development Labs
Copyright (C) 2002-2008 Nuclex Development Labs
This library is free software; you can redistribute it and/or
modify it under the terms of the IBM Common Public License as

View File

@ -1,7 +1,7 @@
#region CPL License
/*
Nuclex Framework
Copyright (C) 2002-2007 Nuclex Development Labs
Copyright (C) 2002-2008 Nuclex Development Labs
This library is free software; you can redistribute it and/or
modify it under the terms of the IBM Common Public License as

View File

@ -1,7 +1,7 @@
#region CPL License
/*
Nuclex Framework
Copyright (C) 2002-2007 Nuclex Development Labs
Copyright (C) 2002-2008 Nuclex Development Labs
This library is free software; you can redistribute it and/or
modify it under the terms of the IBM Common Public License as

View File

@ -1,7 +1,7 @@
#region CPL License
/*
Nuclex Framework
Copyright (C) 2002-2007 Nuclex Development Labs
Copyright (C) 2002-2008 Nuclex Development Labs
This library is free software; you can redistribute it and/or
modify it under the terms of the IBM Common Public License as

View File

@ -1,7 +1,7 @@
#region CPL License
/*
Nuclex Framework
Copyright (C) 2002-2007 Nuclex Development Labs
Copyright (C) 2002-2008 Nuclex Development Labs
This library is free software; you can redistribute it and/or
modify it under the terms of the IBM Common Public License as

View File

@ -1,7 +1,7 @@
#region CPL License
/*
Nuclex Framework
Copyright (C) 2002-2007 Nuclex Development Labs
Copyright (C) 2002-2008 Nuclex Development Labs
This library is free software; you can redistribute it and/or
modify it under the terms of the IBM Common Public License as

View File

@ -1,7 +1,7 @@
#region CPL License
/*
Nuclex Framework
Copyright (C) 2002-2007 Nuclex Development Labs
Copyright (C) 2002-2008 Nuclex Development Labs
This library is free software; you can redistribute it and/or
modify it under the terms of the IBM Common Public License as

View File

@ -1,7 +1,7 @@
#region CPL License
/*
Nuclex Framework
Copyright (C) 2002-2007 Nuclex Development Labs
Copyright (C) 2002-2008 Nuclex Development Labs
This library is free software; you can redistribute it and/or
modify it under the terms of the IBM Common Public License as

View File

@ -1,7 +1,7 @@
#region CPL License
/*
Nuclex Framework
Copyright (C) 2002-2007 Nuclex Development Labs
Copyright (C) 2002-2008 Nuclex Development Labs
This library is free software; you can redistribute it and/or
modify it under the terms of the IBM Common Public License as

View File

@ -1,7 +1,7 @@
#region CPL License
/*
Nuclex Framework
Copyright (C) 2002-2007 Nuclex Development Labs
Copyright (C) 2002-2008 Nuclex Development Labs
This library is free software; you can redistribute it and/or
modify it under the terms of the IBM Common Public License as

View File

@ -0,0 +1,38 @@
#region CPL License
/*
Nuclex Framework
Copyright (C) 2002-2008 Nuclex Development Labs
This library is free software; you can redistribute it and/or
modify it under the terms of the IBM Common Public License as
published by the IBM Corporation; either version 1.0 of the
License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
IBM Common Public License for more details.
You should have received a copy of the IBM Common Public
License along with this library
*/
#endregion
using System;
namespace Nuclex.Support.Plugins {
/// <summary>Attribute that prevents a class from being seen by the PluginHost</summary>
/// <remarks>
/// When this attribute is attached to a class it will be invisible to the
/// PluginHost and not become accessable as a plugin.
/// </remarks>
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
public class NoPluginAttribute : System.Attribute {
/// <summary>Initializes an instance of the NoPluginAttributes</summary>
public NoPluginAttribute() : base() { }
}
} // namespace Nuclex.Support.Plugins

View File

@ -0,0 +1,48 @@
#region CPL License
/*
Nuclex Framework
Copyright (C) 2002-2008 Nuclex Development Labs
This library is free software; you can redistribute it and/or
modify it under the terms of the IBM Common Public License as
published by the IBM Corporation; either version 1.0 of the
License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
IBM Common Public License for more details.
You should have received a copy of the IBM Common Public
License along with this library
*/
#endregion
using System;
namespace Nuclex.Support.Plugins {
/// <summary>Plugin type employer</summary>
/// <remarks>
/// This class is used by the plugin host to assess whether a concrete type found
/// in a plugin assembly is suited to be processed the plugin user. If so,
/// the employer can employ the type. Employing can typically mean to create an
/// instance of the type in the plugin assembly or to build a runtime-factory
/// that can create instances of the type when it is needed.
/// </remarks>
public abstract class Employer {
/// <summary>Determines whether the type suites the employer's requirements</summary>
/// <param name="type">Type which will be assessed</param>
/// <returns>True if the type can be employed</returns>
public virtual bool CanEmploy(Type type) {
return Support.HasDefaultConstructor(type);
}
/// <summary>Employs the specified plugin type</summary>
/// <param name="type">Type to be employed</param>
public abstract void Employ(Type type);
}
} // namespace Nuclex.Support.Plugins

View File

@ -0,0 +1,116 @@
#region CPL License
/*
Nuclex Framework
Copyright (C) 2002-2008 Nuclex Development Labs
This library is free software; you can redistribute it and/or
modify it under the terms of the IBM Common Public License as
published by the IBM Corporation; either version 1.0 of the
License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
IBM Common Public License for more details.
You should have received a copy of the IBM Common Public
License along with this library
*/
#endregion
using System;
using System.Collections.Generic;
namespace Nuclex.Support.Plugins {
/// <summary>Abstract factory</summary>
/// <typeparam name="T">Interface or base class of the product of the factory</typeparam>
public interface IFactory<T> {
/// <summary>The concrete type as implemented by the factory instance</summary>
Type ConcreteType { get; }
/// <summary>Creates a new instance of the type to which the factory is specialized</summary>
/// <returns>The newly created instance</returns>
T CreateInstance();
}
/// <summary>Employer to create factories of suiting types found in plugins</summary>
/// <typeparam name="T">Interface or base class that the types need to implement</typeparam>
/// <remarks>
/// <para>
/// This employer will not directly instanciate any compatible types found in
/// plugin assemblies, but generated runtime-factories of these types, enabling the
/// user to decide when and how many instances of a type will be created.
/// </para>
/// <para>
/// This approach has the advantage that it enables even assemblies that were not
/// intended to be plugins can be loaded as plugins, without risking an instanciation
/// or complex and possibly heavy-weight types. The disadvantage is that the
/// runtime-factory can not provide decent informationa about the plugin type like
/// a human-readable name, capabilities or an icon.
/// </para>
/// </remarks>
public class FactoryEmployer<T> : Employer {
#region class Factory
/// <summary>Concrete factory for the types in a plugin assembly</summary>
private class Factory : IFactory<T> {
/// <summary>Initializes a factory and configures it for the specified product</summary>
/// <param name="type">Type of which the factory creates instances</param>
public Factory(Type type) {
this.concreteType = type;
}
/// <summary>The concrete type as produced by the factory</summary>
public Type ConcreteType {
get { return this.concreteType; }
}
/// <summary>Create a new instance of the type that the factory is configured to</summary>
/// <returns>The newly created instance</returns>
public T CreateInstance() {
return (T)Activator.CreateInstance(this.concreteType);
}
/// <summary>Concrete product which the factory instance creates</summary>
private Type concreteType;
}
#endregion // class Factory
/// <summary>Initializes a new FactoryEmployer</summary>
public FactoryEmployer() {
this.employedFactories = new List<IFactory<T>>();
}
/// <summary>List of all factories that the instance employer has created</summary>
public List<IFactory<T>> Factories {
get { return this.employedFactories; }
}
/// <summary>Determines whether the type suites the employer's requirements</summary>
/// <param name="type">Type which will be assessed</param>
/// <returns>True if the type can be employed</returns>
public override bool CanEmploy(Type type) {
return
Support.HasDefaultConstructor(type) &&
typeof(T).IsAssignableFrom(type);
}
/// <summary>Employs the specified plugin type</summary>
/// <param name="type">Type to be employed</param>
public override void Employ(Type type) {
this.employedFactories.Add(new Factory(type));
}
/// <summary>All factories that the instance employer has created</summary>
private List<IFactory<T>> employedFactories;
}
} // namespace Nuclex.Support.Plugins

View File

@ -0,0 +1,79 @@
#region CPL License
/*
Nuclex Framework
Copyright (C) 2002-2008 Nuclex Development Labs
This library is free software; you can redistribute it and/or
modify it under the terms of the IBM Common Public License as
published by the IBM Corporation; either version 1.0 of the
License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
IBM Common Public License for more details.
You should have received a copy of the IBM Common Public
License along with this library
*/
#endregion
using System;
using System.Collections.Generic;
namespace Nuclex.Support.Plugins {
/// <summary>Employer that directly creates instances of the types in a plugin</summary>
/// <typeparam name="T">Interface or base class required for the employed types</typeparam>
/// <remarks>
/// <para>
/// This employer directly creates an instance of any type in a plugin assembly that
/// implements or is derived from the type the generic InstanceEmployer is instanced
/// to. This is useful when the plugin user already has a special plugin interface
/// through which additional informations about a plugin type can be queried or
/// when actually exactly one instance per plugin type is wanted (think of the
/// prototype pattern for example)
/// </para>
/// <para>
/// Because this employer blindly creates an instance of any compatible type found
/// in a plugin assembly it should be used with care. If big types with high
/// construction time or huge memory requirements are loaded this can become
/// a real resource hog. The intention of this employer was to let the plugin user
/// define his own factory interface which possibly provides further details about
/// the type the factory is reponsible for (like a description field). This
/// factory would then be implemented on the plugin side.
/// </para>
/// </remarks>
public class InstanceEmployer<T> : Employer {
/// <summary>Initializes a new instance employer</summary>
public InstanceEmployer() {
this.employedInstances = new List<T>();
}
/// <summary>All instances that have been employed</summary>
public List<T> Instances {
get { return this.employedInstances; }
}
/// <summary>Determines whether the type suites the employer's requirements</summary>
/// <param name="type">Type that is checked for employability</param>
/// <returns>True if the type can be employed</returns>
public override bool CanEmploy(Type type) {
return
Support.HasDefaultConstructor(type) &&
typeof(T).IsAssignableFrom(type);
}
/// <summary>Employs the specified plugin type</summary>
/// <param name="type">Type to be employed</param>
public override void Employ(Type type) {
this.employedInstances.Add((T)Activator.CreateInstance(type));
}
/// <summary>All instances employed by the instance employer</summary>
private List<T> employedInstances;
}
} // namespace Nuclex.Support.Plugins

View File

@ -0,0 +1,43 @@
#region CPL License
/*
Nuclex Framework
Copyright (C) 2002-2008 Nuclex Development Labs
This library is free software; you can redistribute it and/or
modify it under the terms of the IBM Common Public License as
published by the IBM Corporation; either version 1.0 of the
License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
IBM Common Public License for more details.
You should have received a copy of the IBM Common Public
License along with this library
*/
#endregion
using System;
namespace Nuclex.Support.Plugins {
/// <summary>Supporting functions for the assembly</summary>
internal static class Support {
/// <summary>Determines whether the given type has a default constructor</summary>
/// <param name="type">Type which is to be checked</param>
/// <returns>True if the type has a default constructor</returns>
public static bool HasDefaultConstructor(Type type) {
System.Reflection.ConstructorInfo[] constructors = type.GetConstructors();
foreach(System.Reflection.ConstructorInfo constructor in constructors)
if(constructor.IsPublic && (constructor.GetParameters().Length != 0))
return true;
return false;
}
}
} // namespace Nuclex.Support.Plugins

View File

@ -0,0 +1,110 @@
#region CPL License
/*
Nuclex Framework
Copyright (C) 2002-2008 Nuclex Development Labs
This library is free software; you can redistribute it and/or
modify it under the terms of the IBM Common Public License as
published by the IBM Corporation; either version 1.0 of the
License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
IBM Common Public License for more details.
You should have received a copy of the IBM Common Public
License along with this library
*/
#endregion
using System;
using System.Reflection;
namespace Nuclex.Support.Plugins {
/// <summary>Integration host for plugins</summary>
/// <remarks>
/// This class is created by the party that is interested in loading plugins,
/// herein referred to as the "plugin user". The plugin host will monitor a
/// repository and react to any assembly being loaded into that repository by
/// iterating over all types (as in classes and structures) found in the
/// assembly and using the employer to do whatever the plugin user intends
/// to do with the types found in that assembly
/// </remarks>
public class PluginHost {
/// <summary>Initializes a plugin host using a new repository</summary>
/// <param name="employer">Employer used assess and employ the plugin types</param>
public PluginHost(Employer employer)
: this(employer, new PluginRepository()) { }
/// <summary>Initializes the plugin using an existing repository</summary>
/// <param name="employer">Employer used assess and employ the plugin types</param>
/// <param name="repository">Repository in which plugins will be stored</param>
public PluginHost(Employer employer, PluginRepository repository) {
this.employer = employer;
this.repository = repository;
foreach(Assembly assembly in this.repository.LoadedPlugins)
employAssemblyTypes(assembly);
this.repository.AssemblyLoaded += new AssemblyLoadEventHandler(assemblyLoadHandler);
}
/// <summary>The repository containing all loaded plugins</summary>
public PluginRepository Repository {
get { return this.repository; }
}
/// <summary>The employer that is used by this plugin integration host</summary>
public Employer Employer {
get { return this.employer; }
}
/// <summary>Responds to a new plugin being loaded into the repository</summary>
/// <param name="sender">Repository into which the assembly was loaded</param>
/// <param name="arguments">Event arguments; contains the loaded assembly</param>
private void assemblyLoadHandler(object sender, AssemblyLoadEventArgs arguments) {
employAssemblyTypes(arguments.LoadedAssembly);
}
/// <summary>Employs all employable types in an assembly</summary>
/// <param name="assembly">Assembly whose types to assess and to employ</param>
private void employAssemblyTypes(Assembly assembly) {
// Iterate all types contained in the assembly
foreach(Type type in assembly.GetTypes()) {
// We'll ignore abstract and non-public types
if(!type.IsPublic || type.IsAbstract)
continue;
// Types that have been tagged with the [NoPlugin] attribute will be ignored
object[] attributes = type.GetCustomAttributes(true);
foreach(object attribute in attributes)
if(attribute is NoPluginAttribute)
continue;
// Type seems to be acceptable, assess and possibly employ it
try {
if(this.employer.CanEmploy(type))
this.employer.Employ(type);
}
catch(Exception exception) {
System.Console.WriteLine(
"Could not employ " + type.ToString() + ": " + exception.Message
);
}
}
}
/// <summary>Employs and manages types in the loaded plugin assemblies</summary>
private Employer employer;
/// <summary>Repository containing all plugins loaded, shared with other hosts</summary>
private PluginRepository repository;
}
} // namespace Nuclex.Support.Plugins

View File

@ -0,0 +1,119 @@
#region CPL License
/*
Nuclex Framework
Copyright (C) 2002-2008 Nuclex Development Labs
This library is free software; you can redistribute it and/or
modify it under the terms of the IBM Common Public License as
published by the IBM Corporation; either version 1.0 of the
License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
IBM Common Public License for more details.
You should have received a copy of the IBM Common Public
License along with this library
*/
#endregion
using System;
using System.Collections.Generic;
using System.Reflection;
using System.IO;
namespace Nuclex.Support.Plugins {
/// <summary>Stores loaded plugins</summary>
/// <remarks>
/// This class manages a set of assemblies that have been dynamically loaded
/// as plugins. It usually is shared by multiple PluginHosts that handle
/// different interfaces of one plugin type.
/// </remarks>
public class PluginRepository {
/// <summary>Triggered whenever a new assembly is loaded into this repository</summary>
public event AssemblyLoadEventHandler AssemblyLoaded;
/// <summary>Initializes a new instance of the plugin repository</summary>
public PluginRepository() {
this.assemblies = new List<Assembly>();
}
/// <summary>Loads all plugins matching a wildcard specification</summary>
/// <param name="wildcard">Path of one or more plugins via wildcard</param>
/// <remarks>
/// This function always assumes that a plugin is optional. This means that
/// even when you specify a unique file name and a matching file is not found,
/// no exception will be raised and the error is silently ignored.
/// </remarks>
public void AddFiles(string wildcard) {
string directory = Path.GetDirectoryName(wildcard);
string search = Path.GetFileName(wildcard);
// We'll scan the specified directory for all files matching the specified
// wildcard. If only a single file is specified, only that file will match
// the supposed wildcard and everything works as expected
string[] assemblyFiles = Directory.GetFiles(directory, search);
foreach(string assemblyFile in assemblyFiles) {
// A lot of errors can occur when attempting to load an assembly...
try {
AddAssembly(Assembly.LoadFile(assemblyFile));
}
// 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
catch(DllNotFoundException exception) {
System.Console.WriteLine(
"Assembly not found, missing dependencies? " + exception.Message
);
}
// 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
catch(UnauthorizedAccessException exception) {
System.Console.WriteLine(
"Not authorized, user rights problem? " + exception.Message
);
}
// Bad image format - This exception is often thrown when the assembly we
// attempted to load requires a different version of the .NET framework
catch(BadImageFormatException exception) {
System.Console.WriteLine(
"Not a .NET assembly or wrong runtime version. " + exception.Message
);
}
// Unknown error - Our last resort is to show a default error message
catch(Exception exception) {
System.Console.WriteLine(
"Failed to load plugin. " + exception.Message
);
}
}
}
/// <summary>Adds the specified assembly to the repository</summary>
/// <remarks>
/// Also used internally, so any assembly that is to be put into the repository,
/// not matter how, wanders through this method
/// </remarks>
public void AddAssembly(Assembly assembly) {
this.assemblies.Add(assembly);
// Trigger event in case any subscribers have been registered
if(AssemblyLoaded != null)
AssemblyLoaded(this, new AssemblyLoadEventArgs(assembly));
}
/// <summary>List of all loaded plugin assemblies in the repository</summary>
public List<Assembly> LoadedAssemblies {
get { return this.assemblies; }
}
/// <summary>Loaded plugin assemblies</summary>
private List<Assembly> assemblies;
}
} // namespace Nuclex.Support.Plugins

View File

@ -1,7 +1,7 @@
#region CPL License
/*
Nuclex Framework
Copyright (C) 2002-2007 Nuclex Development Labs
Copyright (C) 2002-2008 Nuclex Development Labs
This library is free software; you can redistribute it and/or
modify it under the terms of the IBM Common Public License as

View File

@ -1,7 +1,7 @@
#region CPL License
/*
Nuclex Framework
Copyright (C) 2002-2007 Nuclex Development Labs
Copyright (C) 2002-2008 Nuclex Development Labs
This library is free software; you can redistribute it and/or
modify it under the terms of the IBM Common Public License as

View File

@ -1,7 +1,7 @@
#region CPL License
/*
Nuclex Framework
Copyright (C) 2002-2007 Nuclex Development Labs
Copyright (C) 2002-2008 Nuclex Development Labs
This library is free software; you can redistribute it and/or
modify it under the terms of the IBM Common Public License as

View File

@ -1,7 +1,7 @@
#region CPL License
/*
Nuclex Framework
Copyright (C) 2002-2007 Nuclex Development Labs
Copyright (C) 2002-2008 Nuclex Development Labs
This library is free software; you can redistribute it and/or
modify it under the terms of the IBM Common Public License as

View File

@ -1,7 +1,7 @@
#region CPL License
/*
Nuclex Framework
Copyright (C) 2002-2007 Nuclex Development Labs
Copyright (C) 2002-2008 Nuclex Development Labs
This library is free software; you can redistribute it and/or
modify it under the terms of the IBM Common Public License as

View File

@ -1,7 +1,7 @@
#region CPL License
/*
Nuclex Framework
Copyright (C) 2002-2007 Nuclex Development Labs
Copyright (C) 2002-2008 Nuclex Development Labs
This library is free software; you can redistribute it and/or
modify it under the terms of the IBM Common Public License as

View File

@ -1,7 +1,7 @@
#region CPL License
/*
Nuclex Framework
Copyright (C) 2002-2007 Nuclex Development Labs
Copyright (C) 2002-2008 Nuclex Development Labs
This library is free software; you can redistribute it and/or
modify it under the terms of the IBM Common Public License as

View File

@ -1,7 +1,7 @@
#region CPL License
/*
Nuclex Framework
Copyright (C) 2002-2007 Nuclex Development Labs
Copyright (C) 2002-2008 Nuclex Development Labs
This library is free software; you can redistribute it and/or
modify it under the terms of the IBM Common Public License as

View File

@ -1,7 +1,7 @@
#region CPL License
/*
Nuclex Framework
Copyright (C) 2002-2007 Nuclex Development Labs
Copyright (C) 2002-2008 Nuclex Development Labs
This library is free software; you can redistribute it and/or
modify it under the terms of the IBM Common Public License as

View File

@ -1,7 +1,7 @@
#region CPL License
/*
Nuclex Framework
Copyright (C) 2002-2007 Nuclex Development Labs
Copyright (C) 2002-2008 Nuclex Development Labs
This library is free software; you can redistribute it and/or
modify it under the terms of the IBM Common Public License as

View File

@ -1,7 +1,7 @@
#region CPL License
/*
Nuclex Framework
Copyright (C) 2002-2007 Nuclex Development Labs
Copyright (C) 2002-2008 Nuclex Development Labs
This library is free software; you can redistribute it and/or
modify it under the terms of the IBM Common Public License as

View File

@ -1,7 +1,7 @@
#region CPL License
/*
Nuclex Framework
Copyright (C) 2002-2007 Nuclex Development Labs
Copyright (C) 2002-2008 Nuclex Development Labs
This library is free software; you can redistribute it and/or
modify it under the terms of the IBM Common Public License as

View File

@ -1,7 +1,7 @@
#region CPL License
/*
Nuclex Framework
Copyright (C) 2002-2007 Nuclex Development Labs
Copyright (C) 2002-2008 Nuclex Development Labs
This library is free software; you can redistribute it and/or
modify it under the terms of the IBM Common Public License as

View File

@ -1,7 +1,7 @@
#region CPL License
/*
Nuclex Framework
Copyright (C) 2002-2007 Nuclex Development Labs
Copyright (C) 2002-2008 Nuclex Development Labs
This library is free software; you can redistribute it and/or
modify it under the terms of the IBM Common Public License as

View File

@ -1,7 +1,7 @@
#region CPL License
/*
Nuclex Framework
Copyright (C) 2002-2007 Nuclex Development Labs
Copyright (C) 2002-2008 Nuclex Development Labs
This library is free software; you can redistribute it and/or
modify it under the terms of the IBM Common Public License as

View File

@ -1,7 +1,7 @@
#region CPL License
/*
Nuclex Framework
Copyright (C) 2002-2007 Nuclex Development Labs
Copyright (C) 2002-2008 Nuclex Development Labs
This library is free software; you can redistribute it and/or
modify it under the terms of the IBM Common Public License as

View File

@ -1,7 +1,7 @@
#region CPL License
/*
Nuclex Framework
Copyright (C) 2002-2007 Nuclex Development Labs
Copyright (C) 2002-2008 Nuclex Development Labs
This library is free software; you can redistribute it and/or
modify it under the terms of the IBM Common Public License as

View File

@ -1,7 +1,7 @@
#region CPL License
/*
Nuclex Framework
Copyright (C) 2002-2007 Nuclex Development Labs
Copyright (C) 2002-2008 Nuclex Development Labs
This library is free software; you can redistribute it and/or
modify it under the terms of the IBM Common Public License as

View File

@ -1,7 +1,7 @@
#region CPL License
/*
Nuclex Framework
Copyright (C) 2002-2007 Nuclex Development Labs
Copyright (C) 2002-2008 Nuclex Development Labs
This library is free software; you can redistribute it and/or
modify it under the terms of the IBM Common Public License as

View File

@ -1,7 +1,7 @@
#region CPL License
/*
Nuclex Framework
Copyright (C) 2002-2007 Nuclex Development Labs
Copyright (C) 2002-2008 Nuclex Development Labs
This library is free software; you can redistribute it and/or
modify it under the terms of the IBM Common Public License as

View File

@ -1,7 +1,7 @@
#region CPL License
/*
Nuclex Framework
Copyright (C) 2002-2007 Nuclex Development Labs
Copyright (C) 2002-2008 Nuclex Development Labs
This library is free software; you can redistribute it and/or
modify it under the terms of the IBM Common Public License as

View File

@ -1,7 +1,7 @@
#region CPL License
/*
Nuclex Framework
Copyright (C) 2002-2007 Nuclex Development Labs
Copyright (C) 2002-2008 Nuclex Development Labs
This library is free software; you can redistribute it and/or
modify it under the terms of the IBM Common Public License as

View File

@ -1,7 +1,7 @@
#region CPL License
/*
Nuclex Framework
Copyright (C) 2002-2007 Nuclex Development Labs
Copyright (C) 2002-2008 Nuclex Development Labs
This library is free software; you can redistribute it and/or
modify it under the terms of the IBM Common Public License as

View File

@ -1,7 +1,7 @@
#region CPL License
/*
Nuclex Framework
Copyright (C) 2002-2007 Nuclex Development Labs
Copyright (C) 2002-2008 Nuclex Development Labs
This library is free software; you can redistribute it and/or
modify it under the terms of the IBM Common Public License as

View File

@ -1,7 +1,7 @@
#region CPL License
/*
Nuclex Framework
Copyright (C) 2002-2007 Nuclex Development Labs
Copyright (C) 2002-2008 Nuclex Development Labs
This library is free software; you can redistribute it and/or
modify it under the terms of the IBM Common Public License as

View File

@ -1,7 +1,7 @@
#region CPL License
/*
Nuclex Framework
Copyright (C) 2002-2007 Nuclex Development Labs
Copyright (C) 2002-2008 Nuclex Development Labs
This library is free software; you can redistribute it and/or
modify it under the terms of the IBM Common Public License as

View File

@ -1,7 +1,7 @@
#region CPL License
/*
Nuclex Framework
Copyright (C) 2002-2007 Nuclex Development Labs
Copyright (C) 2002-2008 Nuclex Development Labs
This library is free software; you can redistribute it and/or
modify it under the terms of the IBM Common Public License as

View File

@ -1,7 +1,7 @@
#region CPL License
/*
Nuclex Framework
Copyright (C) 2002-2007 Nuclex Development Labs
Copyright (C) 2002-2008 Nuclex Development Labs
This library is free software; you can redistribute it and/or
modify it under the terms of the IBM Common Public License as