验证父活动中的特定活动类型 [英] Validating a specific activity type in a parent activity

查看:69
本文介绍了验证父活动中的特定活动类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个自定义活动,它将成为另一种特定活动类型的容器.父活动是CustomerLoan,我要放入该活动的活动是CustomerContractActivity.

I have a custom activity that will be the container of another specific type of activity.  The parent activity is CustomerLoan and the activity I want to drop into this activity is CustomerContractActivity.

我要做的是使只有类型为CustomerContractActivity的活动(该活动具有两个类型为Customer和LoanContract的参数)是唯一可以放入父容器的活动.这是我的客户贷款代码 类和验证代码:

What I am trying to do is make it so that only an activity of type CustomerContractActivity, which has two in arguments of type Customer and LoanContract is the only activity that can be dropped into the parent container.  Here is my code for the CustomerLoan class and validation code:

使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用System.Text;
使用System.Activities;
使用System.Activities.Statements;
使用合同;
使用System.Activities.Validation;

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Activities;
using System.Activities.Statements;
using Contracts;
using System.Activities.Validation;

命名空间ActivityActionDemo
{

namespace ActivityActionDemo
{

  公共类CustomerLoan:活动
    {
       public InArgument< Contracts.Customer> myCustomer {get;放; }
       public InArgument< Contracts.LoanContract> myLoan {得到;放; }
       public ActivityAction< Customer,LoanContract> LoanProcessedAction {get;放; }

    public class CustomerLoan : Activity
    {
        public InArgument<Contracts.Customer> myCustomer { get; set; }
        public InArgument<Contracts.LoanContract> myLoan { get; set; }
        public ActivityAction<Customer,LoanContract> LoanProcessedAction { get; set; }

       public CustomerLoan()
       {
           base.Constraints.Add(ValidateChildren());

        public CustomerLoan()
        {
            base.Constraints.Add(ValidateChildren());

          实施=()=>新序列
           {
                            活动=
           {
                            新的InvokeAction<客户,贷款合同>
                             {
                   动作= LoanProcessedAction,
                    Argument1 =新的InArgument< Contracts.Customer>(((env)=> myCustomer.Get(env)),
                    Argument2 =新的InArgument< Contracts.LoanContract>(((env)=> myLoan.Get(env))
                             }
           }
           };
       }
      
      静态约束ValidateChildren()
       {
           DelegateInArgument< CustomerLoan> element = new DelegateInArgument< CustomerLoan>();
           DelegateInArgument< ValidationContext>. context = new DelegateInArgument< ValidationContext>();           sp    
          变量< bool>结果=新的变量< bool>();
           DelegateInArgument< Activity> child = new DelegateInArgument< Activity>();

            this.Implementation = () => new Sequence
            {
                Activities =
            {
                new InvokeAction<Customer,LoanContract>
                {
                    Action = LoanProcessedAction,
                    Argument1 = new InArgument<Contracts.Customer>((env) => myCustomer.Get(env)),
                    Argument2 = new InArgument<Contracts.LoanContract>((env) => myLoan.Get(env))
                }
            }
            };
        }
       
        static Constraint ValidateChildren()
        {
            DelegateInArgument<CustomerLoan> element = new DelegateInArgument<CustomerLoan>();
            DelegateInArgument<ValidationContext> context = new DelegateInArgument<ValidationContext>();                       
            Variable<bool> result = new Variable<bool>();
            DelegateInArgument<Activity> child = new DelegateInArgument<Activity>();

          返回新的Constraint< CustomerLoan>
           {
                            正文=新的ActivityAction< CustomerLoan,ValidationContext>
                             {
                   参数1 =元素,
                   参数2 =上下文,
                   处理程序=新序列
                    {
               b变量=
               b {
              nbsp; bsp   结果
               b },
               b活动=
               b {
              nbsp; bsp   新的ForEach< Activity>
              nbsp; bsp    {              nbsp; bsp ;     
              nbsp; bsp      值=新的GetChildSubtree
              nbsp; bsp       {
              nbsp; bsp           ValidationContext = context              nbsp; bsp&bsp;           
              nbsp; bsp       },
              nbsp; bsp      正文=新的ActivityAction< Activity>
              nbsp; bsp       {  
              nbsp; bsp          论点=子,
              nbsp; bsp          处理程序=新的If()
              nbsp; bsp           {              nbsp; bsp ;               
              nbsp; bsp             条件=新的InArgument< bool>((env) => object.Equals(child.Get(env).GetType(),typeof(CustomerContractActivity))),               nbsp; bsp
              nbsp; bsp             然后=新的Assign< bool>
              nbsp; bsp              {
              nbsp; bsp                 值= true,
              nbsp; bsp                 到=结果
              nbsp; bsp              }
              nbsp; bsp           }
              nbsp; bsp       }              b ;     
              nbsp; bsp    },
              nbsp; bsp   新的AssertValidation
              nbsp; bsp    {
              nbsp; bsp      断言=新的InArgument< bool>(结果),
              nbsp; bsp      消息=新的InArgument< string> ("CustomerContractActivity具有 进入客户贷款活动"),             b ;              nbsp; b ;               
              nbsp; bsp    }
               b }
                    }
                             }
           };
       }
    }
   
}

            return new Constraint<CustomerLoan>
            {
                Body = new ActivityAction<CustomerLoan, ValidationContext>
                {
                    Argument1 = element,
                    Argument2 = context,
                    Handler = new Sequence
                    {
                        Variables =
                        {
                            result
                        },
                        Activities =
                        {
                            new ForEach<Activity>
                            {                               
                                Values = new GetChildSubtree
                                {
                                    ValidationContext = context                                   
                                },
                                Body = new ActivityAction<Activity>
                                {  
                                    Argument = child,
                                    Handler = new If()
                                    {                                         
                                        Condition = new InArgument<bool>((env) => object.Equals(child.Get(env).GetType(),typeof(CustomerContractActivity))),                                       
                                        Then = new Assign<bool>
                                        {
                                            Value = true,
                                            To = result
                                        }
                                    }
                                }                               
                            },
                            new AssertValidation
                            {
                                Assertion = new InArgument<bool>(result),
                                Message = new InArgument<string> ("CustomerContractActivity has to be inside a CustomerLoan activity"),                                                               
                            }
                        }
                    }
                }
            };
        }
    }
   
}

尽管实际上发生的是,进行了一次验证,以确保所放入的活动中至少有一个是CustomerContractActivity类型,但随后我也可以加入任何其他类型的活动.

What is actually happening though is that a validation takes place that makes sure that at least one of the activities dropped in is the CustomerContractActivity type, but then it lets me also drop in any other type of activity.

1.有没有办法做到这一点,以便只允许我放入CustomerContractActivity?
2.我真正想做的是使它成为可能,无论使用父活动的人如何,只要有两个参数Customer和LoanContract,他们就可以拥有他们想要的任何类型的活动,但是我不知道知道如何做到这一点.

1. Is there a way to make this so that it only lets me drop the CustomerContractActivity in?
2. What I really want to do is make it so that whoever is using the parent activity, they can have an activity of any type they want, as long as the have the two arguments, Customer and LoanContract, but I can't figure out how to do this.

有什么想法吗?

STom

推荐答案

1. WorkflowItemPresenter具有"AllowedItemType",可让您限制可以在其中拖动的对象的类型.

1. WorkflowItemPresenter has 'AllowedItemType' which allows you to resrict the type of objects that can be dragged inside.

2.定义一个声明这些参数的接口,并将其用作您的AllowedItemType.您必须继承可拖动的界面.

蒂姆(Tim)

2. Define an interface which declares those arguments and use it as your AllowedItemType. You have to inherit the interface to be draggable.

Tim


这篇关于验证父活动中的特定活动类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