public EmailForm() { InitializeComponent(); comboLanguage.SelectedIndex = 0; _validator = RuntimeEngine.FromXml(File.OpenRead("LocalisedValidationRule.xml")); // Prepare engine for different culture messaging _validator.OnRunning = (eng) => SetupLocalisation(eng.ExecutorSetup); }
private static void BuildDiscountDecision() { DiscountDecision = RuntimeEngine.FromXml(InMemoryFileStore.GetByName("DiscountDecision.xml").AsBytes()); // Capture events DiscountDecision.Events = EventNames.All; // registering custom function DiscountDecision.RegisterFunction(typeof(AgeExtensions)); // build validation plan for executing decision table // Creates a reader to access an excel file DiscountDecision.Entries.Add("Y", "true", true); DiscountDecision.Entries.Add("N", "false", true); }
private static void RunByXmlDecisionTable() { Console.WriteLine("Decision table using XML..."); // Loading decision table from excel document IRuntimeEngine engine = RuntimeEngine.FromXml(File.OpenRead("AgeTitle.xml"), "Sheet1"); // set events to be captured engine.EnableFullLog = true; // executing the decision table ExecuteDecisionTable(engine); }
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); }
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); } }
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); }
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); }
/// <summary> /// Sets Runtime settings from the <see cref="Gala.Dolly.UI.Properties.Settings"/> instance. /// </summary> /// <param name="runtimeEngine"> /// The running of the <see cref="Galatea.Runtime.IRuntimeEngine"/> instance. /// </param> public static void Startup(IRuntimeEngine runtimeEngine) { _runtimeEngine = runtimeEngine; // Set Runtime Properties BaseForm.Current.UIDebugger.LogLevel = Gala.Dolly.UI.Properties.Settings.Default.DebuggerLogLevel; BaseForm.Current.UIDebugger.AlertLevel = Gala.Dolly.UI.Properties.Settings.Default.DebuggerAlertLevel; BaseForm.Current.UIDebugger.ShowAlerts = Gala.Dolly.UI.Properties.Settings.Default.DebuggerShowAlerts; if (Program.RuntimeEngine == null || Program.RuntimeEngine.AI == null || Program.RuntimeEngine.AI.LanguageModel == null || Program.RuntimeEngine.AI.LanguageModel.SpeechModule == null) { BaseForm.Current.UIDebugger.SpeechIsSilent = true; BaseForm.Current.UIDebugger.SpeechMenuEnabled = false; return; } BaseForm.Current.UIDebugger.SpeechIsSilent = Program.RuntimeEngine.AI.LanguageModel.SpeechModule.StaySilent; _started = true; }
/// Initializing the Workflow engine public static void Initialize() { if (_engine != null) { return; } // loading the models/ruleset var rs = ModelLoaderUtility.LoadRuleSet(); // create a workflow engine _engine = RuntimeEngine.FromRuleSet(rs, FlowAddress); var config = new LongRunningProcessConfig(ConfigurationManager.ConnectionStrings["ProcessStateStore"].ConnectionString) { TimeoutNodeExpiredCallback = timeout_node_expired, TimeoutCheckCycle = TimeSpan.FromMinutes(1) }; _engine.Workflow.EnableLongRunningProcess(config); FillTypeIdRegistry(); }
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); }
/// <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); }