Пример #1
0
        public override ScriptsExpression HandleAndGenScripts(IScriptGenerationParams scriptGenerationParams, ScriptType scriptType = ScriptType.Normal)
        {
            string re = GetComment(scriptGenerationParams) + NEW_LINE;

            if (scriptGenerationParams is ValidationUCScriptGenerationParams param)
            {
                string newFunctionContent = "";
                if (param.SpecNode.Attribute == null ||
                    param.SpecNode.Attribute == "")
                {
                    param.SpecNode.Attribute = TEXT;
                }
                foreach (string exp in param.ListExps)
                {
                    if (newFunctionContent != "")
                    {
                        newFunctionContent += NEW_LINE;
                    }
                    if (scriptType == ScriptType.Normal)
                    {
                        newFunctionContent += ValidationSpecUserAction.GetRawScripts(param, exp).Expression;
                    }
                    else if (scriptType == ScriptType.Ranorex)
                    {
                        newFunctionContent += ValidationSpecUserAction.GetRawRanorexScripts(param as IRanorexScriptGenerationParams, exp).Expression;
                    }
                }
                string newClassName = param.ClassName;
                string newFuncName  = param.FunctionName;
                re += newClassName + "." + newFuncName + "();";
                var pair = CheckFunctionExisted(param.ClassExpressions, newClassName, newFuncName, 0, true);
                // if not existed
                if (!pair.Item1)
                {
                    FunctionExpression func = new FunctionExpression(newFuncName);
                    func.setContent(newFunctionContent);
                    UserCodeScriptsExpression re1 = new UserCodeScriptsExpression(re);
                    re1.MapClassAndFuncsAddition = new Dictionary <string, List <FunctionExpression> >
                    {
                        { newClassName, new List <FunctionExpression>()
                          {
                              func
                          } }
                    };
                    return(re1);
                }
                return(new ScriptsExpression(re));
            }
            else
            {
                re += ValidationSpecUserAction.GetRawScripts(scriptGenerationParams, this.Expression).Expression;
                return(new ScriptsExpression(re));
            }
        }
Пример #2
0
        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);
        }