コード例 #1
0
        public override StepResult InvokeStep(bool forceInvoke)
        {
            object instance = null;

            if (Function.Type == FunctionType.InstancePropertySetter)
            {
                instance = Context.VariableMapper.GetParamValue(_instanceVar, Function.Instance,
                                                                Function.ClassType);
            }
            IParameterDataCollection parameters = Function.Parameters;
            IArgumentCollection      arguments  = Function.ParameterType;

            // 开始计时
            StartTiming();
            for (int i = 0; i < _properties.Count; i++)
            {
                if (null == _properties[i])
                {
                    continue;
                }
                if (parameters[i].ParameterType == ParameterType.Variable)
                {
                    // 获取变量值的名称,该名称为变量的运行时名称,其值在InitializeParamValue方法里配置
                    string variableName = ModuleUtils.GetVariableNameFromParamValue(parameters[i].Value);
                    // 根据ParamString和变量对应的值配置参数。
                    _params[i] = Context.VariableMapper.GetParamValue(variableName, parameters[i].Value,
                                                                      arguments[i].Type);
                }
                _properties[i].SetValue(instance, _params[i]);
            }
            // 停止计时
            EndTiming();
            return(StepResult.Pass);
        }
コード例 #2
0
        // 改变StepData.Function.Parameters:如果是variable,则变为运行时$格式
        protected override void InitializeParamsValues()
        {
            IArgumentCollection      argumentInfos = Function.ParameterType;
            IParameterDataCollection parameters    = Function.Parameters;

            for (int i = 0; i < argumentInfos.Count; i++)
            {
                string paramValue = parameters[i].Value;
                if (parameters[i].ParameterType == ParameterType.Value)
                {
                    Params[i] = Context.TypeInvoker.CastConstantValue(argumentInfos[i].Type, paramValue);
                }
                else
                {
                    // 如果是变量,则先获取对应的Varaible变量,真正的值在运行时才更新获取
                    string    variableName = ModuleUtils.GetVariableNameFromParamValue(paramValue);
                    IVariable variable     = ModuleUtils.GetVaraibleByRawVarName(variableName, StepData);
                    if (null == variable)
                    {
                        Context.LogSession.Print(LogLevel.Error, SequenceIndex,
                                                 $"Unexist variable '{variableName}' in sequence data.");
                        throw new TestflowDataException(ModuleErrorCode.SequenceDataError,
                                                        Context.I18N.GetFStr("UnexistVariable", variableName));
                    }
                    // 将变量的值保存到Parameter中
                    string varFullName = CoreUtils.GetRuntimeVariableName(Context.SessionId, variable);
                    parameters[i].Value = ModuleUtils.GetFullParameterVariableName(varFullName, parameters[i].Value);
                    Params[i]           = null;
                }
            }
            //todo 做同步的时候再添加对返回值的处理,代码参照StepExecutionEntity的InitializeParamsValue
        }
コード例 #3
0
        //执行step,然后发送消息
        //todo I18n
        private void ProcessCallBack(CallBackMessage message)
        {
            string        methodName = message.Name;
            List <string> arg        = message.Args;
            bool          result     = false;

            try
            {
                if (!_callBackFunctions.ContainsKey(methodName) || !_callBackMethods.ContainsKey(methodName))
                {
                    throw new TestflowException(ModuleErrorCode.CallBackFunctionNameError, $"Unable to load function name {methodName}");
                }
                IFunctionData            function       = _callBackFunctions[methodName];
                IArgumentCollection      parameterTypes = function.ParameterType;
                IParameterDataCollection parameters     = function.Parameters;

                object[] obj = new object[arg.Count];

                for (int n = 0; n < arg.Count; n++)
                {
                    //undefined的情况应该不存在吧
                    //enum或者value
                    if (parameterTypes[n].VariableType == VariableType.Undefined)
                    {
                        //todo I18n
                        throw new TestflowException(ModuleErrorCode.IncorrectParamType, "Type should not be Undefined.");
                    }
                    if (parameterTypes[n].VariableType == VariableType.Value || parameterTypes[n].VariableType == VariableType.Enumeration)
                    {
                        obj[n] = _typeInvoker.CastValue(parameterTypes[n].Type, (arg[n]));
                    }
                    //class或者struct
                    else
                    {
                        obj[n] = JsonConvert.DeserializeObject(arg[n], _typeInvoker.GetType(parameterTypes[n].Type));
                    }
                }
                _callBackMethods[methodName].Invoke(null, obj);
                result = true;
            }
            catch (TestflowException ex)
            {
                _globalInfo.LogService.Print(LogLevel.Error, 0, ex, $"CallBack has a TestflowException when trying to execute {methodName}: {ex.Message}");
            }
            catch (ThreadAbortException ex)
            {
                _globalInfo.LogService.Print(LogLevel.Error, 0, ex, $"thread {Thread.CurrentThread.Name} stopped abnormally when executing {methodName}: {ex.Message}");
            }
            catch (Exception ex)
            {
                _globalInfo.LogService.Print(LogLevel.Error, 0, ex, $"CallBack has an Exception when executing {methodName}: {ex.Message}");
            }

            if (message.CallBackType == CallBackType.Synchronous)
            {
                SendMessage(message, result);
            }
        }
