Example #1
0
        private static object GetParamValue(object varValue, string paramValueStr)
        {
            object paramValue = varValue;

            // 如果ParamValue使用了类属性的定义,则需要按层取出真实属性的值
            if (paramValueStr.Contains(Constants.PropertyDelim))
            {
                string[]     paramElems = paramValueStr.Split(Constants.PropertyDelim.ToCharArray());
                BindingFlags binding    = BindingFlags.Public | BindingFlags.Instance;
                for (int i = 1; i < paramElems.Length; i++)
                {
                    Type         paramType    = paramValue.GetType();
                    PropertyInfo propertyInfo = paramType.GetProperty(paramElems[i], binding);
                    if (null != propertyInfo)
                    {
                        paramValue = propertyInfo.GetValue(paramValue);
                        continue;
                    }
                    FieldInfo fieldInfo = paramType.GetField(paramElems[i], binding);
                    if (null != fieldInfo)
                    {
                        paramValue = fieldInfo.GetValue(paramValue);
                        continue;
                    }
                    I18N i18N = I18N.GetInstance(Constants.I18nName);
                    throw new TestflowDataException(ModuleErrorCode.SequenceDataError,
                                                    i18N.GetFStr("UnexistVariable", paramValueStr));
                }
            }
            return(paramValue);
        }
Example #2
0
        private static void InitializeArgumentType(ISequenceManager sequenceManager,
                                                   DescriptionDataTable descriptionCollection, IArgumentDescription argumentDescription)
        {
            ArgumentDescription argDescription = (ArgumentDescription)argumentDescription;

            // 如果类型描述类为空且TypeData非空,则说明该argDescription已经被修改过,无需再执行处理
            if (argDescription.TypeDescription == null)
            {
                if (null == argDescription.Type)
                {
                    I18N i18N = I18N.GetInstance(Constants.I18nName);
                    throw new TestflowRuntimeException(ModuleErrorCode.TypeCannotLoad,
                                                       i18N.GetFStr("InvalidArgType", argDescription.Name));
                }
                return;
            }
            string fullName = GetFullName(argDescription.TypeDescription);

            if (descriptionCollection.ContainsType(fullName))
            {
                argDescription.Type = descriptionCollection.GetTypeData(fullName);
            }
            else
            {
                ITypeData typeData = sequenceManager.CreateTypeData(argDescription.TypeDescription);
                descriptionCollection.AddTypeData(fullName, typeData);
                argDescription.Type = typeData;
            }
            argDescription.TypeDescription = null;
        }
        private void SetAssemblyAbsolutePath(ExpressionTypeData typeData, List <string> availableDirs)
        {
            string        path      = typeData.AssemblyPath;
            StringBuilder pathCache = new StringBuilder(200);

            // 如果文件名前面有分隔符则去掉
            while (path.StartsWith(Path.DirectorySeparatorChar.ToString()))
            {
                path = path.Substring(1, path.Length - 1);
            }
            // 转换为绝对路径时反向寻找,先.net库再平台库再用户库
            for (int i = availableDirs.Count - 1; i >= 0; i--)
            {
                pathCache.Clear();
                string availableDir = availableDirs[i];
                pathCache.Append(availableDir).Append(path);
                // 如果库存在则配置为绝对路径,然后返回
                if (File.Exists(pathCache.ToString()))
                {
                    typeData.AssemblyPath = pathCache.ToString();
                    return;
                }
            }
            TestflowRunner.GetInstance().LogService.Print(LogLevel.Fatal, CommonConst.PlatformLogSession,
                                                          $"Assembly of type:{typeData.ClassName} cannot be located.");
            I18N i18N = I18N.GetInstance(Constants.I18nName);

            throw new TestflowRuntimeException(ModuleErrorCode.ConfigDataError,
                                               i18N.GetFStr("InvalidCalculator", typeData.ClassName));
        }
