开源跨平台运行服务插件TaskCore.MainForm(2)

由上面的操作TaskCore.Test项目已经安装了Task.Plugin包,那么我们在项目中分别创建3个子类并继承自Task.Plugin包的父类TPlugin并重写方法TPlugin_Load(),对应文件名称分别为:BlogsObj.cs,BlogsObj01.cs,BlogsObj02.cs,分别添加入下代码内容:

BlogsObj.cs:

namespace TaskCore.Test { // This project can output the Class library as a NuGet Package. // To enable this option, right-click on the project and select the Properties menu item. In the Build tab select "Produce outputs on build". public class BlogsObj : TPlugin { public BlogsObj() { } public override void TPlugin_Load() { var sbLog = new StringBuilder(string.Empty); try { sbLog.Append($"这里是BlogsObj,获取配置文件:{this.XmlConfig.Name}"); //代码块 // new WriteLog()._WriteLog($"{DateTime.Now}测试引用nuget包"); } catch (Exception ex) { sbLog.Append($"异常信息:{ex.Message}"); } finally { PublicClass._WriteLog(sbLog.ToString(), this.XmlConfig.Name); } } } }

BlogsObj01.cs:

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using TaskCore.Plugin; namespace TaskCore.Test { // This project can output the Class library as a NuGet Package. // To enable this option, right-click on the project and select the Properties menu item. In the Build tab select "Produce outputs on build". public class BlogsObj01 : TPlugin { public BlogsObj01() { } public override void TPlugin_Load() { var sbLog = new StringBuilder(string.Empty); try { sbLog.Append($"这里是BlogsObj01,获取配置文件:{this.XmlConfig.Name}"); //代码块 // } catch (Exception ex) { sbLog.Append($"异常信息:{ex.Message}"); } finally { //Console.WriteLine($"这里是Blogs,获取配置文件:{this.XmlConfig.Name}"); PublicClass._WriteLog(sbLog.ToString(), this.XmlConfig.Name); } } } }

BlogsObj02.cs:

using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using TaskCore.Plugin; namespace TaskCore.Test { // This project can output the Class library as a NuGet Package. // To enable this option, right-click on the project and select the Properties menu item. In the Build tab select "Produce outputs on build". public class BlogsObj02 : TPlugin { public BlogsObj02() { } public override void TPlugin_Load() { //Console.WriteLine($"这里是Blogs,获取配置文件:{this.XmlConfig.Name}"); PublicClass._WriteLog($"这里是BlogsObj02,获取配置文件:{this.XmlConfig.Name}", this.XmlConfig.Name); } } }

好了测试代码写完,咋们生成一下,然后把这个TaskCore.Test.dll拷贝到TaskCore.MainForm运行包中,还需要在PluginXml文件夹中分别创建继承TPlugin的子类的配置文件对应的截图如(注:这里xml配置文件名称必须和子类名称一样):

开源跨平台运行服务插件TaskCore.MainForm

配置文件内容如BlogsObj.xml:

<!-- 1.xml配置模板 2.utf-8文件 3.复制到程序根目录下面PluginXml文件夹下 4.每个任务建议创建和程序dll名称相同xml配置文件 --> <TaskMain> <!--固定:执行任务时间计时器(分钟)--> <Timer>1</Timer> <!--固定:任务名称--> <Name>获取博客信息</Name> <!--固定:账号--> <UserName></UserName> <!--固定:密码--> <UserPwd></UserPwd> <!--固定:key--> <ApiKey></ApiKey> <!--固定:key--> <ApiUrl></ApiUrl> <!--固定:是否关闭任务 1:是 0:否--> <CloseTask>0</CloseTask> <!--固定:描述--> <Des>获取博客信息</Des> <!--自定义:其他配置信息--> <Other> <ShenNiuBuXing3>神牛步行3</ShenNiuBuXing3> </Other> </TaskMain>

最后在CrossFiles.xml配置文件中添加TaskCore.Test.dll文件名称如:

<!-- CrossFiles指定对应任务的dll文件,必须存在的文件 --> <TaskMain> <File>TaskCore.Test.dll</File> </TaskMain>

好了完成了,我们在windows开发环境上运行看下效果图:

开源跨平台运行服务插件TaskCore.MainForm

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wdpdzy.html