MOSS工作流开发+ Email提醒

MOSS工作流,其实也很简单。并不象大家想象的那样的复杂!

   

.介绍

MOSS开发工作六

.开収环境&准备工作

? SharePoint Server 2007

? Visual Studio 2005

? .NET Framework 3.0

? Visual Studio 2005 Extensions for Windows Workflow Foundation

? ECM Starter Kit for Visual Studio 2005

   

工作流中只有一个onWorkflowActivated活劢,所有SharePoint工作流都必须从这个活劢开始.

onWorkflowActivated活劢有一些属性值得我们注意:

   

? CorrelationToken : Correlation Token 是将若干相关联的活劢映射到同一集合的标识符,其作用不某些编程语言中RadioButtion组件的GroupId属性类似,注意丌要为任务活劢和工作流活劢指定相同的CorrelationToken.

   

每一个Task都是一个SequenceActivity(IfElseAcitvityParallelActivity的分支也是SequenceActivity), 它依序包含CreateTask,onTaskChanged,CompleteTaskDeleteTask四个活劢,代表了一个任务的一次生命周期.

? 同一组Task活劢都必须设置相同的CorrelationToken属性和TaskId属性(在本例中同一组Task活劢都包含在一个SequenceActivity);而丌同组的Task活劢则需要设置丌同的CorrelationToken属性和TaskId属性.

? Task活劢的OwnerActivityName必须设置为包含它们的SequenceActivity名称.

? onTaskChangedafterProperties属性设置为和CreateTask活劢的TaskProperties属性相同的变量(这样做的目的是默认保存用户对Task的修改).

.部署

关亍部署的文件Feature.xml , Workflow.xmlInstall.bat.

6.1 强签名

因为工作流的程序集需要部署到GAC,所以我们需要为程序集生成一个强签名.

   

? 拷贝并注册工作流表单.

? 将程序集添加到GAC.

? 安装并激活工作流feature

大家明白上面的理论知识拉,现在开始开工 ,我也不在这里废话拉,

首先跟大家讲讲我这个工作流的流程-〉首先用户提交申请,然后流程启动-〉发送EMAIL-〉通知审批人-〉审批人审批通过-〉然后-〉提交到人事部门list,等待以后察看,流程结束。

   

工作流的后台代码

using System;

using System.ComponentModel;

using System.ComponentModel.Design;

using System.Collections;

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;

using System.Xml.Serialization;

using System.Xml;

using Microsoft.SharePoint;

using Microsoft.SharePoint.WorkflowActions;

   

namespace LeaveWorkFlow