Example #4
0
 private void RefreshUsedAssemblies(IAssemblyInfoCollection assemblies, HashSet <string> usedAssembly)
 {
     for (int i = assemblies.Count - 1; i >= 0; i--)
     {
         if (usedAssembly.Contains(assemblies[i].AssemblyName))
         {
             continue;
         }
         assemblies.RemoveAt(i);
     }
     foreach (string assemblyName in usedAssembly)
     {
         IAssemblyInfo assemblyInfo = assemblies.FirstOrDefault(item => item.AssemblyName.Equals(assemblyName));
         if (null != assemblyInfo)
         {
             continue;
         }
         assemblyInfo = _comInterfaceManager.GetAssemblyInfo(assemblyName);
         if (null == assemblyInfo)
         {
             ILogService logService = TestflowRunner.GetInstance().LogService;
             logService.Print(LogLevel.Error, CommonConst.PlatformLogSession, 0,
                              $"Unloaded assembly '{assemblyName}' used.");
             I18N i18N = I18N.GetInstance(Constants.I18nName);
             throw new TestflowDataException(ModuleErrorCode.TypeDataError,
                                             i18N.GetFStr("InvalidAssemblyUsed", assemblyName));
         }
         assemblies.Add(assemblyInfo);
     }
 }
Example #5
0
        public static StepTaskEntityBase GetStepModel(ISequenceStep stepData, SlaveContext context, int sequenceIndex)
        {
            // 如果某个Step的Function为null,且不是块步骤类型,则为该Step分配空类型运行实体
            if (null == stepData.Function && !_blockStepTypes.Contains(stepData.StepType))
            {
                return(new EmptyStepEntity(context, sequenceIndex, stepData));
            }
            StepTaskEntityBase stepEntity;

            switch (stepData.StepType)
            {
            case SequenceStepType.Execution:
                stepEntity = new ExecutionStepEntity(stepData, context, sequenceIndex);
                break;

            case SequenceStepType.ConditionBlock:
                stepEntity = new ConditionBlockStepEntity(stepData, context, sequenceIndex);
                break;

            case SequenceStepType.ConditionStatement:
                stepEntity = new ConditionStatementStepEntity(stepData, context, sequenceIndex);
                break;

            case SequenceStepType.TryFinallyBlock:
                stepEntity = new TryFinallyBlockStepEntity(stepData, context, sequenceIndex);
                break;

            case SequenceStepType.ConditionLoop:
                stepEntity = new ConditionLoopStepEntity(stepData, context, sequenceIndex);
                break;

            case SequenceStepType.SequenceCall:
                stepEntity = new SequenceCallStepEntity(stepData, context, sequenceIndex);
                break;

            case SequenceStepType.Goto:
                stepEntity = new GotoStepEntity(stepData, context, sequenceIndex);
                break;

            case SequenceStepType.MultiThreadBlock:
                stepEntity = new MultiThreadStepEntity(stepData, context, sequenceIndex);
                break;

            case SequenceStepType.TimerBlock:
                stepEntity = new TimerBlockStepEntity(stepData, context, sequenceIndex);
                break;

            case SequenceStepType.BatchBlock:
                stepEntity = new BatchBlockStepEntity(stepData, context, sequenceIndex);
                break;

            default:
                context.LogSession.Print(LogLevel.Error, context.SessionId,
                                         $"The step type of <{stepData.Name}> is invalid.");
                I18N i18N = I18N.GetInstance(Constants.I18nName);
                throw new TestflowDataException(ModuleErrorCode.SequenceDataError,
                                                i18N.GetFStr("UnsupportedStepType", stepData.StepType.ToString()));
            }
            return(stepEntity);
        }
