在Sharepoint Designer 2007 中加入定制的工作流动作(翻译)

原文参见:http://johnholliday.net/archive/2007/03/27/Add-Your-Own-Custom-Workflow-Activities-to-SharePoint-Designer-2007.aspx

如果使用Sharepoint Designer 2007在Sharepoint列表中创建定制的工作流,会发现它是一个强大的工具。使用内嵌的工作流设计器,不写一行代码就可以创建一个还可以的工作流。使用这个工具可以简单的就像在Outlook中创建一个规则一样创建一个工作流。

在Sharepoint Designer 2007中有很多自带的工作流的动作,可以创建、修改列表,发送邮件,创建栏等等。但是如果想做其它的一些操作,怎么办呢? 比如和后台通讯,或者是执行一些高度定制的操作,怎么办呢?

那么你可以扩展Sharepoint Designer 2007, 你可以在设计器中直接引用你定制的动作。开发人员可以关注于建立一个工作流动作的库,业务分析员或管理员可以专注于在更高的层次上来使用它完成实际的工作。

WSS.ACTIONS
完成这个工作主要依靠Sharepoint Server中的一个文件WSS.ACTIONS,这个文件在目录12\TEMPLATE\1033\Workflow(中文是2052) 下。当在Sharepoint Designer中打开或者创建一个工作流的时候,都会首先打开并读取这个文件中的配置信息。这个文件声明了一些可以使用的工作流,以及展现规则,条件,特殊动作等详细信息。通过修改这个文件,可以在Sharepoint Designer中展现不同的工作流、动作。

在Sharepoint Designer中加入一个简单的动作的步骤如下:
1、 创建一个定制的动作
2、 签名、把这个dll加载到GAC中
3、 配置Sharepoint使他识别这个定制的动作
4、 建立一个.ACTIONS文件给Sharepoint Designer使用

创建一个定制的动作:
这个例子就是演示在系统日志中写入一条信息

None.gif using  System;
None.gif
using  System.ComponentModel;
None.gif
using  System.ComponentModel.Design;
None.gif
using  System.Collections;
None.gif
using  System.Diagnostics;
None.gif
using  System.Drawing;
None.gif
using  System.Workflow.ComponentModel.Compiler;
None.gif
using  System.Workflow.ComponentModel.Serialization;
None.gif
using  System.Workflow.ComponentModel;
None.gif
using  System.Workflow.ComponentModel.Design;
None.gif
using  System.Workflow.Runtime;
None.gif
using  System.Workflow.Activities;
None.gif
using  System.Workflow.Activities.Rules;
None.gif
None.gif
None.gif
namespace  MyCustomActivity
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif  
public partial class EventLogger: Activity
ExpandedSubBlockStart.gifContractedSubBlock.gif  
dot.gif{
InBlock.gif    
public EventLogger()
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif      InitializeComponent();
ExpandedSubBlockEnd.gif    }

InBlock.gif
InBlock.gif    
public static DependencyProperty MessageProperty
InBlock.gif      
= System.Workflow.ComponentModel.DependencyProperty.Register(
InBlock.gif      
"Message"typeof(string), typeof(EventLogger));
InBlock.gif    [Category(
"MyCustomActivity"), Browsable(true)]
InBlock.gif    [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
InBlock.gif    
public string Message
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif      
get
ExpandedSubBlockStart.gifContractedSubBlock.gif      
dot.gif{
InBlock.gif        
return ((string)(base.GetValue(EventLogger.MessageProperty)));
ExpandedSubBlockEnd.gif      }

InBlock.gif      
set
ExpandedSubBlockStart.gifContractedSubBlock.gif      
dot.gif{
InBlock.gif        
base.SetValue(EventLogger.MessageProperty, value);
ExpandedSubBlockEnd.gif      }

ExpandedSubBlockEnd.gif    }

InBlock.gif
InBlock.gif    
protected override ActivityExecutionStatus
InBlock.gif      Execute(ActivityExecutionContext executionContext)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif      
using (EventLog log = new EventLog("MyCustomActivity"))
ExpandedSubBlockStart.gifContractedSubBlock.gif      
dot.gif{
InBlock.gif        
try
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif          log.Source 
= "EventLogger Activity";
InBlock.gif          log.WriteEntry(
this.Message, EventLogEntryType.Information);
ExpandedSubBlockEnd.gif        }

InBlock.gif        
catch
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif      }

InBlock.gif      
return ActivityExecutionStatus.Closed;
ExpandedSubBlockEnd.gif    }

ExpandedSubBlockEnd.gif  }

ExpandedBlockEnd.gif}

None.gif
None.gif

这个例子中的Message我们可以在Sharepoint中给它赋值

注册这个动作
首先给这个库加入签名(在解决方案的工程上右键-)属性-〉签名),在把它复制到GAC中(类似于配置一个WebParts)
在Sharepoint网站的Web.config中加入如下节点:
<authorizedType Assembly="JohnHolliday.Workflow.EventLoggerActivity, Version=1.0.0.0,
      Culture=neutral, PublicKeyToken=0b97b340d4a71524"
      Namespace="MyCustomActivity" TypeName="*" Authorized="True" />

创建.ACTIONS文件
最后的步骤就是创建一个.ACTIONS文件。这是一个XML文件,你可以使用VS2005或其它XML编辑器。
以下是一个.ACTIONS文件的示例
<?xml version="1.0" encoding="utf-8" ?>
<WorkflowInfo>
<Actions Sequential="then" Parallel="and">
   <Action Name="Write Message To Event Log"
      ClassName="JohnHolliday.Workflow.EventLogger"
 Assembly="JohnHolliday.Workflow.EventLoggerActivity, Version=1.0.0.0, Culture=neutral, PublicKeyToken=0b97b340d4a71524"
      AppliesTo="all" Category="MyCustomActivities">
   <RuleDesigner Sentence="Write '%1' to the event log">
      <FieldBind Field="Message" DesignerType="TextArea" Id="1"/>
   </RuleDesigner>
   <Parameters>
      <Parameter Name="Message" Type="System.String, mscorlib" Direction="In"/>
   </Parameters>
</Action>
</Actions>
</WorkflowInfo>
(每一个节点的意思我就不翻译了emsmile.gif,可以去查看原文,其实很简单,猜一下应该就知道了)
然后把这个文件复制到服务器(可以直接在WSS.ACTIONS中加入),再打开Sharepoint Designer的工作流设计窗口,就可以如下看到这个动作了:

转载于:https://www.cnblogs.com/firstyi/archive/2007/04/20/721340.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值