示例#1
0
 //todo I18n
 private IWarningInfo CheckVariableValue(IVariable variable)
 {
     try
     {
         if (ValueConvertor.CheckValue(variable.Type.Name, variable.Value))
         {
             return(null);
         }
         else
         {
             return(new WarningInfo()
             {
                 WarnCode = WarnCode.VariableValueInvalid,
                 Infomation = $"Variable {variable.Name} value: \"{variable.Value}\" failed to parse into type of {variable.Type.Name}. Will cause issues during runtime.",
                 SequenceStep = null
             });
         }
     }
     catch (Exception ex)
     {
         throw new TestflowDataException(ModuleErrorCode.InvalidType, "Please make sure VariableType is Value and Type is of the following: Int32, boolean, string, double, e.t.c." + ex.Message);
     }
 }
示例#2
0
        public IWarningInfo CheckParameterData(IFunctionData function, int index, ISequenceFlowContainer[] arr, bool overwriteType)
        {
            IParameterData parameterData = function.Parameters[index];
            IArgument      parameterType = function.ParameterType[index];

            switch (parameterData.ParameterType)
            {
            //还没输入参数值
            //todo这里好像不对?
            case ParameterType.NotAvailable:
                if (function.Type != FunctionType.InstancePropertySetter && function.Type != FunctionType.StaticPropertySetter)
                {
                    return(new WarningInfo()
                    {
                        WarnCode = WarnCode.ParameterDataNotAvailable,
                        Infomation = $"Parameter \"{parameterType.Name}\" not available"
                    });
                }
                return(null);

                break;

            //输入参数值
            //检查参数类型是不是值类型
            case ParameterType.Value:
                //不判断VariableType.Undefined
                //如果为类类型,则报错
                if (parameterType.VariableType == VariableType.Class || parameterType.VariableType == VariableType.Struct)
                {
                    return(new WarningInfo()
                    {
                        WarnCode = WarnCode.TypeInvalid,
                        Infomation = $"Parameter \"{parameterType.Name}\" data type invalid: parameter type is of class, but input is value"
                    });
                }

                else if (parameterType.VariableType == VariableType.Enumeration)
                {
                    //获取assembly信息里的enumeration字典
                    //字典键:namespace.class
                    //字典值:string array含有枚举项
                    IComInterfaceDescription description = _comInterfaceManager.GetComInterfaceByName(parameterType.Type.AssemblyName);
                    if (description == null)
                    {
                        return(new WarningInfo()
                        {
                            WarnCode = WarnCode.ParameterTypeAssemblyInvalid,
                            Infomation = $"Could not find assembly {parameterType.Type.AssemblyName} for parameterType {parameterType.Name}"
                        });
                    }

                    IDictionary <string, string[]> eCollection = description.Enumerations;
                    string[] e = null;
                    if (!eCollection.TryGetValue($"{parameterType.Type.Namespace}.{parameterType.Type.Name}", out e))
                    {
                        return(new WarningInfo()
                        {
                            WarnCode = WarnCode.EnumClassFault,
                            Infomation = $"Could not find enumeration class {parameterType.Type.Namespace}.{parameterType.Type.Name}"
                        });
                    }
                    if (!e.Contains(parameterData.Value))
                    {
                        return(new WarningInfo()
                        {
                            WarnCode = WarnCode.EnumDNE,
                            Infomation = $"Could not find enumeration {parameterData.Value} in class {parameterType.Type.Namespace}.{parameterType.Type.Name}"
                        });
                    }
                }
                else                //parameterType.VariableType == VariableType.Value
                {
                    //判断值类型是符合的值类型吗
                    if (!ValueConvertor.CheckValue(parameterType.Type.Name, parameterData.Value))
                    {
                        return(new WarningInfo()
                        {
                            WarnCode = WarnCode.TypeInvalid,
                            Infomation = $"Parameter \"{parameterType.Name}\" data type invalid: failed to parse input into parameter type"
                        });
                    }
                }

                return(null);

                break;

            case ParameterType.Variable:
                return(FindVariablesCheckPropertyType(arr, parameterData.Value, parameterType.Type, overwriteType));

                break;

            case ParameterType.Expression:
                return(null);

                break;

            default:
                throw new ArgumentOutOfRangeException("Invalid parameter value type.");
                break;
            }
        }