在Workflow工作流中怎么使用角色
发表于:2024-10-26 作者:千家信息网编辑
千家信息网最后更新 2024年10月26日,这篇文章主要介绍在Workflow工作流中怎么使用角色,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!WF(Workflow)中提供来两种方式:ActiveDirectoryRo
千家信息网最后更新 2024年10月26日在Workflow工作流中怎么使用角色
这篇文章主要介绍在Workflow工作流中怎么使用角色,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!
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 EventHandlerSearchBook; }}
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 EventHandlerSearchBook; 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.工作流设计如下:
通过设置检索事件(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如下:
以上是"在Workflow工作流中怎么使用角色"这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注行业资讯频道!
会员
检索
事件
工作流
角色
工作
代码
用户
张三
活动
内容
函数
功能
只有
接口
篇文章
高级
成功
价值
兴趣
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
互联网网络技术专业介绍
服务器桌面不显示驱动
服务器硬盘与普通硬盘区别
网络安全高级工程师证书
苏宁易购软件开发招聘信息
如何将文件通过kvm传给服务器
深圳益城软件开发公司吗
云软件开发咨询
杭州蓝翔网络技术有限公司
张店模具软件开发定制
金算盘数据库表结构
软件开发都有什么平台
系统网络技术部职能
国外数据库logo
网络安全产业环境
西安蓝牙软件开发费用
网络安全综合题库
新兴网络技术
四川省文明城市网络安全
数据库 矩阵表
沈阳三一重工软件开发怎么样
幼儿园网络安全教育领导小组
网易和手机都能进的服务器
网络安全竞赛题库 专业
云服务器如何设置两个网页
西雅图服务器1美元
名人数据库推荐书法家商清瑞
中心服务器的管理与维护
云数据库rds哪家不错
青岛合明软件开发有限公司