Exemplo n.º 1
0
        public DirectoryHelper(IModuleConfigData configData)
        {
            string dotNetLibDir   = configData.GetProperty <string>("DotNetLibDir");
            string dotNetRootDir  = configData.GetProperty <string>("DotNetRootDir");
            string platformLibDir = configData.GetProperty <string>("PlatformLibDir");

            string[] workspaceDirs = configData.GetProperty <string[]>("WorkspaceDir");

            // 本来用上面就可以确定,因为前期版本里对相对路径前加了\,导致相对路径在第一条下会被判定为绝对路径,所以在此做当前处理
            // 暂未考虑Linux的问题,后续版本会去除这里的判断
//            string relativePathFormat = @"^([a-zA-Z]:)?{0}";
            string relativePathFormat = @"^[a-zA-Z]:{0}";
            char   dirDelim           = Path.DirectorySeparatorChar;
            // \在正则表达式中需要转义
            string relativePathRegexStr = dirDelim.Equals('\\')
                ? string.Format(relativePathFormat, @"\\")
                : string.Format(relativePathFormat, dirDelim);

            _absolutePathRegex = new Regex(relativePathRegexStr);

            availableDirs = new List <string>(workspaceDirs.Length + 2);
            availableDirs.AddRange(workspaceDirs);
            availableDirs.Add(platformLibDir);
            availableDirs.Add(dotNetLibDir);
            availableDirs.Add(dotNetRootDir);

            _pathCache = new StringBuilder(200);
        }
Exemplo n.º 2
0
        public RuntimeEngine(IModuleConfigData configData)
        {
            _globalInfo = new ModuleGlobalInfo(configData);
            bool isSyncMessenger = _globalInfo.ConfigData.GetProperty <bool>("EngineSyncMessenger");
            // TODO 暂时写死使用LocalTestMaintainer
            // 初始化消息收发器
            MessageTransceiver messageTransceiver = MessageTransceiver.GetTransceiver(_globalInfo, isSyncMessenger);

            messageTransceiver.Clear();
            _controller          = new EngineFlowController(_globalInfo);
            _statusManager       = new RuntimeStatusManager(_globalInfo);
            _syncManager         = new SynchronousManager(_globalInfo);
            _callBackProcessor   = new CallBackProcessor(_globalInfo);
            _debugManager        = EnableDebug ? new DebugManager(_globalInfo) : null;
            _runtimeInfoSelector = new RuntimeInfoSelector(_globalInfo, this);

            _globalInfo.RuntimeInitialize(messageTransceiver, _debugManager);

            _runtimeObjectManager = new RuntimeObjectManager(_globalInfo);

            RuntimeStateMachine stateMachine = new RuntimeStateMachine();

            _globalInfo.StateMachine = stateMachine;

            RegisterMessageHandler();

            _globalInfo.LogService.Print(LogLevel.Info, CommonConst.PlatformLogSession, "RuntimeEngine constructed.");
        }
Exemplo n.º 3
0
        private static void CheckModelVersion(string version, IModuleConfigData envInfo)
        {
            I18N       i18N         = I18N.GetInstance(Constants.I18nName);
            const char versionDelim = '.';

            string[] versionElem = version.Split(versionDelim);
            string   envVersion  = envInfo.GetProperty <string>(Constants.VersionName);

            string[] envVersionElem  = envVersion.Split(versionDelim);
            int      versionElemSize = versionElem.Length <= envVersionElem.Length
                ? versionElem.Length
                : envVersionElem.Length;

            for (int i = 0; i < versionElemSize; i++)
            {
                int versionId    = int.Parse(versionElem[i]);
                int envVersionId = int.Parse(envVersionElem[i]);
                if (versionId > envVersionId)
                {
                    throw new TestflowDataException(ModuleErrorCode.InvalidModelVersion,
                                                    i18N.GetStr("InvalidModelVersion"));
                }
            }
            for (int i = envVersionElem.Length; i < versionElem.Length; i++)
            {
                if (int.Parse(versionElem[i]) > 0)
                {
                    throw new TestflowDataException(ModuleErrorCode.InvalidModelVersion,
                                                    i18N.GetStr("InvalidModelVersion"));
                }
            }
        }
