成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

詳解在Workflow工作流中如何使用角色

開發 后端
WF提供了一種用于對所有支持數據輸入的活動的、基于角色的訪問機制。工作流創建者可以完全控制如何創建角色和角色集合。這樣將使創建者能夠提供必要的授權機制,在執行活動之前驗證調用者的角色。

WF(Workflow)中提供來兩種方式:ActiveDirectoryRole(通過活動目錄用戶)和WebWorkflowRole(ASP.NET Role)。下面舉例說明:

1.我們使用HandleExternalEventActivity活動來提供圖書檢索功能,當有人檢索的時候會觸發檢索事件,只有會員才可以使用該功能。首先來定義事件參數:

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.實現該接口,代碼如下:

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.工作流設計如下:

image

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

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("會員"); AllowRoles.Add(role); } private void handleExternalEventActivity1_Invoked(object sender, ExternalDataEventArgs e) { Console.WriteLine("查詢成功"); } } }

5.通過如下函數來創建角色和用戶,代碼如下:


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

6.假設以張三的身份來檢索,觸發事件的函數如下:


static void SendSearchRequest() { try { string id = "001"; string name = "C#高級編程"; 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數據庫,app.config如下:

<?xml version="1.0" encoding="utf-8" ?>
<CONFIGURATION>
    <CONNECTIONSTRINGS>
        <ADD name="SqlServerConnection" connectionString="Integrated Security = SSPI;server=.;database=aspnetdb" />
    </CONNECTIONSTRINGS>
    <SYSTEM.WEB>
        <ROLEMANAGER defaultProvider="SqlProvider" enabled="true">
            <PROVIDERS>
                <ADD name="SqlProvider" type="System.Web.Security.SqlRoleProvider, &#13;&#10;                System.Web, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" applicationName="ConsoleAppSample" connectionStringName="SqlServerConnection" />
            </PROVIDERS>
        </ROLEMANAGER>
    </SYSTEM.WEB>
</CONFIGURATION>

9.執行結果如下:

image


【編輯推薦】

  1. 詳解工作流架構與實現
  2. 協同軟件:對工作流的幾點謬誤的解析
  3. 面向構件的中間件:超越工作流管理
責任編輯:彭凡 來源: cnblogs
相關推薦

2021-10-14 11:34:05

技術工作流引擎

2009-11-18 09:14:49

Visual Stud

2011-02-21 13:21:20

.NET Workfl

2009-03-03 09:13:36

工作流BPM業務流程

2024-04-25 08:00:00

DevOps架構軟件開發

2024-08-05 12:46:51

2010-01-14 09:35:10

WF4.0

2013-09-29 17:13:59

PowerShell工作流

2022-10-26 08:00:43

Activiti工作流BPM

2025-05-14 03:20:00

AgenticAIMCP

2021-03-12 06:44:09

Argo Workfl開源項目

2010-11-26 10:59:28

SharePoint

2009-06-11 14:43:34

jbpm工作流引擎jBPM搭建

2013-04-23 10:28:08

IBeamMDAAWF

2022-07-14 10:06:20

工作流引擎營銷自動化vivo

2009-03-27 09:48:56

SnapFlowWaaS工作流

2022-07-10 21:17:01

GitTigLinux

2018-06-04 17:56:58

開發者故事

2011-09-20 09:41:29

.NET 4.5

2010-05-28 15:16:33

SharePoint 工作流
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 亚洲免费在线视频 | 欧美一区二区三区在线视频 | 人妖一区 | 亚洲一区影院 | 噜噜噜色网 | 国产一区www | 精品福利在线 | 国产精品久久久久免费 | 97色在线观看免费视频 | 欧美一区二区免费在线 | 一二三四在线视频观看社区 | 日韩高清一区 | 国产视频久久久 | 蜜桃免费一区二区三区 | 精品久久久久久久久久久久 | 欧美在线视频一区二区 | 欧美亚洲激情 | 亚洲欧美在线观看视频 | 91免费视频 | yeyeav| 欧美国产视频 | 丁香综合 | 日韩成人精品一区 | 日韩欧美中文 | 91免费在线| 精品久久久久久久久久久院品网 | 九九99精品 | 91精品国产日韩91久久久久久 | 亚洲+变态+欧美+另类+精品 | 成人免费视频在线观看 | 欧美video | 成人免费激情视频 | 一区二区日韩 | 亚洲欧洲一区二区 | 欧美激情一区二区三区 | 国产日韩久久久久69影院 | 国产一级片| 嫩草黄色影院 | 欧美日韩一区精品 | 国产精品久久久久久久久久东京 | 亚洲狠狠丁香婷婷综合久久久 |