using System; using System.Collections.Generic; using System.Linq; using OpenAuth.App; using OptimaJet.Workflow.Core.Model; using OptimaJet.Workflow.Core.Runtime; namespace OpenAuth.Mvc.Models { /// /// 流程角色处理 /// public class WorkflowRuleProvider : IWorkflowRuleProvider { private RoleManagerApp _app; public WorkflowRuleProvider() { _app = AutofacExt.GetFromFac(); } /// /// 加载角色列表,供流程设计的时候进行选择 /// public List GetRules() { var roles = _app.Load(Guid.Empty, 1, 100).rows; var rolestrs = new List(); foreach (var role in roles) { rolestrs.Add(role.Name); } return rolestrs; } /// /// Checks the specified process instance. /// 李玉宝于2016-09-05 16:43:07 /// /// The process instance. /// The runtime. /// 用户ID /// Name of the rule. /// The parameter. /// true if XXXX, false otherwise. public bool Check(ProcessInstance processInstance, WorkflowRuntime runtime, string identityId, string ruleName, string parameter) { var userRole = _app.LoadForUser(Guid.Parse(identityId)); foreach (var role in userRole) { if (role.Name == ruleName) return true; } return false; } public IEnumerable GetIdentities(ProcessInstance processInstance, WorkflowRuntime runtime, string ruleName, string parameter) { var userids = _app.GetUsersInRole(ruleName); if (userids == null) return null; return userids.Select(u => u.ToString()); } } }