Пример #1
0
 private void AddExtraRuntimeConfigData(GlobalConfigData globalConfigData)
 {
     globalConfigData.AddConfigItem(Constants.EngineConfig, "TestName", "TestInstance");
     globalConfigData.AddConfigItem(Constants.EngineConfig, "TestDescription", "");
     globalConfigData.AddConfigItem(Constants.EngineConfig, "RuntimeHash", "");
     globalConfigData.AddConfigItem(Constants.EngineConfig, "RuntimeType", RuntimeType.Run);
 }
Пример #2
0
        private ExpressionOperatorConfiguration GetExpressionTokens(GlobalConfigData globalConfigData, ConfigDataLoader dataLoader)
        {
            string testflowHome         = globalConfigData.GetConfigValue <string>(Constants.GlobalConfig, "TestflowHome");
            string expressionConfigFile = $"{testflowHome}{CommonConst.DeployDir}{Path.DirectorySeparatorChar}expressionconfig.xml";
            ExpressionOperatorConfiguration expressionTokens = dataLoader.LoadExpressionTokens(expressionConfigFile);

            // 有效化ExpressTokens
            ValidateExpressionTokens(globalConfigData, expressionTokens);
            return(expressionTokens);
        }
Пример #3
0
        public GlobalConfigData Load(string configFile)
        {
            ConfigData       configData       = GetConfigData(configFile);
            GlobalConfigData globalConfigData = GetGlobalConfigData(configData);

            AddExtraGlobalConfigData(globalConfigData);
            AddExtraRuntimeConfigData(globalConfigData);
            AddExtraDataMaintainConfigData(globalConfigData);
            return(globalConfigData);
        }
Пример #4
0
        public void RuntimeInitialize()
        {
            GlobalConfigData globalConfigData = Initialize();
            TestflowRunner   testflowRunner   = TestflowRunner.GetInstance();

            this.ApplyConfig(globalConfigData.GetGlobalConfigData());
            testflowRunner.DataMaintainer.ApplyConfig(globalConfigData.GetModuleConfigData(Constants.DataMaintain));
            testflowRunner.EngineController.ApplyConfig(globalConfigData.GetModuleConfigData(Constants.EngineConfig));
            testflowRunner.SequenceManager.ApplyConfig(globalConfigData.GetModuleConfigData(Constants.SequenceManage));
            testflowRunner.ResultManager.ApplyConfig(globalConfigData.GetModuleConfigData(Constants.ResultManage));

            globalConfigData.Dispose();
        }
Пример #5
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);
        }
Пример #6
0
        private void AddExtraDataMaintainConfigData(GlobalConfigData globalConfigData)
        {
            string databaseName = globalConfigData.GetConfigValue <string>(Constants.DataMaintain, "DatabaseName");
            string testflowHome = globalConfigData.GetConfigValue <string>(Constants.GlobalConfig, "TestflowHome");
            string dataDirPath  = $"{testflowHome}{CommonConst.DataDir}";

            if (!Directory.Exists(dataDirPath))
            {
                Directory.CreateDirectory(dataDirPath);
            }
            string databaseFilePath =
                $"{testflowHome}{CommonConst.DataDir}{Path.DirectorySeparatorChar}{databaseName}";

            globalConfigData.SetConfigItem(Constants.DataMaintain, "DatabaseName", databaseFilePath);
        }
Пример #7
0
        private void InitializeExpressionInfos(GlobalConfigData globalConfigData, ConfigDataLoader dataLoader)
        {
            // 获取表达式符号信息并添加到SequenceManager和EngineCore的配置信息中
            ExpressionOperatorConfiguration expressionTokens = GetExpressionTokens(globalConfigData, dataLoader);
            // 添加操作符到操作符信息的映射
            Dictionary <string, ExpressionOperatorInfo> operatorInfos = new Dictionary <string, ExpressionOperatorInfo>(expressionTokens.Operators.Count);

            foreach (ExpressionOperatorInfo operatorInfo in expressionTokens.Operators)
            {
                operatorInfos.Add(operatorInfo.Symbol, operatorInfo);
            }
            globalConfigData.AddConfigItem(Constants.SequenceManage, "ExpressionOperators", operatorInfos);
            globalConfigData.AddConfigItem(Constants.EngineConfig, "ExpressionOperators", operatorInfos);
            globalConfigData.AddConfigItem(Constants.ParamCheck, "ExpressionOperators", operatorInfos);
            // 添加计算类的信息
            globalConfigData.AddConfigItem(Constants.SequenceManage, "ExpressionCalculators", expressionTokens.Calculators);
            globalConfigData.AddConfigItem(Constants.EngineConfig, "ExpressionCalculators", expressionTokens.Calculators);
            globalConfigData.AddConfigItem(Constants.ParamCheck, "ExpressionCalculators", expressionTokens.Calculators);
        }
