Exemplo n.º 1
0
        private bool CheckCondition(ExecutionRequestParameters parameters)
        {
            if (parameters.ConditionType != ConditionType.Action || parameters.ConditionMethod == null ||
                parameters.ConditionMethod.OutputParameters.Count() != 1)
            {
                throw new InvalidOperationException();
            }

            if (ConsiderResultOnPreExecution && parameters.ConditionResultOnPreExecution.HasValue)
            {
                return(parameters.ConditionResultOnPreExecution.Value);
            }

            var response = ExecutionResponseParameters.Create(parameters.ProcessId, parameters.ActivityName, parameters.ParameterContainer);

            ExecuteMethod(parameters.ConditionMethod, response, parameters.ParameterContainer);
            var result = response.ParameterContainer.SingleOrDefault(p => p.Name == DefaultDefinitions.ParameterConditionResult.Name);

            if (result == null || result.Value == null || !(result.Value  is bool))
            {
                throw new InvalidOperationException();
            }

            return((bool)result.Value);
        }
Exemplo n.º 2
0
		private bool CheckConditions(ExecutionRequestParameters parameters)
		{
			bool flag;
			bool? nullable = null;
			ConditionDefinition[] conditions = parameters.Conditions;
			for (int i = 0; i < (int)conditions.Length; i++)
			{
				ConditionDefinition conditionDefinition = conditions[i];
				if (conditionDefinition.Type != ConditionType.Action || conditionDefinition.Action == null)
				{
					throw new InvalidOperationException();
				}
				bool value = false;
				if (!this.ConsiderResultOnPreExecution || !conditionDefinition.ResultOnPreExecution.HasValue)
				{
					ActivityExecutor.FillExecutedActivityState(parameters);
					CodeActionsInvoker codeActionsInvoker = parameters.ProcessInstance.ProcessScheme.CodeActionsInvoker;
					if (!this.GlobalActionsInvoker.ExistsCondition(conditionDefinition.Action.ActionName))
					{
						value = (!codeActionsInvoker.ExistsCondition(conditionDefinition.Action.ActionName) ? this.ActionProvider.ExecuteCondition(conditionDefinition.Action.ActionName, parameters.ProcessInstance, this._runtime, conditionDefinition.Action.ActionParameter) : codeActionsInvoker.InvokeCondition(conditionDefinition.Action.ActionName, parameters.ProcessInstance, this._runtime, conditionDefinition.Action.ActionParameter));
					}
					else
					{
						value = this.GlobalActionsInvoker.InvokeCondition(conditionDefinition.Action.ActionName, parameters.ProcessInstance, this._runtime, conditionDefinition.Action.ActionParameter);
					}
					if (conditionDefinition.ConditionInversion)
					{
						value = !value;
					}
				}
				else
				{
					value = conditionDefinition.ResultOnPreExecution.Value;
				}
				if (!nullable.HasValue)
				{
					nullable = new bool?(value);
				}
				else
				{
					if (parameters.ConditionsConcatenationType == ConcatenationType.And)
					{
						flag = (!nullable.Value ? false : value);
					}
					else
					{
						flag = (nullable.Value ? true : value);
					}
					nullable = new bool?(flag);
				}
			}
			if (!nullable.HasValue)
			{
				return false;
			}
			return nullable.Value;
		}
Exemplo n.º 3
0
        private ExecutionResponseParameters ExecuteMethod(ExecutionRequestParameters parameters)
        {
            var response = string.IsNullOrEmpty(parameters.TransitionName)
                               ? ExecutionResponseParameters.Create(parameters.ProcessId, parameters.ActivityName, parameters.ParameterContainer)
                               : ExecutionResponseParameters.Create(parameters.ProcessId, parameters.ActivityName, parameters.TransitionName, parameters.ParameterContainer);



            foreach (var method in parameters.Methods.OrderBy(m => m.Order))
            {
                ExecuteMethod(method, response, response.ParameterContainer);
            }


            return(response);
        }
Exemplo n.º 4
0
        public static ExecutionRequestParameters Create(Guid processId, IEnumerable <ParameterDefinitionWithValue> parameters, ActivityDefinition activityToExecute, ConditionDefinition condition, bool isPreExecution)
        {
            List <ActionDefinitionForActivity> implementation = isPreExecution
                                                                   ? activityToExecute.PreExecutionImplemementation
                                                                   : activityToExecute.Implemementation;

            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }
            var parametersList = parameters.ToList();

            var methods             = new List <MethodToExecuteInfo>(implementation.Count);
            var executionParameters = new ExecutionRequestParameters
            {
                ProcessId     = processId,
                ConditionType = condition.Type,
                ConditionResultOnPreExecution = condition.ResultOnPreExecution,
                ConditionMethod = condition.Type == ConditionType.Action ? GetMethodToExecuteInfo(parametersList, ActionDefinition.Create(condition.Action, 0)) : null,
            };

            methods.AddRange(implementation.Select(method => GetMethodToExecuteInfo(parametersList, method)));

            var parameters1 = new List <ParameterContainerInfo>();

            parameters1.AddRange(parameters.Where(p => p.Name != DefaultDefinitions.ParameterExecutedActivityState.Name).Select(p => new ParameterContainerInfo()
            {
                Name = p.Name, Type = p.Type, Value = p.Value
            }));
            parameters1.Add(new ParameterContainerInfo {
                Name = DefaultDefinitions.ParameterExecutedActivityState.Name, Type = DefaultDefinitions.ParameterExecutedActivityState.Type, Value = activityToExecute.State
            });
            executionParameters.ParameterContainer = parameters1.ToArray();
            executionParameters.Methods            = methods.ToArray();

            executionParameters.ActivityName = activityToExecute.Name;

            return(executionParameters);
        }
