Exemplo n.º 1
0
        public RemainingLife(int remainingLifeId, string attribute, double remainingLifeLimit, string criteria)
        {
            RemainingLifeId    = remainingLifeId;
            Attribute          = attribute;
            RemainingLifeLimit = remainingLifeLimit;

            Criteria = new Criterias("REMAINING_LIFE", "BINARY_CRITERIA", RemainingLifeId.ToString());
            byte[] assemblyCriteria = null;
            string currentCriteria  = "";

            if (!string.IsNullOrWhiteSpace(criteria))
            {
                currentCriteria = Simulation.ConvertOMSAttribute(criteria);
            }
            assemblyCriteria = SimulationMessaging.GetSerializedCalculateEvaluate("REMAINING_LIFE", "BINARY_CRITERIA", RemainingLifeId.ToString(), assemblyCriteria);
            if (assemblyCriteria != null && assemblyCriteria.Length > 0)
            {
                Criteria.Evaluate = (CalculateEvaluate.CalculateEvaluate)AssemblySerialize.DeSerializeObjectFromByteArray(assemblyCriteria);
                if (Criteria.Evaluate.OriginalInput != currentCriteria)
                {
                    Criteria.Evaluate = null;
                }
            }

            if (Criteria.Evaluate != null && Criteria.Evaluate.m_cr != null)
            {
                if (!File.Exists(Criteria.Evaluate.m_cr.PathToAssembly))
                {
                    Criteria.Evaluate = null;
                }
            }

            Criteria.Criteria = criteria;
            foreach (String str in Criteria.Errors)
            {
                SimulationMessaging.AddMessage(new SimulationMessage("Error: Supersede criteria for " + criteria + " :" + str));
            }
        }
Exemplo n.º 2
0
        public BudgetCriteria(int budgetCriteriaId, string budgetName, string criteria)
        {
            BudgetCriteriaId = budgetCriteriaId;
            BudgetName       = budgetName;

            Criteria = new Criterias("BUDGET", "BINARY_CRITERIA", BudgetCriteriaId.ToString());
            byte[] assemblyCriteria = null;
            string currentCriteria  = "";

            if (!string.IsNullOrWhiteSpace(criteria))
            {
                currentCriteria = Simulation.ConvertOMSAttribute(criteria);
            }
            assemblyCriteria = SimulationMessaging.GetSerializedCalculateEvaluate("BUDGET", "BINARY_CRITERIA", BudgetCriteriaId.ToString(), assemblyCriteria);
            if (assemblyCriteria != null && assemblyCriteria.Length > 0)
            {
                Criteria.Evaluate = (CalculateEvaluate.CalculateEvaluate)AssemblySerialize.DeSerializeObjectFromByteArray(assemblyCriteria);
                if (Criteria.Evaluate.OriginalInput != currentCriteria)
                {
                    Criteria.Evaluate = null;
                }
            }

            if (Criteria.Evaluate != null && Criteria.Evaluate.m_cr != null)
            {
                if (!File.Exists(Criteria.Evaluate.m_cr.PathToAssembly))
                {
                    Criteria.Evaluate = null;
                }
            }

            Criteria.Criteria = criteria;
            foreach (String str in Criteria.Errors)
            {
                SimulationMessaging.AddMessage(new SimulationMessage("Error: Supersede criteria for " + criteria + " :" + str));
            }
        }
