Beispiel #1
0
        public bool IsCriteriaMet(Hashtable hashAttributeValue)
        {
            if (string.IsNullOrWhiteSpace(_criteria))
            {
                return(true);
            }
            object[] input = new object[_attributesCriteria.Count];
            int      i     = 0;

            foreach (String str in _attributesCriteria)
            {
                input[i] = hashAttributeValue[str];
                i++;
            }
            try
            {
                if (_evaluate.m_methodInfo == null)
                {
                    if (_evaluate.m_cr == null)
                    {
                        _evaluate.BuildClass(_evaluate.Expression, false, cgOMS.Prefix + _table + "_" + _column + "_" + _performanceID);
                        _evaluate.CompileAssembly();
                        SimulationMessaging.SaveSerializedCalculateEvaluate(cgOMS.Prefix + _table, _column, _performanceID, _evaluate);
                    }
                }
                bool isMet = (bool)_evaluate.RunMethod(input);
                return(isMet);
            }
            catch (Exception exc)
            {
                SimulationMessaging.AddMessage(new SimulationMessage("Error in RunMethod.   " + _evaluate.OriginalInput + " " + exc.Message));
                return(false);
            }
        }
Beispiel #2
0
        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);
                }
            }
        }
Beispiel #3
0
        public bool IsCriteriaMet(Hashtable hashAttributeValue)
        {
            if (string.IsNullOrWhiteSpace(m_strCriteria))
            {
                return(true);
            }

            object[] input = new object[this.m_listAttributesCriteria.Count];

            int i = 0;

            foreach (String str in this.m_listAttributesCriteria)
            {
                input[i] = hashAttributeValue[str];
                i++;
            }
            try
            {
                if (evaluate.m_methodInfo == null)
                {
                    if (evaluate.m_cr == null)
                    {
                        evaluate.BuildClass(evaluate.Expression, false, cgOMS.Prefix + _tableName + "_" + _columnName + "_" + _ID);
                        evaluate.CompileAssembly();
                        if (_tableName != null)
                        {
                            SimulationMessaging.SaveSerializedCalculateEvaluate(cgOMS.Prefix + _tableName, _columnName, _ID, evaluate);
                        }
                    }
                }

                Object result = this.Evaluate.RunMethod(input);
                return(bool.Parse(result.ToString()));
            }
            catch (Exception exc)
            {
                SimulationMessaging.AddMessage(new SimulationMessage("Error in RunMethod.   " + Evaluate.OriginalInput + " " + exc.Message));
                return(false);
            }
        }
Beispiel #4
0
        /// <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);
                }
            }
        }
Beispiel #5
0
        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);
                }
            }
        }