{

public sealed partial class Workflow1: SequentialWorkflowActivity

{

public Workflow1()

{

InitializeComponent();

}

public Guid workflowId = default(System.Guid);

public Microsoft.SharePoint.Workflow.SPWorkflowActivationProperties workflowProperties = new Microsoft.SharePoint.Workflow.SPWorkflowActivationProperties();

public Guid TaskId = default(System.Guid);

public Microsoft.SharePoint.Workflow.SPWorkflowTaskProperties taskProperties = new Microsoft.SharePoint.Workflow.SPWorkflowTaskProperties();

public Microsoft.SharePoint.Workflow.SPWorkflowTaskProperties beforeProperties = new Microsoft.SharePoint.Workflow.SPWorkflowTaskProperties();

public Microsoft.SharePoint.Workflow.SPWorkflowTaskProperties afterProperties = new Microsoft.SharePoint.Workflow.SPWorkflowTaskProperties();

private string assignto = default(System.String);

private string Comment = default(System.String);

private int currentreviewer = 0;

private string itemtitle = default(System.String);

private string itemContent = default(System.String);

private bool isFinished = false;

   

private void onWorkflowActivated1_Invoked(object sender, ExternalDataEventArgs e)

{

itemtitle = workflowProperties.Item.DisplayName;

this.isFinished = false;

this.workflowId = workflowProperties.WorkflowId;

//XmlSerializer myserializer = new XmlSerializer(typeof(myFields));

//XmlTextReader reader = new XmlTextReader(new System.IO.StringReader(workflowProperties.InitiationData));

//myFields myinitf = (myFields)myserializer.Deserialize(reader);

//assignto = myinitf.ApproveUser;

assignto = "LHVM\\Administrator";

Comment =" myinitf.Comment";

   

}

private void wordflownotFinished(object sender, ConditionalEventArgs e)

{

if (this.assignto.Split(Convert.ToChar(";")).Length currentreviewer + 1)

{

e.Result = false;

}

else

{

e.Result = true;

}

}

private void taskNotFinished(object sender, ConditionalEventArgs e)

{

if (taskProperties.Title == itemtitle + "拒绝!")

{

this.isFinished = true;

}

e.Result = !isFinished;

}

private void onTaskChanged1_Invoked(object sender, ExternalDataEventArgs e)

{

this.isFinished = bool.Parse(afterProperties.ExtendedProperties["isFinished"].ToString());

if (isFinished)

{

this.Comment = afterProperties.ExtendedProperties["Conceit"].ToString();

   

}

else

{

taskProperties.Title = itemtitle + "拒绝!";

this.isFinished = true;

}

}

private void createTask1_MethodInvoking(object sender, EventArgs e)

{

TaskId = Guid.NewGuid();

taskProperties.Title = "Please Review Say:" + itemtitle;

taskProperties.AssignedTo = this.assignto.Split(Convert.ToChar(";"))[this.currentreviewer].ToString();

taskProperties.Description = this.Comment;

taskProperties.ExtendedProperties["Comment"] = this.Comment;

}

private void completeTask1_MethodInvoking(object sender, EventArgs e)

{

this.currentreviewer++;

}

private void sendEmail1_MethodInvoking(object sender, EventArgs e)

{

//this.sendEmail1.To = this.workflowProperties.OriginatorEmail;

//this.sendEmail1.To = "wanghao-3@tom.com";

//this.sendEmail1.Subject = "请假申请";

//this.sendEmail1.Body = "Your request ";

sendEmail1_Headers1.Add("To", "wanghao-3@tom.com");

sendEmail1_Headers1.Add("From", "wanghao-3@tom.com");

sendEmail1_Headers1.Add("Subject", "WorkFlow VS 2005");

sendEmail1_Body1 = "aa programado " + workflowProperties.Item.DisplayName;

   

// this.sendEmail1.

}

public String sendEmail1_From1 = default(System.String);

public String sendEmail1_Body1 = default(System.String);

public String sendEmail1_CC1 = default(System.String);

public System.Collections.Specialized.StringDictionary sendEmail1_Headers1 = new System.Collections.Specialized.StringDictionary();

public String sendEmail1_Subject1 = default(System.String);

public String sendEmail1_To1 = default(System.String);

private void codeActivity1_ExecuteCode(object sender, EventArgs e)

{

   

SPSite site = new SPSite(@"http://lh-vmpc/personal/test/workflow");

SPWeb web = site.OpenWeb();

web.AllowUnsafeUpdates = true;

SPList list = web.Lists["WorkFlow"];

SPListItem item = list.Items.Add();

item["标题"] = this.itemtitle;

item["请假内容"] = "Content"+this.itemContent;

item["请假人"] = "lhvm\administrator"+workflowProperties.Web.CurrentUser.Name;

item["请假时间"] = "1";

item.Update();

}

}

}

   

feature.xml

?xml version="1.0" encoding="utf-8"?

!-- _lcid="1033" _version="12.0.3111" _dal="1" --

!-- _LocalBinding --

!-- Insert Feature.xml Code Snippet here. To do this:

1) Right click on this page and select "Insert Snippet" (or press Ctrl+K, then X)

2) Select Snippets-Windows SharePoint Services Workflow-Feature.xml Code --

Feature Id="{79f5f0c4-3b4e-4a32-addf-9d59b33147dc}"

Title="AA LeaveWorkFlow"

Description="AA LeaveWordFlow."

Version="12.0.0.0"

Scope="Site"

ReceiverAssembly="Microsoft.Office.Workflow.Feature, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"

ReceiverClass="Microsoft.Office.Workflow.Feature.WorkflowFeatureReceiver"

xmlns="http://schemas.microsoft.com/sharepoint/"

ElementManifests

ElementManifest Location="workflow.xml" /

/ElementManifests

Properties

Property Key="GloballyAvailable" Value="true" /

!-- Value for RegisterForms key indicates the path to the forms relative to feature file location --

!-- if you don't have forms, use *.xsn --

Property Key="RegisterForms" Value="*.xsn" /

/Properties

/Feature

workflow.xml

?xml version="1.0" encoding="utf-8" ?

!-- _lcid="1033" _version="12.0.3015" _dal="1" --

!-- _LocalBinding --

!-- Insert Workflow.xml Code Snippet here. To do this:

