Page tree
Skip to end of metadata
Go to start of metadata

1.描述

以创建服务端MyServerCommand插件为例,介绍如何创建服务端命令插件。

查看完整代码请参见:https://gitee.com/huozige-china/my-server-command

2.创建服务端命令插件

操作步骤

  下载PluginsProjectCreator.zip,解压后运行ForguncyPluginCreator.exe,在弹出的对话框中,输入您的插件名称,选择插件类型为命令,并设置插件输出的路径。

设置完成后,单击“OK”。

  打开您创建的插件所在的文件夹,使用Visual Studio打开.csproj文件。

  在解决方案资源管理器中将Forguncy.Commands和Forguncy.PluginCommon移除掉。

  在解决方案资源管理器中,“引用”上右击,选择添加引用。

  在右下角单击“浏览”,选择活字格安装文件所在的bin文件夹,如果是默认安装,则路径为"C:\Program Files (x86)\Forguncy 6\Website\designerBin",找到以下五个文件,将其添加到解决方案资源管理器中。

  • Forguncy.Commands.dll
  • Forguncy.Commands.Design.dll
  • GrapeCity.Forguncy.Plugin.dll
  • GrapeCity.Forguncy.Plugin.Design.dll
  • GrapeCity.Forguncy.ServerApi.dll

并且将这些文件的属性中的“复制本地”设置为“False”。

  在MyServerCommand.cs文件中添加代码,需要实现 ICommandExecutableInServerSide 接口。

[Icon("pack://application:,,,/MyServerCommand;component/Resources/Icon.png")]
public class MyServerCommand : Command, ICommandExecutableInServerSide
{
	public ExecuteResult Execute(IServerCommandExecuteContext dataContext)
	{
		//Do some thing
		return new ExecuteResult();
	}
}
说明

生成新参数

如果服务端命令生成了新的参数,需要将新的值赋给新的参数,并实现 IServerCommandParamGenerator 接口告诉服务端命令新增加的参数名称。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

[Icon("pack://application:,,,/MyServerCommand;component/Resources/Icon.png")]
public class MyServerCommand : Command, ICommandExecutableInServerSide, IServerCommandParamGenerator
{
    public string NewParameter { get; set; }
    public ExecuteResult Execute(IServerCommandExecuteContext dataContext)
    {
         //Do some thing
         dataContext.Parameters[NewParameter] = newValue;
         return new ExecuteResult();
    }
    public IEnumerable<GenerateParam> GetGenerateParams()
    {
        yield return new GenerateNormalParam()
        {
            ParamName = NewParameter,
        };
    }
}



  您可以自定义插件图标、logo、介绍等信息。编辑完成后,在插件名称上右击,选择“生成”或者“重新生成”。完成后重启活字格设计器,新建的插件就会安装到活字格设计器中。

在设计器中,创建一个服务端命令,编辑命令时就可以选择刚才创建的MyServerCommand服务端命令插件。


回到顶部

  • No labels

1 Comment

  1. Anonymous

    newValue报错。。没有定义。。。