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)); } }
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)); } }
/// <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); }
/// <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); }
/// <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); }
public CompoundTreatmentElement(string compoundTreatmentID, string compoundTreatmentName, string attributeFrom, string attributeTo, string costEquation, string extentEquation, string quantityCriteria, string criteriaString) { _compoundTreatmentID = compoundTreatmentID; _compoundTreatmentName = compoundTreatmentName; // Begin building the relavent attribute list. This list contains all attributes used in the various // criteria and equations. _attributeFrom = attributeFrom; if (!_relevantAttributes.Contains(_attributeFrom)) { _relevantAttributes.Add(_attributeFrom); } _attributeTo = attributeTo; if (!_relevantAttributes.Contains(_attributeTo)) { _relevantAttributes.Add(_attributeTo); } // Add cost attributes byte[] assembly = SimulationMessaging.GetSerializedCalculateEvaluate(cgOMS.Prefix + "COMPOUNDTREATMENT", "COST", compoundTreatmentID, null); if (assembly != null && assembly.Length > 0) { _cost = (CalculateEvaluate.CalculateEvaluate)AssemblySerialize.DeSerializeObjectFromByteArray(assembly); if (SimulationMessaging.Area.OriginalInput != costEquation) { _cost = null; } } if (_cost == null) { _cost = new CalculateEvaluate.CalculateEvaluate(); _cost.BuildClass(costEquation, true, cgOMS.Prefix + "COMPOUNDTREATMENT_COST_" + compoundTreatmentID); _cost.CompileAssembly(); SimulationMessaging.SaveSerializedCalculateEvaluate(cgOMS.Prefix + "COMPOUNDTREATMENT", "COST", compoundTreatmentID, _cost); } foreach (string parameter in _cost.m_listParameters) { if (!_relevantAttributes.Contains(parameter)) { _relevantAttributes.Add(parameter); } } assembly = null; assembly = SimulationMessaging.GetSerializedCalculateEvaluate(cgOMS.Prefix + "COMPOUNDTREATMENT", "EXTENT", compoundTreatmentID, null); if (assembly != null && assembly.Length > 0) { _extent = (CalculateEvaluate.CalculateEvaluate)AssemblySerialize.DeSerializeObjectFromByteArray(assembly); if (SimulationMessaging.Area.OriginalInput != extentEquation) { _extent = null; } } if (_extent == null) { // Add extent attributes _extent = new CalculateEvaluate.CalculateEvaluate(); _extent.BuildClass(extentEquation, true, cgOMS.Prefix + "COMPOUNDTREATMENT_EXTENT_" + compoundTreatmentID); _extent.CompileAssembly(); SimulationMessaging.SaveSerializedCalculateEvaluate(cgOMS.Prefix + "COMPOUNDTREATMENT", "EXTENT", compoundTreatmentID, _extent); } foreach (string parameter in _extent.m_listParameters) { if (!_relevantAttributes.Contains(parameter)) { _relevantAttributes.Add(parameter); } } assembly = null; assembly = SimulationMessaging.GetSerializedCalculateEvaluate(cgOMS.Prefix + "COMPOUNDTREATMENT", "QUANTITY", compoundTreatmentID, null); if (assembly != null && assembly.Length > 0) { _quantity = (CalculateEvaluate.CalculateEvaluate)AssemblySerialize.DeSerializeObjectFromByteArray(assembly); if (SimulationMessaging.Area.OriginalInput != extentEquation) { _quantity = null; } } if (_quantity == null) { // Add quantity attributes _quantity = new CalculateEvaluate.CalculateEvaluate(); _quantity.BuildClass(quantityCriteria, true, cgOMS.Prefix + "COMPOUNDTREATMENT_QUANTITY_" + compoundTreatmentID); _quantity.CompileAssembly(); SimulationMessaging.SaveSerializedCalculateEvaluate(cgOMS.Prefix + "COMPOUNDTREATMENT", "QUANTITY", compoundTreatmentID, _quantity); } foreach (string parameter in _quantity.m_listParameters) { if (!_relevantAttributes.Contains(parameter)) { _relevantAttributes.Add(parameter); } } // Add any criteria attributes _criteria = new Criterias(); if (!string.IsNullOrEmpty(criteriaString)) { _criteria.Criteria = criteriaString; foreach (string parameter in _criteria.CriteriaAttributes) { if (!_relevantAttributes.Contains(parameter)) { _relevantAttributes.Add(parameter); } } } }