/// <summary> /// 获取某角色名称的审批角色 /// </summary> /// <param name="workflowName">工作流名称</param> /// <param name="roleName">角色名称</param> /// <returns></returns> public static ApprovalRole GetUserRoleByName(string workflowName, string roleName) { WorkFlowDefine workflow = WorkflowRuntime.Current.GetService <IWorkFlowDefinePersistService>().GetWorkflowDefine(workflowName); return(GetUserRoleByName(workflow, roleName)); }
/// <summary> /// 按照工作流名称获取工作流定义 /// </summary> /// <param name="workflowName">工作流名称</param> /// <returns></returns> public WorkFlowDefine GetWorkflowDefine(string workflowName) { string cacheName = GetCacheName(workflowName); WorkFlowDefine wf = null; _memoryCache.TryGetValue <WorkFlowDefine>(cacheName, out wf); if (wf == null) { WorkflowConfig config = GetConfig(); bool found = false; foreach (WorkflowApplication app in config.Applications) { for (int i = 0; i < app.Defines.Count; i++) { if (app.Defines[i].Name.Equals(workflowName, StringComparison.OrdinalIgnoreCase)) { string fullFileName = GetFileName(app.Defines[i].File); //CacheDependency fileDependency = new System.Web.Caching.CacheDependency(fullFileName); // HttpContext.Current.Cache.Add(cacheName, ReadFromFile(app, fullFileName), fileDependency, DateTime.MaxValue, System.Web.Caching.Cache.NoSlidingExpiration, CacheItemPriority.High, null); wf = ReadFromFile(app, fullFileName); _memoryCache.Set <WorkFlowDefine>(cacheName, wf); found = true; break; } } } if (!found) { throw new ArgumentException(string.Format("workflowName '{0}' must in config", workflowName)); } } return(wf); // if (HttpContext.Current == null) //非http应用,无法从缓存中获取,只能读取. //{ // //List<WorkflowDefineConfig> defines = new List<WorkflowDefineConfig>(); // WorkflowConfig config = GetConfig(); // foreach (WorkflowApplication app in config.Applications) // { // for (int i = 0; i < app.Defines.Count; i++) // { // if (app.Defines[i].Name.Equals(workflowName, StringComparison.OrdinalIgnoreCase)) // { // string fullFileName = GetFileName(app.Defines[i].File); // return ReadFromFile(app, fullFileName); // } // } // } // throw new ArgumentException(string.Format("workflowName '{0}' must in config", workflowName)); //} ////有缓冲对象,则从缓存对象中获取 ////获取缓存名字 //string cacheName = GetCacheName(workflowName); ////从缓存中读取 //if (HttpContext.Current.Cache[cacheName] == null) //{ // WorkflowConfig config = GetConfig(); // bool found = false; // foreach (WorkflowApplication app in config.Applications) // { // for (int i = 0; i < app.Defines.Count; i++) // { // if (app.Defines[i].Name.Equals(workflowName, StringComparison.OrdinalIgnoreCase)) // { // string fullFileName = GetFileName(app.Defines[i].File); // CacheDependency fileDependency = new System.Web.Caching.CacheDependency(fullFileName); // HttpContext.Current.Cache.Add(cacheName, ReadFromFile(app,fullFileName), fileDependency, DateTime.MaxValue, System.Web.Caching.Cache.NoSlidingExpiration, CacheItemPriority.High, null); // found = true; // break; // } // } // } // if(!found) // throw new ArgumentException(string.Format("workflowName '{0}' must in config", workflowName)); //} //return (WorkFlowDefine)HttpContext.Current.Cache[cacheName]; }
/// <summary> /// Gets the name of the user role by. /// </summary> /// <param name="define">The define.</param> /// <param name="roleName">Name of the role.</param> /// <returns></returns> public static ApprovalRole GetUserRoleByName(WorkFlowDefine define, string roleName) { StateMachineWorkflow workflow = define as StateMachineWorkflow; return(workflow.GetRoleByName(roleName)); }
/// <summary> /// Saves the specified workflow. /// </summary> /// <param name="workflow">The workflow.</param> /// <param name="applicationName">Name of the application.</param> public void Save(WorkFlowDefine workflow, string applicationName) { }