public ActionResult SaveRule([FromBody] ClientRequest data) { Result result = new Result(); // See the comments in the LoadSettings() method RuleEditor editor = this.GetRuleEditor(); // Load the rule into the editor editor.LoadClientData(data.Data); if (editor.Rule.IsEmpty()) { result.IsRuleEmpty = true; } else if (!editor.Rule.IsValid(new StorageService(this.environment).LoadRuleXml)) { result.IsRuleValid = false; // Load the json string of invalid data into the Result object result.ClientInvalidData = editor.GetClientInvalidData(); } else { // Save the rule new StorageService(this.environment) .SaveRule(editor.Rule.Id.ToString(), editor.Rule.GetRuleXml(), editor.Rule.IsLoadedRuleOfEvalType == null ? true : (bool)editor.Rule.IsLoadedRuleOfEvalType); // Send ID of this rule to the client result.Output = editor.Rule.Id.ToString(); } return(Json(result)); }
private RuleEditor GetRuleEditor(string ruleXml) { // Pass ID of the DIV elemnt that hosts the editor RuleEditor editor = new RuleEditor("divRuleEditor") { Mode = Common.RuleType.Execution, SourceType = typeof(Patient) }; if (ruleXml != null) { editor.Rule = Rule.Models.RuleModel.Create(ruleXml, typeof(Models.Patient)); } //if (ruleXml == null) editor.Rule = Rule.Models.RuleModel.Create(typeof(Models.Patient)); //else editor.Rule = Rule.Models.RuleModel.Create(ruleXml, typeof(Models.Patient)); StorageService storage = new StorageService(this.environment); // These are the rules displayed in the Rules menu of the ToolBar editor.ToolBarRules = storage.GetAllRules(); // These are reusable evaluation rules displayed in field menus; see documentation details on reusable rules editor.ContextMenuRules = storage.GetEvaluationRules(); return(editor); }
private void EditRule(Node node) { if (node.Tag is Rule) { var rule = (Rule)node.Tag; if (string.IsNullOrEmpty(rule.Script)) { var ruleEditor = new RuleEditor(rule, false); ruleEditor.Location = Location; ruleEditor.ShowDialog(); if (ruleEditor.Save) { node.Tag = rule; node.Text = rule.Name; } } else { var scriptEditor = new ScriptEditor(rule); scriptEditor.Location = Location; scriptEditor.ShowDialog(); if (scriptEditor.Save) { node.Tag = rule; node.Text = rule.Name; } } } }
public static void OpenWindow() { RuleEditor window = GetWindow <RuleEditor>(); window.title = @"规则编辑器"; window.InitData(); }
public JsonResult EvaluateRule([FromBody] ClientRequest data) { Result result = new Result(); // See the comments in the LoadSettings() method RuleEditor editor = this.GetRuleEditor(); // Load the rule into the editor editor.LoadClientData(data.Data); // We are not saving the rule, just evaluating it. Tell the editor not to enforce the rule name validation editor.Rule.SkipNameValidation = true; StorageService storage = new StorageService(this.environment); if (editor.Rule.IsEmpty()) { result.IsRuleEmpty = true; } else if (!editor.Rule.IsValid(storage.LoadRuleXml)) { result.IsRuleValid = false; // Load the json string of invalid data into the Result object result.ClientInvalidData = editor.GetClientInvalidData(); } else { // Create an instance of the Evaluator class. Because our rules might reference other rules of evaluation type // we use constructor that takes rule's XML and delegate of the method that can load referenced rules by their IDs. Evaluator <Patient> evaluator = new Evaluator <Patient>(editor.Rule.GetRuleXml(), storage.LoadRuleXml); Patient patient = GetSource(); // Evaluate the patient against the rule bool success = evaluator.Evaluate(patient); // Return the evaluated patient back to the client result.Patient = patient; // Output the result of the evaluation to the client result.Output = string.IsNullOrWhiteSpace(patient.Output) ? "The rule evaluated to " + success.ToString() : patient.Output; result.Output += Environment.NewLine; result.Output += "The rule calculation resulted in: " + result.Patient.CalculatedValue; result.Output += Environment.NewLine; var calculationShould = patient.CountOfSku("TenDollarSku") * 10 + patient.CountOfSku("TwentyDollarSku") * 20 + // These are never included in the calculation for some reason. patient.CountOfSku("FortyDollarSku") * 40 + 50; result.Output += "The rule SHOULD have calculated to: " + calculationShould; } return(Json(result)); }
private void editListParserRulesToolStripMenuItem_Click(object sender, EventArgs e) { if (ruleEditor == null || ruleEditor.IsDisposed) { ruleEditor = new RuleEditor(); } ruleEditor.SetFileName(SessionsManager.TemplateParserFileName); ruleEditor.Show(); }
public IActionResult LoadSettings() { ClientSettings s = new ClientSettings(); RuleEditor editor = this.GetRuleEditor(); s.EditorData = editor.GetInitialSettings(); s.SourceData = editor.GetClientSettings(); // Send the settings back to the client return(Json(s)); }
public IActionResult LoadRule([FromBody] ClientRequest data) { // Load the rule from the storage file by its ID string ruleXml = new StorageService(this.environment).LoadRuleXml(data.Data); // See the comments in the LoadSettings() method RuleEditor editor = this.GetRuleEditor(ruleXml); // Get the rule's client data string ruleJson = editor.GetClientRuleData(); // Send it back to the server return(Json(ruleJson)); }
private void BeComAddRuleClick(object sender, EventArgs e) { var rule = new Rule(); var ruleEditor = new RuleEditor(rule, false); ruleEditor.Location = Location; ruleEditor.ShowDialog(); if (ruleEditor.Save) { rule = ruleEditor.Rule; if (BeTabs.SelectedTab.Name.Equals("TabCombat")) { AddCondition(rule, BeComRules); } } }
private void button_ruleList_Click(object sender, EventArgs e) { RuleEditor r = new RuleEditor(); r.ShowDialog(Rules); }