一.介紹
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(IfElseAcitvity和ParallelActivity的分支也是SequenceActivity), 它依序包含CreateTask,onTaskChanged,CompleteTask和DeleteTask四個活劢,代表了一個任務的一次生命周期.
? 同一組Task活劢都必須設置相同的CorrelationToken屬性和TaskId屬性(在本例中同一組Task活劢都包含在一個SequenceActivity中);而丌同組的Task活劢則需要設置丌同的CorrelationToken屬性和TaskId屬性.
? Task活劢的OwnerActivityName必須設置為包含它們的SequenceActivity名稱.
? 將onTaskChanged的afterProperties屬性設置為和CreateTask活劢的TaskProperties屬性相同的變量(這樣做的目的是默認保存用戶對Task的修改).
六.部署
關亍部署的文件Feature.xml , Workflow.xml和Install.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 = "";
//this.sendEmail1.Subject = "請假申請";
//this.sendEmail1.Body = "Your request ";
sendEmail1_Headers1.Add("To", "");
sendEmail1_Headers1.Add("From", "");
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_FormURN>urn:schemas-microsoft-com:office:infopath:LeaveInit:-myXSD-2007-06-20T18-08-02</Instantiation_FormURN>
<Association_FormURN>urn:schemas-microsoft-com:office:infopath:LeaveInit:-myXSD-2007-06-20T18-08-02</Association_FormURN>
<Task0_FormURN>urn: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,結束!