public void Load(bool checkAsofdate = false) { VariablesInfo result = null; if (m_isCombile) { result = LoadFromFile(Path.Combine(m_dsFolder, combileVariablesFile)); } else { result = Load3Files(); Save(); m_isCombile = true; } var asofdateItem = result.Variables.FirstOrDefault(o => o.Name.Equals(asofdateVal, StringComparison.CurrentCultureIgnoreCase)); if (asofdateItem != null) { var obj = asofdateItem.Items.FirstOrDefault(o => o.Value.Equals("TRUE", StringComparison.CurrentCultureIgnoreCase)); if (obj.Value != null) { if (checkAsofdate && m_asofdate != obj.Key) { throw new Exception("变量: SimulationBegin的值和当前的asofdate不相符"); } m_asofdate = obj.Key; } result.Variables.Remove(asofdateItem); } Variables = result; }
/// <summary> /// update info based on the expression /// </summary> /// <param name="exp"></param> public void UpdateByExpression(Expression exp) { if (exp is VariableDeclaration) { //variable declaration expression var vdExp = (VariableDeclaration)exp; VariableInfo vi = new VariableInfo(vdExp); VariablesInfo.Add(vi); //update if it contains assignment if (vdExp.Initializer != null) { var subExps = new List <Expression>(); if (vdExp.Initializer.Components.Count == 0) { subExps.Add(vdExp.Initializer); } else { subExps = vdExp.Initializer.Components.ToList(); } UpdateAssignmentExpRightHand(subExps, 0, vi, false); //TO DO: ex. = new school() } } else if (exp is MethodCall) { //Method call expression var mcExp = (MethodCall)exp; UpdateMethodCall(mcExp); } else { //Update the expression var subExps = exp.Components.ToList(); int curPos = 0; // Checks keyword new if (subExps.Count > 0) { var oUse = subExps.ElementAt(0) as OperatorUse; if (oUse != null && oUse.Text == "new") { if (InReturnStmt > 0) { IsReturnNewObj = true; } curPos++; } } UpdateByExpToTheEnd(subExps, curPos); } }
private static void AddVariableInfoExcelTableRowData(DmnInfo dmnInfo, VariablesInfo variableInfo, int rowIndex, ExcelWorksheet wsSheet, string[] dmnFields, string variableUseType = null) { var startTableCellAddress = wsSheet.Tables.FirstOrDefault()?.Address.Start.Address; for (int i = 0; i < dmnFields.Length; i++) { var value = GetPropertyStringValue(dmnInfo, dmnFields[i]) ?? GetPropertyStringValue(variableInfo, dmnFields[i]); if (dmnFields[i] == "VariablesUseType" && !string.IsNullOrEmpty(variableUseType)) { value = variableUseType; } var cellAdress = AddRowAndColumnToCellAddress(startTableCellAddress, rowIndex + 1, i); wsSheet.Cells[cellAdress].Value = value; } }
private VariablesInfo Load3Files() { VariablesInfo result = new VariablesInfo(); VariablesInfo result1 = LoadFromFile(pastVariablesFile); VariablesInfo result2 = LoadFromFile(currentVariablesFile); if (result2.Dates == null || result2.Dates.Count == 0) { throw new Exception("无法加载: currentVariablesFile"); } m_asofdate = result2.Dates[0]; VariablesInfo result3 = LoadFromFile(futureVariablesFile); List <VariablesCsvRecord> items = new List <VariablesCsvRecord>(); items.AddRange(result1.Variables); items.AddRange(result2.Variables); items.AddRange(result3.Variables); items = items.GroupBy(o => new { o.Name }).Select(o => { var item = new VariablesCsvRecord { Name = o.Key.Name, Description = o.First().Description }; var values = o.SelectMany(m => m.Items); foreach (var v in values) { if (!item.Items.ContainsKey(v.Key)) { item.Items.Add(v.Key, v.Value); } } return(item); }).ToList(); result.Variables = items; result.Dates.AddRange(result1.Dates); result.Dates.AddRange(result2.Dates); result.Dates.AddRange(result3.Dates); result.Dates = result.Dates.Distinct().OrderBy(o => o).ToList(); return(result); }
/// <summary> /// update info based on the expression /// </summary> /// <param name="exp"></param> public void UpdateByExpression(Expression exp) { if (exp is VariableDeclaration) { //variable declaration expression var vdExp = (VariableDeclaration)exp; VariableInfo vi = new VariableInfo(vdExp); VariablesInfo.Add(vi); //update if it contains assignment if (vdExp.Initializer != null) { var subExps = new List <Expression>(); if (vdExp.Initializer.Components.Count == 0) { subExps.Add(vdExp.Initializer); } else { subExps = vdExp.Initializer.Components.ToList(); } UpdateAssignmentExpRightHand(subExps, 0, vi.Variable, false); //TO DO: ex. = new school() } else { //Special process, since Linq is not in Srcml.net if (vdExp.Location.EndingLineNumber - vdExp.Location.StartingLineNumber > 1) { var assignedVar = vdExp; HashSet <VariableDeclaration> AssigningVars = new HashSet <VariableDeclaration>(); Statement stmt = vdExp.ParentStatement; var assigningVar = this.VAssignmentManager.FindMostComplecatedVD(); if (assigningVar != null) { AssigningVars.Add(assigningVar); } if (AssigningVars.Count > 0 && stmt != null) { VAssignmentManager.AddNewRelations(assignedVar, AssigningVars, stmt); } } } } else if (exp is MethodCall) { //Method call expression var mcExp = (MethodCall)exp; UpdateMethodCall(mcExp); } else { //Update the expression var subExps = exp.Components.ToList(); int curPos = 0; // Checks keyword new if (subExps.Count > 0) { var oUse = subExps.ElementAt(0) as OperatorUse; if (oUse != null && oUse.Text == "new") { if (InReturnStmt > 0) { IsReturnNewObj = true; } curPos++; } } UpdateByExpToTheEnd(subExps, curPos); } }