Esempio n. 1
0
        /// <summary>
        /// Creates a new Workflow Application instance and executes the Current Workflow
        /// </summary>
        private void CmdWorkflowRun(object sender, ExecutedRoutedEventArgs e)
        {
            _wfApp?.Abort();

            var name = Name;
            var m    = new ExecutionMessage()
            {
                ExecutionState = "WorkflowStart", Sender = Name, ParentNames = new string[0]
            };

            subject.OnNext(m);
            var s = string.Format("[{0}] [{1}] [{2}]",
                                  DateTime.Now.ToString("HH:mm:ss"),
                                  m.Sender,
                                  m.ExecutionState);

            LogExecution(s);

            var activityExecute = GetActivity();

            //configure workflow application
            executionLog.Text = string.Empty;
            //consoleOutput.Text = string.Empty;
            _executionLog         = new ExecutionLogger();
            disposable.Disposable = _executionLog.Messages.Subscribe(InjectExecutionLog);

            _wfApp = new WorkflowApplication(activityExecute);
            _wfApp.Extensions.Add(_executionLog);
            _wfApp.Completed = WfExecutionCompleted;
            _wfApp.Aborted   = WfAborted;

            //execute
            _wfApp.Run();
        }
            public void Run()
            {
                Guid id;

                Guid.TryParse(DataTransferObject.ParentInstanceID, out id);
                ID          = DataTransferObject.ResourceID;
                ParentID    = DataTransferObject.ParentID;
                WorkspaceID = DataTransferObject.WorkspaceID;

                // handle queuing
                WaitForSlot();

                // abort the execution - no space at the inn
                if (!ExecutableServiceRepository.Instance.DoesQueueHaveSpace())
                {
                    _instance.Abort();
                }
                else
                {
                    ExecutableServiceRepository.Instance.Add(this);
                    // here is space at the inn ;)
                    var wfappUtils = new WfApplicationUtils();

                    if (DataTransferObject.IsDebugMode())
                    {
                        ErrorResultTO invokeErrors;
                        wfappUtils.DispatchDebugState(DataTransferObject, StateType.Start, AllErrors.HasErrors(), AllErrors.MakeDisplayReady(), out invokeErrors, null, true);
                        AllErrors.MergeErrors(invokeErrors);
                    }

                    _previousNumberOfSteps           = DataTransferObject.NumberOfSteps;
                    DataTransferObject.NumberOfSteps = 0;
                    _instance.Run();
                }
            }
Esempio n. 3
0
 public void Dispose()
 {
     if (!_isComplete && _wfApp != null)
     {
         _wfApp.Abort();
     }
 }
Esempio n. 4
0
 protected override void StopInternal()
 {
     if (IsRunning && workflowApplication != null)
     {
         workflowApplication.Abort();
     }
 }
Esempio n. 5
0
        private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            Debug.WriteLine("UI Closing");

            wfApp.Aborted = null;
            wfApp.Abort();
        }
Esempio n. 6
0
 public override void Stop()
 {
     if (IsRunning && workflowApplication != null)
     {
         workflowApplication.Abort();
     }
 }
 private void CleanupWorkflow()
 {
     if (_workflowInstance != null)
     {
         _onWorkflowCleanup = true;
         _workflowInstance.Abort();
         _workflowInstance = null;
     }
 }
 /// <summary>
 /// Stops the Current Workflow
 /// </summary>
 private void CmdWorkflowStop(object sender, ExecutedRoutedEventArgs e)
 {
     //manual stop
     if (_wfApp != null)
     {
         _wfApp.Abort("Stopped by User");
         _timer.Stop();
         UpdateTrackingData();
     }
 }