Exemplo n.º 4
0
 public ModuleGlobalInfo(IModuleConfigData configData)
 {
     TestflowRunner        = TestflowRunner.GetInstance();
     this.I18N             = I18N.GetInstance(Constants.I18nName);
     this.LogService       = TestflowRunner.LogService;
     this.ConfigData       = configData;
     this.ExceptionManager = new ExceptionManager(LogService);
     this.RuntimeHash      = ModuleUtils.GetRuntimeHash(configData.GetProperty <Encoding>("PlatformEncoding"));
 }
Exemplo n.º 5
0
 public void ApplyConfig(IModuleConfigData configData)
 {
     if (null == this.ConfigData)
     {
         this.ConfigData = configData;
     }
     else
     {
         foreach (KeyValuePair <string, object> keyValuePair in configData.Properties)
         {
             this.ConfigData.SetProperty(keyValuePair.Key, keyValuePair.Value);
         }
     }
 }
Exemplo n.º 6
0
        public RuntimeSerializeTest()
        {
            Type runnerType = typeof(TestflowRunner);
            TestflowRunnerOptions option             = new TestflowRunnerOptions();
            FieldInfo             fieldInfo          = runnerType.GetField("_runnerInst", BindingFlags.Static | BindingFlags.NonPublic);
            FakeTestflowRunner    fakeTestflowRunner = new FakeTestflowRunner(option);

            fieldInfo.SetValue(null, fakeTestflowRunner);

            _sequenceManager = new SequenceManager.SequenceManager();
            _configData      = new TestConfigData();
            _configData.InitExtendProperties();
            _sequenceManager.ApplyConfig(_configData);
            Directory.CreateDirectory("Test");
        }
Exemplo n.º 7
0
        public static TestProject LoadTestProject(string filePath, bool forceLoad, IModuleConfigData envInfo)
        {
            filePath = ModuleUtils.GetAbsolutePath(filePath, Directory.GetCurrentDirectory());

            if (!filePath.EndsWith($".{CommonConst.TestGroupFileExtension}"))
            {
                I18N i18N = I18N.GetInstance(Constants.I18nName);
                throw new TestflowRuntimeException(ModuleErrorCode.InvalidFileType, i18N.GetStr("InvalidFileType"));
            }
            TestProject testProject = null;

            testProject = XmlReaderHelper.ReadTestProject(filePath);

            // 需要单独配置Setup和TearDown的索引号
            testProject.SetUp.Index    = CommonConst.SetupIndex;
            testProject.TearDown.Index = CommonConst.TeardownIndex;

            CheckModelVersion(testProject.ModelVersion, envInfo);
            foreach (ISequenceGroup sequenceGroup in testProject.SequenceGroups)
            {
                CheckModelVersion(sequenceGroup.Info.Version, envInfo);
            }
            foreach (SequenceGroupLocationInfo sequenceGroupLocation in testProject.SequenceGroupLocations)
            {
                SequenceGroup sequenceGroup = null;

                string sequenceGroupFile = ModuleUtils.GetAbsolutePath(sequenceGroupLocation.SequenceFilePath, filePath);
                if (File.Exists(sequenceGroupFile))
                {
                    sequenceGroup        = LoadSequenceGroup(sequenceGroupFile, forceLoad, envInfo);
                    sequenceGroup.Parent = testProject;
                }
                else
                {
                    ILogService logService = TestflowRunner.GetInstance().LogService;
                    logService.Print(LogLevel.Warn, CommonConst.PlatformLogSession, 0, "Sequence group file not exist.");
                    sequenceGroup = new SequenceGroup();
                    sequenceGroup.Initialize(testProject);
                    sequenceGroup.Info.SequenceGroupFile = sequenceGroupFile;
                    sequenceGroup.Available = false;
                }
                testProject.SequenceGroups.Add(sequenceGroup);
            }
            ValidateTypeDatas(testProject);

            return(testProject);
        }
