Example #1
0
        /// <summary>
        /// Starts the workflow execution
        /// </summary>
        public void Start()
        {
            if (_workflow == null)
            {
                return;
            }

            _invoker = new WorkflowInvoker(_workflow);
            _invoker.InvokeCompleted += InvokerOnInvokeCompleted;
            _invoker.Extensions.Add(new OutputWriter(this.Log));
            _invoker.Extensions.Add((_uiTextReader = new GuiTextReader()));

            if (_inputs != null && _inputs.Count > 0)
            {
                Log.Add("Input values:");
                foreach (var item in _inputs)
                {
                    Log.Add(string.Format("  {0} = {1}", item.Key, item.Value));
                }
            }

            try
            {
                IsRunning = true;
                _invoker.InvokeAsync(_inputs, this);
            }
            catch (Exception ex)
            {
                Log.Add(string.Format("Failed to start workflow: {0}", ex.Message));
                Log.Add(ex.StackTrace);
            }
        }
Example #2
0
        /// <summary>
        /// Use InvokeAsync
        /// </summary>
        private static void WorkflowInvokerAsync()
        {
            Console.WriteLine("Host: About to run workflow - Thread:{0}",
                              System.Threading.Thread.CurrentThread.ManagedThreadId);

            try
            {
                WorkflowInvoker instance = new WorkflowInvoker(
                    new HostingDemoWorkflow());
                instance.InvokeCompleted +=
                    delegate(Object sender, InvokeCompletedEventArgs e)
                {
                    Console.WriteLine(
                        "Host: Workflow completed - Thread:{0} - {1}",
                        System.Threading.Thread.CurrentThread.ManagedThreadId,
                        e.Outputs["Result"]);
                    waitEvent.Set();
                };

                instance.InvokeAsync(new Dictionary <String, Object>
                {
                    { "ArgNumberToEcho", 1001 },
                });

                Console.WriteLine("Host: Workflow started - Thread:{0}",
                                  System.Threading.Thread.CurrentThread.ManagedThreadId);
                waitEvent.WaitOne();
            }
            catch (Exception exception)
            {
                Console.WriteLine("Host: Workflow exception:{0}:{1}",
                                  exception.GetType(), exception.Message);
            }
        }
Example #3
0
        /// <summary>
        /// Executes the given action
        /// </summary>
        private async Task <IHttpActionResult> ExecuteActionAsync(
            ActionLink actionLink,
            AuthTicket authTicket,
            ContactItem contact,
            PropertyDictionary properties,
            CancellationToken cancellationToken)
        {
            var action = await _projectManager.GetActionByIdAsync(actionLink.ActionId, cancellationToken);

            if (action == null)
            {
                return(NotFound());
            }
            var project = await _projectManager.FindByIdAsync(action.Project.Id, cancellationToken);

            var users = await _securityManager.GetAccessRulesAsync(project, cancellationToken);

            var context   = Request.Properties["MS_HttpContext"] as HttpContextWrapper;
            var eventItem = context.Request.CreateEvent();

            eventItem.CustomUri = actionLink.CustomUri;
            var result = await _workflowInvoker.InvokeAsync(
                new ActionActivityContext(
                    project,
                    action,
                    authTicket,
                    contact,
                    ObjectState.Unchanged,
                    properties,
                    eventItem),
                cancellationToken);

            if (result == null)
            {
                return(new WorkflowContentResult(this));
            }
            if (result.StatusCode == ActionActivityStatusCode.Forbidden)
            {
                return(StatusCode(HttpStatusCode.Forbidden));
            }
            return(new WorkflowContentResult(result, this));
        }
Example #4
0
        // CancelAsync
        static void snippet34()
        {
            //<snippet34>
            AutoResetEvent syncEvent = new AutoResetEvent(false);

            WorkflowInvoker invoker = new WorkflowInvoker(new LongRunningDiceRoll());

            invoker.InvokeCompleted += delegate(object sender, InvokeCompletedEventArgs args)
            {
                if (args.Cancelled == true)
                {
                    Console.WriteLine("The workflow was cancelled.");
                }
                else if (args.Error != null)
                {
                    Console.WriteLine("Exception: {0}\n{1}",
                                      args.Error.GetType().FullName,
                                      args.Error.Message);
                }
                else
                {
                    Console.WriteLine("The two dice are {0} and {1}.",
                                      args.Outputs["D1"], args.Outputs["D2"]);
                }

                syncEvent.Set();
            };

            string userState = "CancelAsync Example";

            invoker.InvokeAsync(userState);

            Console.WriteLine("Waiting for the workflow to complete.");
            Thread.Sleep(TimeSpan.FromSeconds(1));

            Console.WriteLine("Attempting to cancel the workflow.");
            invoker.CancelAsync(userState);

            // Wait for the workflow to complete.
            syncEvent.WaitOne();

            Console.WriteLine("The workflow is either completed or cancelled.");
            //</snippet34>
        }
Example #5
0
        protected async void LoadFile()
        {
            if (authMethod == AuthMethodManual)
            {
                System.Diagnostics.Process.Start("IExplore.exe", authUrl);
                return;
            }


            //Try/catch
            Directory.CreateDirectory(AuthDirectoryName);
            filepath = Path.Combine(AuthDirectoryName, filename);
            AutoResetEvent syncEvent = new AutoResetEvent(false);

            if (!File.Exists(filepath))
            {
                HttpResponseMessage response = await HttpAgent.Request(HttpMethod.Get, resourceUrl, null, null, null);

                string responseContent = await response.Content.ReadAsStringAsync();

                File.WriteAllText(filepath, responseContent);

                LoadReadmeFile();
            }

            ActivityXamlServicesSettings settings = new ActivityXamlServicesSettings
            {
                CompileExpressions = true
            };

            Activity        workflow = ActivityXamlServices.Load(filepath, settings);
            WorkflowInvoker invoker  = new WorkflowInvoker(workflow);

            invoker.InvokeCompleted += delegate(object sender, InvokeCompletedEventArgs args)
            {
                syncEvent.Set();
            };
            invoker.InvokeAsync(authArguments);

            syncEvent.WaitOne();
        }
Example #6
0
        //</snippet32>

        // InvokeAsync
        static void snippet33()
        {
            //<snippet33>
            AutoResetEvent syncEvent = new AutoResetEvent(false);

            WorkflowInvoker invoker = new WorkflowInvoker(new LongRunningDiceRoll());

            invoker.InvokeCompleted += delegate(object sender, InvokeCompletedEventArgs args)
            {
                if (args.Cancelled == true)
                {
                    Console.WriteLine("Workflow was cancelled.");
                }
                else if (args.Error != null)
                {
                    Console.WriteLine("Exception: {0}\n{1}",
                                      args.Error.GetType().FullName,
                                      args.Error.Message);
                }
                else
                {
                    Console.WriteLine("The two dice are {0} and {1}.",
                                      args.Outputs["D1"], args.Outputs["D2"]);
                }

                syncEvent.Set();
            };

            invoker.InvokeAsync("InvokeAsync Example");

            Console.WriteLine("Waiting for the workflow to complete.");

            // Wait for the workflow to complete.
            syncEvent.WaitOne();

            Console.WriteLine("The workflow is complete.");
            //</snippet33>
        }