Пример #8
0
        public void DesigntimeInitialize()
        {
            GlobalConfigData globalConfigData = Initialize();
            TestflowRunner   testflowRunner   = TestflowRunner.GetInstance();

            this.ApplyConfig(globalConfigData.GetGlobalConfigData());
            testflowRunner.ComInterfaceManager.ApplyConfig(globalConfigData.GetModuleConfigData(Constants.InterfaceLoad));
            testflowRunner.DataMaintainer.ApplyConfig(globalConfigData.GetModuleConfigData(Constants.DataMaintain));
            testflowRunner.EngineController.ApplyConfig(globalConfigData.GetModuleConfigData(Constants.EngineConfig));
            testflowRunner.SequenceManager.ApplyConfig(globalConfigData.GetModuleConfigData(Constants.SequenceManage));
            testflowRunner.ResultManager.ApplyConfig(globalConfigData.GetModuleConfigData(Constants.ResultManage));
            testflowRunner.ParameterChecker.ApplyConfig(globalConfigData.GetModuleConfigData(Constants.ParamCheck));

            this.ConfigData.Properties.Add("TestName", "");
            this.ConfigData.Properties.Add("TestDescription", "");
            this.ConfigData.Properties.Add("RuntimeHash", "");
            this.ConfigData.Properties.Add("RuntimeType", RuntimeType.Run);


            globalConfigData.Dispose();
        }
Пример #9
0
        private void ValidateExpressionTokens(GlobalConfigData configData, ExpressionOperatorConfiguration expressionTokens)
        {
            List <string> availableDirs = new List <string>(5);

            availableDirs.AddRange(configData.GetConfigValue <string[]>(Constants.GlobalConfig, "WorkspaceDir"));
            availableDirs.Add(configData.GetConfigValue <string>(Constants.GlobalConfig, "PlatformLibDir"));
            availableDirs.Add(configData.GetConfigValue <string>(Constants.GlobalConfig, "DotNetLibDir"));
            availableDirs.Add(configData.GetConfigValue <string>(Constants.GlobalConfig, "DotNetRootDir"));

            string calculatorName = string.Empty;

            try
            {
                foreach (ExpressionCalculatorInfo calculatorInfo in expressionTokens.Calculators)
                {
                    // 获取表达式计算类的对象
                    SetAssemblyAbsolutePath(calculatorInfo.CalculatorClass, availableDirs);
                    SetAssemblyAbsolutePath(calculatorInfo.SourceType, availableDirs);
                    if (null != calculatorInfo.ArgumentsType)
                    {
                        foreach (ExpressionTypeData argumentTypeInfo in calculatorInfo.ArgumentsType)
                        {
                            SetAssemblyAbsolutePath(argumentTypeInfo, availableDirs);
                        }
                    }
                }
            }
            catch (TestflowException)
            {
                throw;
            }
            catch (ApplicationException ex)
            {
                TestflowRunner.GetInstance().LogService.Print(LogLevel.Fatal, CommonConst.PlatformLogSession, ex,
                                                              $"Invalid expression token {calculatorName}");
                throw new TestflowRuntimeException(ModuleErrorCode.ConfigDataError,
                                                   ex.Message, ex);
            }
        }
Пример #10
0
        private void AddExtraGlobalConfigData(GlobalConfigData configData)
        {
            // 更新TestflowHome字段
            string homeDir = Environment.GetEnvironmentVariable(CommonConst.EnvironmentVariable);

            if (null != homeDir && !homeDir.EndsWith(Path.DirectorySeparatorChar.ToString()))
            {
                homeDir += Path.DirectorySeparatorChar;
            }
            configData.AddConfigItem(Constants.GlobalConfig, "TestflowHome", homeDir);

            // 更新WorkspaceDir字段

            // 更新.NET运行时目录
            string dotNetVersion    = configData.GetConfigValue <string>(Constants.GlobalConfig, "DotNetVersion");
            string runtimeDirectory = GetDotNetDir(dotNetVersion);

            configData.AddConfigItem(Constants.GlobalConfig, "DotNetLibDir", runtimeDirectory);

            // 更新.NET安装根目录
            string dotNetRootDir = GetDotNetRootDir();

            configData.AddConfigItem(Constants.GlobalConfig, "DotNetRootDir", dotNetRootDir);

            // 更新Testflow平台默认库目录
            string platformDir = configData.GetConfigValue <string>(Constants.GlobalConfig, "PlatformLibDir");
            string libDir      = $"{homeDir}{platformDir}";

            if (libDir.EndsWith(Path.DirectorySeparatorChar.ToString()))
            {
                libDir += Path.DirectorySeparatorChar;
            }
            configData.SetConfigItem(Constants.GlobalConfig, "PlatformLibDir", libDir);

            // 更新Testflow工作空间目录
            string workspaceDirs = Environment.GetEnvironmentVariable(CommonConst.WorkspaceVariable);

            if (string.IsNullOrWhiteSpace(workspaceDirs) || !Directory.Exists(workspaceDirs))
            {
                TestflowRunner.GetInstance().LogService.Print(LogLevel.Fatal, CommonConst.PlatformLogSession,
                                                              $"Invalid environment variable:{CommonConst.WorkspaceVariable}");
                I18N i18N = I18N.GetInstance(Constants.I18nName);
                throw new TestflowRuntimeException(ModuleErrorCode.InvalidEnvDir, i18N.GetStr("InvalidHomeVariable"));
            }
            string[]      workSpaceDirElems = workspaceDirs.Split(';');
            List <string> workspaceDirList  = new List <string>(workSpaceDirElems.Length);

            foreach (string workSpaceDir in workSpaceDirElems)
            {
                if (string.IsNullOrWhiteSpace(workSpaceDir))
                {
                    continue;
                }
                string dirPath = workSpaceDir;
                if (!workSpaceDir.EndsWith(Path.DirectorySeparatorChar.ToString()))
                {
                    dirPath += Path.DirectorySeparatorChar;
                }
                workspaceDirList.Add(dirPath);
            }
            configData.SetConfigItem(Constants.GlobalConfig, "WorkspaceDir", workspaceDirList.ToArray());
        }