コード例 #1
0
ファイル: Program.cs プロジェクト: farzadrabiee/Samples-v8
        static private void ValidateUsingValidationEngine()
        {
            Person person = GetPerson();
            // This runs the first logic (complete person test)
            // which as the result (complete person test) calls the other logic as well

            var result = _validator.Run(person);

            Console.WriteLine("Was the input person valid?  {0}", result.Outcome);
            foreach (var item in result.Context.Notifications.Default.Notices)
            {
                Console.WriteLine(item.Message);
            }

            person.Email  = "*****@*****.**";
            person.Family = "Aghlara";
            result        = _validator.Run(person);
            Console.WriteLine("Was the input person valid?  {0}", result.Outcome);
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: farzadrabiee/Samples-v8
        private static void ValidateUsingProceduralEngine()
        {
            // we called a procedure and then it called a validation
            // this console application -> procedure -> validation
            var person = GetPerson();
            var result = _procedure.Run(person);

            // We still collect the notification for validation
            // although if was called indirectly from a procedure
            foreach (var item in result.Context.Notifications.Default.Notices)
            {
                Console.WriteLine(item.Message);
            }
        }
コード例 #3
0
        private string[] ValidateEmail()
        {
            // Creating entity to be validated
            var per = new Person {
                Email = textBox1.Text
            };

            var runParameter = new RunParameter("check email", per);

            // Calling into engine for validation
            var result = _validator.Run(runParameter);

            // we select only text here to display in the UI
            // In a real application you can do more interesting stuff with notifications
            return(result.Context.Notifications.Default.Notices.Select(x => x.Message).ToArray());
        }
コード例 #4
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);
        }
コード例 #5
0
        private static void Check_Adult_Female(IRuntimeEngine engine)
        {
            var person = new Person("Ava", 36, Gender.Female);
            var result = engine.Run(person);

            if (!(bool)result.Context.VariableContainer["canDrink"])
            {
                foreach (var n in result.Context.Notifications.Default.Notices)
                {
                    Console.WriteLine("{0}: {1}", n.Type, n.Message);
                }
            }
            else
            {
                Console.WriteLine("{0}, Cheerrrssss!", person.Name);
            }
        }
コード例 #6
0
        static private void ExecuteDecisionTable(IRuntimeEngine engine)
        {
            // getting a fact
            var person = new { Age = 10 };

            // running the fact against decision table
            var result = engine.Run(person);

            // read values from context
            var title = result.Context.VariableContainer["title"];

            Console.WriteLine("Title: {0}", title);

            Console.WriteLine();
            Console.WriteLine("** Events Log: {0} events are created.", result.Events.Count());
            Console.WriteLine("** Below log is generated based on events:");
            Console.WriteLine(result.ConclusionLog);
        }
コード例 #7
0
        private void AskUserForDetails(IRuntimeEngine eng, Letter letter)
        {
            var res = eng.Run(letter);
            var ctx = (WorkflowExecutionContext)res.Context;

            WriteContext(ctx);

            // Keep resuming the workflow while it is in the Suspended state
            while (ctx.State == FlowState.Suspended)
            {
                var state = (string)ctx.VariableContainer["state"];
                Console.Write("Enter '{0}' Message> ", state);

                // Get user input
                var value = Console.ReadLine();

                // Load the context from storage
                ctx = ReadContext();

                // update the value in the context
                switch (state.ToLower())
                {
                case "title":
                    ((Letter)ctx.VariableContainer["letter"]).Title = value;
                    break;

                case "body":
                    ((Letter)ctx.VariableContainer["letter"]).Body = value;
                    break;
                }

                // resume the workflow
                res = eng.Workflow.Resume(ctx);
                ctx = (WorkflowExecutionContext)res.Context;

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

                // and keep doing it until it is finished!
            }
            letter = (Letter)res.Context.VariableContainer["letter"];
            Console.WriteLine("State of workflow: {0}", ctx.State);
            Console.WriteLine("Letter:\r\n\t{0}\r\n\t{1}", letter.Title, letter.Body);
        }
コード例 #8
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);
        }
コード例 #9
0
ファイル: Program.cs プロジェクト: farzadrabiee/Samples-v8
        /// <summary>
        /// RuntimeEngine class simplifies the integration and is a tread-safe class and one instance of it should be used to execute multiple requests.
        /// </summary>
        /// <param name="engine"></param>
        private void RunEngine(IRuntimeEngine engine)
        {
            var result = engine.Run("Joe");

            WriteResult(result.Context.VariableContainer);
        }
コード例 #10
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            var result = Engine.Run(GetCar());

            UpdateView((Car)result.Context.VariableContainer["car"]);
        }
コード例 #11
0
        /// <summary>
        /// Creates an engine to process a new request
        /// </summary>
        /// <returns></returns>
        public WorkflowExecutionContext New(params object[] inputs)
        {
            var res = _engine.Run(inputs);

            return((WorkflowExecutionContext)res.Context);
        }