首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >恢复持久化WorkFlow (WorkFlow Foundation4.5)

恢复持久化WorkFlow (WorkFlow Foundation4.5)
EN

Stack Overflow用户
提问于 2013-03-25 16:43:24
回答 1查看 4.1K关注 0票数 1

我试图恢复一个持续的工作流程。工作流在客户端机器上本地运行,并附加到WindowsForms应用程序

书签是在一个扩展活动中创建的,如下所示:

代码语言:javascript
复制
 /// <summary>
    /// Will be executed if the bookmark gets executed.
    /// </summary>
    protected override void Execute(NativeActivityContext context)
    {
        ScanBarcodeExtension requestToScanBarcode = context.GetExtension<ScanBarcodeExtension>();
        requestToScanBarcode.GetScanResult(UserMessage.Get(context), BookmarkName.Get(context), ExpectedScanActivity.Get(context));
        context.CreateBookmark(BookmarkName.Get(context),  new BookmarkCallback(scanBarcodeCallback));
    }

    /// <summary>
    /// Scans the magazine barcode callback.
    /// </summary>
    /// <param name="context">The context.</param>
    /// <param name="bookmark">The bookmark.</param>
    /// <param name="value">The value.</param>
    private void scanBarcodeCallback(NativeActivityContext context, Bookmark bookmark, object value)
    {
        WorkflowArgumentContainer container = context.GetValue(this.ArgumentContainer);
        switch ((ScanActivity)ExpectedScanActivity.Get(context))
        {
            case ScanActivity.FAUF:
                container.FaufId = (value as string);
                break;
            case ScanActivity.Magazine:
                container.CurrentMagazine.ID = (value as string);
                break;
            case ScanActivity.AluPack:
                container.PrintAluPackLabelProcessResult.ScannedLabelContent = (value as string);
                break;
            case ScanActivity.Box:
                container.PrintBoxLabelProcessResult.ScannedLabelContent = (value as string);
                break;
            default:
                break;
        }

        Result.Set(context, container);
    }

当我打电话的时候

代码语言:javascript
复制
wfApp.ResumeBookmark(bookmarkName, value);

从运行中的应用程序来看,一切都很好。

现在关闭应用程序并执行以下操作:

  • 签入sql表中的现有id。
  • 拿到身份证
  • 配置工作流
  • 试图恢复书签

A这个看起来是这样的:

代码语言:javascript
复制
   logger.Info("Persisted workflow found. Loading workflow states...");
        WorkflowApplicationInstance instance = WorkflowApplication.GetInstance(this.workflowInstanceId, sqlStore);
        WorkflowApplication wfApp = new WorkflowApplication(new ConditioningWF(), instance.DefinitionIdentity);

        logger.Info("Configuring persisted workflow...");
        this.configureWorkflowApplication(wfApp);

        wfApp.Load(instance);
        logger.Info("Getting blocking bookmarks from persisted workflow...");
        string bookmark = this.getBlockingBookmarksFromPersistedWorkFlow(wfApp.Id);
        if (string.IsNullOrEmpty(bookmark))
            throw new MissingArgumentExceptions(string.Format("Kein Bookmark für den persistierten WorkFlow mit der ID '{0}' gefunden!", wfApp.Id));

        logger.Info("Running persisted workflow...");
        wfApp.Run();

        logger.InfoFormat("Resuming bookmark '{0}'...", bookmark);
        wfApp.ResumeBookmark("ScanMagazine", string.Empty);

configureWorkFlowApplication的实现如下所示:

代码语言:javascript
复制
 private void configureWorkflowApplication(WorkflowApplication wfApp)
    {
        // Configure the persistence store.
        wfApp.InstanceStore = sqlStore;

        // Instance the extensions...
        MESWebserviceExtension mesDataAccessExtension = new MESWebserviceExtension();
        ExceptionNotificationExtension exceptionNotifiyExtension = new ExceptionNotificationExtension();
        ScanBarcodeExtension scanBarcodeExtension = new ScanBarcodeExtension();
        NotifyFaufRegisteredExtension notifyFaufRegisteredExtension = new NotifyFaufRegisteredExtension();
        FuseAluPackExtension fuseAluPackExtension = new FuseAluPackExtension();

        exceptionNotifiyExtension.OnNotifiyException += exceptionNotifiyExtension_OnNotifiyException;
        scanBarcodeExtension.OnGetFaufScan += scanBarcodeExtension_OnGetFaufScan;
        notifyFaufRegisteredExtension.OnFaufRegistered += notifyFaufRegisteredExtension_OnFaufRegistered;
        scanBarcodeExtension.OnGetMagazinScan += scanBarcodeExtension_OnGetMagazinScan;
        fuseAluPackExtension.OnGetFuseResult += fuseAluPackExtension_OnGetFuseResult;


        //...add extensions
        wfApp.Extensions.Add(exceptionNotifiyExtension);
        wfApp.Extensions.Add(mesDataAccessExtension);

        wfApp.Extensions.Add(notifyFaufRegisteredExtension);
        wfApp.Extensions.Add(scanBarcodeExtension);
        wfApp.Extensions.Add(fuseAluPackExtension);

        #region WF States changed
        wfApp.Completed = delegate(WorkflowApplicationCompletedEventArgs e)
        {
            if (e.CompletionState == ActivityInstanceState.Faulted)
            {
                logger.Error(String.Format("...Workflow '{0}' terminated: {1}", e.InstanceId, e.TerminationException.Message), e.TerminationException);

                if (System.Diagnostics.Debugger.IsAttached)
                {
                    MboxStatus(string.Format("Workflow Terminated. Exception: {0}\r\n{1}",
                        e.TerminationException.GetType().FullName,
                        e.TerminationException.Message));
                }
            }
            else if (e.CompletionState == ActivityInstanceState.Canceled)
            {

                logger.WarnFormat("...Workflow '{0}' canceled...", e.InstanceId);

                if (System.Diagnostics.Debugger.IsAttached)
                {
                    MboxStatus("Workflow Canceled.");
                }
            }
            else
            {
                logger.WarnFormat("...Workflow '{0}' completed...", e.InstanceId);

                if (System.Diagnostics.Debugger.IsAttached)
                {
                    MboxStatus("Fertig");
                }
            }
        };

        wfApp.Aborted = delegate(WorkflowApplicationAbortedEventArgs e)
        {
            logger.Error(String.Format("...Workflow '{0}' aborted  '{0}' : {1}",
                    e.InstanceId, e.Reason.Message), e.Reason);


            if (System.Diagnostics.Debugger.IsAttached)
            {
                MboxStatus(string.Format("Workflow Aborted. Exception: {0}\r\n{1}",
                        e.Reason.GetType().FullName,
                        e.Reason.Message));
            }
        };

        wfApp.OnUnhandledException = delegate(WorkflowApplicationUnhandledExceptionEventArgs e)
        {
            logger.Error(String.Format("...UnhandledException occured in Workflow '{0}' : {1}",
                                    e.InstanceId, e.UnhandledException.Message), e.UnhandledException);


            if (System.Diagnostics.Debugger.IsAttached)
            {
                MboxStatus(string.Format("Unhandled Exception: {0}\r\n{1}",
                        e.UnhandledException.GetType().FullName,
                        e.UnhandledException.Message));
            }
            return UnhandledExceptionAction.Terminate;
        };

        wfApp.PersistableIdle = delegate(WorkflowApplicationIdleEventArgs e)
        {
            logger.InfoFormat("...Workflow '{0}' unloaded...", e.InstanceId);

            return PersistableIdleAction.Unload;
        };

        // Workflow lifecycle events omitted except idle.
        AutoResetEvent idleEvent = new AutoResetEvent(false);
        wfApp.Idle = delegate(WorkflowApplicationIdleEventArgs e)
        {
            idleEvent.Set();
        };
        #endregion

        logger.Info("...configuring WorkflowApplication finished...");
    }

调用后的问题

代码语言:javascript
复制
   wfApp.ResumeBookmark("ScanMagazine", string.Empty);

什么都没发生..。真的什么都没有。我认为程序应该跳转到scanBarcodeCallback,还是我做错了什么?就目前而言,这真的是令人沮丧的,因为我不能处理这件事。提前感谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-04-04 23:28:02

问题是,您正在进行第一次运行,然后继续运行:

wfApp.Run();

wfApp.ResumeBookmark("ScanMagazine", string.Empty);

对于恢复书签,只需要ResumeBookmark。只要删除wfApp.Run();,它就能工作了。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15620233

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档