1) Right click on this page and select "Insert Snippet" (or press Ctrl+K, then X)

2) Select Snippets-Windows SharePoint Services Workflow-Workflow.xml Code --

Elements xmlns="http://schemas.microsoft.com/sharepoint/"

Workflow

Name="LeaveWorkFlow Show"

Description="this is LeaveWorkFlow"

Id="{44fb0f07-5c96-48ab-8d12-1f99d31620ba}"

CodeBesideClass="LeaveWorkFlow.Workflow1"

CodeBesideAssembly="LeaveWorkFlow, Version=1.0.0.0, Culture=neutral, PublicKeyToken=e106055d8d054c38"

TaskListContentTypeId="0x01080100C9C9515DE4E24001905074F980F93160"

InstantiationUrl="_layouts/IniWrkflIP.aspx"

ModificationUrl="_layouts/ModWrkflIP.aspx"

Categories/

!-- Tags to specify InfoPath forms for the workflow; delete tags for forms that you do not have --

MetaData

Instantiation_FormURNurn:schemas-microsoft-com:office:infopath:LeaveInit:-myXSD-2007-06-20T18-08-02/Instantiation_FormURN

Association_FormURNurn:schemas-microsoft-com:office:infopath:LeaveInit:-myXSD-2007-06-20T18-08-02/Association_FormURN

Task0_FormURNurn:schemas-microsoft-com:office:infopath:LeaveTaskEdit:-myXSD-2007-06-21T01-20-17/Task0_FormURN

StatusPageUrl_layouts/WrkStat.aspx/StatusPageUrl

/MetaData

/Workflow

/Elements

Install.bat

   

:: Before running this file, sign the assembly in Project properties

::

:: To customize this file, find and replace

:: a) "LeaveWorkFlow" with your own feature names

:: b) "feature.xml" with the name of your feature.xml file

:: c) "workflow.xml" with the name of your workflow.xml file

:: d) "http://lh-vmpc/personal/test" with the name of the site you wish to publish to

echo Copying the feature...

rd /s /q "%CommonProgramFiles%\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES\LeaveWorkFlow"

mkdir "%CommonProgramFiles%\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES\LeaveWorkFlow"

copy /Y feature.xml "%CommonProgramFiles%\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES\LeaveWorkFlow\"

copy /Y workflow.xml "%CommonProgramFiles%\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES\LeaveWorkFlow\"

xcopy /s /Y *.xsn "%programfiles%\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES\LeaveWorkFlow\"

   

echo Adding assemblies to the GAC...

"%programfiles%\Microsoft Visual Studio 8\SDK\v2.0\Bin\gacutil.exe" -uf LeaveWorkFlow

"%programfiles%\Microsoft Visual Studio 8\SDK\v2.0\Bin\gacutil.exe" -if bin\Debug\LeaveWorkFlow.dll

:: Note: 64-bit alternative to lines above; uncomment these to install on a 64-bit machine

::"%programfiles% (x86)\Microsoft Visual Studio 8\SDK\v2.0\Bin\gacutil.exe" -uf LeaveWorkFlow

::"%programfiles% (x86)\Microsoft Visual Studio 8\SDK\v2.0\Bin\gacutil.exe" -if bin\Debug\LeaveWorkFlow.dll

echo Verifying InfoPath Forms...

::Note: Verify InfoPath forms; copy line for each form

::"%programfiles%\common files\microsoft shared\web server extensions\12\bin\stsadm" -o verifyformtemplate -filename [IP_FORM_FILENAME]

   

echo Activating the feature...

pushd %programfiles%\common files\microsoft shared\web server extensions\12\bin

::Note: Uncomment these lines if you've modified your deployment xml files or IP forms

::stsadm -o deactivatefeature -filename LeaveWorkFlow\feature.xml -url http://lh-vmpc/personal/test

::stsadm -o uninstallfeature -filename LeaveWorkFlow\feature.xml

stsadm -o installfeature -filename LeaveWorkFlow\feature.xml -force

stsadm -o activatefeature -filename LeaveWorkFlow\feature.xml -url http://lh-vmpc/personal/test

   

echo Doing an iisreset...

popd

iisreset

编译,把DLL放入GAC

程序全部设计开发完成后。直接运行bat文件就OK,结束!

   

本文来自于BlogJava 作者:wanghao

http://www.cnblogs.com/wanghao-3/archive/2007/06/26/795844.html

转载于:https://www.cnblogs.com/gill/archive/2010/05/27/1745225.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值