QuickFlow之任务代理-TaskDelegation
1)概述
QuickFlow最新版本增加了任務代理功能。
所謂代理,指的是用戶可以事先配置其他用戶在指定的時間段來代替自己處理所有任務。
QuickFlow默認的代理配置采用一個列表實現,樣式如下:
2)如何啟用代理
默認情況下,代理沒有啟用,若要啟用代理,首先建立一個如上圖所示的列表,列表名QuickFlowDelegation,字段:
DelegatedUser,用戶類型,不能為空;
DelegateUser,用戶類型,不能為空;
BeginTime,時間類型,可以為空;
EndTime,時間類型,可以為空;
Enabled,bool類型,不能為空;
如果是英文站點,QuickFlow的安裝包內有個列表模板文件QuickFlowDelegationListEng.stp,可以將這個文件上傳到列表模板庫,然后基于這個模板創建列表。
創建好列表后,打開C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\TEMPLATE\LAYOUTS\QuickFlow目錄的global.config文件。將TaskDelegationProvider的注釋取消,如下:
<?xml version="1.0" encoding="utf-8"?> <GlobalConfiguration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><CustomRoleUserProvider>QuickFlow.Core.SPRoleUserProvider,QuickFlow, Version=1.0.0.0, Culture=neutral, PublicKeyToken=ec1e0fe6e1745628</CustomRoleUserProvider><TaskDelegationProvider>QuickFlow.Core.DefaultTaskDelegationProvider,QuickFlow, Version=1.0.0.0, Culture=neutral, PublicKeyToken=ec1e0fe6e1745628</TaskDelegationProvider><!--if DelegationListSiteUrl is empty, system will use current site--><!--<DelegationListSiteUrl>http://codeartserver:81/sites/s1</DelegationListSiteUrl>--><DelegationListUrl>Lists/QuickFlowDelegation</DelegationListUrl><EventReceivers><Receiver Enabled="false" Name="Exception" Type="QuickFlow.EventBus.ExceptionEventReceiver,QuickFlow, Version=1.0.0.0, Culture=neutral, PublicKeyToken=ec1e0fe6e1745628" /><Receiver Enabled="true" Name="Tracing" Type="QuickFlow.EventBus.TracingEventReceiver,QuickFlow, Version=1.0.0.0, Culture=neutral, PublicKeyToken=ec1e0fe6e1745628" /></EventReceivers> </GlobalConfiguration>然后重啟iis,代理功能就啟用了。
如果已經部署了QuickFlow,安裝最新版本wsp后,需要重新激活QuickFlow Feature。
啟用代理后,在代理有效期內,發給被代理人的任務都會自動分配給代理人,但是被代理人依然具有操作任務的權限。在QF最新的默認任務頁面上,系統的WorkflowHisboty控件也會顯示代理情況:
3)代理配置的擴展和自定義
如果你要實現自己的代理配置邏輯,可以自己實現一個類,實現ITaskDelegationProvider接口,部署到GAC,然后修改配置即可。
自己實現代理邏輯,可以參考系統默認實現的代碼:
public class DefaultTaskDelegationProvider : ITaskDelegationProvider{//public const string ListUrl = "Lists/QuickFlowDelegation";static LookupQueryField fieldDelegatedUser = new LookupQueryField("DelegatedUser");static TypedQueryField<DateTime> fieldBeginTime = new TypedQueryField<DateTime>("BeginTime");static TypedQueryField<DateTime> fieldEndTime = new TypedQueryField<DateTime>("EndTime");static QueryField fieldEnabled = new QueryField("Enabled");DateTime GetDate(string date){if (String.IsNullOrEmpty(date))return DateTime.MinValue;elsereturn Convert.ToDateTime(date);}#region ITasDelegateProvider Memberspublic TaskDelegate GetTaskDelegate(SPWorkflowActivationProperties prop, string delegatedUser){var siteUrl = GlobalConfiguration.GetInstance().DelegationListSiteUrl;if (siteUrl == null || String.IsNullOrEmpty(siteUrl.Value)){return this.GetTaskDeletate(prop.Web, delegatedUser);}else{using (SPSite site = new SPSite(siteUrl.Value)){using (SPWeb web2 = site.OpenWeb()){return this.GetTaskDeletate(web2, delegatedUser);}}}} public TaskDelegate GetTaskDeletate(SPWeb web, string delegatedUser){string fullUrl = web.Site.ServerRelativeUrl.TrimEnd('/') + "/" + GlobalConfiguration.GetInstance().DelegationListUrl.Value;SPList list = null;try{list = web.GetList(fullUrl);}catch(Exception ex){throw new Exception("can't find the delegate confit list:" + fullUrl);}SPUser user = web.AllUsers[delegatedUser];if (user == null){throw new Exception("user doen't exist in the web: " + delegatedUser);}var now = DateTime.Now;var items = ListQuery.Select(1).From(list).Where(fieldDelegatedUser == user.ID &&(fieldBeginTime.IsNull || fieldBeginTime <= now) &&(fieldEndTime.IsNull || fieldEndTime > now.AddDays(-1)) &&(fieldEnabled == 1)).GetItems();if (items == null || items.Count == 0){return null;}var item = items[0];SPFieldUserValue userValue = item.Fields.GetField("DelegateUser").GetFieldValue(item["DelegateUser"].ToString()) as SPFieldUserValue;var del = new TaskDelegate();del.DelegateUser = userValue.User.LoginName;del.BeginTime = this.GetDate("" + item["BeginTime"]);del.EndTime = this.GetDate("" + item["EndTime"]);return del;}#endregion}注:本文所述功能,需要QuickFlow.wsp(Build101031)之后版本支持。
總結
以上是生活随笔為你收集整理的QuickFlow之任务代理-TaskDelegation的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Seam开发环境的搭建
- 下一篇: Silverlight撤消重做功能的实现