zoukankan      html  css  js  c++  java
  • wf HandlExternalEvent传递参数到自定义属性中

    如果在Workflow中定义了一个属性,如何才能在工作流创建后对这个属性进行修改呢?
    今天折腾了一天,也不见有什么效果,只搞懂了一半,先写出来,没有领悟到的等以后想通了再写。
    在创建工作流的时候,可以用CreateWorkflow(typeof(wf),Dictionary<string,object>)这样的方式将参数值传入工作流。但是如果工作流已经创建,宿主程序又如何把值传入工作流呢?
    需要用到ExternalDataEventArgs这个东东,需要自己继承一个这样的类
    [Serializable]
        
    public class BillExternalDataEventArgs : ExternalDataEventArgs {
            
    private Decimal _mycash;
            
    public Decimal Cash {
                
    get return _mycash; }
                
    set { _mycash = value; }
            }

            
    public BillExternalDataEventArgs(Guid instanceId,Decimal decCash) : base(instanceId) {
                _mycash 
    = decCash;
            }

        }
    然后在把对应的接口进行相应的调整
        [ExternalDataExchange]
        
    public interface IBillWorkFlow
        
    {
            Decimal GetCash(Decimal decCash);
            
    event EventHandler<BillExternalDataEventArgs> BillSubmit;
            
    event EventHandler<BillExternalDataEventArgs> BillOk;
        }

    [Serializable]
        
    public class MyBillWorkFlow : IBillWorkFlow {
            
    public MyBillWorkFlow() {
                System.Diagnostics.Debug.WriteLine(
    "MyBillWorkFlow Init");
            }


            Dictionary
    <string, EventHandler<BillExternalDataEventArgs>> _EventList = new Dictionary<string, EventHandler<BillExternalDataEventArgs>>();

            
    public void RaisEvent(string strName,Guid guidInstanceId,Decimal decCash) {
                
    if (_EventList[strName] != null)
                
    {
                    
    try
                    
    {
                        EventHandler
    <BillExternalDataEventArgs> evehandler = _EventList[strName];
                        BillExternalDataEventArgs ede 
    = new BillExternalDataEventArgs(guidInstanceId,decCash);
                        evehandler(
    this, ede);
                    }

                    
    catch 
                    
                    }

                }

            }


            
    public Decimal GetCash(Decimal decCash)
            

                
    return decCash;
            }


            
    public event EventHandler<BillExternalDataEventArgs> BillSubmit
            
    {
                add 
    {
                    System.Diagnostics.Debug.WriteLine(
    "add BillSubmit event");
                    _EventList.Add(
    "BillSubmit", value); 
                }

                remove 
    { _EventList.Remove("BillSubmit"); }
            }


            
    public event EventHandler<BillExternalDataEventArgs> BillOk
            
    {
                add 
    { _EventList.Add("BillOk", value); }
                remove 
    { _EventList.Remove("BillOk"); }
            }

        }

    然后在工作流中定义
    public Billdayone.BillExternalDataEventArgs _cash = default(Billdayone.BillExternalDataEventArgs);

    这个_cash就是宿主与工作流之间传递的重要属性。

    只需要调用
    RaisEvent(string strName,Guid guidInstanceId,Decimal decCash)//Decimal decCash就是宿主向工作流传递的参数,将传递给_cash.Cash
    这样就完成了宿主向工作流传递参数。

    但是我还没有弄明白怎么能够得到工作流中的属性值。还在学习中。。。还不知道怎么办?。。。
  • 相关阅读:
    Longest Palindromic Substring问题
    twosum问题
    longest substring问题
    特殊的ARP
    【转】人肉搜索技巧
    ARP攻击
    Linux kali安装及常用命令收集
    【转】ICMP协议
    SpringBoot集成Mybatis-XML方式通用Mapper
    springMVC的controller中insert()多次,记优惠券被多次领取
  • 原文地址:https://www.cnblogs.com/poplau/p/1237783.html
Copyright © 2011-2022 走看看