2013-03-25 91 views
1

我試圖恢復持續工作流程。工作流運行在客戶機上的本地和附加到WindowsForms應用恢復持續工作流程(WorkFlow Foundation 4.5)

書籤是在擴展活動創造喜歡這裏:

/// <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); 
    } 

當我打電話

wfApp.ResumeBookmark(bookmarkName, value); 

從運行應用程序,一切工作正常。

現在我關閉應用程序,做了以下幾件事:

  • 檢查設置SQL表中現有的ID
  • 獲取ID
  • 配置工作流程
  • 試圖恢復書籤

看起來像這樣:

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的實施看起來是這樣的:

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..."); 
    } 

的問題 調用

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

後沒有任何反應..真的沒什麼。 我認爲該程序應該跳轉到scanBarcodeCallback還是我做錯了什麼?目前它真的令人沮喪因爲我不能處理這個問題。 在此先感謝

+0

在msdn論壇中發現以下內容:工作流引擎不需要此數據即可恢復工作流實例。爲了將引擎加載工作流實例恢復到內存中,然後嘗試恢復書籤。所以得到最後的書籤是不必要的?!但是,我如何恢復工作流程呢?令人困惑... – 2013-03-26 07:56:56

回答

3

問題是,你正在做的第一次運行,然後恢復:

wfApp.Run();

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

對於恢復書籤只需要ResumeBookmark。只要刪除wfApp.Run();,它應該工作。

+0

非常感謝!太簡單了......永遠不要相信MSDN論壇; x – 2013-04-05 12:36:53

相關問題