public List <ClassExpression> parse(FunctionDescriptionSheet funcSheet, MyLog myLog) { // parseOneFile title row Excel.Range xlRange = funcSheet.getSheet().UsedRange; int rowCount = xlRange.Rows.Count; int columnCount = xlRange.Columns.Count; Excel.Range firstRow = funcSheet.getSheet().Rows[1]; setColumnIndex(firstRow, myLog, ref columnCount); if (columnCount < 0) { return(null); } List <ClassExpression> classExpressions = new List <ClassExpression>(); ClassExpression classExpression = new ClassExpression(); for (int fi = 2; fi <= rowCount; fi++) { Excel.Range row = funcSheet.getSheet().Rows[fi]; string funcName = getValueCell(row, FUNCTION_NAME_COLUMN_INDEX); // indicate end sheet if (funcName == null || funcName.Equals("")) { break; } string workspace = getValueCell(row, WORKSPACE_COLUMN_INDEX); string _class = getValueCell(row, CLASS_COLUMN_INDEX); string accessibility = getValueCell(row, ACCESSIBILITY_COLUMN_INDEX); string summary = getValueCell(row, SUMMARY_COLUMN_INDEX); string parameters = getValueCell(row, PARAMETERS_COLUMN_INDEX); string _returns = getValueCell(row, RETURNS_COLUMN_INDEX); string implementation = getValueCell(row, IMPLEMENTATION_COLUMN_INDEX); string last_workspace = workspace == null || workspace.Equals("") ? classExpression.getWorkspace() : workspace; string last_class = _class == null || _class.Equals("") ? classExpression.getName() : _class; if (last_workspace == null || last_workspace.Equals("")) { myLog.Warn("Not know workspace for row #" + (fi + 1) + " in \"" + funcSheet.getSheet().Name + "\" sheet", logger); } if (last_class == null || last_workspace.Equals("")) { myLog.Warn("Not know workspace for row #" + (fi + 1) + " in \"" + funcSheet.getSheet().Name + "\" sheet", logger); } if (workspace != null && !workspace.Equals("") || (_class != null && !_class.Equals(""))) { classExpression = new ClassExpression(last_workspace, last_class); classExpressions.Add(classExpression); } List <ParameterExpression> _params = parseParams(parameters, myLog); FunctionExpression funcEpx = new FunctionExpression( funcName, accessibility, summary, _params); funcEpx.setReturnDescription(_returns); funcEpx.setContent(implementation); if (classExpression.getListFunction() == null) { classExpression.setListFunction(new List <FunctionExpression>()); } classExpression.getListFunction().Add(funcEpx); } return(classExpressions); }
/// <summary> /// /// </summary> /// <param name="filePath"></param> /// <param name="elementsAndIndicator">indication to determine root elements or list of all elements</param> /// <param name="myLog"></param> /// <returns></returns> private List <SpecScreen> DoParse(string filePath, ListUIElements elementsAndIndicator, MyLog myLog) { string newFilePath = Utils.CreateTempFile(filePath); //Create COM Objects. Create a COM object for everything that is referenced Excel.Application xlApp = new Excel.Application(); Excel.Workbook xlWorkbook = xlApp.Workbooks.Open(newFilePath); //Excel._Worksheet xlWorksheet = xlWorkbook.Sheets[1]; List <AbstractSheet> listAbstractSheets = new List <AbstractSheet>(); for (int fi = 1; fi <= xlWorkbook.Sheets.Count; fi++) { Excel._Worksheet sheet = xlWorkbook.Sheets[fi]; string name = sheet.Name; AbstractSheet abstractSheet = null; foreach (Tuple <string, string> pairSheetNameRule in SHEET_NAME_TEMPLATE_LIST) { Regex regex = new Regex(pairSheetNameRule.Item1); MatchCollection matches = regex.Matches(name); if (matches.Count > 0) { string featureName = matches[0].Groups[1].Value; abstractSheet = new TestSpecificationSheet(featureName, sheet); } else { Regex regex2 = new Regex(pairSheetNameRule.Item2); MatchCollection matches2 = regex2.Matches(name); if (matches2.Count > 0) { string featureName = matches2[0].Groups[1].Value; abstractSheet = new FunctionDescriptionSheet(featureName, sheet); } } } if (abstractSheet == null) { abstractSheet = new NormalSheet(name, sheet); } listAbstractSheets.Add(abstractSheet); } List <NormalSheet> normalSheets = new List <NormalSheet>(); List <Tuple <TestSpecificationSheet, FunctionDescriptionSheet> > pairSheets = new List <Tuple <TestSpecificationSheet, FunctionDescriptionSheet> >(); foreach (AbstractSheet abstractSheet in listAbstractSheets) { if (abstractSheet is NormalSheet) { normalSheets.Add((NormalSheet)abstractSheet); } else if (abstractSheet is TestSpecificationSheet) { FunctionDescriptionSheet funcDescSheet = findFuncDesc(abstractSheet.getFeatureName(), listAbstractSheets); pairSheets.Add(new Tuple <TestSpecificationSheet, FunctionDescriptionSheet>( (TestSpecificationSheet)abstractSheet, funcDescSheet)); } } List <SpecScreen> screenList = new List <SpecScreen>(); foreach (Tuple <TestSpecificationSheet, FunctionDescriptionSheet> pairSheet in pairSheets) { SpecScreen screen = parsePairSheet(pairSheet, elementsAndIndicator, myLog); if (screen != null) { screenList.Add(screen); } } foreach (NormalSheet normalSheet in normalSheets) { SpecScreen screen = parseNormalSheet(normalSheet, elementsAndIndicator, myLog); if (screen != null) { screenList.Add(screen); } } //return screenList; //cleanup //GC.Collect(); //GC.WaitForPendingFinalizers(); //rule of thumb for releasing com objects: // never use two dots, all COM objects must be referenced and released individually // ex: [somthing].[something].[something] is bad //close and release xlWorkbook.Close(false); Marshal.ReleaseComObject(xlWorkbook); //quit and release xlApp.Quit(); Marshal.ReleaseComObject(xlApp); return(screenList); }