Beispiel #1
0
        static ValueConvertor()
        {
            _convertorHandler = new Dictionary <string, Func <string, object> >(12)
            {
                { typeof(string).Name, (valueStr) => valueStr },
                { typeof(int).Name, (valueStr) => int.Parse(valueStr) },
                { typeof(uint).Name, (valueStr) => uint.Parse(valueStr) },
                { typeof(short).Name, (valueStr) => short.Parse(valueStr) },
                { typeof(ushort).Name, (valueStr) => ushort.Parse(valueStr) },
                { typeof(long).Name, (valueStr) => long.Parse(valueStr) },
                { typeof(ulong).Name, (valueStr) => ulong.Parse(valueStr) },
                { typeof(double).Name, (valueStr) => double.Parse(valueStr) },
                { typeof(byte).Name, (valueStr) => byte.Parse(valueStr) },
                { typeof(char).Name, (valueStr) => char.Parse(valueStr) },
                { typeof(bool).Name, (valueStr) => bool.Parse(valueStr) },
                { typeof(DateTime).Name, (valueStr) => DateTime.Parse(valueStr) }
            };

            #region 记录
            IComInterfaceManager     _interfaceManager = TestflowRunner.GetInstance().ComInterfaceManager;
            IComInterfaceDescription comDescription    = _interfaceManager.GetComInterfaceByName("mscorlib");
            _valueTypes = new HashSet <ITypeData>();
            _valueTypes.Add(comDescription.VariableTypes.FirstOrDefault(item => item.Name.Equals("Boolean")));
            _valueTypes.Add(comDescription.VariableTypes.FirstOrDefault(item => item.Name.Equals("Double")));
            _valueTypes.Add(comDescription.VariableTypes.FirstOrDefault(item => item.Name.Equals("Single")));
            _valueTypes.Add(comDescription.VariableTypes.FirstOrDefault(item => item.Name.Equals("Int64")));
            _valueTypes.Add(comDescription.VariableTypes.FirstOrDefault(item => item.Name.Equals("UInt64")));
            _valueTypes.Add(comDescription.VariableTypes.FirstOrDefault(item => item.Name.Equals("Int32")));
            _valueTypes.Add(comDescription.VariableTypes.FirstOrDefault(item => item.Name.Equals("Int16")));
            _valueTypes.Add(comDescription.VariableTypes.FirstOrDefault(item => item.Name.Equals("UInt16")));
            _valueTypes.Add(comDescription.VariableTypes.FirstOrDefault(item => item.Name.Equals("Char")));
            _valueTypes.Add(comDescription.VariableTypes.FirstOrDefault(item => item.Name.Equals("Byte")));
            _valueTypes.Add(comDescription.VariableTypes.FirstOrDefault(item => item.Name.Equals("String")));
            #endregion
        }
Beispiel #2
0
 //to ask
 public IComInterfaceDescription AddComponent(IComInterfaceDescription comInterface)
 {
     //to ask: 是否要加到TestProject.Assemblies的assemblyinfo?; 估计不要
     //TestProject.Assemblies.Add(comInterface.Assembly);
     if (!Components.ContainsKey(comInterface.Assembly.AssemblyName))
     {
         Components.Add(comInterface.Assembly.AssemblyName, comInterface);
     }
     return(comInterface);
 }
Beispiel #3
0
 //to do
 public IComInterfaceDescription RemoveComponent(IComInterfaceDescription comInterface)
 {
     if (Components.ContainsKey(comInterface.Assembly.AssemblyName))
     {
         Components.Remove(comInterface.Assembly.AssemblyName);
     }
     else
     {
         //I18N
         throw new TestflowRuntimeException(ModuleErrorCode.TargetNotExist, "没有该组件");
     }
     return(comInterface);
 }
Beispiel #4
0
        //to do
        public IComInterfaceDescription RemoveComponent(string componentName)
        {
            IComInterfaceDescription comInterfaceDescription = null;

            if (Components.TryGetValue(componentName, out comInterfaceDescription))
            {
                Components.Remove(componentName);
            }
            else
            {
                //I18N
                throw new TestflowDataException(ModuleErrorCode.TargetNotExist, "没有该组件");
            }
            return(comInterfaceDescription);
        }
