• WF4.0 Beta1 持久化(SqlPersistenceProviderFactory)


    WF4.0 Beta1 持久化 (SqlPersistenceProviderFactory)

    SqlPersistenceProviderFactory与PersistenceProvider

    名称空间: System.ServiceModel.Persistence

    类文件: System.WorkflowServices.dll

    数据库脚本: [\Windows\Microsoft.NET\Framework\v4.0.20506\SQL\en] 目录中

    功能类

    public class wfTools

    {

    //System.ServiceModel.Persistence

    //System.WorkflowServices.dll

    static SqlPersistenceProviderFactory persistenceProviderFactory;

     

    public static void openPersistence()

    {

    persistenceProviderFactory =new SqlPersistenceProviderFactory

    (

    @"Data Source=.\SQLEXPRESS;AttachDbFilename=c:\persistence.mdf;Integrated Security=True",

    false,

    false,

    TimeSpan.FromSeconds(60)

    );

    persistenceProviderFactory.Open();

    }

     

    public static void closePersistence()

    {

    persistenceProviderFactory.Close();

    }

     

    public static WorkflowInstance createWorkflow(WorkflowElement workflow, Guid id)

    {

     

    WorkflowInstance instance = new WorkflowInstance(workflow, id);

     

    bindingInstanceEvent(instance);

     

    PersistenceProvider pp = persistenceProviderFactory.CreateProvider(id);

    instance.Extensions.Add(pp);

     

    return instance;

    }

     

     

    public static WorkflowInstance loadWorkflow(WorkflowElement workflow, Guid id)

    {

    PersistenceProvider pp = persistenceProviderFactory.CreateProvider(id);

    WorkflowInstance instance = WorkflowInstance.Load(workflow, pp);

    bindingInstanceEvent(instance);

    return instance;

    }

     

     

    static void bindingInstanceEvent(WorkflowInstance instance)

    {

     

    instance.OnIdle = idel;

    instance.OnUnloaded = unloaded;

    instance.OnUnhandledException = unhandledException;

    instance.OnCompleted = completed;

    }

     

     

     

    static void unloaded()

    {

    System.Console.WriteLine("unloaded");

    }

     

    static IdleAction idel()

    {

    System.Console.WriteLine("idel");

    return IdleAction.Unload;

    }

     

    static void completed(WorkflowCompletedEventArgs e)

    {

    System.Console.WriteLine("completed");

    }

     

    static void aborted(WorkflowAbortedEventArgs e)

    {

    System.Console.WriteLine("aborted", e.Reason.Message);

    }

     

    static UnhandledExceptionAction unhandledException(WorkflowUnhandledExceptionEventArgs e)

    {

    System.Console.WriteLine("unhandledException{0}", e.UnhandledException.Message);

     

    return UnhandledExceptionAction.Abort;

    }

     

    }

     

    例子流程

    等待触发

    public class myBookmark : NativeActivity

    {

    public string bookmarkName { get; set; }

    protected override void Execute(ActivityExecutionContext context)

    {

    context.CreateNamedBookmark(bookmarkName);

    }

    }

    流程

     

     

    使用

    第一组代码

    Guid id = new Guid("DB35221A-C901-46F7-8075-E65A8D97FE13");

    wfTools.openPersistence();

     

    WorkflowInstance myInstance = wfTools.createWorkflow(new Sequence1(), id);

    myInstance.Run();

     

    System.Console.Read();

     

    第二组代码

    Guid id = new Guid("DB35221A-C901-46F7-8075-E65A8D97FE13");

    wfTools.openPersistence();

     

    WorkflowInstance myInstance = wfTools.loadWorkflow(new Sequence1(), id);

    myInstance.ResumeBookmark("wxd", null);

     

    System.Console.Read();

     

     

     

  • 相关阅读:
    STL 算法 std::min
    SAP UI5 初学者教程之五:视图控制器初探 试读版
    SAP UI5 的初始化过程
    Angular 应用里的摇树优化
    Angular 应用里的 vendor.js 是用来干什么的?
    SAP UI5 初学者教程之四:XML 视图初探试读版
    SAP UI5 初学者教程之三:开始接触第一个 SAP UI5 控件 试读版
    SAP UI5 初学者教程之二:SAP UI5 的引导过程(Bootstrap) 试读版
    SAP UI5 初学者教程之一:Hello World 试读版
    SAP UI5 初学者教程的学习目录
  • 原文地址:https://www.cnblogs.com/foundation/p/1532422.html
Copyright © 2020-2023  润新知