コード例 #1
0
ファイル: WorkflowInstance.cs プロジェクト: zergmk2/openrpa
 public void Run()
 {
     try
     {
         runWatch = new System.Diagnostics.Stopwatch();
         runWatch.Start();
         if (string.IsNullOrEmpty(InstanceId))
         {
             wfApp.Run();
             InstanceId = wfApp.Id.ToString();
             state      = "running";
             Save();
         }
         else
         {
             foreach (var b in Bookmarks)
             {
                 if (b.Value != null && !string.IsNullOrEmpty(b.Value.ToString()))
                 {
                     wfApp.ResumeBookmark(b.Key, b.Value);
                 }
             }
             if (Bookmarks.Count() == 0)
             {
                 wfApp.Run();
             }
             state = "running";
             Save();
         }
     }
     catch (Exception ex)
     {
         Log.Error(ex, "");
         hasError    = true;
         isCompleted = true;
         //isUnloaded = true;
         state        = "failed";
         Exception    = ex;
         errormessage = ex.Message;
         Save();
         if (runWatch != null)
         {
             runWatch.Stop();
         }
         OnIdleOrComplete?.Invoke(this, EventArgs.Empty);
     }
 }
コード例 #2
0
        public void Abort(string Reason)
        {
            if (wfApp == null)
            {
                return;
            }
            var _state = typeof(System.Activities.WorkflowApplication).GetField("state", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance).GetValue(wfApp);

            if (_state.ToString() != "Aborted")
            {
                wfApp.Abort(Reason);
                return;
            }
            hasError     = true;
            isCompleted  = true;
            state        = "aborted";
            errormessage = Reason;
            _            = Save();
            if (runWatch != null)
            {
                runWatch.Stop();
            }
            OnIdleOrComplete?.Invoke(this, EventArgs.Empty);
        }
コード例 #3
0
        private void addwfApphandlers(System.Activities.WorkflowApplication wfApp)
        {
            wfApp.Completed = delegate(System.Activities.WorkflowApplicationCompletedEventArgs e)
            {
                isCompleted = true;
                if (e.CompletionState == System.Activities.ActivityInstanceState.Faulted)
                {
                }
                else if (e.CompletionState == System.Activities.ActivityInstanceState.Canceled)
                {
                }
                else if (e.CompletionState == System.Activities.ActivityInstanceState.Closed)
                {
                    state = "completed";
                    foreach (var o in e.Outputs)
                    {
                        Parameters[o.Key] = o.Value;
                    }
                    if (runWatch != null)
                    {
                        runWatch.Stop();
                    }
                    OnIdleOrComplete?.Invoke(this, EventArgs.Empty);
                }
                else if (e.CompletionState == System.Activities.ActivityInstanceState.Executing)
                {
                }
                else
                {
                    throw new Exception("Unknown completetion state!!!" + e.CompletionState);
                }
            };

            wfApp.Aborted = delegate(System.Activities.WorkflowApplicationAbortedEventArgs e)
            {
                hasError     = true;
                isCompleted  = true;
                state        = "aborted";
                Exception    = e.Reason;
                errormessage = e.Reason.Message;
                _            = Save();
                if (runWatch != null)
                {
                    runWatch.Stop();
                }
                OnIdleOrComplete?.Invoke(this, EventArgs.Empty);
            };

            wfApp.Idle = delegate(System.Activities.WorkflowApplicationIdleEventArgs e)
            {
                var bookmarks = new Dictionary <string, object>();
                foreach (var b in e.Bookmarks)
                {
                    bookmarks.Add(b.BookmarkName, null);
                }
                Bookmarks = bookmarks;
                state     = "idle";
                _         = Save();
                if (state != "completed")
                {
                    OnIdleOrComplete?.Invoke(this, EventArgs.Empty);
                }
            };

            wfApp.PersistableIdle = delegate(System.Activities.WorkflowApplicationIdleEventArgs e)
            {
                //return PersistableIdleAction.Unload;
                _ = Save();
                return(System.Activities.PersistableIdleAction.Persist);
            };

            wfApp.Unloaded = delegate(System.Activities.WorkflowApplicationEventArgs e)
            {
                if (!isCompleted && !hasError)
                {
                    state = "unloaded";
                }
                else
                {
                    DeleteFile();
                }
                //isUnloaded = true;
                if (global.isConnected)
                {
                    _ = Save();
                }
            };

            wfApp.OnUnhandledException = delegate(System.Activities.WorkflowApplicationUnhandledExceptionEventArgs e)
            {
                hasError     = true;
                isCompleted  = true;
                state        = "failed";
                Exception    = e.UnhandledException;
                errormessage = e.UnhandledException.ToString();
                //exceptionsource = e.ExceptionSource.Id;
                if (runWatch != null)
                {
                    runWatch.Stop();
                }
                OnIdleOrComplete?.Invoke(this, EventArgs.Empty);
                return(System.Activities.UnhandledExceptionAction.Terminate);
            };
        }