Esempio n. 9
0
        private static void RunActivity(Activity activity, TestType testType)
        {
            Console.WriteLine("\n{0} {1}", activity.DisplayName, testType);

            AutoResetEvent      waitEvent = new AutoResetEvent(false);
            WorkflowApplication wfApp     = new WorkflowApplication(activity);

            wfApp.Completed = (e) =>
            {
                Console.WriteLine("WorkflowApplication.Completed");
                waitEvent.Set();
            };

            wfApp.Aborted = (e) =>
            {
                Console.WriteLine("WorkflowApplication.Aborted");
                waitEvent.Set();
            };

            wfApp.OnUnhandledException = (e) =>
            {
                Console.WriteLine("WorkflowApplication.OnUnhandledException: {0}",
                                  e.UnhandledException.Message);
                return(UnhandledExceptionAction.Cancel);
            };

            wfApp.Run();

            switch (testType)
            {
            case TestType.Cancel:
                Thread.Sleep(100);
                wfApp.Cancel();
                break;

            case TestType.Abort:
                Thread.Sleep(100);
                wfApp.Abort("Abort was called");
                break;

            case TestType.Terminate:
                Thread.Sleep(100);
                wfApp.Terminate("Terminate was called");
                break;

            default:
                break;
            }

            waitEvent.WaitOne(TimeSpan.FromSeconds(60));
        }
        private void GetBookMarksOnAbortedWorkflow(bool isDefaultTimeout)
        {
            const string traceToWaitMsg = "Continue WaitForTrace1";
            Sequence     sequence       = new Sequence()
            {
                Activities =
                {
                    new WaitForTrace()
                    {
                        DisplayName = "WaitForTrace1",
                        TraceToWait = new InArgument <string>(traceToWaitMsg)
                    },
                    new ReadLine <string>(bookMarkName_InvalidOperationsOnAbortedWorkflow)
                    {
                    }
                }
            };

            WorkflowApplication instance = new WorkflowApplication(sequence)
            {
                Aborted = OnWorkflowInstanceAborted
            };

            instance.Run();

            TestTraceManager.Instance.WaitForTrace(instance.Id, new SynchronizeTrace(WaitForTrace.EnterExecute), 1);
            instance.Abort();
            //Continue WaitForTrace. The instance should get aborted after WaitForTrace1 activity is done
            TestTraceManager.Instance.AddTrace(instance.Id, new SynchronizeTrace(traceToWaitMsg));
            SynchronizeTrace.Trace(instance.Id, traceToWaitMsg);

            TestTraceManager.Instance.WaitForTrace(instance.Id, new SynchronizeTrace(WorkflowInstanceAbortTests.AbortedHandlerCalled), 1);
            string message = String.Format(ExceptionStrings.WorkflowApplicationAborted, instance.Id);

            ExceptionHelpers.CheckForException(typeof(WorkflowApplicationAbortedException), message,
                                               delegate
            {
                if (isDefaultTimeout)
                {
                    instance.GetBookmarks();
                }
                else
                {
                    instance.GetBookmarks(TimeSpan.FromMilliseconds(1));
                }
            });
        }