コード例 #4
0
        protected override void InitializeParamsValues()
        {
            IArgumentCollection      argumentInfos = Function.ParameterType;
            IParameterDataCollection parameters    = Function.Parameters;

            for (int i = 0; i < argumentInfos.Count; i++)
            {
                string paramValue = parameters[i].Value;
                switch (parameters[i].ParameterType)
                {
                case ParameterType.Value:
                    Params[i] = Context.TypeInvoker.CastConstantValue(argumentInfos[i].Type, paramValue);
                    break;

                case ParameterType.Variable:
                    // 如果是变量,则先获取对应的Varaible变量,真正的值在运行时才更新获取
                    string    variableName = ModuleUtils.GetVariableNameFromParamValue(paramValue);
                    IVariable variable     = ModuleUtils.GetVaraibleByRawVarName(variableName, StepData);
                    if (null == variable)
                    {
                        Context.LogSession.Print(LogLevel.Error, Context.SessionId,
                                                 $"Unexist variable '{variableName}' in sequence data.");
                        throw new TestflowDataException(ModuleErrorCode.SequenceDataError,
                                                        Context.I18N.GetFStr("UnexistVariable", variableName));
                    }
                    // 将变量的值保存到Parameter中
                    string varFullName = CoreUtils.GetRuntimeVariableName(Context.SessionId, variable);
                    parameters[i].Value = ModuleUtils.GetFullParameterVariableName(varFullName, parameters[i].Value);
                    Params[i]           = null;
                    break;

                default:
                    Context.LogSession.Print(LogLevel.Error, Context.SessionId,
                                             $"The value of parameter '{argumentInfos[i].Name}' is not configured");
                    throw new TestflowDataException(ModuleErrorCode.SequenceDataError,
                                                    Context.I18N.GetStr("InvalidParamVar"));
                    break;
                }
            }
            if (null != Function.ReturnType && CoreUtils.IsValidVaraible(Function.Return))
            {
                // 如果是变量,则先获取对应的Varaible变量,真正的值在运行时才更新获取
                string    variableName = ModuleUtils.GetVariableNameFromParamValue(Function.Return);
                IVariable variable     = ModuleUtils.GetVaraibleByRawVarName(variableName, StepData);
                if (null == variable)
                {
                    Context.LogSession.Print(LogLevel.Error, SequenceIndex,
                                             $"Unexist variable '{variableName}' in sequence data.");
                    throw new TestflowDataException(ModuleErrorCode.SequenceDataError,
                                                    Context.I18N.GetFStr("UnexistVariable", variableName));
                }
                ReturnVar = CoreUtils.GetRuntimeVariableName(Context.SessionId, variable);
            }
            CommonStepDataCheck(InstanceVar);
        }
コード例 #5
0
        protected override void InitializeParamsValues()
        {
            string instanceVarName = null;

            if (!string.IsNullOrWhiteSpace(Function.Instance))
            {
                instanceVarName = ModuleUtils.GetVariableNameFromParamValue(Function.Instance);
                _instanceVar    = ModuleUtils.GetVariableFullName(instanceVarName, StepData, Context.SessionId);
            }
            IParameterDataCollection parameters = Function.Parameters;

            for (int i = 0; i < _properties.Count; i++)
            {
                string    paramValue = parameters[i].Value;
                IArgument argument   = Function.ParameterType[i];
                if (null == _properties[i] || string.IsNullOrEmpty(paramValue))
                {
                    _params.Add(null);
                    continue;
                }
                switch (parameters[i].ParameterType)
                {
                case ParameterType.NotAvailable:
                    _params.Add(null);
                    break;

                case ParameterType.Value:
                    _params.Add(Context.TypeInvoker.CastConstantValue(argument.Type,
                                                                      paramValue));
                    break;

                case ParameterType.Variable:
                    string variableRawName = ModuleUtils.GetVariableNameFromParamValue(paramValue);
                    string varFullName     = ModuleUtils.GetVariableFullName(variableRawName, StepData,
                                                                             Context.SessionId);
                    // 将parameter的Value中,变量名称替换为运行时变量名
                    parameters[i].Value = ModuleUtils.GetFullParameterVariableName(varFullName, paramValue);
                    _params.Add(null);
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }
            CommonStepDataCheck(instanceVarName);
        }
コード例 #6
0
        // 因为Variable的值在整个过程中会变化,所以需要在运行前实时获取
        private void SetVariableParamValue()
        {
            IArgumentCollection      arguments  = Function.ParameterType;
            IParameterDataCollection parameters = Function.Parameters;

            if (null == parameters)
            {
                return;
            }
            for (int i = 0; i < parameters.Count; i++)
            {
                if (parameters[i].ParameterType == ParameterType.Variable)
                {
                    // 获取变量值的名称,该名称为变量的运行时名称,其值在InitializeParamValue方法里配置
                    string variableName = ModuleUtils.GetVariableNameFromParamValue(parameters[i].Value);
                    // 根据ParamString和变量对应的值配置参数。
                    Params[i] = Context.VariableMapper.GetParamValue(variableName, parameters[i].Value,
                                                                     arguments[i].Type);
                }
            }
        }
コード例 #7
0
 private static void FillParameterDataToSequenceData(ISequenceStep sequenceStep, ISequenceStepParameter parameter)
 {
     if (sequenceStep.HasSubSteps)
     {
         for (int i = 0; i < sequenceStep.SubSteps.Count; i++)
         {
             FillParameterDataToSequenceData(sequenceStep.SubSteps[i], parameter.SubStepParameters[i]);
         }
     }
     else if (null != sequenceStep.Function)
     {
         parameter.Instance = sequenceStep.Function.Instance;
         parameter.Return   = sequenceStep.Function.Return;
         IParameterDataCollection parameterValues = sequenceStep.Function.Parameters;
         for (int i = 0; i < parameterValues.Count; i++)
         {
             parameter.Parameters[i].ParameterType = parameterValues[i].ParameterType;
             parameter.Parameters[i].Value         = parameterValues[i].Value;
         }
     }
 }