Introduction
I guess I need to start off with the customary, "This is my first CodeProject article, so please be nice." Now that it's been said, let's move on the the meat of this article. The sample project/application was designed to demonstrate the creation of an infrastructure within an application in order to provide some extensibility through plug-ins. This project is hosted on SourceForge. If you wish to contribute to it, provide feedback or alternative approaches, please feel free to contact me. The solution provided, Plug-in, includes five C# projects:
TaskPluginInterface: The main library.
TaskPluginTest: An application provided to test the plug-ins.
FileCopyPlugin: A plug-in created to demonstrate the implementation of ITaskPluginInterface. This plug-in copies one or more files from one directory to another.
RunCommandPlugin: A plug-in created to demonstrate the implementation of ITaskPluginInterface. This plug-in will run commands using the System.Diagnostics.Process class.
PluginShellPlugin: This plug-in provides a basic shell for implementing the ITaskPluginInterface.
Technologies used
Microsoft .NET Framework v2.0, although v1.1 could be used with some modifications.
System.configuration
System.Reflection
System.Collections.Generic
System.File.IO
System.Diagnostics
Delegates, events, and event arguments
Log4Net
Guadagno.Utilties.dll, a series of classes that provides common functionality amongst most of my projects. The key class is ConfigurationBase, which is used for the application configuration.
SchedulerTime.dll, a class library used for the scheduling. See the reference article below.
Quick and dirty: how-to
Create the plug-in host
Step 1: Include a reference to the TaskPluginInterface.dll in your solution.
Step 2: Get the folder location for the plug-ins. I use \Plugins. Call the Utilities.GetPluginFolder() method.
Step 3: Get a list of plug-ins. Call Utilities.GetPlugins(folderName).
Step 4: Call the plug-ins Execute method.
Create the plug-in
Option 1: code from scratch
Step 1: Include a reference to the TaskPluginInterface.dll in your solution.
Step 2: Create a class that inherits from ITaskPlugin.
public class RunCommand : ITaskPlugin
{
}
Step 3: If you are using Visual Studio 2005, you can use the Intellisense or SmartTag to create the stub implementation of ITaskPlugin.
Step 4: Place your code in the Execute method.
Option 2: use the PluginShellPlugin class
Step 1: Rename the class to what ever name you want.
Step 2: Change the resource file strings to accurately describe your plug-in.
Step 3: Change the code in the DoWork() method.
TaskPluginInterface namespace
ITaskPlugin interface
The ITaskPlugin interface defines the methods, events and properties that the plug-ins must implement.
Methods
Enumeration Name Description
Execute Executes the task
Properties
Enumeration Name Description
Author The author of the plug-in.
Description The description of the plug-in.
Extension The file extension(s) that this plug-in handles. This is currently not used.
Extension Description A description of the extension(s) that this plug-in handles. This is currently not used.
Name The name of the plug-in.
Schedule The schedule for the plug-in. This was created for a future project, the pluggable task scheduler.
Version The version of the plug-in.
Events
Enumeration Name Description
EventEnd This is used to notify the host about the ending of the Execute method.
EventException This is used to notify the host about any Exceptions that have occurred.
EventProcessing This is used to notify the host about the processing of the Execute method.
EventStart This is used to notify the host about the starting of the Execute method.
PluginAttribute class
The PluginAttribute class defines the class attributes which can be applied to a class that is implementing the ITaskPlugin interface. This class defines an Attribute, which is PluginType. The PluginType corresponds to the PluginType class. Syntax:
TaskPluginInterface.Plugin(PluginType.Executable)]
public class RunCommand : ITaskPlugin
{
}
Enumerations
ExecuteResult
This enumeration is used as the return value of the Execute method for the ITaskPlugin interface.
Enumeration Name Description
Cancelled Indicates that the Execute method of the plug-in was cancelled.
Exception Indicates that an exception was raised by the plug-in.
Failed Indicates that the plug-in has failed.
Ok Indicates that everything went OK with execute of the plug-in.
PluginType
This enumeration is used to indicate the type of plug-in that is being created. Applying the PluginType attribute to a class does not have an effect the functionality of the class. Its only purpose is to provide a classification of the plug-ins available for list boxes or separate functionality.
Enumeration Name Description
Executable Indicates that the plug-in is used for launching executables.
Import Indicates that the plug-in is used for importing data.
SQL Indicates that the plug-in is used for processing SQL statements.
Unknown Denotes that the type of plug-in is not known.
PluginEventArgs class
The PluginEventArgs class provides information back to the plug-in host. This information is provided back to the plug-in host via one of the four events. PluginEventArgs properties:
Name Description
Cancel Indicates if the operation should be canceled.
Message A message returned from the plug-in.
Progress Indicates the current progress of the plug-in. The Progress is returned as a struct, which is defined in the Utilities class.
RaisedException An exception raised from the plug-in.
ScheduleConfig class
The ScheduleConfig class provides functions that will load the schedule configuration. Note that this was created for a future version of the application.
Utilities class
The Utilities class provides helper functions to interact with and discover plug-ins. All of the provided methods are static, so there is no need to create an instance of the Utilities class. Utilities class methods:
Method Name Description
FileContainsPlugins Determines if the file contains at least one plug-in. There is one overload that allows you specify a PluginType.
GetPlugin Returns a plug-in of the specified class from the specified file.
GetPluginFileList Gets a list files that contain plug-ins within the specified directory. There is one overload that allows you specify a PluginType.
GetPluginFolder Returns the plug-in directory.
GetPlugins Gets a List of plug-ins from the specified file. There is one overload that allows you specify a PluginType.
Included plug-ins
FileCopy
The FileCopy plug-in provides the ability to copy files that fit a mask from one directory to another. This plug-in reads the configuration file, FileCopyPlugin.Settings.xml, for all of the Directory nodes listed in the Directories element. For example:
<Directories>
<Directory FromDir="C:\Temp\" ToDir="d:\Temp\" FileMask="*.*" />
<Directory FromDir="C:\Temp\junk" ToDir="d:\Temp\junk" FileMask="*.txt" />
<Directory FromDir="C:\Temp\junk" ToDir="d:\Temp\junk" FileMask="*.xyz" />
</Directories>
The following configuration contains three copy commands.
Will copy all of the files located in the c:\temp directory to d:\temp
Will copy all of the TXT files located in the c:\temp\junk directory to the d:\temp\junk directory
Will copy all of the XYZ files located in the c:\temp\junk directory to the d:\temp\junk directory
PluginShell
The PluginShell plug-in provides a class that contains everything needed to implement the ITaskPluginInterface.
RunCommand
The RunCommand plug-in provides the ability to execute processes using the System.Diagnostics.Process namespace. This plug-in reads the configuration file. RunCommandPlugin.Settings.xml, for Command elements listed in the Commands node. Each command element has XmlChildNodes that correspond to parameters of the ProcessStartInfo struct of the Process object.
TaskPluginTest
The TaskPluginTest is a sample application that demonstrates the use of the TaskPluginInterface library. This application utilizes the TaskPluginInterface utilities to load the list of application plug-ins. In addition, this application displays the plug-in metadata, executes the plug-in and handles events from the plug-in.
Future enhancements
Create NUnit test cases for entire library.
Create VB.NET sample plug-ins.
Improve on the Schedule library to allow for the displaying of all future schedules.
Integrate the ITaskPlugin interface into a Windows Service application to provide a flexible version of the Windows Task Scheduler.
References
.NET Scheduled Timer by Andy Brummer
History
Version Date What was done
1.0 4/21/07 Initial release.
1.0.0.1 4/21/07 Fixed an issue with spaces in the path.
1.0.0.2 5/5/07 Added better logging information to the plug-ins and the plug-in host.
Updated the Utilities class to replace the logic for GetPluginFolder.
1.0.0.2 6/12/07 Article edited and posted to the main CodeProject.com article base.
About Joseph Guadagno
I have been a developer, technical leader and technical manager for over 13 years. In my spare time, I coach my son's soccer team and baseball teams.
For more on me, visit my website http://www.josephguadagno.net.
Click here to view Joseph Guadagno's online profile.
Other popular C# Libraries articles:
IconLib - Icons Unfolded (MultiIcon and Windows Vista supported)
Library to manipulate icons and icons libraries with support to create, load, save, import and export icons in ico, icl, dll, exe, cpl and src format. (Windows Vista icons supported).
OpenTheme : An open source graphic user interface (GUI) toolkit
An innovative alternative to XAML and XUL
Gios PDF .NET library
A .NET library for generating impressive PDF reports.
DuckTyping: Runtime Dynamic Interface Implementation
Dynamic typing (DuckTyping) implementation for .NET.
分享到:
相关推荐
cd task-router-csharp 复制样本配置文件并编辑它以匹配您的配置。 copy TaskRouter.Web \L ocal.config.example TaskRouter.Web \L ocal.config 您可以在找到您的帐户SID和身份验证令牌。 另外,应用程序初始...
vue-task-node 是一个基于Vue的任务节点图绘制插件(vue-task-node is a Vue based task node mapping plug-in) 在线Demo 如有问题欢迎邮箱:envelope:: 一、安装 npm install vue-task-node -S 二、引入 import ...
1. **跨平台**:RSocket.NET 是一个完全跨平台的库,可以在 Windows、Linux 和 macOS 上运行,并且支持 .NET Core 和 .NET Framework。 2. **NuGet发布**:项目通过 NuGet 包管理器发布,这使得开发者可以方便地在...
总的来说,"Reactive-Programming-in-C-8-and-.NET-Core-3.0"的视频教程涵盖了从基础到高级的反应式编程技术,包括C# 8和.NET Core 3.0的新特性,以及如何利用Rx.NET、Akka.NET进行异步编程和构建高效、反应式的应用...
2. **Task 并发**:利用 .NET 的 Task 类来处理异步任务,可以更好地管理和控制并发操作。 3. **Channel** 或 **ConcurrentQueue**:可能用到了队列数据结构(如 Channel 或 ConcurrentQueue)来存储待处理的请求或...
在每个节点上,我们都可以生成由.Net Task-Parallel库(TPL)处理的新并行任务。 运行时复杂性概述 手术 不变的2D阵列 四绳 指数 O(1) O(log n) 放 上) O(log n) 地图 上) O(n +米) 减少 上) O...
Termux:Task A Termux add-on app ...Edit the configuration to specify the executable in ~/.termux/tasker/ to execute, and if it should be executed in the background (the default) or in a new termi
1. **编译模式**:ASP.NET支持两种编译模式——预编译和Just-In-Time (JIT)编译。预编译可以提高首次请求的响应速度,而JIT编译则是在运行时进行,允许更灵活的代码更新。 2. **页面生命周期管理**:理解ASP.NET...
task 概念为单独一个:house:Installnpm install koa-setup -g注意 nodejs 版本必须大于 12Usagekoa-setupRun testsnpm testAuthor:bust_in_silhouette: cuixiaoruiWebsite: beijingGithub:Show your supportGive a :...
Ben Watson讲解了如何使用.NET Framework提供的Task Parallel Library (TPL)、Parallel LINQ (PLINQ)以及线程池,同时也提醒开发者注意线程安全和死锁等问题。 此外,本书还关注了代码优化技巧,如使用内联函数、...
自述文件Ookii.Dialogs.Wpf WPF应用程序的类库,提供几个常用对话框。 其中包括任务对话框,凭据对话框,进度对话框和通用文件对话框的类。给个星星! :star: 如果您喜欢或正在使用此项目,请给它加星号。...
7. **并发和异步编程**:探讨.NET中的多线程、Task并行库(TPL)、异步编程模型,以及如何处理并发问题。 8. **设计模式**:介绍常见的设计模式,如工厂模式、单例模式、装饰器模式,以及如何在.NET开发中应用它们...
【标题】"Task5-Web-App:任务5进行EPAM .Net培训" 在这个任务中,我们关注的是EPAM .Net培训的第五个阶段,它着重于开发Web应用程序。EPAM是一家全球领先的软件工程公司,其.NET培训课程旨在提升开发者在使用微软的...
- bugfix: Reduced the number of CSS files in OpenGoo to bypass a limitation in IE that won't let you include more than 32 CSS files in one page. - bugfix: search in a workspace returned no results ...
插件任务ECMASCRIPT6 JavaScript乘法任务模块...npm install --save plug-task例子TypeScript代码import * as plugtask from 'plug-task' ;function * subtask ( id : number ) : plugtask . TaskIterator < number>{ c
public async Task<IActionResult> Upload(IFormFile file) { if (file == null || file.Length ) return BadRequest("No file selected."); // 文件处理逻辑 // ... return Ok("File uploaded ...
.NET Echo API 是一个用于调试和故障排除的工具,它在.NET开发环境中扮演着重要的角色。这个API主要设计用于测试网络连接、数据传输以及接口调用的正确性,尤其是在开发和维护分布式系统时。通过发送一个请求到Echo ...
【.NET面试题详解】 1. .NET的内置对象: .NET框架提供了六个主要的内置对象,它们对于ASP.NET开发至关重要: - Response:该对象用于服务器向客户端浏览器发送信息,包括HTML、文本、文件等。 - Request:通过此...
oschina地址: ://git.oschina.net/hugui/light-task-scheduler 例子: : 文档地址(正在更新中,后面以这个为准): ://www.gitbook.com/book/qq254963746/lts/details 这两个地址都会同步更新。景点,请加QQ群:...
- ADO.NET:连接数据库,执行SQL语句,数据适配器,数据集和数据视图。 - Entity Framework:ORM(对象关系映射),简化数据库操作。 9. **线程与并发**: - 线程创建与同步:线程池,Mutex、Semaphore、Monitor...