Example #6
0
        private object SetParamValue(string paramValueStr, object varValue, object paramValue)
        {
            if (!paramValueStr.Contains(Constants.PropertyDelim))
            {
                return(paramValue);
            }
            object parentValue = varValue;
            Type   parentType  = varValue.GetType();

            string[]     paramElems = paramValueStr.Split(Constants.PropertyDelim.ToCharArray());
            BindingFlags binding    = BindingFlags.Public | BindingFlags.Instance;

            for (int i = 1; i < paramElems.Length - 1; i++)
            {
                PropertyInfo propertyInfo = parentType.GetProperty(paramElems[i], binding);
                if (null != propertyInfo)
                {
                    parentType  = propertyInfo.PropertyType;
                    parentValue = propertyInfo.GetValue(parentValue);
                    continue;
                }
                FieldInfo fieldInfo = parentType.GetField(paramElems[i], binding);
                if (null != fieldInfo)
                {
                    parentType  = fieldInfo.FieldType;
                    parentValue = fieldInfo.GetValue(parentValue);
                    continue;
                }
                I18N i18N = I18N.GetInstance(Constants.I18nName);
                throw new TestflowDataException(ModuleErrorCode.SequenceDataError, i18N.GetFStr("UnexistVariable", paramValueStr));
            }
            PropertyInfo paramProperty = parentType.GetProperty(paramElems[paramElems.Length - 1], binding);
            FieldInfo    paramField    = null;
            Type         propertyType;

            if (null == paramProperty)
            {
                paramField = parentType.GetField(paramElems[paramElems.Length - 1], binding);
                if (null == paramField)
                {
                    I18N i18N = I18N.GetInstance(Constants.I18nName);
                    throw new TestflowDataException(ModuleErrorCode.SequenceDataError, i18N.GetFStr("UnexistVariable", paramValueStr));
                }
                propertyType = paramField.FieldType;
            }
            else
            {
                propertyType = paramProperty.PropertyType;
            }
            // 如果变量值不为null,并且变量类型和待写入属性类型不匹配则执行类型转换
            if (null != paramValue && !propertyType.IsInstanceOfType(paramValue) &&
                _context.Convertor.IsValidValueCast(paramValue.GetType(), propertyType))
            {
                paramValue = _context.Convertor.CastValue(propertyType, paramValue);
            }
            paramProperty?.SetValue(parentValue, paramValue);
            paramField?.SetValue(parentValue, paramValue);
            return(varValue);
        }
Example #7
0
        private void LogAndThrowExpressionError(string logMessage, int errorCode, string errorLabel, params string[] extraParams)
        {
            TestflowRunner runnerInstance = TestflowRunner.GetInstance();
            I18N           i18N           = I18N.GetInstance(Constants.I18nName);

            runnerInstance.LogService.Print(LogLevel.Error, CommonConst.PlatformLogSession, logMessage);
            throw new TestflowDataException(errorCode, i18N.GetFStr(errorLabel, extraParams));
        }
Example #8
0
        private void CheckPropertyDescription(ITypeData typeData, string property)
        {
            if (null != _loader.Exception)
            {
                return;
            }
            I18N        i18N       = I18N.GetInstance(Constants.I18nName);
            ILogService logService = TestflowRunner.GetInstance().LogService;

            switch (_loader.ErrorCode)
            {
            case ModuleErrorCode.LibraryLoadError:
                logService.Print(LogLevel.Error, CommonConst.PlatformLogSession, _loader.Exception,
                                 $"Assembly '{typeData.AssemblyName}' load error.");
                throw new TestflowRuntimeException(ModuleErrorCode.LibraryLoadError,
                                                   i18N.GetStr("RuntimeError"));
                break;

            case ModuleErrorCode.PropertyNotFound:
                logService.Print(LogLevel.Error, CommonConst.PlatformLogSession, _loader.Exception,
                                 $"Property '{property}' of type '{typeData.Name}' does not exist.");
                throw new TestflowRuntimeException(ModuleErrorCode.PropertyNotFound,
                                                   i18N.GetFStr("PropertyNotFound", typeData.Name, property));
                break;

            case ModuleErrorCode.TypeCannotLoad:
                logService.Print(LogLevel.Error, CommonConst.PlatformLogSession, _loader.Exception,
                                 $"Type '{typeData.Name}' does not exist.");
                throw new TestflowRuntimeException(ModuleErrorCode.TypeCannotLoad,
                                                   i18N.GetFStr("TypeNotFound", typeData.Name));
                break;

            case ModuleErrorCode.AssemblyNotLoad:
                logService.Print(LogLevel.Error, CommonConst.PlatformLogSession, _loader.Exception,
                                 $"Assemly '{typeData.AssemblyName}' does not exist.");
                throw new TestflowRuntimeException(ModuleErrorCode.AssemblyNotLoad,
                                                   i18N.GetFStr("AssemblyNotLoad", typeData.AssemblyName));
                break;

            default:
                break;
            }
        }