Exemplo n.º 8
0
        internal ExpressionParser(IModuleConfigData configData, ILogService logService)
        {
            Dictionary <string, ExpressionOperatorInfo> operatorInfos =
                configData.GetProperty <Dictionary <string, ExpressionOperatorInfo> >("ExpressionOperators");

            _calculatorInfos = configData.GetProperty <ExpressionCalculatorInfo[]>("ExpressionCalculators");
            _logService      = logService;
            _parseOverRegex  = new Regex(Constants.SingleExpPattern, RegexOptions.Compiled);
            _digitRegex      = new Regex(Constants.DigitPattern, RegexOptions.Compiled);
            _strRegex        = new Regex(Constants.StringPattern, RegexOptions.Compiled);
            _boolRegex       = new Regex(Constants.BoolPattern, RegexOptions.Compiled);

            _expressionDelim = new HashSet <char>();
            foreach (KeyValuePair <string, ExpressionOperatorInfo> operatorInfoPair in operatorInfos)
            {
                string operatorSymbol = operatorInfoPair.Key;
                char[] symbolElem     = operatorSymbol.ToCharArray();
                foreach (char elem in symbolElem)
                {
                    _expressionDelim.Add(elem);
                }
            }



            string argumentPattern = GetArgumentPattern(_expressionDelim);

            _operatorAdapters = new List <OperatorAdapter>(_operatorAdapters.Count);
            // 正则表达式中的元符号
            HashSet <char> metaCharacters = new HashSet <char>
            {
                '^', '[', '.', '$', '{', '*', '(', '\\', '+', ')', '|', '?', '<', '>'
            };

            // 创建各个Operator的符号匹配器
            foreach (KeyValuePair <string, ExpressionOperatorInfo> operatorInfoPair in operatorInfos)
            {
                OperatorAdapter operatorAdapter = new OperatorAdapter(operatorInfoPair.Value, argumentPattern, metaCharacters);
                _operatorAdapters.Add(operatorAdapter);
            }
            // 按照优先级,从大到小排序
            _operatorAdapters.Sort(new OperatorAdapterComparer());
        }
Exemplo n.º 9
0
        public RuntimeEngine(IModuleConfigData configData)
        {
            _globalInfo = new ModuleGlobalInfo(configData);
            bool isSyncMessenger = _globalInfo.ConfigData.GetProperty <bool>("EngineSyncMessenger");
            // TODO 暂时写死使用LocalTestMaintainer
            // 初始化消息收发器
            MessageTransceiver messageTransceiver = MessageTransceiver.GetTransceiver(_globalInfo, isSyncMessenger);

            _controller    = new EngineFlowController(_globalInfo);
            _statusManager = new RuntimeStatusManager(_globalInfo);
            _syncManager   = new SynchronousManager(_globalInfo);

            _globalInfo.RuntimeInitialize(messageTransceiver, _controller.Debugger);

            _runtimeObjectManager = new RuntimeObjectManager();

            RuntimeStateMachine stateMachine = new RuntimeStateMachine();

            _globalInfo.StateMachine = stateMachine;

            RegisterMessageHandler();
        }