Exemplo n.º 5
0
        public static ExecutionRequestParameters Create(Guid processId, IEnumerable<ParameterDefinitionWithValue> parameters, ActivityDefinition activityToExecute, ConditionDefinition condition, bool isPreExecution)
        {
            List<ActionDefinitionForActivity> implementation = isPreExecution
                                                                   ? activityToExecute.PreExecutionImplemementation
                                                                   : activityToExecute.Implemementation;

            if (parameters == null) throw new ArgumentNullException("parameters");
            var parametersList = parameters.ToList();

            var methods = new List<MethodToExecuteInfo>(implementation.Count);
            var executionParameters = new ExecutionRequestParameters
                                          {
                                              ProcessId = processId,
                                              ConditionType = condition.Type,
                                              ConditionResultOnPreExecution = condition.ResultOnPreExecution,
                                              ConditionMethod = condition.Type == ConditionType.Action ? GetMethodToExecuteInfo(parametersList, ActionDefinition.Create(condition.Action, 0)) : null,
                                          };

            methods.AddRange(implementation.Select(method => GetMethodToExecuteInfo(parametersList, method)));

            var parameters1 = new List<ParameterContainerInfo>();

            parameters1.AddRange(parameters.Where(p => p.Name != DefaultDefinitions.ParameterExecutedActivityState.Name).Select(p => new ParameterContainerInfo() { Name = p.Name, Type = p.Type, Value = p.Value }));
            parameters1.Add(new ParameterContainerInfo{Name = DefaultDefinitions.ParameterExecutedActivityState.Name,Type = DefaultDefinitions.ParameterExecutedActivityState.Type,Value = activityToExecute.State});
            executionParameters.ParameterContainer = parameters1.ToArray();
            executionParameters.Methods = methods.ToArray();

            executionParameters.ActivityName = activityToExecute.Name;

            return executionParameters;
        }
Exemplo n.º 6
0
Arquivo: NullBus.cs Projeto: lulzzz/WF
 public void QueueExecution(ExecutionRequestParameters requestParameters)
 {
     QueueExecution(new[] { requestParameters });
 }
Exemplo n.º 7
0
		public void QueueExecution(ExecutionRequestParameters requestParameters)
		{
			this.QueueExecution(new ExecutionRequestParameters[] { requestParameters });
		}
Exemplo n.º 8
0
 public void QueueExecution(ExecutionRequestParameters requestParameters)
 {
     QueueExecution(new[] {requestParameters});
 }
Exemplo n.º 9
0
        private static ExecutionResponseParameters GetExecutionResponseErrorParameters(ExecutionRequestParameters always,
                                                                                       Exception ex)
        {
            var errorResponse = string.IsNullOrEmpty(always.TransitionName)
                                    ? ExecutionResponseParameters.Create(always.ProcessId, always.ActivityName, ex)
                                    : ExecutionResponseParameters.Create(always.ProcessId, always.ActivityName,
                                                                         always.TransitionName, ex);

            return(errorResponse);
        }
Exemplo n.º 10
0
        private static ExecutionResponseParameters GetExecutionResponseErrorParameters(ExecutionRequestParameters always,
                                                                                       Exception ex)
        {
            var errorResponse = string.IsNullOrEmpty(always.TransitionName)
                                    ? ExecutionResponseParameters.Create(always.ProcessId, always.ActivityName, ex)
                                    : ExecutionResponseParameters.Create(always.ProcessId, always.ActivityName,
                                                                         always.TransitionName, ex);

            return errorResponse;
        }