Esempio n. 11
0
        /// <summary>
        /// Allows the demonstration of various scenarios using
        /// WorkflowApplication
        /// </summary>
        private static void BasicApplicationTest(TestScenario scenario)
        {
            AutoResetEvent waitEvent = new AutoResetEvent(false);

            WorkflowApplication wfApp = new WorkflowApplication(
                new HostingDemoWorkflow(),
                new Dictionary <String, Object>
            {
                { "ArgNumberToEcho", 1001 },
            });

            wfApp.Completed = delegate(WorkflowApplicationCompletedEventArgs e)
            {
                switch (e.CompletionState)
                {
                case ActivityInstanceState.Closed:
                    Console.WriteLine("Host: {0} Closed - Thread:{1} - {2}",
                                      wfApp.Id,
                                      System.Threading.Thread.CurrentThread.ManagedThreadId,
                                      e.Outputs["Result"]);
                    break;

                case ActivityInstanceState.Canceled:
                    Console.WriteLine("Host: {0} Canceled - Thread:{1}",
                                      wfApp.Id,
                                      System.Threading.Thread.CurrentThread.ManagedThreadId);
                    break;

                case ActivityInstanceState.Executing:
                    Console.WriteLine("Host: {0} Executing - Thread:{1}",
                                      wfApp.Id,
                                      System.Threading.Thread.CurrentThread.ManagedThreadId);
                    break;

                case ActivityInstanceState.Faulted:
                    Console.WriteLine(
                        "Host: {0} Faulted - Thread:{1} - {2}:{3}",
                        wfApp.Id,
                        System.Threading.Thread.CurrentThread.ManagedThreadId,
                        e.TerminationException.GetType(),
                        e.TerminationException.Message);
                    break;

                default:
                    break;
                }
                waitEvent.Set();
            };

            wfApp.OnUnhandledException =
                delegate(WorkflowApplicationUnhandledExceptionEventArgs e)
            {
                Console.WriteLine(
                    "Host: {0} OnUnhandledException - Thread:{1} - {2}",
                    wfApp.Id,
                    System.Threading.Thread.CurrentThread.ManagedThreadId,
                    e.UnhandledException.Message);
                waitEvent.Set();
                return(UnhandledExceptionAction.Cancel);
            };

            wfApp.Aborted = delegate(WorkflowApplicationAbortedEventArgs e)
            {
                Console.WriteLine("Host: {0} Aborted - Thread:{1} - {2}:{3}",
                                  wfApp.Id,
                                  System.Threading.Thread.CurrentThread.ManagedThreadId,
                                  e.Reason.GetType(), e.Reason.Message);
                waitEvent.Set();
            };

            wfApp.Idle = delegate(WorkflowApplicationIdleEventArgs e)
            {
                Console.WriteLine("Host: {0} Idle - Thread:{1}",
                                  wfApp.Id,
                                  System.Threading.Thread.CurrentThread.ManagedThreadId);
            };

            wfApp.PersistableIdle = delegate(WorkflowApplicationIdleEventArgs e)
            {
                Console.WriteLine("Host: {0} PersistableIdle - Thread:{1}",
                                  wfApp.Id,
                                  System.Threading.Thread.CurrentThread.ManagedThreadId);
                return(PersistableIdleAction.Unload);
            };

            wfApp.Unloaded = delegate(WorkflowApplicationEventArgs e)
            {
                Console.WriteLine("Host: {0} Unloaded - Thread:{1}",
                                  wfApp.Id,
                                  System.Threading.Thread.CurrentThread.ManagedThreadId);
            };

            try
            {
                Console.WriteLine("Host: About to run {0} - Thread:{1}",
                                  wfApp.Id,
                                  System.Threading.Thread.CurrentThread.ManagedThreadId);

                //determine the demonstration scenario
                switch (scenario)
                {
                case TestScenario.Normal:
                    wfApp.Run();
                    waitEvent.WaitOne();
                    break;

                //case TestScenario.TimeSpan:
                //    wfApp.Run(TimeSpan.FromSeconds(1));
                //    waitEvent.WaitOne();
                //    break;

                case TestScenario.Cancel:
                    wfApp.Run();
                    //Wait just a bit then cancel the workflow
                    Thread.Sleep(1000);
                    wfApp.Cancel();
                    waitEvent.WaitOne();
                    break;

                case TestScenario.Abort:
                    wfApp.Run();
                    //Wait just a bit then abort the workflow
                    Thread.Sleep(1000);
                    wfApp.Abort("My aborted reason");
                    waitEvent.WaitOne();
                    break;

                case TestScenario.Terminate:
                    wfApp.Run();
                    //Wait just a bit then terminate the workflow
                    Thread.Sleep(1000);
                    wfApp.Terminate("My termination reason");
                    waitEvent.WaitOne();
                    break;

                case TestScenario.BeginRun:
                    wfApp.BeginRun(delegate(IAsyncResult ar)
                    {
                        Console.WriteLine(
                            "Host: {0} BeginRunCallback - Thread:{1}",
                            wfApp.Id,
                            System.Threading.Thread.CurrentThread.ManagedThreadId);
                        ((WorkflowApplication)ar.AsyncState).EndRun(ar);
                    }, wfApp);
                    waitEvent.WaitOne();
                    break;

                default:
                    break;
                }
            }
            catch (Exception exception)
            {
                Console.WriteLine("Host: {0} exception:{1}:{2}",
                                  wfApp.Id, exception.GetType(), exception.Message);
            }
        }
Esempio n. 12
0
 private void Abort_Click(object sender, RoutedEventArgs e)
 {
     wa.Abort();
 }
Esempio n. 13
0
 public void Abort()
 {
     _workflow.Abort();
 }
Esempio n. 14
0
        static void Main(string[] args)
        {
            Activity wf  = new SampleWorkflow();
            var      app = new WorkflowApplication(wf);

            // http://blogs.msmvps.com/theproblemsolver/2011/01/07/doing-synchronous-workflow-execution-using-the-workflowapplication/
            // app.SynchronizationContext = new SynchronousSynchronizationContext();

            app.Run();
            while (true)
            {
                System.Threading.Thread.Sleep(100);
                try
                {
                    var bms = app.GetBookmarks();
                    Console.WriteLine();
                    Console.WriteLine();
                    var n = 0;
                    foreach (var bm in bms)
                    {
                        n++;
                        Console.WriteLine("[{1} {0}] ", bm.BookmarkName, n);
                    }
                    Console.Write("Enter 1..{0} or q-quit: ", bms.Count);
                    var l = Console.ReadLine();
                    switch (l.Trim().ToLowerInvariant())
                    {
                    case "q":
                        app.Abort();
                        return;

                    case "1":
                        app.ResumeBookmark(bms[0].BookmarkName, null);
                        break;

                    case "2":
                        app.ResumeBookmark(bms[1].BookmarkName, null);
                        break;

                    case "3":
                        app.ResumeBookmark(bms[2].BookmarkName, null);
                        break;

                    case "4":
                        app.ResumeBookmark(bms[3].BookmarkName, null);
                        break;

                    case "5":
                        app.ResumeBookmark(bms[4].BookmarkName, null);
                        break;
                    }
                }
                catch (Exception ex)
                {
                    app.Abort();
                    Console.Write("{0}. Press return to quit ... ", ex.Message);
                    Console.ReadLine();
                    return;
                }
            }
        }