private void SaveButton_Click(object sender, EventArgs e) //Save lines in historic to historic.txt { string result = Save.ToText(historic); ComputeResult.AppendText(result); historic = new List <string>(); }
private void LoadHistoric() { List <string> loadedHistoric = Loading.FromTextFile(); foreach (string line in loadedHistoric) { ComputeResult.AppendText(line + "\r\n"); } }
private ComputeResult Compute(Rule rule, Fact fact) { var result = new ComputeResult(); try { #region 参数校验 if (rule.IsNull()) { throw new ArgumentNullException(nameof(rule)); } if (rule.Name.IsNullOrEmpty()) { throw new ArgumentNullException(nameof(rule.Name)); } if (fact.IsNull()) { throw new ArgumentNullException(nameof(fact)); } if (!rule.Enabled) { throw new AggregateException($"Rule.Name:{rule.Name} 未启用"); } #endregion if (!rule.Items.Any()) { return(result); } var trueCount = 0; foreach (var item in rule.Items.Where(x => x.Enabled)) { if (Compute(item, fact)) { trueCount++; } else { result.Infos.Add(new ComputeResultInfo { MissRuleItemType = item.RuleItemType, ComputeMessage = $"RuleValue:{item.Value} FactValue:{fact.GetValueOrDefault(item.RuleItemType) ?? "Null"}" }); break; } } result.Success = rule.Items.Count == trueCount; } catch (Exception ex) { throw new RuleComputeException($"规则运算出错:{ex.Message}", ex); } return(result); }
public ComputeResult Compute(List <Rule> rules, Fact fact) { var result = new ComputeResult(); foreach (var rule in rules.OrderByDescending(x => x.Priority)) { result = Compute(rule, fact); if (!result.Success) { continue; } result.HitRule = rule; break; } return(result); }
private void UpdateHistoric(List <string> allInputs, string result) { string line = currentFunction + " : " + allInputs[0]; for (int i = 1; i < allInputs.Count(); i++) { line += " and " + allInputs[i]; } historic.Add(line); historic.Add("=" + result); //Using AppendText makes the scrollbar to follow new line ComputeResult.AppendText(line + "\r\n"); ComputeResult.AppendText("=" + result + "\r\n"); //clear all inputs foreach (TextBox textbox in myInputs) { textbox.Text = ""; } }
private void Compute_Click(object sender, EventArgs e) { List <string> allInputs = new List <string>(); foreach (TextBox t in myInputs) { allInputs.Add(t.Text); } if (Check.CheckInputs(myInputs, currentFunction)) { //Result type must accept toString() string result = Computer.Computing(currentFunction, allInputs, filePath).ToString(); //Add to historic to save later in text file UpdateHistoric(allInputs, result); } else { ComputeResult.AppendText("No function selected or one input blank"); } }
public ComputeResult SegmentCode(string path) { IntPtr codePtr = IntPtr.Zero; var computeResult = new ComputeResult(path); SegmentCodes(path, out ArrayStruct result, ref codePtr); if (codePtr == IntPtr.Zero) { return(computeResult); } byte[] codeImageBytes = new byte[result.length]; Marshal.Copy(codePtr, codeImageBytes, 0, codeImageBytes.Length); Marshal.FreeCoTaskMem(codePtr); var stream = new MemoryStream(codeImageBytes); computeResult.SegmentedCode = (Bitmap)Image.FromStream(stream); if (result.array.All(t => t.Width > 0 && t.Width <= LetterWidth && t.Height > 0 && t.Height <= LetterHeight)) { computeResult.Letters = new List <Bitmap>(25); var bitmapData = computeResult.SegmentedCode.LockBits(new Rectangle(0, 0, computeResult.SegmentedCode.Width, computeResult.SegmentedCode.Height), ImageLockMode.ReadOnly, computeResult.SegmentedCode.PixelFormat); foreach (var codeRect in result.array) { var cropped = CropImage(bitmapData, computeResult.SegmentedCode.Palette, codeRect.Left, codeRect.Top, codeRect.Left + codeRect.Width, codeRect.Top + codeRect.Height); computeResult.Letters.Add(cropped); } computeResult.SegmentedCode.UnlockBits(bitmapData); } return(computeResult); }