Exemple #1
0
        static void Main(string[] args)
        {
            Boolean isRunning = true;

            while (isRunning)
            {
                try
                {
                    AutoResetEvent syncEvent = new AutoResetEvent(false);

                    WorkflowApplication wfApp =
                        new WorkflowApplication(new BookmarkCalculatorExtension());

                    wfApp.Completed = delegate(
                        WorkflowApplicationCompletedEventArgs e)
                    {
                        if (e.CompletionState == ActivityInstanceState.Closed)
                        {
                            Console.WriteLine("Result = {0}", e.Outputs["Result"]);
                        }
                        syncEvent.Set();
                    };

                    wfApp.Idle = delegate(WorkflowApplicationIdleEventArgs e)
                    {
                        Console.WriteLine("Workflow is idle");
                    };

                    wfApp.OnUnhandledException = delegate(
                        WorkflowApplicationUnhandledExceptionEventArgs e)
                    {
                        Console.WriteLine(e.UnhandledException.Message.ToString());
                        return(UnhandledExceptionAction.Terminate);
                    };

                    HostEventNotifier extension = new HostEventNotifier();
                    extension.Notification += delegate(
                        Object sender, HostNotifyEventArgs e)
                    {
                        Console.WriteLine(e.Message);
                        String expression = Console.ReadLine();

                        if ((String.IsNullOrEmpty(expression)) ||
                            (!String.IsNullOrEmpty(expression) &&
                             expression.Trim().ToLower() == "quit"))
                        {
                            wfApp.Cancel();
                            Console.WriteLine("Exiting program");
                            isRunning = false;
                        }
                        else if (IsBookmarkValid(wfApp, e.BookmarkName))
                        {
                            wfApp.ResumeBookmark(e.BookmarkName, expression);
                        }
                    };

                    wfApp.Extensions.Add(extension);
                    wfApp.Run();
                    syncEvent.WaitOne();
                }
                catch (Exception exception)
                {
                    Console.WriteLine("Error: {0}", exception.Message);
                }
            }
        }
Exemple #2
0
        static void Main(string[] args)
        {
            try
            {
                AutoResetEvent syncEvent = new AutoResetEvent(false);

                WorkflowApplication wfApp =
                    new WorkflowApplication(new ProblemReporting());

                wfApp.Completed = delegate(
                    WorkflowApplicationCompletedEventArgs e)
                {
                    syncEvent.Set();
                };

                wfApp.Idle = delegate(WorkflowApplicationIdleEventArgs e)
                {
                    Console.WriteLine("Workflow is idle");
                };

                wfApp.OnUnhandledException = delegate(
                    WorkflowApplicationUnhandledExceptionEventArgs e)
                {
                    Console.WriteLine(e.UnhandledException.Message.ToString());
                    return(UnhandledExceptionAction.Terminate);
                };

                HostEventNotifier extension = new HostEventNotifier();
                extension.Notification += delegate(
                    Object sender, HostNotifyEventArgs e)
                {
                    Console.WriteLine(e.Message);

                    var bookmarks = wfApp.GetBookmarks();
                    if (bookmarks != null && bookmarks.Count > 0)
                    {
                        Console.WriteLine("Select one of these available actions:");
                        foreach (BookmarkInfo bookmark in bookmarks)
                        {
                            Console.WriteLine("->{0}", bookmark.BookmarkName);
                        }
                    }

                    Boolean isWaitingForChoice = true;
                    while (isWaitingForChoice)
                    {
                        String newAction = Console.ReadLine();
                        if (IsBookmarkValid(wfApp, newAction))
                        {
                            isWaitingForChoice = false;
                            wfApp.ResumeBookmark(newAction, null);
                        }
                        else
                        {
                            Console.WriteLine("Incorrect choice!");
                        }
                    }
                };

                wfApp.Extensions.Add(extension);
                wfApp.Run();
                syncEvent.WaitOne();
            }
            catch (Exception exception)
            {
                Console.WriteLine("Error: {0}", exception.Message);
            }
        }