コード例 #1
0
 private static Constraint ConfirmWithNoTarget()
 {
     DelegateInArgument<Confirm> element = new DelegateInArgument<Confirm> {
         Name = "element"
     };
     DelegateInArgument<ValidationContext> argument = new DelegateInArgument<ValidationContext> {
         Name = "validationContext"
     };
     Variable<bool> assertFlag = new Variable<bool> {
         Name = "assertFlag"
     };
     Variable<IEnumerable<Activity>> elements = new Variable<IEnumerable<Activity>> {
         Name = "elements"
     };
     Variable<int> index = new Variable<int> {
         Name = "index"
     };
     Constraint<Confirm> constraint = new Constraint<Confirm>();
     ActivityAction<Confirm, ValidationContext> action = new ActivityAction<Confirm, ValidationContext> {
         Argument1 = element,
         Argument2 = argument
     };
     Sequence sequence = new Sequence {
         Variables = { assertFlag, elements, index }
     };
     If item = new If {
         Condition = new InArgument<bool>(env => element.Get(env).Target != null)
     };
     Assign<bool> assign = new Assign<bool> {
         To = assertFlag,
         Value = 1
     };
     item.Then = assign;
     Sequence sequence2 = new Sequence();
     Assign<IEnumerable<Activity>> assign2 = new Assign<IEnumerable<Activity>> {
         To = elements
     };
     GetParentChain chain = new GetParentChain {
         ValidationContext = argument
     };
     assign2.Value = chain;
     sequence2.Activities.Add(assign2);
     While @while = new While(env => !assertFlag.Get(env) && (index.Get(env) < elements.Get(env).Count<Activity>()));
     Sequence sequence3 = new Sequence();
     If if2 = new If(env => elements.Get(env).ElementAt<Activity>(index.Get(env)).GetType() == typeof(CompensationParticipant));
     Assign<bool> assign3 = new Assign<bool> {
         To = assertFlag,
         Value = 1
     };
     if2.Then = assign3;
     sequence3.Activities.Add(if2);
     Assign<int> assign4 = new Assign<int> {
         To = index,
         Value = new InArgument<int>(env => index.Get(env) + 1)
     };
     sequence3.Activities.Add(assign4);
     @while.Body = sequence3;
     sequence2.Activities.Add(@while);
     item.Else = sequence2;
     sequence.Activities.Add(item);
     AssertValidation validation = new AssertValidation {
         Assertion = new InArgument<bool>(assertFlag),
         Message = new InArgument<string>(System.Activities.SR.ConfirmWithNoTargetConstraint)
     };
     sequence.Activities.Add(validation);
     action.Handler = sequence;
     constraint.Body = action;
     return constraint;
 }
コード例 #2
0
ファイル: PSWorkflowValidator.cs プロジェクト: nickchal/pash
		private Constraint ValidateActivitiesConstraint(string runtimeAssembly, PSWorkflowValidationResults validationResults)
		{
			var activityToValidate = new DelegateInArgument<Activity>();
			DelegateInArgument<ValidationContext> delegateInArgument1 = new DelegateInArgument<ValidationContext>();
			Constraint<Activity> constraint = new Constraint<Activity>();
			ActivityAction<Activity, ValidationContext> activityAction = new ActivityAction<Activity, ValidationContext>();
			activityAction.Argument1 = activityToValidate;
			activityAction.Argument2 = delegateInArgument1;
			AssertValidation assertValidation = new AssertValidation();
			assertValidation.IsWarning = false;
			ParameterExpression parameterExpression = Expression.Parameter(typeof(ActivityContext), "env");
			Expression[] expressionArray = new Expression[3];
			Expression[] expressionArray1 = new Expression[1];
			expressionArray1[0] = parameterExpression;
			expressionArray[0] = Expression.Call(Expression.Field(Expression.Constant(this), FieldInfo.GetFieldFromHandle(activityToValidate)), (MethodInfo)MethodBase.GetMethodFromHandle(Get, DelegateInArgument<Activity>), expressionArray1);
			expressionArray[1] = Expression.Field(Expression.Constant(this), FieldInfo.GetFieldFromHandle(runtimeAssembly));
			expressionArray[2] = Expression.Field(Expression.Constant(this), FieldInfo.GetFieldFromHandle(validationResults));
			ParameterExpression[] parameterExpressionArray = new ParameterExpression[1];
			parameterExpressionArray[0] = parameterExpression;
			assertValidation.Assertion = new InArgument<bool>(Expression.Lambda<Func<ActivityContext, bool>>(Expression.Call(Expression.Constant(this, typeof(PSWorkflowValidator)), (MethodInfo)MethodBase.GetMethodFromHandle(ValidateActivity), expressionArray), parameterExpressionArray));
			ParameterExpression parameterExpression1 = Expression.Parameter(typeof(ActivityContext), "env");
			Expression[] expressionArray2 = new Expression[3];
			expressionArray2[0] = Expression.Property(null, typeof(CultureInfo).GetProperty ("CurrentCulture", BindingFlags.Static)); //TODO: REIVEW: (MethodInfo)MethodBase.GetMethodFromHandle(CultureInfo.get_CurrentCulture));
			expressionArray2[1] = Expression.Property(null, typeof(Resources).GetProperty ("InvalidActivity", BindingFlags.Static)); //TODO: REVIEW: (MethodInfo)MethodBase.GetMethodFromHandle(Resources.get_InvalidActivity));
			Expression[] expressionArray3 = new Expression[1];
			Expression[] expressionArray4 = new Expression[1];
			expressionArray4[0] = parameterExpression1;
			expressionArray3[0] = Expression.Property(Expression.Call(Expression.Call(Expression.Field(Expression.Constant(this), FieldInfo.GetFieldFromHandle(PSWorkflowValidator.PSWorkflowValidator.activityToValidate)), (MethodInfo)MethodBase.GetMethodFromHandle(Get, DelegateInArgument<Activity>), expressionArray4), (MethodInfo)MethodBase.GetMethodFromHandle(GetType), new Expression[0]), (MethodInfo)MethodBase.GetMethodFromHandle(get_FullName));
			expressionArray2[2] = Expression.NewArrayInit(typeof(object), expressionArray3);
			ParameterExpression[] parameterExpressionArray1 = new ParameterExpression[1];
			parameterExpressionArray1[0] = parameterExpression1;
			assertValidation.Message = new InArgument<string>(Expression.Lambda<Func<ActivityContext, string>>(Expression.Call(null, (MethodInfo)MethodBase.GetMethodFromHandle(string.Format), expressionArray2), parameterExpressionArray1));
			activityAction.Handler = assertValidation;
			constraint.Body = activityAction;
			return constraint;
		}