public Assignment Process(Assignment co)
        {
            if (co == null)
            {
                throw new ArgumentNullException("co");
            }
            if (co.FlowInstanceIdentifier == null)
            {
                throw new ArgumentNullException("co.FlowInstanceIdentifier");
            }

            var signale = new ReceiverSignal("http://helpdesk/CaseHandling", "Accept", "AcceptAction");
            var context = Context.WorkflowManager.Resume(co.FlowInstanceIdentifier.Value, signale);


            if (context.State == FlowState.Waiting ||
                context.State == FlowState.Completed)
            {
                Assignment assignment = null;
                // it was timeout
                if (context.State == FlowState.Waiting)
                {
                    assignment = null;
                }
                // it was accepted
                if (context.State == FlowState.Completed)
                {
                    assignment = (Assignment)context.VariableContainer["assignment"];
                }

                return(assignment);
            }
            // send user friendly as a fault message in the service
            throw new Exception("Error occurred, we expected a suspend or completed state for workflow", context.Exception);
        }
Esempio n. 2
0
        private void AskOptions(IRuntimeEngine eng, Application app)
        {
            var res = eng.Run(app);
            var ctx = (WorkflowExecutionContext)res.Context;

            WriteContext(ctx);

            // Keep resuming the workflow while it is in the Waiting state
            while (ctx.State == FlowState.Waiting)
            {
                // Retrieve the available options from the Workflow
                var options = ctx.GetReceivers().ToList();
                Console.WriteLine("Please select options below:");
                for (int index = 0; index < options.Count; index++)
                {
                    var op = options[index];
                    Console.WriteLine("({0}) {1} ({2})", index + 1, op.Title, op.DisplayName);
                }
                Console.Write("Select the number>");
                // Get user input
                var value = Console.ReadLine();

                int selection = 0;
                if (int.TryParse(value, out selection))
                {
                    // Load the context from storage
                    ctx = ReadContext();

                    // creating a signal
                    var signal = new ReceiverSignal(options[selection - 1].Title);

                    // resume the workflow using a signal
                    res = eng.Workflow.Resume(ctx, signal);
                }

                ctx = (WorkflowExecutionContext)res.Context;

                // update the context in the storage
                WriteContext(ctx);

                // and keep doing it until it is finished!
            }
            app = (Application)res.Context.VariableContainer["app"];
            Console.WriteLine("Your application is: {0}", app.Status);
            Console.WriteLine("State of workflow: {0}", ctx.State);
        }
Esempio n. 3
0
        private void Vote(IRuntimeEngine eng)
        {
            // Run the workflow voting on majority vote 50% and higher decide on the output
            var votingThreshold = 0.5;
            var res             = eng.Run(votingThreshold);

            var ctx = (WorkflowExecutionContext)res.Context;

            WriteContext(ctx);

            // Keep resuming the workflow while it is in the Waiting state
            while (ctx.State == FlowState.Waiting)
            {
                // Retrieve the available options from the Workflow
                var task = ctx.GetReceivers().ToList();
                Console.WriteLine("Please select options below:");
                var workIdentity = task[0];
                var outcomes     = workIdentity.Outcomes;
                var service      = eng.Workflow.Registry.GetService <ITaskService>();
                var options      = outcomes.Select(x => x.Name).ToArray();
                var work         = service.Load(new WorkLoadParameters()
                {
                    Category = workIdentity.Category, Name = workIdentity.Name, Title = workIdentity.Title
                });
                foreach (var wi in work.WorkItems.Where(x => x.Status == WorkItemStatus.PenddingResponse))
                {
                    var actor = wi.Participant.Name;
                    Console.WriteLine("{0} ({1})", actor, string.Join("/", options));
                }

                Console.Write("Select answer in this format:User Answer\r\nFor example enter 'Arash Yes' will send the Arash's answer as Yes to workflow.\r\nAnswer>");
                // Get user input
                var value = Console.ReadLine();

                var workItem = UpdateWorkItem(work, value, options);
                if (workItem != null)
                {
                    // Load the context from storage
                    ctx = ReadContext();

                    // creating a signal
                    var signal = new ReceiverSignal(workIdentity.Title)
                    {
                        Outcome = workItem.Outcome
                    };

                    // resume the workflow using a signal
                    res = eng.Workflow.Resume(ctx, signal);

                    ctx = (WorkflowExecutionContext)res.Context;

                    // update the context in the storage
                    WriteContext(ctx);
                }

                // and keep doing it until it is finished!
                Console.WriteLine();
            }

            Console.WriteLine("State of workflow: {0}", ctx.State);
        }
Esempio n. 4
0
 protected virtual ReceiverSignal AddReceiverSignal(ReceiverSignal sig)
 {
     return(ValueSignal = ValueSignal ?? sig);
 }