Beispiel #5
0
        static TypeChecker()
        {
            IComInterfaceManager     _interfaceManager = TestflowRunner.GetInstance().ComInterfaceManager;
            IComInterfaceDescription comDescription    = _interfaceManager.GetComInterfaceByName("mscorlib");

            _valueTypes = new HashSet <ITypeData>();
            _valueTypes.Add(comDescription.VariableTypes.FirstOrDefault(item => item.Name.Equals("Boolean")));
            _valueTypes.Add(comDescription.VariableTypes.FirstOrDefault(item => item.Name.Equals("Double")));
            _valueTypes.Add(comDescription.VariableTypes.FirstOrDefault(item => item.Name.Equals("Single")));
            _valueTypes.Add(comDescription.VariableTypes.FirstOrDefault(item => item.Name.Equals("Int64")));
            _valueTypes.Add(comDescription.VariableTypes.FirstOrDefault(item => item.Name.Equals("UInt64")));
            _valueTypes.Add(comDescription.VariableTypes.FirstOrDefault(item => item.Name.Equals("Int32")));
            _valueTypes.Add(comDescription.VariableTypes.FirstOrDefault(item => item.Name.Equals("Int16")));
            _valueTypes.Add(comDescription.VariableTypes.FirstOrDefault(item => item.Name.Equals("UInt16")));
            _valueTypes.Add(comDescription.VariableTypes.FirstOrDefault(item => item.Name.Equals("Char")));
            _valueTypes.Add(comDescription.VariableTypes.FirstOrDefault(item => item.Name.Equals("Byte")));
            _valueTypes.Add(comDescription.VariableTypes.FirstOrDefault(item => item.Name.Equals("String")));
        }
 public void LoadDllInterfaceTest()
 {
     // 未编写自动化监测,需要手动检查description的值
     IComInterfaceDescription description = _interfaceManager.GetComponentInterface(
         @"C:\SeeSharp\JYTEK\Hardware\DSA\JYPCI69527\Bin\JYPCI69527.dll");
     //            Assembly assembly =
     //                Assembly.LoadFile(@"C:\SeeSharp\JYTEK\SeeSharpTools\Bin\SeeSharpTools.JY.ArrayUtility.dll");
     //            IClassInterfaceDescription classDescription = description.Classes[0];
     //            Type classType =
     //                assembly.GetType($"{classDescription.ClassType.Namespace}.{classDescription.ClassType.Name}");
     //            IFuncInterfaceDescription funcDescription = classDescription.Functions[0];
     //            Type[] parameterTypes = new Type[funcDescription.Arguments.Count];
     //            ParameterModifier[] modifiers = new ParameterModifier[funcDescription.Arguments.Count];
     //            Type[] arguments = classType.GenericTypeArguments;
     //            Type[] genericArguments = classType.GetGenericArguments();
     //            for (int i = 0; i < funcDescription.Arguments.Count; i++)
     //            {
     //                string name = $"{funcDescription.Arguments[i].Type.Namespace}.{funcDescription.Arguments[i].Type.Name}";
     //                parameterTypes[i] = assembly.GetType(name);
     //                modifiers[i] = new ParameterModifier();
     //            }
     //            classType.GetMethod(funcDescription.Name, BindingFlags.Instance | BindingFlags.Public, null, parameterTypes, modifiers);
 }
Beispiel #7
0
        public SequenceCreator()
        {
            TestflowRunner testflowRunner = TestflowRunner.GetInstance();

            _sequenceManager = testflowRunner.SequenceManager;
            IComInterfaceManager interfaceManager = testflowRunner.ComInterfaceManager;

            Type   testClassType = typeof(CoreTestClass);
            string location      = testClassType.Assembly.Location;
            IComInterfaceDescription interfaceDescription = interfaceManager.GetComponentInterface(location);

            Type intType = typeof(int);

            _intTypeData = interfaceManager.GetTypeByName(intType.Name, intType.Namespace);

            Type testCallBackType = typeof(CallBackClass);

            //同一个程序集,不需要再一次加载component
            //location = testClassType.Assembly.Location;
            //interfaceDescription = interfaceManager.GetComponentInterface(location);

            _testClassTypeData    = interfaceManager.GetTypeByName(testClassType.Name, testClassType.Namespace);
            _testCallBackTypeData = interfaceManager.GetTypeByName(testCallBackType.Name, testCallBackType.Namespace);
        }
Beispiel #8
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;
            }
        }