⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 schedulingsample1authorizationhandler.cs

📁 工作流的基本资料(文档资料
💻 CS
字号:
using System;
using NetBpm.Workflow.Delegation;
using NetBpm.Workflow.Execution;
using NetBpm.Workflow.Execution.EComp;
using NetBpm.Workflow.Organisation;
using NetBpm.Util.Client;
using log4net;
using Iesi.Collections;
using System.Collections;

namespace NetBpm.Example.Delegate
{
	
	public class SchedulingSample1AuthorizationHandler : IAuthorizationHandler
	{
		private static readonly ILog log = LogManager.GetLogger(typeof (SchedulingSample1AuthorizationHandler));
		private static readonly ServiceLocator serviceLocator = ServiceLocator.Instance;
		
		public void  CheckRemoveProcessInstance(String authenticatedActorId, Int64 processInstanceId)
		{
		}
		
		public void  CheckRemoveProcessDefinition(String authenticatedActorId, Int64 processDefinitionId)
		{
		}
		
		public void  CheckStartProcessInstance(String authenticatedActorId, Int64 processDefinitionId, IDictionary attributeValues, String transitionName)
		{
		}
		
		public void  CheckGetStartForm(String authenticatedActorId, Int64 processDefinitionId)
		{
		}
		
		public void  CheckGetActivityForm(String authenticatedActorId, Int64 flowId)
		{
		}
		
		public void  CheckPerformActivity(String authenticatedActorId, Int64 flowId, IDictionary attributeValues, String transitionName)
		{
			
			//only actor assigned for that activity can perform an activity
			IExecutionSessionLocal executionComponent = (IExecutionSessionLocal) serviceLocator.GetService(typeof(IExecutionSessionLocal));
			try
			{
				IFlow flow = executionComponent.GetFlow(flowId);
				if (flow.GetActor().Id.Equals(authenticatedActorId) == false)
				{
					throw new AuthorizationException("only actor assigned for that activity can perform an activity");
				}
			}
			catch (ExecutionException e)
			{
				log.Error("failed doing authorization : ", e);
				throw new System.SystemException("failed doing authorization : " + e.Message);
			}
			finally
			{
				serviceLocator.Release(executionComponent);
			}		
		}
		
		public void  CheckDelegateActivity(String authenticatedActorId, Int64 flowId, String delegateActorId)
		{
			//only director can delegate an activity
			IExecutionSessionLocal executionComponent = (IExecutionSessionLocal) serviceLocator.GetService(typeof(IExecutionSessionLocal));
			try
			{
				IFlow flow = executionComponent.GetFlow(flowId, new Relations("attributeInstances"));
				IActor director = null;
				
				ISet attributeInstances = flow.AttributeInstances;
				for (IEnumerator iter = attributeInstances.GetEnumerator(); iter.MoveNext(); )
				{
					IAttributeInstance attributeInstance = (IAttributeInstance) iter.Current;
					if ("director".Equals(attributeInstance.Attribute.Name))
					{
						director = (IActor) attributeInstance.GetValue();
					}
				}
				
				if (director.Id.Equals(authenticatedActorId) == false)
				{
					throw new AuthorizationException("Only director is allowed to delegate activity");
				}
			}
			catch (AuthorizationException e)
			{
				throw e;
			}
			catch (System.Exception e)
			{
				log.Error("failed doing authorization : ", e);
				throw new System.SystemException("failed doing authorization : " + e.Message);
			}
			finally
			{
				serviceLocator.Release(executionComponent);
			}
		}
		
		public void  CheckCancelProcessInstance(String authenticatedActorId, Int64 processInstanceId)
		{
		}
		
		public void  CheckCancelFlow(String authenticatedActorId, Int64 flowId)
		{
		}
		
		public void  CheckGetFlow(String authenticatedActorId, Int64 flowId)
		{
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -