承接MOSS各种工作流开发 联系人:王先生.电话:18618405729QQ:252385878 QQ群:41696750 MSN:wanghao-3@hotmail.com

导航

WFDemo 开发篇

再发一个WF的例子演示

DelayActivity,ListenActivity,CallExternalMethodActivity,HandleExternalEventActivity实现申请,审批,超时否决的演示
使用Winform作为客户端
使用WCF作为客户端与服务器的通信方式
代码很短,很适合正在学习WF,并想快速将WF应用到商业开发的人

例子是在Windwos server 2008 ,VS2008 ,NET3.5下写的
下载   http://files.cnblogs.com/foundation/wxwinter3.rar

应用场景说明:


 流程设计



使用说明
1.启动引擎服务


2.客户端提交申请




3.审批者登录



4.审批者审批


5.申请者查看审批结果




引擎服务的全部代码

namespace WorkflowConsoleApplication2
{
    
class Program
    
{
        
static void Main(string[] args)
        
{
            DataSet1 ds 
= new DataSet1();
            WorkflowRuntime workflowRuntime 
= new WorkflowRuntime();
            ExternalDataExchangeService exchange 
= new ExternalDataExchangeService();
            workflowRuntime.AddService(exchange);
            exchangeEvent obj 
= new exchangeEvent(ds);
            exchange.AddService(obj);
            control ctrl 
= new control(workflowRuntime, obj);
            
string WCFurl = "http://localhost:567/wxwinter/";
            ServiceHost host 
= new ServiceHost(ctrl, new Uri(WCFurl));
            
string WCFClassName = "wxdTest"
            host.AddServiceEndpoint(
typeof(Icontrol), new BasicHttpBinding(), WCFClassName);
            host.Open();
            Console.WriteLine(
"引擎已启动");
            Console.Read();
        }

    }


    
class exchangeEvent : IExternalEvent
    
{
        DataSet1 ds;
        
public exchangeEvent(DataSet1 v)
        
{ds = v;}
        
public event EventHandler<NextStepEventArgs> ApproveEvent;

        
public void Approve(string gid, string userResult)
        
{
            Guid guid 
= new Guid(gid);
            NextStepEventArgs e 
= new NextStepEventArgs(guid);
            e.result 
= userResult;
            ApproveEvent(
null, e);
         
        }


        
public System.Data.DataSet  GetApproverTask(string username)
        
{
            System.Data.DataView dv 
= new System.Data.DataView(ds.infoTab);
            dv.RowFilter 
= string.Format("[approver]='{0}' and [state] = 1", username);
            System.Data.DataSet temp 
= new System.Data.DataSet();
            temp.Tables.Add(dv.ToTable());
            
return temp;
            
        }


        
public System.Data.DataSet GetProposerTask(string username)
        
{
            System.Data.DataView dv 
= new System.Data.DataView(ds.infoTab);
            dv.RowFilter 
= string.Format("[proposer]='{0}'", username);
            System.Data.DataSet temp 
= new System.Data.DataSet();
            temp.Tables.Add(dv.ToTable());
            
return temp;
        }

        
        
public void Notify(dataform df)
        
{
            System.Data.DataView dv 
= new System.Data.DataView(ds.infoTab);
            dv.RowFilter 
= string.Format("[guid]='{0}'", df.guid);
            
switch  (df.state)
            
{
                
case 1
                DataSet1.infoTabRow r 
= ds.infoTab.NewinfoTabRow();
                r.guid 
= df.guid;
                r.approver 
= df.approver;
                r.content 
= df.content;
                r.proposer 
= df.proposer;
                r.result 
= df.result;
                r.state 
= df.state;
                ds.infoTab.Rows.Add(r);
                
break;
                
case 2:
              
                ((DataSet1.infoTabRow)dv[
0].Row).state = df.state;
                ((DataSet1.infoTabRow)dv[
0].Row).result = df.result;

                
break;
                
case 3 :

                ((DataSet1.infoTabRow)dv[
0].Row).state = df.state;
                
break ;
            }
 
        }

    }


    [ServiceBehavior(InstanceContextMode 
= InstanceContextMode.Single)]
    
class control : Icontrol
    
{
        WorkflowRuntime workflowRuntime;
        exchangeEvent obj;
        
public control(WorkflowRuntime r, exchangeEvent o)
        
{
            workflowRuntime 
= r;
            obj 
= o;
        }

        
public void begingWF(string proposer, string approver, string content)
        
{
            Dictionary
<stringobject> dc = new Dictionary<stringobject>();
            dataform df 
= new dataform();
            df.approver 
= approver;
            df.content 
= content;
            df.proposer 
= proposer;
            df.result 
= "";
            dc.Add(
"DF", df);
            WorkflowInstance instance 
= workflowRuntime.CreateWorkflow(typeof(Workflow1), dc);
            instance.Start();
        }


        
public void Approve(string guid, string result)
        
{obj.Approve(guid, result);}

        
public System.Data.DataSet GetApproverTask(string username)
        
return obj.GetApproverTask(username);}

        
public System.Data.DataSet GetProposerTask(string username)
        
return obj.GetProposerTask(username);}
    }


  [ServiceContract]
   
public interface Icontrol
    
{
        [OperationContract]
        
void Approve(string guid, string result);
        [OperationContract]
        
void begingWF(string proposer, string approver, string content);
        [OperationContract]
        System.Data.DataSet GetApproverTask(
string username);
        [OperationContract]
        System.Data.DataSet GetProposerTask(
string username);
    }

}


补充一点,对于流程结节的控制,我更喜欢用规则实现,具体见
规则引擎    http://www.cnblogs.com/foundation/archive/2007/08/18/860911.html



主要目的,方便我以后更好的查询,谢谢哥们提供这样好的东西。谢谢

posted on 2007-09-06 12:10  A A  阅读(788)  评论(1编辑  收藏  举报