private static CodeExpressionStatement getInvokeDetailStatement(RecordStep step, string dataClass)
        {
            CodeExpressionStatement statement = new CodeExpressionStatement();

            CodeExpression[] paras;
            if (step.ActionParams != null)
            {
                paras = new CodeExpression[step.ActionParams.Count];
                ///判断是否参数化函数代码
                if (dataClass == null)
                {
                    for (int i = 0; i < step.ActionParams.Count; i++)
                    {
                        paras[i] = new CodePrimitiveExpression(step.ActionParams[i].Value);
                    }
                }
                else
                {
                    for (int i = 0; i < step.ActionParams.Count; i++)
                    {
                        paras[i] = step.ActionParams[i].GetVariableReference(dataClass);
                    }
                }
            }
            else
            {
                paras = new CodeExpression[0];
            }

            CodeMethodInvokeExpression method = new CodeMethodInvokeExpression(step.CompInfo.FindMethod, step.ActionName, paras);

            statement.Expression = method;
            return(statement);
        }
        public static List <CodeStatement> GetCodeStatement(this RecordStep step, string dataClassParameter = null)
        {
            List <CodeStatement> codes      = new List <CodeStatement>();
            CodeStatement        actionCode = null;

            switch (step.Action)
            {
            case BindingFlags.SetProperty:
                actionCode = getAssignDetailStatement(step, dataClassParameter);
                break;

            case BindingFlags.InvokeMethod:
                actionCode = getInvokeDetailStatement(step, dataClassParameter);
                break;

            default:
                break;
            }
            if (actionCode != null)
            {
                codes.Add(actionCode);
            }

            if (step.TakeScreenShot)
            {
                CodeExpressionStatement screenShotCode = new CodeExpressionStatement();
                screenShotCode.Expression = new CodeMethodInvokeExpression(
                    new CodeVariableReferenceExpression("SAPTestHelper.Current"),
                    "TakeScreenShot",
                    new CodePrimitiveExpression(step.StepId.ToString() + ".jpg"));
                codes.Add(screenShotCode);
            }
            return(codes);
        }
        private static CodeExpressionStatement getInvokeDetailStatement(RecordStep step, string dataClass)
        {
            CodeExpressionStatement statement = new CodeExpressionStatement();
            CodeExpression[] paras;
            if (step.ActionParams != null)
            {
                paras = new CodeExpression[step.ActionParams.Count];
                ///判断是否参数化函数代码
                if(dataClass == null)
                {
                    for (int i = 0; i < step.ActionParams.Count; i++)
                    {
                        paras[i] = new CodePrimitiveExpression(step.ActionParams[i].Value);
                    }
                }
                else
                {
                    for (int i = 0; i < step.ActionParams.Count; i++)
                    {
                        paras[i] = step.ActionParams[i].GetVariableReference(dataClass);
                    }
                }

            }
            else
            {
                paras = new CodeExpression[0];
            }

            CodeMethodInvokeExpression method = new CodeMethodInvokeExpression(step.CompInfo.FindMethod, step.ActionName, paras);
            statement.Expression = method;
            return statement;
        }
        private static CodeAssignStatement getAssignDetailStatement(RecordStep step, string dataClass)
        {
            CodeAssignStatement asStatement = new CodeAssignStatement();

            asStatement.Left = new CodePropertyReferenceExpression(step.CompInfo.FindMethod, step.ActionName);

            if (dataClass == null)
                asStatement.Right = new CodePrimitiveExpression(step.ActionParams[0].Value);
            else
                asStatement.Right = step.ActionParams[0].GetVariableReference(dataClass);
            return asStatement;
        }
        private static CodeAssignStatement getAssignDetailStatement(RecordStep step, string dataClass)
        {
            CodeAssignStatement asStatement = new CodeAssignStatement();

            asStatement.Left = new CodePropertyReferenceExpression(step.CompInfo.FindMethod, step.ActionName);

            if (dataClass == null)
            {
                asStatement.Right = new CodePrimitiveExpression(step.ActionParams[0].Value);
            }
            else
            {
                asStatement.Right = step.ActionParams[0].GetVariableReference(dataClass);
            }
            return(asStatement);
        }
        public object RunAction(RecordStep step)
        {
            GuiComponent comp = GetSAPComponentById <GuiComponent>(step.CompInfo.Id);

            if (comp == null)
            {
                throw new Exception(string.Format("Can't find component using id {0}", step.CompInfo.Id));
            }
            string typeName = _prefix + comp.Type;
            Type   t        = _sapGuiApiAssembly.GetType(typeName);

            if (t == null)
            {
                throw new Exception(string.Format("Can't find type {0}", typeName));
            }
            return(t.InvokeMember(step.ActionName, step.Action, null, comp, step.ActionParams == null ? null : step.ActionParams.Select(a => a.Value).ToArray()));
        }
        void _sapGuiSession_Change(GuiSession Session, GuiComponent Component, object CommandArray)
        {
            if (_stepAction == null)
            {
                return;
            }
            SapCompInfo cpInfo = new SapCompInfo();

            cpInfo.Id   = Component.Id;
            cpInfo.Name = Component.Name;
            cpInfo.Type = Component.GetDetailType();

            if (Component is GuiVComponent)
            {
                var vc = Component as GuiVComponent;
                try
                {
                    cpInfo.Tip = vc.DefaultTooltip == "" ? vc.Tooltip : vc.DefaultTooltip;
                }
                catch
                {
                }
            }


            if (_isFindById)
            {
                cpInfo.FindMethod = Component.FindByIdCode();
            }
            else
            {
                cpInfo.FindMethod = Component.FindByNameCode();
            }

            RecordStep step = new RecordStep();

            step.CompInfo = cpInfo;

            object[] objs = CommandArray as object[];

            objs = objs[0] as object[];
            switch (objs[0].ToString().ToLower())
            {
            case "m":
                step.Action = BindingFlags.InvokeMethod;
                break;

            case "sp":
                step.Action = BindingFlags.SetProperty;
                break;
            }

            var action = objs[1].ToString();

            upperFirstChar(ref action);

            step.ActionName = action;

            var count = objs.Count();

            if (count > 2)
            {
                step.ActionParams = new List <SAPDataParameter>();

                if (step.Action == BindingFlags.InvokeMethod)
                {
                    MethodInfo method = GetSAPTypeInfo(step.CompInfo.Type).GetMethod(step.ActionName);
                    //MethodInfo method = SAPAutomationHelper.Current.GetSAPTypeInfo<MethodInfo>(step.CompInfo.Type, t => t.GetMethod(step.ActionName));
                    int index = 2;
                    foreach (var pInfo in method.GetParameters())
                    {
                        var para = new SAPDataParameter();
                        para.Type    = pInfo.ParameterType;
                        para.Comment = pInfo.Name;
                        para.Value   = objs[index];
                        para.Name    = pInfo.Name;
                        step.ActionParams.Add(para);
                        index++;
                    }
                }
                else
                {
                    for (int i = 2; i < count; i++)
                    {
                        var para = new SAPDataParameter();
                        para.Type    = objs[i].GetType();
                        para.Value   = objs[i];
                        para.Comment = step.CompInfo.Tip;

                        step.ActionParams.Add(para);
                    }
                }
            }

            _stepAction(step);
        }