您的位置:软件首页 / 应用程序 / 在Sharepoint Designer 2007 中加入定制的工作流动作

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

ZDNet 软件频道 更新时间:2007-11-04 作者: 来源:cnblogs

本文关键词:应用 技术 工作流 SharePoint

如果使用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]
技术关注
当前技术类目:
协作办公本类技术关注比例:
2软件关注排行:2--
3企业级技术关注度:3--

协作办公技术相关文章:

文章类型收录数量
94 协作办公的解决方案:
91 协作办公的成功案例:
40 协作办公的相关产品:

软件频道 应用 最新报道

软件频道 技术 最新报道

软件频道 工作流 最新报道

软件频道 SharePoint 最新报道

爱卡汽车网 | CNET科技资讯网 | CWEEK | 蜂鸟网 | GameSpot China | 个人电脑 | 开发者在线 | PChome | Solidot | SPN |
投影顾问网 | 万维家电网 | 网友世界 | 西域IT | ZDNet China | 中关村在线 | 中小企业成长网
CNET Networks
Copyright © 1997-2007 CNET Networks 版权所有。 ZDNet 是CNET Networks公司注册服务商标。
中华人民共和国电信与信息服务业务经营许可证编号:京ICP证010391号