Exemplo n.º 11
0
        private void ExecuteMethod(ExecutionRequestParameters.MethodToExecuteInfo method,
                                         ExecutionResponseParametersComplete response, ParameterContainerInfo[] parameterContainer )
        {
            var type = Type.GetType(method.Type);
            if (type == null)
                throw new InvalidOperationException();

            var types = method.InputParameters.OrderBy(ip => ip.Order).Select(ip => ip.Type).ToList();
            types.AddRange(method.OutputParameters.OrderBy(ip => ip.Order).Select(ip => ip.Type.MakeByRefType()));

            var values = method.InputParameters.OrderBy(ip => ip.Order).Select(ip => GetParameterValue(parameterContainer, ip)).ToList();
            values.AddRange(method.OutputParameters.OrderBy(ip => ip.Order).Select(ip => GetParameterValueNullable(parameterContainer, ip.Name, ip.Type)));

            var valuesArr = values.ToArray();

            var methodInfo = type.GetMethod(method.MethodName, types.ToArray());

            if (methodInfo.IsStatic)
            {
                var a = methodInfo.Invoke(null, valuesArr);
            }
            else
            {
                var obj = Activator.CreateInstance(type, BindingFlags.NonPublic);
                methodInfo.Invoke(obj, valuesArr);
            }

            response.AddNewParameterValues(method.OutputParameters.OrderBy(output => output.Order).ToList(), valuesArr.Skip(method.InputParameters.Count()).ToList());
        }
Exemplo n.º 12
0
        private ExecutionResponseParameters ExecuteMethod(ExecutionRequestParameters parameters)
        {
            var response = string.IsNullOrEmpty(parameters.TransitionName)
                               ? ExecutionResponseParameters.Create(parameters.ProcessId, parameters.ActivityName, parameters.ParameterContainer)
                               : ExecutionResponseParameters.Create(parameters.ProcessId, parameters.ActivityName, parameters.TransitionName, parameters.ParameterContainer);

                foreach (var method in parameters.Methods.OrderBy(m => m.Order))
                {
                    ExecuteMethod(method, response, response.ParameterContainer);
                }

            return response;
        }
Exemplo n.º 13
0
        private bool CheckCondition(ExecutionRequestParameters parameters)
        {
            if (parameters.ConditionType != ConditionType.Action || parameters.ConditionMethod == null ||
                parameters.ConditionMethod.OutputParameters.Count() != 1)
                throw new InvalidOperationException();

            if (ConsiderResultOnPreExecution && parameters.ConditionResultOnPreExecution.HasValue)
                return parameters.ConditionResultOnPreExecution.Value;

            var response = ExecutionResponseParameters.Create(parameters.ProcessId, parameters.ActivityName, parameters.ParameterContainer);
            ExecuteMethod(parameters.ConditionMethod, response, parameters.ParameterContainer);
            var result = response.ParameterContainer.SingleOrDefault(p => p.Name == DefaultDefinitions.ParameterConditionResult.Name);
            if (result == null || result.Value == null || !(result.Value  is bool))
                throw new InvalidOperationException();

            return (bool)result.Value;
        }
Exemplo n.º 14
0
		public static ExecutionRequestParameters Create(OptimaJet.Workflow.Core.Model.ProcessInstance processInstance, ActivityDefinition activityToExecute, List<ConditionDefinition> conditions, bool isPreExecution)
		{
			List<ActionDefinitionReference> actionDefinitionReferences = (isPreExecution ? activityToExecute.PreExecutionImplementation : activityToExecute.Implementation);
			if (processInstance == null)
			{
				throw new ArgumentNullException("processInstance");
			}
			ExecutionRequestParameters executionRequestParameter = new ExecutionRequestParameters()
			{
				ProcessInstance = processInstance,
				Conditions = conditions.ToArray(),
				Methods = actionDefinitionReferences.ToArray(),
				ActivityName = activityToExecute.Name,
				Activity = activityToExecute,
				ConditionsConcatenationType = ConcatenationType.And
			};
			return executionRequestParameter;
		}
Exemplo n.º 15
0
		private static void FillExecutedActivityState(ExecutionRequestParameters parameters)
		{
			string state = parameters.Activity.State;
			if (string.IsNullOrEmpty(state))
			{
				state = parameters.ProcessInstance.CurrentState;
			}
			parameters.ProcessInstance.ExecutedActivityState = state;
			parameters.ProcessInstance.ExecutedActivity = parameters.Activity;
			if (!string.IsNullOrEmpty(parameters.TransitionName))
			{
				parameters.ProcessInstance.ExecutedTransition = parameters.ProcessInstance.ProcessScheme.FindTransition(parameters.TransitionName);
			}
		}
Exemplo n.º 16
0
		private ExecutionResponseParameters ExecuteMethod(ExecutionRequestParameters parameters)
		{
			ExecutionResponseParametersComplete executionResponseParametersComplete = (string.IsNullOrEmpty(parameters.TransitionName) ? ExecutionResponseParameters.Create(parameters.ProcessInstance, parameters.ActivityName) : ExecutionResponseParameters.Create(parameters.ProcessInstance, parameters.ActivityName, parameters.TransitionName));
			ActivityExecutor.FillExecutedActivityState(parameters);
			foreach (ActionDefinitionReference actionDefinitionReference in 
				from m in (IEnumerable<ActionDefinitionReference>)parameters.Methods
				orderby m.Order
				select m)
			{
				this.ExecuteMethod(actionDefinitionReference, executionResponseParametersComplete);
			}
			return executionResponseParametersComplete;
		}