internal void SetFunction(string equation) { _costEquation = equation; // Get list of attributes _attributesEquation = SimulationMessaging.ParseAttribute(_costEquation); if (_attributesEquation == null) { return; } if (_calculate == null) { _calculate = new CalculateEvaluate.CalculateEvaluate(); //Allow functions to utilize strings and dates. string functionEquation = _costEquation; List <string> attributes = SimulationMessaging.ParseAttribute(functionEquation); foreach (String attribute in attributes) { String attributeType = SimulationMessaging.GetAttributeType(attribute); if (attributeType == "STRING") { String oldValue = "[" + attribute + "]"; String newValue = "[@" + attribute + "]"; functionEquation = functionEquation.Replace(oldValue, newValue); } else if (attributeType == "DATETIME") { String oldValue = "[" + attribute + "]"; String newValue = "[$" + attribute + "]"; functionEquation = functionEquation.Replace(oldValue, newValue); } } _calculate.BuildFunctionClass(functionEquation, "double", cgOMS.Prefix + "COSTS_BINARY_EQUATION_" + CostID); if (_calculate.m_cr == null) { _compilerResultsEquation = _calculate.CompileAssembly(); SimulationMessaging.SaveSerializedCalculateEvaluate(cgOMS.Prefix + "COSTS", "BINARY_EQUATION", CostID, _calculate); } } }
/// <summary> /// Sets the function version of consequences. /// </summary> /// <param name="equation"></param> public void SetFunction(string equation) { _consequenceEquation = equation; IsEquation = true; _attributesEquation = SimulationMessaging.ParseAttribute(_consequenceEquation); if (_calculate == null) { _calculate = new CalculateEvaluate.CalculateEvaluate(); string functionEquation = _consequenceEquation; foreach (String attribute in _attributesEquation) { String attributeType = SimulationMessaging.GetAttributeType(attribute); if (attributeType == "STRING") { String oldValue = "[" + attribute + "]"; String newValue = "[@" + attribute + "]"; functionEquation = functionEquation.Replace(oldValue, newValue); } else if (attributeType == "DATETIME") { String oldValue = "[" + attribute + "]"; String newValue = "[$" + attribute + "]"; functionEquation = functionEquation.Replace(oldValue, newValue); } } _calculate.BuildFunctionClass(_consequenceEquation, "double", cgOMS.Prefix + "CONSEQUENCES_BINARY_EQUATION_" + _id); if (_calculate.m_cr == null) { _compilerResultsEquation = _calculate.CompileAssembly(); SimulationMessaging.SaveSerializedCalculateEvaluate(cgOMS.Prefix + "CONSEQUENCES", "BINARY_EQUATION", _id, _calculate); } } }
internal void SetFunction(string equation) { _equation = equation; // Get list of attributes _attributesEquation = SimulationMessaging.ParseAttribute(_equation); if (_attributesEquation == null) { return; } if (_attributesEquation.Count == 1 && _attributesEquation[0].ToUpper() == "AGE") { _isAgeOnly = true; } if (_equation.Length >= 6 && _equation.Substring(0, 6) == "MODULE") { IsModule = true; //this will crash the program for equations with less than 10 characters //if (m_strEquation.Substring(0, 6) == "MODULE") if (_equation.Length >= 10 && _equation.Substring(7, 3) == "CRS") { IsCRS = true; } else if (_equation.Length >= 10 && _equation.Substring(7, 3) == "OCI") { IsOCI = true; } return; } else { if (_calculate == null) { _calculate = new CalculateEvaluate.CalculateEvaluate(); //Allow functions to utilize strings and dates. string functionEquation = _equation; List <string> attributes = SimulationMessaging.ParseAttribute(functionEquation); foreach (String attribute in attributes) { String attributeType = SimulationMessaging.GetAttributeType(attribute); if (attributeType == "STRING") { String oldValue = "[" + attribute + "]"; String newValue = "[@" + attribute + "]"; functionEquation = functionEquation.Replace(oldValue, newValue); } else if (attributeType == "DATETIME") { String oldValue = "[" + attribute + "]"; String newValue = "[$" + attribute + "]"; functionEquation = functionEquation.Replace(oldValue, newValue); } } _calculate.BuildFunctionClass(functionEquation, "double", cgOMS.Prefix + _table + "_BINARY_EQUATION_" + _performanceID); if (_calculate.m_cr == null) { _compilerResultsEquation = _calculate.CompileAssembly(); if (_table != null) { SimulationMessaging.SaveSerializedCalculateEvaluate(cgOMS.Prefix + _table, "BINARY_EQUATION", _performanceID, _calculate); } } if (_calculate.m_listError.Count > 0) { foreach (String str in _calculate.m_listError) { _errors.Add(str); } } } //If [AGE] is the only variable. This only needs to be solved once so might //as well solve it right now. if (_isAgeOnly) { Hashtable hash = new Hashtable(); hash.Add("AGE", "0"); this.Solve(hash); } } }