/// <summary> /// 集合中的值在表达式中做运算,得出得结果Bool集合 /// </summary> /// <param name="arr">数组集</param> /// <returns>Bool集合</returns> private List <bool> ProcessDataToBoolArray(string formulaRule) { string formula = formulaRule; ExpressionEval eval = new ExpressionEval(); List <bool> contented = new List <bool>(); if (data != null) { if (data.Data != null) { for (int i = 0; i < data.Data.Length; i++) { if (!formula.ToUpper().Contains("$PREVVALUE") && !formula.ToUpper().Contains("$MAX")) { eval.Expression = ReplaceFormulaDefinedVariable(formula, data.Data[i].ToString()); contented.Add(eval.EvaluateBool()); } //处理包含最大最小值 if (formula.ToUpper().Contains("$MAX")) { eval.Expression = ReplaceFormulaDefinedVariable(formula, data.Data[i].ToString()); //contented.Add(eval.EvaluateBool()); if (eval.EvaluateBool()) { if (data.Data[i] == data.Max || data.Data[i] == data.Min) { contented.Add(true); } else { contented.Add(false); } } } //处理上升或下降趋势 if (formula.ToUpper().Contains("$PREVVALUE") && i != 0) { eval.Expression = ReplaceFormulaDefinedVariable(formula, data.Data[i].ToString(), data.Data[i - 1].ToString()); contented.Add(eval.EvaluateBool()); } if (formula.ToUpper().Contains("$PREVVALUE") && i == 0) { contented.Add(true); } } } } return(contented); }
/// <summary> /// 获取N,P对照值 /// </summary> public void AnalysisData(out string message) { message = string.Empty; clsSTConstract constractRule = new clsSTConstract(); if (m_isSelfConstractValue) { constractRule = this.m_constract; } else { constractRule.Analysis(m_lstBoardItems); this.m_constract = constractRule; } string formula = this.m_checkProject.Formula; formula = formula.Replace("N", constractRule.NegativeValue.ToString()); formula = formula.Replace("P", constractRule.PositiveValue.ToString()); formula = formula.Replace("B", constractRule.BlankValue.ToString()); ExpressionEval eval = new ExpressionEval(); foreach (clsSTBoardItem boardItem in m_lstBoardItems) { if (boardItem.BoardStyle.SampleStyle == enmSTSampleStyle.NONE) { continue; } string evalExpression = formula.Replace("V", boardItem.DataNum); eval.Expression = evalExpression; bool result = false; try { result = eval.EvaluateBool(); } catch (Exception ex) { message = "公式配置不对或者数据不正确! 系统消息:" + ex.Message; return; } boardItem.IsPositive = result; } if (DataChanged != null) { DataChanged(this, new DataChangedEventArgs(enmSTTextBoxShowStatus.ResultText)); } }
public bool IsScheduling(DateTime date, string cronExpression, int recursionCount = 0) { string buildExpression = ""; int p = 0; while (p < cronExpression.Length) { char token = cronExpression[p]; if (token == '(' || token == ')' || token == ';' || token == ':') { buildExpression += token; p++; continue; } string currentExpression = token.ToString(); p++; while (p < cronExpression.Length) { token = cronExpression[p]; if (token != '(' && token != ')' && token != ';' && token != ':') { currentExpression += token; p++; } else { break; } } currentExpression = currentExpression.Trim(new char[] { ' ', '\t' }); if (String.IsNullOrEmpty(currentExpression)) { continue; } bool isEntryActive = false; if (currentExpression.StartsWith("@")) { // Check expresion from scheduled item with a given name var eventItem = Get(currentExpression.Substring(1)); if (eventItem == null) { masterControlProgram.HomeGenie.MigService.RaiseEvent( this, Domains.HomeAutomation_HomeGenie, SourceModule.Scheduler, cronExpression, Properties.SchedulerError, JsonConvert.SerializeObject("Unknown event name '" + currentExpression + "'")); } else if (recursionCount >= MAX_EVAL_RECURSION) { recursionCount = 0; masterControlProgram.HomeGenie.MigService.RaiseEvent( this, Domains.HomeAutomation_HomeGenie, SourceModule.Scheduler, cronExpression, Properties.SchedulerError, JsonConvert.SerializeObject("Too much recursion in expression '" + currentExpression + "'")); eventItem.IsEnabled = false; } else { recursionCount++; try { isEntryActive = (eventItem.IsEnabled && IsScheduling(date, eventItem.CronExpression, recursionCount)); } catch { } recursionCount--; if (recursionCount < 0) { recursionCount = 0; } } } else { isEntryActive = EvaluateCronEntry(date, currentExpression); } buildExpression += (isEntryActive ? "1" : "0"); } buildExpression = buildExpression.Replace(":", "+"); buildExpression = buildExpression.Replace(";", "*"); bool success = false; try { ExpressionEval eval = new ExpressionEval(); eval.Expression = buildExpression; success = eval.EvaluateBool(); } catch (Exception ex) { masterControlProgram.HomeGenie.MigService.RaiseEvent( this, Domains.HomeAutomation_HomeGenie, // before v1.1 it was: Domains.HomeAutomation_HomeGenie_Automation, SourceModule.Scheduler, // before v1.1 it was: cronExpression, cronExpression, // before v1.1 it was: "Scheduler Expression", Properties.SchedulerError, JsonConvert.SerializeObject(ex.Message)); } return(success); }
public bool IsScheduling(string cronExpression) { string buildExpression = ""; int p = 0; while (p < cronExpression.Length) { char token = cronExpression[p]; if (token == '(' || token == ')' || token == ';' || token == ':') { buildExpression += token; p++; continue; } string currentExpression = token.ToString(); p++; while (p < cronExpression.Length) { token = cronExpression[p]; if (token != '(' && token != ')' && token != ';' && token != ':') { currentExpression += token; p++; } else { break; } } currentExpression = currentExpression.Trim(new char[] { ' ', '\t' }); if (String.IsNullOrEmpty(currentExpression)) { continue; } bool isEntryActive = false; if (currentExpression.StartsWith("@")) { // Check expresion from scheduled item with a given name var eventItem = Get(currentExpression.Substring(1)); isEntryActive = (eventItem != null && eventItem.IsEnabled && EvaluateCronEntry(eventItem.CronExpression)); } else { isEntryActive = EvaluateCronEntry(currentExpression); } buildExpression += (isEntryActive ? "1" : "0"); } buildExpression = buildExpression.Replace(":", "+"); buildExpression = buildExpression.Replace(";", "*"); bool success = false; try { ExpressionEval eval = new ExpressionEval(); eval.Expression = buildExpression; success = eval.EvaluateBool(); } catch (Exception ex) { masterControlProgram.HomeGenie.MigService.RaiseEvent( this, Domains.HomeAutomation_HomeGenie_Scheduler, cronExpression, "Scheduler Expression", Properties.SCHEDULER_ERROR, JsonConvert.SerializeObject(ex.Message)); } return(success); }
private void m_cmdAnalysis_Click(object sender, EventArgs e) { if (m_selectProject == null || m_selectProject.Name == string.Empty) { MessageBox.Show("请选择检验项目!"); return; } if (m_selectTemplate == null || m_selectTemplate.TemplateName == string.Empty) { MessageBox.Show("请选择模板!"); return; } if (m_lstCheckResults == null || m_lstCheckResults.Count == 0) { MessageBox.Show("没有酶标检验项目结果!"); return; } clsSTConstract constractRule = new clsSTConstract(); float fltNegative = 0; float fltPositive = 0; try { fltNegative = float.Parse(this.m_txtNegative.Text); } catch { fltNegative = -1; } try { fltPositive = float.Parse(this.m_txtPositive.Text); } catch { fltPositive = -1; } if (fltNegative == -1 || fltPositive == -1) { constractRule.Analysis(m_lstBoard); this.m_txtNegative.Text = constractRule.NegativeValue.ToString(); this.m_txtPositive.Text = constractRule.PositiveValue.ToString(); fltNegative = constractRule.NegativeValue; fltPositive = constractRule.PositiveValue; } string formula = this.m_selectProject.Formula; formula = formula.Replace("N", fltNegative.ToString()); formula = formula.Replace("P", fltPositive.ToString()); ExpressionEval eval = new ExpressionEval(); foreach (clsSTBoardItem boardItem in m_lstBoard) { formula = formula.Replace("V", boardItem.DataNum); eval.Expression = formula; if (eval.EvaluateBool()) { boardItem.IsPositive = true; } else { boardItem.IsPositive = false; } } DisplayCheckResult(enmSTTextBoxShowStatus.ResultText); }