Example #9
0
        private void ThrowIfVariableNotFound(string variableName, ISequenceFlowContainer parent)
        {
            ILogService logService = TestflowRunner.GetInstance().LogService;

            logService.Print(LogLevel.Warn, CommonConst.PlatformLogSession, 0,
                             $"Undeclared variable '{0}' in sequence '{parent.Name}'");
            I18N i18N = I18N.GetInstance(Constants.I18nName);

            throw new TestflowDataException(ModuleErrorCode.VariableError,
                                            i18N.GetFStr("UndeclaredVariable", variableName, parent.Name));
        }
Example #10
0
        public static TDataType GetDeleage <TDataType>(Delegate action) where TDataType : class
        {
            TDataType delegateAction = action as TDataType;

            if (null == delegateAction)
            {
                I18N i18N = I18N.GetInstance(Constants.I18nName);
                throw new TestflowInternalException(ModuleErrorCode.IncorrectDelegate,
                                                    i18N.GetFStr("IncorrectDelegate", action.GetType().Name));
            }
            return(delegateAction);
        }
Example #11
0
        public static TDataType GetParamValue <TDataType>(object[] eventParams, int index) where TDataType : class
        {
            TDataType paramValueObject = null;

            if (eventParams.Length > index && null == (paramValueObject = eventParams[index] as TDataType))
            {
                I18N i18N = I18N.GetInstance(Constants.I18nName);
                throw new TestflowInternalException(ModuleErrorCode.IncorrectParamType,
                                                    i18N.GetFStr("IncorrectParamType", typeof(TDataType).Name));
            }

            return(paramValueObject);
        }
Example #12
0
        private GlobalConfigData GetGlobalConfigData(ConfigData configData)
        {
            GlobalConfigData globalConfigData = new GlobalConfigData();

            foreach (ConfigBlock configBlock in configData.ModuleConfigData)
            {
                string blockName = configBlock.Name;
                globalConfigData.AddConfigRoot(blockName);
                foreach (ConfigItem configItem in configBlock.ConfigItems)
                {
                    Type valueType = Type.GetType(configItem.Type);
                    if (null == valueType)
                    {
                        valueType = Assembly.GetAssembly(typeof(IConfigurationManager)).GetType(configItem.Type);
                        if (null == valueType)
                        {
                            valueType = Assembly.GetAssembly(typeof(Messenger)).GetType(configItem.Type);
                            if (null == valueType)
                            {
                                I18N i18N = I18N.GetInstance(Constants.I18nName);
                                throw new TestflowRuntimeException(ModuleErrorCode.ConfigDataError,
                                                                   i18N.GetFStr("CannotLoadType", configItem.Type));
                            }
                        }
                    }
                    object value;
                    if (valueType.IsEnum)
                    {
                        value = Enum.Parse(valueType, configItem.Value);
                    }
                    else if (valueType.IsValueType || valueType == typeof(string))
                    {
                        value = _valueConvertor[GetFullName(valueType)].Invoke(configItem.Value);
                    }
                    else if (valueType == typeof(Encoding))
                    {
                        value = Encoding.GetEncoding(configItem.Value);
                    }
                    else
                    {
                        I18N i18N = I18N.GetInstance(Constants.I18nName);
                        throw new TestflowRuntimeException(ModuleErrorCode.ConfigDataError,
                                                           i18N.GetFStr("UnsupportedCast", configItem.Type));
                    }
                    globalConfigData.AddConfigItem(blockName, configItem.Name, value);
                }
            }
            return(globalConfigData);
        }
Example #13
0
        public object CastValue(ITypeData type, string valueStr)
        {
            object value    = null;
            Type   dataType = _typeDataMapping[ModuleUtils.GetTypeFullName(type)];

            if (dataType.IsValueType && !dataType.IsEnum)
            {
                value = _valueTypeConvertors[dataType.Name].Invoke(valueStr);
            }
            else if (dataType.IsEnum)
            {
                value = Enum.Parse(dataType, valueStr);
            }
            else if (dataType == typeof(string))
            {
                value = valueStr;
            }
            else
            {
                throw new TestflowRuntimeException(ModuleErrorCode.UnsupportedTypeCast,
                                                   _I18N.GetFStr("InvalidTypeCast", type.Name));
            }
            return(value);
        }
Example #14
0
        public string GetAbsolutePath(string path)
        {
            if (!IsRelativePath(path))
            {
                return(path);
            }
            string abosolutePath = InternalGetAbosolutePath(path);

            if (null == abosolutePath)
            {
                ILogService logService = TestflowRunner.GetInstance().LogService;
                logService.Print(LogLevel.Error, CommonConst.PlatformLogSession,
                                 $"File in relative path '{path}' cannot be found.");
                I18N i18N = I18N.GetInstance(Constants.I18nName);
                throw new TestflowDataException(ModuleErrorCode.DeSerializeFailed,
                                                i18N.GetFStr("FileCannotFound", path));
            }
            return(abosolutePath);
        }
Example #15
0
        public static void LogAndRaiseRuntimeException(LogLevel level, string logInfo, int errorCode,
                                                       Exception innerException, string message, params string[] param)
        {
            I18N        i18N       = I18N.GetInstance(Constants.I18nName);
            ILogService logService = TestflowRunner.GetInstance().LogService;

            string exMessage = (null == param || 0 == param.Length)
                ? i18N.GetStr(message)
                : i18N.GetFStr(message, param);

            if (null == innerException)
            {
                logService.Print(level, CommonConst.PlatformLogSession, logInfo);
                throw new TestflowRuntimeException(errorCode, exMessage);
            }
            else
            {
                logService.Print(level, CommonConst.PlatformLogSession, innerException, logInfo);
                throw new TestflowRuntimeException(errorCode, exMessage, innerException);
            }
        }
Example #16
0
        private static ISequenceStep GetStepFromStack(ISequence sequence, IList <int> stack, string stackStr)
        {
            if (sequence.Steps.Count <= stack[0])
            {
                I18N i18N = I18N.GetInstance(UtilityConstants.UtilsName);
                throw new TestflowDataException(ModuleErrorCode.SequenceDataError,
                                                i18N.GetFStr("InvalidCallStack", stackStr));
            }
            ISequenceStep step = sequence.Steps[stack[0]];

            for (int i = 1; i < stack.Count; i++)
            {
                if (!step.HasSubSteps || step.SubSteps.Count < stack[i])
                {
                    I18N i18N = I18N.GetInstance(UtilityConstants.UtilsName);
                    throw new TestflowDataException(ModuleErrorCode.SequenceDataError,
                                                    i18N.GetFStr("InvalidCallStack", stackStr));
                }
                step = step.SubSteps[stack[i]];
            }
            return(step);
        }
        private static Type GetTargetType(string assemblyDir, string className, Type baseType)
        {
            if (!File.Exists(assemblyDir))
            {
                TestflowRunner.GetInstance().LogService.Print(LogLevel.Fatal, CommonConst.PlatformLogSession,
                                                              $"Assembly of type:{className} cannot be located.");
                I18N i18N = I18N.GetInstance(Constants.I18nName);
                throw new TestflowRuntimeException(ModuleErrorCode.ConfigDataError,
                                                   i18N.GetFStr("InvalidCalculator", className));
            }
            Assembly assembly   = Assembly.LoadFrom(assemblyDir);
            Type     targetType = assembly.GetType(className);

            if (null == targetType || (null != baseType && !targetType.IsSubclassOf(baseType)))
            {
                TestflowRunner.GetInstance().LogService.Print(LogLevel.Fatal, CommonConst.PlatformLogSession,
                                                              $"Invalid expression calculator:{className}.");
                I18N i18N = I18N.GetInstance(Constants.I18nName);
                throw new TestflowRuntimeException(ModuleErrorCode.ConfigDataError,
                                                   i18N.GetFStr("InvalidCalculator", className));
            }
            return(targetType);
        }
Example #18
0
 private void SetToAbsolutePath(IAssemblyInfoCollection assemblies)
 {
     foreach (IAssemblyInfo assemblyInfo in assemblies)
     {
         // 如果是绝对路径则继续执行
         string path = assemblyInfo.Path;
         if (!IsRelativePath(path))
         {
             continue;
         }
         string abosolutePath = InternalGetAbosolutePath(path);
         // 如果没找到库,则抛出异常
         if (null == abosolutePath)
         {
             ILogService logService = TestflowRunner.GetInstance().LogService;
             logService.Print(LogLevel.Error, CommonConst.PlatformLogSession,
                              $"Assembly '{assemblyInfo.AssemblyName}' cannot be found in '{assemblyInfo.Path}'.");
             I18N i18N = I18N.GetInstance(Constants.I18nName);
             throw new TestflowDataException(ModuleErrorCode.DeSerializeFailed,
                                             i18N.GetFStr("AssemblyCannotFound", assemblyInfo.AssemblyName));
         }
         assemblyInfo.Path = abosolutePath;
     }
 }
Example #19
0
        private void CheckAssemblyDescription(ComInterfaceDescription description, string assemblyName, string path)
        {
            if (null != description && _loader.Exception == null && _loader.ErrorCode == 0)
            {
                return;
            }
            I18N        i18N       = I18N.GetInstance(Constants.I18nName);
            ILogService logService = TestflowRunner.GetInstance().LogService;
            string      assembly   = assemblyName;

            if (string.IsNullOrWhiteSpace(assembly))
            {
                assembly = path;
            }
            switch (_loader.ErrorCode)
            {
            case ModuleErrorCode.HighVersion:
                logService.Print(LogLevel.Warn, CommonConst.PlatformLogSession,
                                 $"The version of assembly '{assembly}' is higher than version defined in data.");
                break;

            case ModuleErrorCode.LowVersion:
                logService.Print(LogLevel.Error, CommonConst.PlatformLogSession,
                                 $"The version of assembly '{assembly}' is lower than version defined in data.");
                throw new TestflowRuntimeException(ModuleErrorCode.LowVersion,
                                                   i18N.GetFStr("LowAssemblyVersion", assembly));
                break;

            case ModuleErrorCode.LibraryLoadError:
                if (null != _loader.Exception)
                {
                    logService.Print(LogLevel.Error, CommonConst.PlatformLogSession, _loader.Exception,
                                     $"Assembly '{assembly}' load error.");
                    throw new TestflowRuntimeException(ModuleErrorCode.LibraryLoadError,
                                                       i18N.GetFStr(_loader.Exception.Message), _loader.Exception);
                }
                else
                {
                    logService.Print(LogLevel.Error, CommonConst.PlatformLogSession,
                                     $"Assembly '{assembly}' load error.");
                    throw new TestflowRuntimeException(ModuleErrorCode.LibraryLoadError,
                                                       i18N.GetStr("RuntimeError"));
                }

            case ModuleErrorCode.LibraryNotFound:
                throw new TestflowRuntimeException(ModuleErrorCode.LibraryNotFound,
                                                   i18N.GetFStr("LibNotFound", assembly));

            default:
                if (null != _loader.Exception)
                {
                    throw new TestflowRuntimeException(ModuleErrorCode.LibraryLoadError,
                                                       i18N.GetFStr("RuntimeError", _loader.Exception.Message), _loader.Exception);
                }
                if (null == description)
                {
                    throw new TestflowRuntimeException(ModuleErrorCode.LibraryLoadError,
                                                       i18N.GetStr("RuntimeError"));
                }
                break;
            }
        }
Example #20
0
        public void Unregister(Delegate callBack, string eventName)
        {
            switch (eventName)
            {
            case Constants.TestGenerationStart:
                TestGenerationStart -= ModuleUtils.GetDeleage <RuntimeDelegate.TestGenerationAction>(callBack);
                break;

            case Constants.TestGenerationEnd:
                TestGenerationEnd -= ModuleUtils.GetDeleage <RuntimeDelegate.TestGenerationAction>(callBack);
                break;

            case Constants.SessionGenerationStart:
                SessionGenerationStart -= ModuleUtils.GetDeleage <RuntimeDelegate.SessionGenerationAction>(callBack);
                break;

            case Constants.SessionGenerationReport:
                SessionGenerationReport -= ModuleUtils.GetDeleage <RuntimeDelegate.SessionGenerationAction>(callBack);
                break;

            case Constants.SessionGenerationEnd:
                SessionGenerationEnd -= ModuleUtils.GetDeleage <RuntimeDelegate.SessionGenerationAction>(callBack);
                break;

            case Constants.TestProjectStart:
                TestProjectStart -= ModuleUtils.GetDeleage <RuntimeDelegate.TestProjectStatusAction>(callBack);
                break;

            case Constants.SessionStart:
                SessionStart -= ModuleUtils.GetDeleage <RuntimeDelegate.SessionStatusAction>(callBack);
                break;

            case Constants.SequenceStarted:
                SequenceStarted -= ModuleUtils.GetDeleage <RuntimeDelegate.SequenceStatusAction>(callBack);
                break;

            case Constants.StatusReceived:
                StatusReceived -= ModuleUtils.GetDeleage <RuntimeDelegate.StatusReceivedAction>(callBack);
                break;

            case Constants.SequenceOver:
                SequenceOver -= ModuleUtils.GetDeleage <RuntimeDelegate.SequenceStatusAction>(callBack);
                break;

            case Constants.SessionOver:
                SessionOver -= ModuleUtils.GetDeleage <RuntimeDelegate.SessionStatusAction>(callBack);
                break;

            case Constants.BreakPointHitted:
                BreakPointHitted -= ModuleUtils.GetDeleage <RuntimeDelegate.BreakPointHittedAction>(callBack);
                break;

            case Constants.TestProjectOver:
                TestProjectOver -= ModuleUtils.GetDeleage <RuntimeDelegate.TestProjectStatusAction>(callBack);
                break;

            default:
                I18N i18N = I18N.GetInstance(Constants.I18nName);
                throw new TestflowInternalException(ModuleErrorCode.UnexistEvent, i18N.GetFStr("UnexistEvent", eventName));
                break;
            }
        }
Example #21
0
        private void InvokeEvent(object state)
        {
            EventParam eventParams = (EventParam)state;
            string     eventName   = eventParams.EventName;
            int        sessionId   = eventParams.Session;

            object[] eventParam = eventParams.EventParams;
            switch (eventName)
            {
            case Constants.TestGenerationStart:
                OnTestGenerationStart(ModuleUtils.GetParamValue <ITestGenerationInfo>(eventParam, 0));
                break;

            case Constants.TestGenerationEnd:
                OnTestGenerationEnd(ModuleUtils.GetParamValue <ITestGenerationInfo>(eventParam, 0));
                break;

            case Constants.SessionGenerationStart:
                OnSessionGenerationStart(ModuleUtils.GetParamValue <ISessionGenerationInfo>(eventParam, 0));
                break;

            case Constants.SessionGenerationReport:
                OnSessionGenerationReport(ModuleUtils.GetParamValue <ISessionGenerationInfo>(eventParam, 0));
                break;

            case Constants.SessionGenerationEnd:
                OnSessionGenerationEnd(ModuleUtils.GetParamValue <ISessionGenerationInfo>(eventParam, 0));
                break;

            case Constants.TestProjectStart:
                OnTestProjectStart(ModuleUtils.GetParamValue <List <ITestResultCollection> >(eventParam, 0));
                break;

            case Constants.SessionStart:
                OnTestStart(ModuleUtils.GetParamValue <ITestResultCollection>(eventParam, 0));
                break;

            case Constants.SequenceStarted:
                OnSequenceStarted(ModuleUtils.GetParamValue <ISequenceTestResult>(eventParam, 0));
                break;

            case Constants.StatusReceived:
                OnStatusReceived(ModuleUtils.GetParamValue <IRuntimeStatusInfo>(eventParam, 0));
                break;

            case Constants.SequenceOver:
                OnSequenceOver(ModuleUtils.GetParamValue <ISequenceTestResult>(eventParam, 0));
                break;

            case Constants.SessionOver:
//                    eventHandle.OnTestOver(ModuleUtil.GetParamValue<ITestResultCollection>(eventParams, 0),
//                        ModuleUtil.GetParamValue<ISequenceGroup>(eventParams, 1));
                OnTestOver(ModuleUtils.GetParamValue <ITestResultCollection>(eventParam, 0));
                break;

            case Constants.TestProjectOver:
                OnTestProjectOver(ModuleUtils.GetParamValue <List <ITestResultCollection> >(eventParam, 0));
                break;

            case Constants.BreakPointHitted:
                OnBreakPointHitted(ModuleUtils.GetParamValue <IDebuggerHandle>(eventParam, 0),
                                   ModuleUtils.GetParamValue <IDebugInformation>(eventParam, 1));
                break;

            default:
                I18N i18N = I18N.GetInstance(Constants.I18nName);
                throw new TestflowInternalException(ModuleErrorCode.UnexistEvent,
                                                    i18N.GetFStr("UnexistEvent", eventName));
                break;
            }
        }