Exemplo n.º 3
0
        public SplitTreatment(string splitTreamentId, string description, string criteria, List <ISplitTreatmentLimit> limits)
        {
            Id          = splitTreamentId;
            Description = description;
            Limits      = limits;
            Criteria    = new Criterias("SPLIT_TREATMENT", "BINARY_CRITERIA", splitTreamentId);
            byte[] assemblyCriteria = null;
            string currentCriteria  = "";

            if (!string.IsNullOrWhiteSpace(criteria))
            {
                currentCriteria = Simulation.ConvertOMSAttribute(criteria);
            }
            assemblyCriteria = SimulationMessaging.GetSerializedCalculateEvaluate("SPLIT_TREATMENT", "BINARY_CRITERIA", splitTreamentId, assemblyCriteria);
            if (assemblyCriteria != null && assemblyCriteria.Length > 0)
            {
                Criteria.Evaluate = (CalculateEvaluate.CalculateEvaluate)RoadCareGlobalOperations.AssemblySerialize.DeSerializeObjectFromByteArray(assemblyCriteria);
                if (Criteria.Evaluate.OriginalInput != currentCriteria)
                {
                    Criteria.Evaluate = null;
                }
            }

            if (Criteria.Evaluate != null && Criteria.Evaluate.m_cr != null)
            {
                if (!File.Exists(Criteria.Evaluate.m_cr.PathToAssembly))
                {
                    Criteria.Evaluate = null;
                }
            }

            Criteria.Criteria = criteria;
            foreach (String str in Criteria.Errors)
            {
                SimulationMessaging.AddMessage(new SimulationMessage("Error: Split treatment criteria for " + criteria + " :" + str));
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Load all consequence information associated with treat.
        /// </summary>
        public bool LoadConsequences(object APICall, IMongoCollection <SimulationModel> Simulations, string m_strSimulationID)
        {
            Consequences consequence;
            String       select = "SELECT ATTRIBUTE_,CHANGE_,CRITERIA,EQUATION,ISFUNCTION, CONSEQUENCEID FROM " + cgOMS.Prefix + "CONSEQUENCES WHERE TREATMENTID='" + _treatmentID + "'";

            if (SimulationMessaging.IsOMS)
            {
                select = "SELECT ATTRIBUTE_,CHANGE_,CRITERIA,EQUATION,NULL AS ISFUNCTION, CONSEQUENCEID FROM " + cgOMS.Prefix + "CONSEQUENCES WHERE TREATMENTID='" + _treatmentID + "'";
            }

            DataSet ds;

            try
            {
                ds = DBMgr.ExecuteQuery(select);
            }
            catch (Exception exception)
            {
                SimulationMessaging.AddMessage(new SimulationMessage("Fatal Error: Opening CONSEQUENCES table. SQL Message - " + exception.Message));
                if (APICall.Equals(true))
                {
                    var updateStatus = Builders <SimulationModel> .Update
                                       .Set(s => s.status, "Fatal Error: Opening CONSEQUENCES table. SQL Message - " + exception.Message);

                    Simulations.UpdateOne(s => s.simulationId == Convert.ToInt32(m_strSimulationID), updateStatus);
                }
                return(false);
            }

            var consequenceCount = 0;

            foreach (DataRow row in ds.Tables[0].Rows)
            {
                string id = row["CONSEQUENCEID"].ToString();
                consequence = new Consequences(id);
                String strAttribute = row["ATTRIBUTE_"].ToString();
                String strChange    = row["CHANGE_"].ToString();
                String strCriteria  = row["CRITERIA"].ToString();
                String strEquation  = row["EQUATION"].ToString();
                consequence.TreatmentID = this.TreatmentID;
                consequence.Treatment   = this.Treatment;

                SimulationMessaging.AddMessage(new SimulationMessage("Compiling treatment consequence " + consequenceCount));
                if (APICall.Equals(true))
                {
                    var updateStatus = Builders <SimulationModel> .Update
                                       .Set(s => s.status, "Compiling treatment consequence " + consequenceCount);

                    Simulations.UpdateOne(s => s.simulationId == Convert.ToInt32(m_strSimulationID), updateStatus);
                }
                consequenceCount++;


                if (strCriteria.Trim().Length == 0)
                {
                    consequence.Default = true;
                }
                else
                {
                    consequence.Default = false;

                    byte[] assemblyCriteria = null;
                    assemblyCriteria = SimulationMessaging.GetSerializedCalculateEvaluate(cgOMS.Prefix + "CONSEQUENCES", "BINARY_CRITERIA", id, assemblyCriteria);
                    if (assemblyCriteria != null && assemblyCriteria.Length > 0)
                    {
                        consequence.Criteria.Evaluate = (CalculateEvaluate.CalculateEvaluate)AssemblySerialize.DeSerializeObjectFromByteArray(assemblyCriteria);
                        if (consequence.Criteria.Evaluate.OriginalInput != strCriteria)
                        {
                            consequence.Criteria.Evaluate = null;
                        }
                    }

                    consequence.Criteria.Criteria = strCriteria;
                    //Get attributes from consequence criteria
                    foreach (String str in consequence.Criteria.CriteriaAttributes)
                    {
                        if (!SimulationMessaging.IsAttribute(str))
                        {
                            SimulationMessaging.AddMessage(new SimulationMessage("Error: " + str + " which is used by the Consequence criteria is not present in the database."));
                            if (APICall.Equals(true))
                            {
                                var updateStatus = Builders <SimulationModel> .Update
                                                   .Set(s => s.status, "Error: " + str + " which is used by the Consequence criteria is not present in the database");

                                Simulations.UpdateOne(s => s.simulationId == Convert.ToInt32(m_strSimulationID), updateStatus);
                            }
                        }
                        if (!_attributes.Contains(str))
                        {
                            _attributes.Add(str);
                        }
                    }
                }


                if (string.IsNullOrWhiteSpace(strEquation.Trim()))
                {
                    consequence.IsEquation = false;;
                }
                else
                {
                    byte[] assembly = SimulationMessaging.GetSerializedCalculateEvaluate(cgOMS.Prefix + "CONSEQUENCES", "BINARY_EQUATION", id, null);
                    if (assembly != null && assembly.Length > 0)
                    {
                        consequence._calculate = (CalculateEvaluate.CalculateEvaluate)AssemblySerialize.DeSerializeObjectFromByteArray(assembly);
                        if (consequence._calculate.OriginalInput != strEquation)
                        {
                            consequence._calculate = null;
                        }
                    }

                    bool isFunction = false;
                    if (row["ISFUNCTION"] != DBNull.Value)
                    {
                        isFunction = Convert.ToBoolean(row["ISFUNCTION"]);
                    }

                    if (isFunction)
                    {
                        consequence.SetFunction(strEquation);
                    }
                    else
                    {
                        consequence.Equation = strEquation;
                    }
                    //Get attributes from consequence criteria
                    foreach (string attribute in consequence._attributesEquation)
                    {
                        if (!SimulationMessaging.IsAttribute(attribute))
                        {
                            SimulationMessaging.AddMessage(new SimulationMessage("Error: " + attribute + " which is used by the Consequence criteria is not present in the database."));
                            if (APICall.Equals(true))
                            {
                                var updateStatus = Builders <SimulationModel> .Update
                                                   .Set(s => s.status, "Error: " + attribute + " which is used by the Consequence criteria is not present in the database");

                                Simulations.UpdateOne(s => s.simulationId == Convert.ToInt32(m_strSimulationID), updateStatus);
                            }
                        }
                        if (!_attributes.Contains(attribute))
                        {
                            _attributes.Add(attribute);
                        }
                    }
                }

                consequence.LoadAttributeChange(strAttribute, strChange);
                ConsequenceList.Add(consequence);

                // Get attributes from Attribute change
                foreach (String str in consequence.Attributes)
                {
                    if (!_attributes.Contains(str))
                    {
                        _attributes.Add(str);
                    }
                }
            }
            return(true);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Load all cost information associated with this treatment.
        /// </summary>
        public bool LoadCost(object APICall, IMongoCollection <SimulationModel> Simulations, string m_strSimulationID)
        {
            Costs  cost;
            String select = "SELECT COST_,UNIT,CRITERIA,BINARY_CRITERIA,ISFUNCTION, COSTID FROM " + cgOMS.Prefix + "COSTS WHERE TREATMENTID='" + this.TreatmentID + "'";

            if (SimulationMessaging.IsOMS)
            {
                select = "SELECT COST_,UNIT,CRITERIA,BINARY_CRITERIA,NULL AS ISFUNCTION, COSTID FROM " + cgOMS.Prefix + "COSTS WHERE TREATMENTID='" + this.TreatmentID + "'";
            }
            DataSet ds;

            try
            {
                //SimulationMessaging.AddMessage("DEBUGGING: Attempting cost select...");
                ds = DBMgr.ExecuteQuery(select);
                //SimulationMessaging.AddMessage("DEBUGGING: Cost select successful.");
            }
            catch (Exception exception)
            {
                SimulationMessaging.AddMessage(new SimulationMessage("Fatal Error: Opening COSTS table.  SQL message - " + exception.Message));
                if (APICall.Equals(true))
                {
                    var updateStatus = Builders <SimulationModel> .Update
                                       .Set(s => s.status, "Fatal Error: Opening COSTS table.  SQL message - " + exception.Message);

                    Simulations.UpdateOne(s => s.simulationId == Convert.ToInt32(m_strSimulationID), updateStatus);
                }
                return(false);
            }


            foreach (DataRow row in ds.Tables[0].Rows)
            {
                string id = row["COSTID"].ToString();
                cost = new Costs(id);

                if (row["CRITERIA"].ToString().Trim().Length == 0)
                {
                    cost.Default = true;
                }
                else
                {
                    cost.Default = false;
                    string criteria         = row["CRITERIA"].ToString();
                    byte[] assemblyCriteria = null;
                    assemblyCriteria = SimulationMessaging.GetSerializedCalculateEvaluate(cgOMS.Prefix + "COSTS", "BINARY_CRITERIA", cost.CostID, assemblyCriteria);
                    if (assemblyCriteria != null && assemblyCriteria.Length > 0)
                    {
                        cost.Criteria.Evaluate = (CalculateEvaluate.CalculateEvaluate)AssemblySerialize.DeSerializeObjectFromByteArray(assemblyCriteria);
                        if (cost.Criteria.Evaluate.OriginalInput != criteria)
                        {
                            cost.Criteria.Evaluate = null;
                        }
                    }

                    cost.Criteria.Criteria = criteria;
                    foreach (String str in cost.Criteria.CriteriaAttributes)
                    {
                        if (!SimulationMessaging.IsAttribute(str))
                        {
                            SimulationMessaging.AddMessage(new SimulationMessage("Error: " + str + " which is used by the Cost criteria is not present in the database."));
                            if (APICall.Equals(true))
                            {
                                var updateStatus = Builders <SimulationModel> .Update
                                                   .Set(s => s.status, "Error: " + str + " which is used by the Cost criteria is not present in the database");

                                Simulations.UpdateOne(s => s.simulationId == Convert.ToInt32(m_strSimulationID), updateStatus);
                            }
                        }
                        if (!_attributes.Contains(str))
                        {
                            _attributes.Add(str);
                        }
                    }
                }


                byte[] assemblyCost = null;
                //objectValue = row["BINARY_COST"];
                //if (objectValue != System.DBNull.Value)
                //{
                //    assemblyCost = (byte[])row["BINARY_COST"];
                //}
                String strCost = row["COST_"].ToString();
                assemblyCost = SimulationMessaging.GetSerializedCalculateEvaluate(cgOMS.Prefix + "COSTS", "BINARY_EQUATION", cost.CostID, assemblyCost);
                if (assemblyCost != null && assemblyCost.Length > 0)
                {
                    cost.Calculate = (CalculateEvaluate.CalculateEvaluate)AssemblySerialize.DeSerializeObjectFromByteArray(assemblyCost);
                    if (cost.Calculate.OriginalInput != strCost)
                    {
                        cost.Calculate = null;
                    }
                }

                if (strCost.Trim() == "")
                {
                    SimulationMessaging.AddMessage(new SimulationMessage("Fatal Error: Cost equation is blank for treatment - " + _treatment));
                    if (APICall.Equals(true))
                    {
                        var updateStatus = Builders <SimulationModel> .Update
                                           .Set(s => s.status, "Fatal Error: Cost equation is blank for treatment - " + _treatment);

                        Simulations.UpdateOne(s => s.simulationId == Convert.ToInt32(m_strSimulationID), updateStatus);
                    }
                    return(false);
                }

                bool   isFunction = false;
                object function   = row["ISFUNCTION"];
                if (row["ISFUNCTION"] != DBNull.Value)
                {
                    isFunction = Convert.ToBoolean(row["ISFUNCTION"]);
                }
                if (isFunction)
                {
                    cost.SetFunction(row["COST_"].ToString());
                }
                else
                {
                    cost.Equation = row["COST_"].ToString();
                }

                foreach (String str in cost._attributesEquation)
                {
                    if (str != "AREA" && str != "LENGTH")
                    {
                        if (!SimulationMessaging.IsAttribute(str))
                        {
                            SimulationMessaging.AddMessage(new SimulationMessage("Error: " + str + " which is used by the Cost equation is not present in the database."));
                            if (APICall.Equals(true))
                            {
                                var updateStatus = Builders <SimulationModel> .Update
                                                   .Set(s => s.status, "Error: " + str + " which is used by the Cost equation is not present in the database");

                                Simulations.UpdateOne(s => s.simulationId == Convert.ToInt32(m_strSimulationID), updateStatus);
                            }
                        }
                        if (!_attributes.Contains(str))
                        {
                            _attributes.Add(str);
                        }
                    }
                }
                if (!cost.IsCompoundTreatment)
                {
                    if (cost._calculate.m_listError.Count > 0)
                    {
                        foreach (String str in cost.Calculate.m_listError)
                        {
                            SimulationMessaging.AddMessage(new SimulationMessage("Fatal Error: Cost equation:" + str));
                            if (APICall.Equals(true))
                            {
                                var updateStatus = Builders <SimulationModel> .Update
                                                   .Set(s => s.status, "Fatal Error: Cost equation:" + str);

                                Simulations.UpdateOne(s => s.simulationId == Convert.ToInt32(m_strSimulationID), updateStatus);
                            }
                            return(false);
                        }
                    }
                }
                _costs.Add(cost);
            }
            return(true);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Loads all feasibility criteria for this treatment in for this treatment ID.
        /// </summary>
        public bool LoadFeasibility(object APICall, IMongoCollection <SimulationModel> Simulations, string m_strSimulationID)
        {
            String strSelect = "SELECT CRITERIA,BINARY_CRITERIA,FEASIBILITYID FROM " + cgOMS.Prefix + "FEASIBILITY WHERE TREATMENTID='" + this.TreatmentID + "'";

            _table  = cgOMS.Prefix + "FEASIBILITY";
            _column = "BINARY_CRITERIA";

            DataSet ds;

            try
            {
                ds = DBMgr.ExecuteQuery(strSelect);
            }
            catch (Exception exception)
            {
                SimulationMessaging.AddMessage(new SimulationMessage("Fatal Error: Opening Treatment FEASIBILITY table.  SQL Message - " + exception.Message));
                if (APICall.Equals(true))
                {
                    var updateStatus = Builders <SimulationModel> .Update
                                       .Set(s => s.status, "Fatal Error: Opening Treatment FEASIBILITY table.");

                    Simulations.UpdateOne(s => s.simulationId == Convert.ToInt32(m_strSimulationID), updateStatus);
                }
                return(false);
            }


            foreach (DataRow row in ds.Tables[0].Rows)
            {
                _id = row["FEASIBILITYID"].ToString();
                Criterias criteria         = new Criterias(_table, _column, _id);
                byte[]    assemblyCriteria = null;
                string    currentCriteria  = "";
                if (row["CRITERIA"] != DBNull.Value)
                {
                    currentCriteria = Simulation.ConvertOMSAttribute(row["CRITERIA"].ToString());
                }
                assemblyCriteria = SimulationMessaging.GetSerializedCalculateEvaluate(_table, _column, _id, assemblyCriteria);
                if (assemblyCriteria != null && assemblyCriteria.Length > 0)
                {
                    criteria.Evaluate = (CalculateEvaluate.CalculateEvaluate)AssemblySerialize.DeSerializeObjectFromByteArray(assemblyCriteria);
                    if (criteria.Evaluate.OriginalInput != currentCriteria)
                    {
                        criteria.Evaluate = null;
                    }
                }

                if (criteria.Evaluate != null && criteria.Evaluate.m_cr != null)
                {
                    if (!File.Exists(criteria.Evaluate.m_cr.PathToAssembly))
                    {
                        criteria.Evaluate = null;
                    }
                }

                criteria.Criteria = Simulation.ConvertOMSAttribute(row["CRITERIA"].ToString());

                foreach (String str in criteria.Errors)
                {
                    SimulationMessaging.AddMessage(new SimulationMessage("Error: Treatment feasibility criteria for Treatment " + _treatment + ":" + str));
                    if (APICall.Equals(true))
                    {
                        var updateStatus = Builders <SimulationModel> .Update
                                           .Set(s => s.status, "Error: Treatment feasibility criteria for Treatment " + _treatment + ":" + str);

                        Simulations.UpdateOne(s => s.simulationId == Convert.ToInt32(m_strSimulationID), updateStatus);
                    }
                }

                this.CriteriaList.Add(criteria);
                foreach (String str in criteria.CriteriaAttributes)
                {
                    if (!SimulationMessaging.IsAttribute(str))
                    {
                        SimulationMessaging.AddMessage(new SimulationMessage("Error: " + str + " which is used by the Feasibility criteria is not present in the database."));
                        if (APICall.Equals(true))
                        {
                            var updateStatus = Builders <SimulationModel> .Update
                                               .Set(s => s.status, "Error: " + str + " which is used by the Feasibility criteria is not present in the database");

                            Simulations.UpdateOne(s => s.simulationId == Convert.ToInt32(m_strSimulationID), updateStatus);
                        }
                    }
                    if (!_attributes.Contains(str))
                    {
                        _attributes.Add(str);
                    }
                }
            }
            return(true);
        }