posts - 17,  comments - 19,  trackbacks - 0
今天做WF 的.NET编程
一直弄了好久,对状态机方式今天终于有了一点小小的入门。还要感谢 曲滨 的程序

asp.net使用wwf
1,配置 web.config
    在 <configuration> 与<system.web>之间需要添加
<configSections>
    
<section name="WorkflowRuntime" type="System.Workflow.Runtime.Configuration.WorkflowRuntimeSection, System.Workflow.Runtime, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
    
<section name="ExternalDataExchangeService" type="System.Workflow.Activities.ExternalDataExchangeServiceSection, System.Workflow.Activities, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
  
</configSections>
 
<appSettings/>
 
<connectionStrings/>
2,在网站运行的时候就加载wf服务,编写 global.asax
System.Workflow.Runtime.WorkflowRuntime WorkflowRuntime = new System.Workflow.Runtime.WorkflowRuntime("WorkflowRuntime");

/*下面几句后面再解释*/
 System.Workflow.Activities.ExternalDataExchangeService dataService 
= new System.Workflow.Activities.ExternalDataExchangeService();
 WorkflowRuntime.AddService(dataService);
 Billdayone.MyBillWorkFlow myBillWorkFlow 
= new Billdayone.MyBillWorkFlow();
 dataService.AddService(myBillWorkFlow);
 
/*上面几句后面再解释*/
Application[
"WorkflowRuntime"= WorkflowRuntime;
 WorkflowRuntime.StartRuntime();

3.接口Interface的理解
以前一直都没怎么接触这个东东,现在觉得接口其实就是一个抽象类,由于知识有限,记住关于状态的Interface写法就好了
[ExternalDataExchange]//一定要写这个
 public interface IBillWorkFlow
 
{
        
event EventHandler<ExternalDataEventArgs> BillSubmit;//自定义状态转移事件
        event EventHandler<ExternalDataEventArgs> BillOk;
 }

//下面照着模式写,依葫芦画票
 [Serializable]
    
public class MyBillWorkFlow : IBillWorkFlow {
        
public MyBillWorkFlow() {
            System.Diagnostics.Debug.WriteLine(
"MyBillWorkFlow Init");
        }

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

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

                
catch 
                
                }

            }

        }


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

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


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

    }

4.再来解释一下global.asax中的那几个东东
 
System.Workflow.Activities.ExternalDataExchangeService dataService = new System.Workflow.Activities.ExternalDataExchangeService();
 WorkflowRuntime.AddService(dataService);
 Billdayone.MyBillWorkFlow myBillWorkFlow 
= new Billdayone.MyBillWorkFlow();
 dataService.AddService(myBillWorkFlow);
//这几个东东是把自己定义的接口类加载到WorkflowRuntime的实例中去,很重要的。

5.接下来就是操作
a.创建一个工作流
System.Workflow.Runtime.WorkflowRuntime workflowruntime = Application["WorkflowRuntime"as System.Workflow.Runtime.WorkflowRuntime;
System.Workflow.Runtime.WorkflowInstance workflowinstance 
=  workflowruntime.CreateWorkflow(typeof(Billdayone.BillWorkFlow));
workflowinstance.Start();
b.得到该WorkflowRuntime的所有正在执行的工作流
System.Workflow.Runtime.WorkflowRuntime workflowruntime = application["WorkflowRuntime"as System.Workflow.Runtime.WorkflowRuntime;
System.Collections.ObjectModel.ReadOnlyCollection
<System.Workflow.Runtime.WorkflowInstance> listWorkflowInstance = workflowruntime.GetLoadedWorkflows();
foreach (System.Workflow.Runtime.WorkflowInstance key in listWorkflowInstance) {
            System.Workflow.Activities.StateMachineWorkflowInstance stateWorkflow 
= new System.Workflow.Activities.StateMachineWorkflowInstance(workflowruntime, key.InstanceId);
            WorkFlowShow 
+= key.InstanceId + " " + stateWorkflow.CurrentState.QualifiedName + " <input type=\"button\" name=\"button\" id=\"button\" value=\"next\" onclick=\"document.getElementById('TextBox2').value='"+key.InstanceId+"'\" />" + "</br>";
        }

c.执行一个工作流,转化其状态
Billdayone.MyBillWorkFlow mMyworkflow = (Application["WorkflowRuntime"as System.Workflow.Runtime.WorkflowRuntime).GetService<Billdayone.MyBillWorkFlow>();

if (mMyworkflow != null)
        
{
            System.Workflow.Activities.StateMachineWorkflowInstance stateWorkflow 
= new System.Workflow.Activities.StateMachineWorkflowInstance(Application["WorkflowRuntime"as System.Workflow.Runtime.WorkflowRuntime, instanceId);
            
if (stateWorkflow.CurrentStateName == "stateInit")
            
{
                mMyworkflow.RaisEvent(
"BillSubmit", instanceId);
            }

            
if (stateWorkflow.CurrentStateName == "stateFinance")
            
{
                mMyworkflow.RaisEvent(
"BillOk", instanceId);
            }


        }

        
else {
            System.Diagnostics.Debug.WriteLine(
"mMyworkflow not found");
        }

好了,只能做到这里,关于如何传参数以及把工作流从内存中保存下来要进一步学些。。。

downloadBilldayone.rar 开发环境 .net2005安装.net framework 3.0安装winfx安装Visual Studio 2005 extensions for .NET Framework 3.0 (Windows Workflow Foundation)
iis 5.1 os winxp
posted on 2008-07-06 21:45 poplau 阅读(230) 评论(0)  编辑 收藏 所属分类: workflow

标题  
姓名  
主页
Email (博主才能看到) 
验证码 *  看不清,换一张 [登录][注册]
内容(请不要发表任何与政治相关的内容)  
博客园首页

新闻频道

社区

小组

博问

网摘

闪存

  登录  使用高级评论  新用户注册  返回页首  恢复上次提交      
该文被作者在 2008-07-07 13:34 编辑过
成果网帮您增加网站收入


相关链接:
 


<2008年7月>
293012345
6789101112
13141516171819
20212223242526
272829303112
3456789

我要找工作,熟悉.NET(AJAX) 和JAVASCRIPT,也会CSS+DIV,做界面还不错,想在重庆找工作啊。 9-1 18:18

与我联系

搜索

 

常用链接

留言簿

我参加的小组

我的标签

随笔分类

随笔档案

最新评论

  • 1. re: application和站点停止
  • @斧头帮少帮主
    恩,可能是这样的,因此,使用IISRESET命令或者更改WEBCONFIG文件是最好的,可以把APPLICATION里面的数据清空
  • --poplau
  • 2. re: application和站点停止
  • 不太确定的说,停止后得等一会才能把缓存和正在执行的线程停止.好些不是立即回收.
  • --斧头帮少帮主
  • 3. re: 遗憾
  • 你要是看过颁奖礼仪的服装,就会感觉这个其实还算不错
  • --丁学
  • 4. re: 遗憾
  • 看看这里,一切都会明白:



  • --要有好的心情
  • 5. re: 遗憾
  • 我是愤青,我很愤怒!!!!
  • --鬼不灵

阅读排行榜

评论排行榜