Example #22
0
        private void CheckClassDescription(IClassInterfaceDescription description, string assemblyName, string fullName)
        {
            if (null != description && _loader.Exception == null && _loader.ErrorCode == 0)
            {
                return;
            }
            I18N        i18N       = I18N.GetInstance(Constants.I18nName);
            ILogService logService = TestflowRunner.GetInstance().LogService;
            string      assembly   = assemblyName;

            switch (_loader.ErrorCode)
            {
            case ModuleErrorCode.HighVersion:
                logService.Print(LogLevel.Warn, CommonConst.PlatformLogSession,
                                 $"The version of assembly '{assembly}' is higher than version defined in data.");
                break;

            case ModuleErrorCode.LowVersion:
                logService.Print(LogLevel.Error, CommonConst.PlatformLogSession,
                                 $"The version of assembly '{assembly}' is lower than version defined in data.");
                throw new TestflowRuntimeException(ModuleErrorCode.LowVersion,
                                                   i18N.GetFStr("LowAssemblyVersion", assembly));
                break;

            case ModuleErrorCode.LibraryLoadError:
                if (null != _loader.Exception)
                {
                    logService.Print(LogLevel.Error, CommonConst.PlatformLogSession, _loader.Exception,
                                     $"Assembly '{assembly}' load error.");
                    throw new TestflowRuntimeException(ModuleErrorCode.LibraryLoadError,
                                                       i18N.GetFStr(_loader.Exception.Message), _loader.Exception);
                }
                else
                {
                    logService.Print(LogLevel.Error, CommonConst.PlatformLogSession,
                                     $"Assembly '{assembly}' load error.");
                    throw new TestflowRuntimeException(ModuleErrorCode.LibraryLoadError,
                                                       i18N.GetStr("RuntimeError"));
                }

            case ModuleErrorCode.TypeCannotLoad:
                logService.Print(LogLevel.Error, CommonConst.PlatformLogSession, _loader.Exception,
                                 $"Type '{fullName}' does not exist.");
                throw new TestflowRuntimeException(ModuleErrorCode.TypeCannotLoad,
                                                   i18N.GetFStr("TypeNotFound", fullName));

            case ModuleErrorCode.LibraryNotFound:
                logService.Print(LogLevel.Error, CommonConst.PlatformLogSession,
                                 $"Assembly '{assembly}' has not been loaded.");
                throw new TestflowRuntimeException(ModuleErrorCode.LibraryNotFound,
                                                   i18N.GetFStr("LibNotFound", assembly));

            case ModuleErrorCode.AssemblyNotLoad:
                logService.Print(LogLevel.Error, CommonConst.PlatformLogSession, _loader.Exception,
                                 $"Assemly '{assemblyName}' does not exist.");
                throw new TestflowRuntimeException(ModuleErrorCode.AssemblyNotLoad,
                                                   i18N.GetFStr("AssemblyNotLoad", assemblyName));
                break;

            default:
                if (null != _loader.Exception)
                {
                    throw new TestflowRuntimeException(ModuleErrorCode.LibraryLoadError,
                                                       i18N.GetFStr("RuntimeError", _loader.Exception.Message), _loader.Exception);
                }
                if (null == description)
                {
                    throw new TestflowRuntimeException(ModuleErrorCode.LibraryLoadError,
                                                       i18N.GetStr("RuntimeError"));
                }
                break;
            }
        }