Exemplo n.º 10
0
        protected DatabaseProxy(IModuleConfigData configData, bool isRuntimeModuleModule)
        {
            this.ConfigData = configData;
            IsRuntimeModule = isRuntimeModuleModule;

            I18NOption i18NOption = new I18NOption(this.GetType().Assembly, "i18n_datamaintain_zh", "i18n_datamaintain_en")
            {
                Name = Constants.I18nName
            };

            I18N.InitInstance(i18NOption);
            I18N   = I18N.GetInstance(Constants.I18nName);
            Logger = TestflowRunner.GetInstance().LogService;
            try
            {
                // 使用DbProviderFactory方式连接需要在App.Config文件中定义DbProviderFactories节点
                // 但是App.Config文件只在入口Assembly中时才会被默认加载,所以目前写死为SqlConnection
//                DbProviderFactory factory = DbProviderFactories.GetFactory("System.Data.SQLite");
//                Connection = factory.CreateConnection();
//                if (null == Connection)
//                {
//                    Logger.Print(LogLevel.Fatal, CommonConst.PlatformLogSession, "Connect db failed.");
//                    throw new TestflowRuntimeException(ModuleErrorCode.ConnectDbFailed, I18N.GetStr("ConnectDbFailed"));
//                }
                InitializeDatabaseAndConnection();
            }
            catch (DbException ex)
            {
                Logger.Print(LogLevel.Fatal, CommonConst.PlatformLogSession, ex, "Connect db failed.");
                throw new TestflowRuntimeException(ModuleErrorCode.ConnectDbFailed, I18N.GetStr("ConnectDbFailed"), ex);
            }

            this._databaseLock = new ReaderWriterLockSlim();

            DataModelMapper = new DataModelMapper();
        }
Exemplo n.º 11
0
 public RuntimeDatabaseProxy(IModuleConfigData configData) : base(configData, true)
 {
 }
Exemplo n.º 12
0
 public DesigntimeDatabaseProxy(IModuleConfigData configData) : base(configData, false)
 {
 }
Exemplo n.º 13
0
 void IController.ApplyConfig(IModuleConfigData configData)
 {
     // TODO to implement
 }
Exemplo n.º 14
0
 public void ApplyConfig(IModuleConfigData configData)
 {
     // TODO
 }
Exemplo n.º 15
0
 public void ApplyConfig(IModuleConfigData configData)
 {
     this._configData = configData;
 }
Exemplo n.º 16
0
        public static SequenceGroup LoadSequenceGroup(string filePath, bool forceLoad, IModuleConfigData envInfo)
        {
            filePath = ModuleUtils.GetAbsolutePath(filePath, Directory.GetCurrentDirectory());

            if (!filePath.EndsWith($".{CommonConst.SequenceFileExtension}"))
            {
                I18N i18N = I18N.GetInstance(Constants.I18nName);
                throw new TestflowDataException(ModuleErrorCode.InvalidFileType, i18N.GetStr("InvalidFileType"));
            }
            SequenceGroup          sequenceGroup     = XmlReaderHelper.ReadSequenceGroup(filePath);
            string                 sequenceParamFile = ModuleUtils.GetAbsolutePath(sequenceGroup.Info.SequenceParamFile, filePath);
            SequenceGroupParameter parameter         =
                XmlReaderHelper.ReadSequenceGroupParameter(sequenceParamFile);

            if (!forceLoad && !sequenceGroup.Info.Hash.Equals(parameter.Info.Hash))
            {
                I18N i18N = I18N.GetInstance(Constants.I18nName);
                throw new TestflowDataException(ModuleErrorCode.UnmatchedFileHash, i18N.GetStr("UnmatchedHash"));
            }
            sequenceGroup.Parameters = parameter;
            SetParameterToSequenceData(sequenceGroup, parameter);
            ValidateTypeDatas(sequenceGroup);
            return(sequenceGroup);
        }
Exemplo n.º 17
0
 public void ApplyConfig(IModuleConfigData configData)
 {
     this.ConfigData = configData;
     this.Version    = configData.GetProperty <string>(Constants.VersionName);
 }
Exemplo n.º 18
0
 public void ApplyConfig(IModuleConfigData configData)
 {
     // TODO to implement
 }
Exemplo n.º 19
0
 public void ApplyConfig(IModuleConfigData configData)
 {
     this.ConfigData       = configData;
     this.Version          = configData.GetProperty <string>(Constants.VersionName);
     this._directoryHelper = new DirectoryHelper(configData);
 }