现在的位置: 首页 > 综合 > 正文

在Sharepoint Designer 2007 中加入定制的工作流动作

2012年01月29日 ⁄ 综合 ⁄ 共 3401字 ⁄ 字号 评论关闭

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

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

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

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

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

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

using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Collections;
using System.Diagnostics;
using System.Drawing;
using System.Workflow.ComponentModel.Compiler;
using System.Workflow.ComponentModel.Serialization;
using System.Workflow.ComponentModel;
using System.Workflow.ComponentModel.Design;
using System.Workflow.Runtime;
using System.Workflow.Activities;
using System.Workflow.Activities.Rules;


namespace MyCustomActivity
{
  
public partial class EventLogger: Activity
  
{
    
public EventLogger()
    
{
      InitializeComponent();
    }


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

      
set
      
{
        
base.SetValue(EventLogger.MessageProperty, value);
      }

    }


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

        
catch
        
{
        }

      }

      
return ActivityExecutionStatus.Closed;
    }

  }

}


这个例子中的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>
(每一个节点的意思我就不翻译了,可以去查看原文,其实很简单,猜一下应该就知道了)
然后把这个文件复制到服务器(可以直接在WSS.ACTIONS中加入),再打开Sharepoint Designer的工作流设计窗口,就可以如下看到这个动作了:

[an error occurred while processing this directive]

抱歉!评论已关闭.