public static string GetRuleExecutionFlowXml(RuleSetDef ruleSetDef) { string xml = null; StringWriter sw = new StringWriter(); XmlTextWriter xw = new XmlTextWriter(sw); //TODO: this hack is described on the variable definition _workingRuleAppDef = ruleSetDef.GetRuleApp(); using (xw) { xw.WriteStartElement(ruleSetDef.Name); foreach (RuleRepositoryDefBase def in ruleSetDef.Rules) { //xw.WriteRaw("<Collection3>"); AppendToExecutionFlowXml(def as RuleElementDef, xw); //xw.WriteRaw("</Collection3>"); } xw.WriteEndElement(); xml = sw.ToString(); } _workingRuleAppDef = null; return(xml); }
public static RuleSetDef AddAutoSeqRuleSet(this EntityDef entityDef, string name) { var ruleSetDef = new RuleSetDef(name); ruleSetDef.FireMode = RuleSetFireMode.Auto; ruleSetDef.RunMode = RuleSetRunMode.Sequential; entityDef.RuleElements.Add(ruleSetDef); return(ruleSetDef); }
public static string GetMemberRuleSetByName(RuleSetDef parentRuleSetDef, string ruleSetName) { string memberRuleSetName = string.Empty; //TODO: this doesn't process each rule, just the last one foreach (var rule in parentRuleSetDef.Rules) { if (rule is ExecuteMemberRuleSetActionDef) { // if this is Execute Member action, get the name of the RuleSet so we can find it memberRuleSetName = ((ExecuteMemberRuleSetActionDef)rule).RuleSet.FormulaText; } } return(memberRuleSetName); }
public CatalogSearchResultViewModel(DefInfo ruleAppDef, RuleSetDef ruleSetDef, string matchedValue, CatalogSearchSettings settings, RuleElementDef ruleDef = null) { RuleAppName = ruleAppDef.Name + " v" + ruleAppDef.PublicRevision; RuleSetName = ruleSetDef.AuthoringElementPath; MatchedValue = matchedValue; //TODO: The way we're navigating to the item does not work properly - add this back in once that works IsInCurrentRuleApp = false;// settings.CurrentRuleApp != null && ruleAppDef.Key.Guid == settings.CurrentRuleApp.Value; RuleSetDef = ruleSetDef; if (ruleDef != null) { RuleElementName = ruleDef.AuthoringElementPath; RuleDef = ruleDef; } }
public static RuleSetDef GetRuleSetByName(RuleApplicationDef ruleAppDef, string ruleSetName) { RuleSetDef ruleSetDef = null; // first look in Entities for the RuleSet foreach (EntityDef entityDef in ruleAppDef.Entities) { ruleSetDef = GetRuleSetByName(entityDef, ruleSetName); if (ruleSetDef != null) { return(ruleSetDef); } } // if we haven't found it, look in the independent rulesets foreach (RuleSetDef indRuleSetDef in ruleAppDef.GetAllRuleSets()) { if (indRuleSetDef.Name == ruleSetName) { return(indRuleSetDef); } } return(ruleSetDef); }
private void Submit(object obj) { try { //var ruleApp = new FileSystemRuleApplicationReference(Properties.Settings.Default.RuleappFilePath); RuleApplicationDef ruleApp = RuleApplicationService.RuleApplicationDef; //using (var session = new RuleSession(ruleApp)) //{ var entityName = string.Empty; var rulesetName = string.Empty; if (SelectionManager.SelectedItem as RuleSetDef != null) { RuleSetDef rulesetDef = (RuleSetDef)SelectionManager.SelectedItem; //System.Windows.Forms.MessageBox.Show(rulesetDef.Name); //var rootEntity = session.CreateEntity(rulesetDef.ThisEntity.Name); string executionFlow = RuleEngineUtil.GetRuleExecutionFlowXml(rulesetDef); XmlDocument xmlExecutionFlow = new XmlDocument(); xmlExecutionFlow.LoadXml(executionFlow); StringWriter sw = new StringWriter(); XmlToJson(xmlExecutionFlow, sw); string curDir = System.IO.Path.GetDirectoryName(RuleApplicationService.EditorAssembly.Location); //File.WriteAllText(curDir + @"\FlowVisualizer_files\ruleapp_data.js", "var ruleapp_data = " + sw.ToString()); //byte[] bytes = ReadBytesFromStream(InRule.Authoring.Extensions.RuleAppFlowVisualizer.Properties.Resources.FlowVisualizer1); //string s = GetResourceStream("FlowVisualizer1.htm"); //string s = Encoding.UTF8.GetString(bytes, 0, bytes.Length); //Uri uri = new Uri(@"pack://*****:*****@"C:\Temp\InRuleRuleAppFlowVisualizer.htm")); userControl2.webReport.Loaded += delegate { //userControl2.webReport.NavigateToStream(source); userControl2.webReport.NavigateToString(s); }; userControl2.SelectionChanged += delegate { //userControl2.webReport.NavigateToStream(source); RuleSetDef selectedRuleset = null; EntityDef entity = null; if (userControl2.SelectedRuleset.Contains("_ForEach_")) { entity = ruleApp.Entities[userControl2.SelectedRuleset.Substring(userControl2.SelectedRuleset.IndexOf("_ForEach_") + 9)]; selectedRuleset = entity.GetRuleSet(userControl2.SelectedRuleset.Substring(0, userControl2.SelectedRuleset.IndexOf("_ForEach_"))); } else { entity = rulesetDef.ThisEntity; selectedRuleset = entity.GetRuleSet(userControl2.SelectedRuleset); //System.Windows.Forms.MessageBox.Show(userControl2.SelectedRuleset); } if (selectedRuleset != null) { SelectionManager.SelectedItem = selectedRuleset; } }; //userControl2.webReport.Document. //userControl2.webReport.NavigateToString(s); //userControl2.webReport.Navigate(new Uri(@".\FlowVisualizer.htm")); userControl2.Title = "Rule Execution Flow: " + rulesetDef.Name; //SelectionManager.SelectedItem = ruleApp.GetRuleSet("GetFinalQuote"); userControl2.Show(); //var window = WindowFactory.CreateWindow("Execution Flow", userControl2, true); //window.Show(); //mshtml.HTMLDocument doc; //doc = (mshtml.HTMLDocument)userControl2.webReport.Document; //mshtml.HTMLDocumentEvents2_Event iEvent; } else { System.Windows.Forms.MessageBox.Show("You must select a ruleset for this report!"); } //} } catch (Exception ex) { System.Windows.Forms.MessageBox.Show(ex.Message); } }
static void Main(string[] args) { var ruleAppDef = new RuleApplicationDef("CallWebServiceExample1"); //Create a new Web Service Endpoint WebServiceDef webServiceDef = new WebServiceDef(); webServiceDef.Name = "WebService1"; webServiceDef.WsdlUri = "http://localhost/WcfService1/Service1.svc?wsdl"; webServiceDef.PortName = "BasicHttpBinding_IService1"; webServiceDef.Operations.Add(new WebServiceDef.OperationDef("GetData")); //Add the new Web Service Endpoint to the Rule Application ruleAppDef.EndPoints.Add(webServiceDef); //Add an Entity for output EntityDef entity1 = ruleAppDef.Entities.Add(new EntityDef("Entity1")); //Add field to the new Entity that will contain the output value FieldDef resultField1 = entity1.Fields.Add(new FieldDef("InputData", DataType.Integer)); FieldDef resultField2 = entity1.Fields.Add(new FieldDef("OutputData", DataType.String)); //Create a new Execute Web Service Action ExecuteWebServiceOperationActionDef executeWebServiceActionDef = new ExecuteWebServiceOperationActionDef(); executeWebServiceActionDef.Name = "ExecuteWebService1"; executeWebServiceActionDef.WebServiceEndPointName = "WebService1"; executeWebServiceActionDef.OperationName = "GetData"; var inputMapping1 = new TypeMapping("value", "Int32"); inputMapping1.FieldMappings.Add(new FieldMapping("InputData", "value", "Integer", false, false)); executeWebServiceActionDef.Inputs.Add(inputMapping1); var outputMapping1 = new TypeMapping("[return]", "String"); outputMapping1.FieldMappings.Add(new FieldMapping("OutputData", "[return]", "Text", false, false)); executeWebServiceActionDef.Outputs.Add(outputMapping1); //Create a Rule Set container to hold the Action RuleSetDef ruleSetDef = new RuleSetDef("RuleSet"); ruleSetDef.FireMode = RuleSetFireMode.Auto; ruleSetDef.RunMode = RuleSetRunMode.Sequential; //Add the Rule Set to the Entity entity1.RuleElements.Add(ruleSetDef); //Add the Action to the Rule Set ruleSetDef.Rules.Add(executeWebServiceActionDef); ruleAppDef.SaveToFile(@"c:\temp\GeneratedRuleApp"); //Confirm the Rule Application works by creating a Rule Session var session = new RuleSession(ruleAppDef); //Create a session Entity using the output Entity var entity1Runtime = session.CreateEntity("Entity1"); entity1Runtime.Fields["InputData"].Value = "123"; //Apply the Rule session.ApplyRules(); //Get the result from the Entity used for the session and return the result from the Result Field string result = entity1Runtime.Fields["OutputData"]; //Verify. Copy the TinyURL from the command and paste into a browser to confirm it takes you to http://www.inrule.com Console.WriteLine("Result: {0}", result); Console.Read(); }
static void Main(string[] args) { //Create a new Rule Application var ruleAppDef = new RuleApplicationDef("RESTService"); //Create a new REST Service Endpoint RestServiceDef restServiceDef = new RestServiceDef(); restServiceDef.Name = "RestService"; restServiceDef.AuthenticationType = RestServiceAuthenticationType.None; restServiceDef.RootUrl = "http://tinyurl.com/"; //Add the new REST Service Endpoint to the Rule Application ruleAppDef.EndPoints.Add(restServiceDef); //Create a new REST Resource Template RestOperationDef restOperationDef = new RestOperationDef(); restOperationDef.Name = "RestResourceTemplate"; restOperationDef.RestService = restServiceDef.Name; restOperationDef.Verb = RestOperationVerb.Get; restOperationDef.WaitForResponse = true; restOperationDef.UriPrototype = "/api-create.php?url=http://www.inrule.com/"; //Add the new REST Resaource Template to the Rule Application ruleAppDef.DataElements.Add(restOperationDef); //Add an Entity for output EntityDef tinyUrlOutput = ruleAppDef.Entities.Add(new EntityDef("TinyUrlOutput")); //Add field to the new Entity that will contain the output value FieldDef resultField = tinyUrlOutput.Fields.Add(new FieldDef("Result", DataType.String)); //Create a new Execute REST Service Action ExecuteRestServiceActionDef executeRestServiceActionDef = new ExecuteRestServiceActionDef(); executeRestServiceActionDef.Name = "ExecuteRestService"; executeRestServiceActionDef.Operation = restOperationDef.Name; executeRestServiceActionDef.AssignReturnValueToField = new CalcDef(DataType.String, resultField.Name); //Create a Rule Set container to hold the Action RuleSetDef ruleSetDef = new RuleSetDef("RuleSet"); ruleSetDef.FireMode = RuleSetFireMode.Auto; ruleSetDef.RunMode = RuleSetRunMode.Sequential; //Add the Rule Set to the Entity tinyUrlOutput.RuleElements.Add(ruleSetDef); //Add the Action to the Rule Set ruleSetDef.Rules.Add(executeRestServiceActionDef); //Confirm the Rule Application works by creating a Rule Session var session = new RuleSession(ruleAppDef); //Create a session Entity using the output Entity var entityWithEntityFieldRef = session.CreateEntity(tinyUrlOutput.Name); //Apply the Rule session.ApplyRules(); //Get the result from the Entity used for the session and return the result from the Result Field string result = entityWithEntityFieldRef.Fields["Result"]; //Verify. Copy the TinyURL from the command and paste into a browser to confirm it takes you to http://www.inrule.com Console.WriteLine(String.Format("Result: {0}", result)); Console.Read(); }
public static SimpleRuleDef AddSimpleRule(this RuleSetDef ruleDefContainer, string name, string condition) { return(ruleDefContainer.Rules.AddSimpleRule(name, condition)); }