日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
詳解在Workflow工作流中如何使用角色

WF(Workflow)中提供來(lái)兩種方式:ActiveDirectoryRole(通過(guò)活動(dòng)目錄用戶)和WebWorkflowRole(ASP.NET Role)。下面舉例說(shuō)明:

1.我們使用HandleExternalEventActivity活動(dòng)來(lái)提供圖書檢索功能,當(dāng)有人檢索的時(shí)候會(huì)觸發(fā)檢索事件,只有會(huì)員才可以使用該功能。首先來(lái)定義事件參數(shù):

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Workflow.Activities; namespace CaryWFRole { [Serializable] public class BookEventArgs : ExternalDataEventArgs { public string ID { get; set; } public string Name { get; set; } public string Author { get; set; } public BookEventArgs() : base(Guid.NewGuid()) { } public BookEventArgs(Guid instanceID, string id, string name, string author) : base(instanceID) { this.ID = id; this.Name = name; this.Author = author; } } }

2.事件接口如下:

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Workflow.Activities; namespace CaryWFRole { [ExternalDataExchangeAttribute()] public interface ISearchBookService { event EventHandler SearchBook; } }

3.實(shí)現(xiàn)該接口,代碼如下:

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Security.Principal; namespace CaryWFRole { public class SearchBookService:ISearchBookService { public event EventHandler SearchBook; public void OnSearchRequest(Guid instanceId, string id,string name,string author, IIdentity identity) { BookEventArgs args = new BookEventArgs(instanceId, id, name, author); String securityIdentifier = null; WindowsIdentity windowsIdentity = identity as WindowsIdentity; if (windowsIdentity != null && windowsIdentity.User != null) securityIdentifier = windowsIdentity.User.Translate(typeof(NTAccount)).ToString(); else if (identity != null) securityIdentifier = identity.Name; args.Identity = securityIdentifier; Console.WriteLine("return book by: {0}", identity.Name); if (SearchBook != null) SearchBook(null, args); } } }

4.工作流設(shè)計(jì)如下:

通過(guò)設(shè)置檢索事件(HandleExternalEventActivity)活動(dòng)的的Roles屬性來(lái)控制,只有該角色集合的用戶才有權(quán)限。在工作流中我們只允許會(huì)員才可以做
檢索,代碼如下:

using System; using System.ComponentModel; using System.ComponentModel.Design; using System.Collections; using System.Drawing; using System.Linq; 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 CaryWFRole { public sealed partial class BookWorkflow : SequentialWorkflowActivity { public BookWorkflow() { InitializeComponent(); } private WorkflowRoleCollection sAllowRoles = new WorkflowRoleCollection(); public WorkflowRoleCollection AllowRoles { get { return sAllowRoles; } } private void codeActivity1_ExecuteCode(object sender, EventArgs e) { WebWorkflowRole role = new WebWorkflowRole("會(huì)員"); AllowRoles.Add(role); } private void handleExternalEventActivity1_Invoked(object sender, ExternalDataEventArgs e) { Console.WriteLine("查詢成功"); } } }

5.通過(guò)如下函數(shù)來(lái)創(chuàng)建角色和用戶,代碼如下:


static void CreateRoles() { if (!System.Web.Security.Roles.RoleExists("會(huì)員")) { System.Web.Security.Roles.CreateRole("會(huì)員"); string[] users = { "張三", "李四", "王五" }; string[] ClerkRole = { "會(huì)員" }; System.Web.Security.Roles.AddUsersToRoles(users, ClerkRole); } }

6.假設(shè)以張三的身份來(lái)檢索,觸發(fā)事件的函數(shù)如下:


static void SendSearchRequest() { try { string id = "001"; string name = "C#高級(jí)編程"; string author = "某某某"; GenericIdentity genIdentity = new GenericIdentity("張三"); sBook.OnSearchRequest(workflowInstanceId, id, name, author, genIdentity); } catch (Exception e) { Console.WriteLine("Exception message: {0}", e.ToString()); } }

7.宿主程序如下:

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; using System.Workflow.Runtime; using System.Workflow.Runtime.Hosting; using System.Security.Principal; using System.Workflow.Activities; namespace CaryWFRole { class Program { static SearchBookService sBook; static Guid workflowInstanceId; static AutoResetEvent waitHandle = new AutoResetEvent(false); static void Main() { CreateRoles(); using (WorkflowRuntime workflowRuntime = new WorkflowRuntime()) { workflowRuntime.StartRuntime(); Type type = typeof(BookWorkflow); ExternalDataExchangeService dataService = new ExternalDataExchangeService(); workflowRuntime.AddService(dataService); sBook = new SearchBookService(); dataService.AddService(sBook); workflowRuntime.WorkflowCompleted += OnWorkflowCompleted; workflowRuntime.WorkflowTerminated += OnWorkflowTerminated; WorkflowInstance instance = workflowRuntime.CreateWorkflow(type); workflowInstanceId = instance.InstanceId; instance.Start(); SendSearchRequest(); waitHandle.WaitOne(); workflowRuntime.StopRuntime(); } } static void OnWorkflowCompleted(object sender, WorkflowCompletedEventArgs e) { waitHandle.Set(); } static void OnWorkflowTerminated(object sender, WorkflowTerminatedEventArgs e) { Console.WriteLine(e.Exception.Message); waitHandle.Set(); } } }

8.我們要配置aspnetdb數(shù)據(jù)庫(kù),app.config如下:



   
       
   

   
       
           
               
           

       

   

9.執(zhí)行結(jié)果如下:


【編輯推薦】

  1. 詳解工作流架構(gòu)與實(shí)現(xiàn)
  2. 協(xié)同軟件:對(duì)工作流的幾點(diǎn)謬誤的解析
  3. 面向構(gòu)件的中間件:超越工作流管理

文章題目:詳解在Workflow工作流中如何使用角色
本文URL:http://m.5511xx.com/article/cdghiph.html