public TestSpecificationScreen parse(TestSpecificationSheet testSpecSheet,
                                             ListUIElements elementsAndIndicator, MyLog myLog, List <ClassExpression> classExpressions)
        {
            NormalSheetParser normalSheetParser = new NormalSheetParser();
            SpecScreen        screen            = normalSheetParser.Parse(testSpecSheet, elementsAndIndicator, myLog);

            if (screen == null)
            {
                return(null);
            }
            TestSpecificationScreen re = new TestSpecificationScreen();

            re.AllUIElements          = elementsAndIndicator;
            re.ListSpecNodes          = screen.ListSpecNodes;
            re.ListValidationUserCode = screen.ListValidationUserCode;
            re.MappingAliasWithNode   = screen.MappingAliasWithNode;
            re.Name             = testSpecSheet.getFeatureName();
            re.Scenarios        = screen.Scenarios;
            re.ClassExpressions = classExpressions;
            return(re);
        }
Beispiel #2
0
        /// <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);
        }