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); } }
public SlaveContext(string configDataStr) { _configData = JsonConvert.DeserializeObject <Dictionary <string, string> >(configDataStr); this._msgIndex = -1; this.I18N = I18N.GetInstance(Constants.I18nName); this.Convertor = new TypeConvertor(this); SessionId = this.GetProperty <int>("Session"); State = RuntimeState.NotAvailable; this.StatusQueue = new LocalEventQueue <SequenceStatusInfo>(CoreConstants.DefaultEventsQueueSize); string instanceName = _configData["InstanceName"]; string sessionName = _configData["SessionName"]; this.LogSession = new RemoteLoggerSession(instanceName, sessionName, SessionId, GetProperty <LogLevel>("LogLevel")); this.MessageTransceiver = new MessageTransceiver(this, SessionId); this.UplinkMsgProcessor = new UplinkMessageProcessor(this); this.CallBackEventManager = new CallBackEventManager(); this.FlowControlThread = null; this.RmtGenMessage = null; this.CtrlStartMessage = null; this.CtrlStartMessage = null; this.TraceVariables = new HashSet <string>(); this.ReturnVariables = new HashSet <string>(); this.RuntimeType = GetProperty <RuntimeType>("RuntimeType"); this.Cancellation = new CancellationTokenSource(); this.TimingManager = new StopWatchManager(this); this.CoroutineManager = new CoroutineManager(this); this.DebugManager = new DebugManager(this); LogSession.Print(LogLevel.Debug, SessionId, "Slave context constructed."); }
/// <summary> /// 创建日志服务实例 /// </summary> public LogService() { if (null != _inst) { I18N i18N = I18N.GetInstance(Constants.I18NName); throw new TestflowRuntimeException(CommonErrorCode.InternalError, i18N.GetStr("InstAlreadyExist")); } lock (_instLock) { Thread.MemoryBarrier(); if (null != _inst) { I18N i18N = I18N.GetInstance(Constants.I18NName); throw new TestflowRuntimeException(CommonErrorCode.InternalError, i18N.GetStr("InstAlreadyExist")); } _runtimeLogSessions = new Dictionary <int, LocalLogSession>(Constants.DefaultLogStreamSize); I18NOption i18NOption = new I18NOption(this.GetType().Assembly, "i18n_logger_zh", "i18n_logger_en") { Name = Constants.I18NName }; _i18N = I18N.GetInstance(i18NOption); _testflowInst = TestflowRunner.GetInstance(); _context = _testflowInst.Context; _inst = this; } }
public static SequenceGroup LoadSequenceGroup(string seqFilePath, bool forceLoad, IModuleConfigData envInfo) { seqFilePath = ModuleUtils.GetAbsolutePath(seqFilePath, Directory.GetCurrentDirectory()); if (!seqFilePath.EndsWith($".{CommonConst.SequenceFileExtension}")) { I18N i18N = I18N.GetInstance(Constants.I18nName); throw new TestflowDataException(ModuleErrorCode.InvalidFileType, i18N.GetStr("InvalidFileType")); } SequenceGroup sequenceGroup = XmlReaderHelper.ReadSequenceGroup(seqFilePath); // 需要单独配置Setup和TearDown的索引号 sequenceGroup.SetUp.Index = CommonConst.SetupIndex; sequenceGroup.TearDown.Index = CommonConst.TeardownIndex; string paramFilePath = ModuleUtils.GetAbsolutePath(sequenceGroup.Info.SequenceParamFile, seqFilePath); SequenceGroupParameter parameter = XmlReaderHelper.ReadSequenceGroupParameter(paramFilePath); 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); sequenceGroup.Info.SequenceGroupFile = seqFilePath; sequenceGroup.Info.SequenceParamFile = paramFilePath; return(sequenceGroup); }
public EngineHandle() { I18NOption i18NOption = new I18NOption(typeof(EngineHandle).Assembly, "i18n_engineCore_zh.resx", "i18n_engineCore_en.resx") { Name = Constants.I18nName }; I18N.InitInstance(i18NOption); if (null != _instance) { I18N i18N = I18N.GetInstance(Constants.I18nName); throw new TestflowRuntimeException(CommonErrorCode.InternalError, i18N.GetStr("InstAlreadyExist")); } lock (_instLock) { Thread.MemoryBarrier(); if (null != _instance) { I18N i18N = I18N.GetInstance(Constants.I18nName); throw new TestflowRuntimeException(CommonErrorCode.InternalError, i18N.GetStr("InstAlreadyExist")); } _instance = this; } }
//todo I18n public void RemoveSequenceStep(ISequenceFlowContainer parent, ISequenceStep step) { bool removed = false; if (parent is ISequence) { removed = ((ISequence)parent).Steps.Remove(step); } else if (parent is ISequenceStep) { ISequenceStep parentStep = (ISequenceStep)parent; if (parentStep.StepType == SequenceStepType.TryFinallyBlock || parentStep.StepType == SequenceStepType.SequenceCall) { I18N i18N = I18N.GetInstance(Constants.I18nName); throw new TestflowDataException(ModuleErrorCode.InvalidEditOperation, i18N.GetStr("InvalidOperation")); } removed = (parentStep).SubSteps.Remove(step); } else { throw new TestflowDataException(ModuleErrorCode.InvalidEditOperation, "Parent needs to be Sequence or SequenceStep"); } //判断成功remove与否 if (removed) { ContextSequenceGroupModify(); } else { throw new TestflowDataException(ModuleErrorCode.TargetNotExist, $"Step {step.Name} could not be found in parent {parent.Name}"); } }
public SequenceManager() { if (null != _instance) { I18N i18N = I18N.GetInstance(Constants.I18nName); throw new TestflowRuntimeException(CommonErrorCode.InternalError, i18N.GetStr("InstAlreadyExist")); } lock (_instLock) { Thread.MemoryBarrier(); if (null != _instance) { I18N i18N = I18N.GetInstance(Constants.I18nName); throw new TestflowRuntimeException(CommonErrorCode.InternalError, i18N.GetStr("InstAlreadyExist")); } I18NOption i18NOption = new I18NOption(this.GetType().Assembly, "i18n_sequence_zh", "i18n_sequence_en") { Name = Constants.I18nName }; I18N.InitInstance(i18NOption); this.ConfigData = null; this.Version = string.Empty; _instance = this; } }
private static ISequence GetSequence(ISequenceGroup sequenceGroup, int index) { ISequence sequence; switch (index) { case CommonConst.SetupIndex: sequence = sequenceGroup.SetUp; break; case CommonConst.TeardownIndex: sequence = sequenceGroup.TearDown; break; default: if (sequenceGroup.Sequences.Count <= index || index < 0) { I18N i18N = I18N.GetInstance(UtilityConstants.UtilsName); throw new TestflowDataException(ModuleErrorCode.SequenceDataError, i18N.GetStr("CannotFindSequence")); } sequence = sequenceGroup.Sequences[index]; break; } return(sequence); }
public virtual void Print(LogLevel logLevel, int sessionId, string message) { switch (logLevel) { case LogLevel.Debug: Logger.Debug(message); break; case LogLevel.Info: Logger.Info(message); break; case LogLevel.Warn: Logger.Warn(message); break; case LogLevel.Error: Logger.Error(message); break; case LogLevel.Fatal: Logger.Fatal(message); break; default: I18N i18N = I18N.GetInstance(Constants.I18NName); throw new TestflowRuntimeException(ModuleErrorCode.InvalidLogArgument, i18N.GetStr("InvalidLogArgument")); break; } }
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; }
public void GetEntity() { I18N.InitInstance(_i18NOption); I18N i18N = I18N.GetInstance(I18nName); Assert.AreNotEqual(null, i18N); }
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)); }
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")); } } }
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); }
public ISequenceStep AddSequenceStep(ISequenceFlowContainer parent, IList <ISequenceStep> stepDatas, int index) { if (parent is ISequence) { for (int n = 0; n < stepDatas.Count; n++) { ((ISequence)parent).Steps.Insert(n + index, stepDatas[n]); stepDatas[n].Parent = parent; } } else if (parent is ISequenceStep) { for (int n = 0; n < stepDatas.Count; n++) { ISequenceStep parentStep = (ISequenceStep)parent; if (parentStep.StepType == SequenceStepType.TryFinallyBlock || parentStep.StepType == SequenceStepType.SequenceCall) { I18N i18N = I18N.GetInstance(Constants.I18nName); throw new TestflowDataException(ModuleErrorCode.InvalidEditOperation, i18N.GetStr("InvalidOperation")); } parentStep.SubSteps.Insert(n + index, stepDatas[n]); stepDatas[n].Parent = parent; } } else { throw new TestflowDataException(ModuleErrorCode.InvalidEditOperation, "Parent needs to be Sequence or SequenceStep"); } ContextSequenceGroupModify(); return(stepDatas[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); }
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); }
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)); }
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")); }
public void I18NEnglishTest() { I18N.RemoveInstance(I18nName); Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US"); _i18N = I18N.GetInstance(_i18NOption); string str = _i18N.GetStr(TestLabel); Assert.AreEqual(str, i18n_test_en.TestLabel); }
// 使用TypeDescription信息更新VariableTypes和Class中的ClassType信息 public static void ValidateComDescription(ISequenceManager sequenceManager, ComInterfaceDescription description, DescriptionDataTable descriptionCollection) { int componentId = description.ComponentId; foreach (ITypeDescription typeDescription in description.TypeDescriptions) { ITypeData classType = GetTypeDataByDescription(sequenceManager, descriptionCollection, typeDescription); description.VariableTypes.Add(classType); if (null != typeDescription.Enumerations) { description.Enumerations.Add(GetFullName(typeDescription), typeDescription.Enumerations); } } description.TypeDescriptions.Clear(); description.TypeDescriptions = null; ((List <ITypeData>)description.VariableTypes).TrimExcess(); foreach (ClassInterfaceDescription classDescription in description.Classes) { ITypeData classType = GetTypeDataByDescription(sequenceManager, descriptionCollection, classDescription.ClassTypeDescription); classDescription.ClassType = classType; classDescription.ClassTypeDescription = null; } ((List <IClassInterfaceDescription>)description.Classes).TrimExcess(); I18N i18N = I18N.GetInstance(Constants.I18nName); foreach (IClassInterfaceDescription classDescription in description.Classes) { foreach (IFuncInterfaceDescription functionDescription in classDescription.Functions) { // 配置实例属性配置方法和静态属性配置方法的描述信息 if (functionDescription.FuncType == FunctionType.InstancePropertySetter) { functionDescription.Description = i18N.GetStr("InstancePropertySetter"); } else if (functionDescription.FuncType == FunctionType.StaticPropertySetter) { functionDescription.Description = i18N.GetStr("StaticPropertySetter"); } foreach (IArgumentDescription argumentDescription in functionDescription.Arguments) { InitializeArgumentType(sequenceManager, descriptionCollection, argumentDescription); } ((List <IArgumentDescription>)functionDescription.Arguments).TrimExcess(); functionDescription.ClassType = classDescription.ClassType; if (null != functionDescription.Return) { InitializeArgumentType(sequenceManager, descriptionCollection, functionDescription.Return); } } } }
/// <summary> /// 抽象类的构造方法 /// </summary> /// <param name="options"></param> protected TestflowRunner(TestflowRunnerOptions options) { this.Option = options; this.Context = new TestflowContext(); I18NOption i18NOption = new I18NOption(typeof(TestflowRunner).Assembly, "i18n_common_cn", "i18n_common_en") { Name = CommonConst.I18nName }; I18N i18N = I18N.GetInstance(i18NOption); }
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)); }
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); }
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); }
/// <summary> /// 创建库类型属性实例 /// </summary> /// <param name="categoryString"></param> public TestflowCategoryAttribute(string categoryString) { I18NOption i18NOption = new I18NOption(Assembly.GetAssembly(this.GetType()), "i18n_userlib_zh", "i18n_userlib_en") { Name = Constants.I18nName }; I18N.InitInstance(i18NOption); I18N i18N = I18N.GetInstance(Constants.I18nName); this.CategoryString = i18N.GetStr(categoryString) ?? categoryString; Category = LibraryCategory.Miscellaneous; }
public static void LoadParameter(SequenceGroup sequenceGroup, string filePath, bool forceLoad) { filePath = ModuleUtils.GetAbsolutePath(filePath, Directory.GetCurrentDirectory()); SequenceGroupParameter parameter = XmlReaderHelper.ReadSequenceGroupParameter(filePath); 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); }
/// <summary> /// 创建库类型属性实例 /// </summary> public TestflowCategoryAttribute(LibraryCategory category) { I18NOption i18NOption = new I18NOption(Assembly.GetAssembly(this.GetType()), "i18n_userlib_zh", "i18n_userlib_en") { Name = Constants.I18nName }; I18N.InitInstance(i18NOption); I18N i18N = I18N.GetInstance(Constants.I18nName); this.Category = category; this.CategoryString = i18N.GetStr(category.ToString()); }
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); }
/// <summary> /// 获取或创建当前AppDomain下的FlowRunner实例 /// </summary> /// <returns></returns> public static TestflowRunner GetInstance() { if (null != _runnerInst) { return(_runnerInst); } lock (_instLock) { if (null != _runnerInst) { I18N i18N = I18N.GetInstance(CommonConst.I18nName); throw new TestflowInternalException(CommonErrorCode.InternalError, i18N.GetStr("PlatformNotInitialized")); } } return(_runnerInst); }