public static string GetRuntimeVariableString(WatchDataObject watchDataObj, ISequenceFlowContainer sequenceData) { const char delim = '.'; string[] watchElem = watchDataObj.WatchData.Split(delim); string variableName = watchElem[0]; int sequenceIndex = watchDataObj.Sequence; IVariable variable = null; if (sequenceData is ITestProject) { ITestProject testProject = sequenceData as ITestProject; if (watchDataObj.Session == CommonConst.TestGroupSession) { variable = GetVariableByNameAndSequence(testProject, sequenceIndex, variableName); } else { variable = GetVariableByNameAndSequence(testProject.SequenceGroups[watchDataObj.Session], sequenceIndex, variableName); } } else if (sequenceData is ISequenceGroup) { ISequenceGroup sequenceGroup = sequenceData as ISequenceGroup; variable = GetVariableByNameAndSequence(sequenceGroup, sequenceIndex, variableName); } if (null == variable) { return(null); } watchElem[0] = CoreUtils.GetRuntimeVariableName(watchDataObj.Session, variable); return(string.Join(delim.ToString(), watchElem)); }
// 改变StepData.Function.Parameters:如果是variable,则变为运行时$格式 protected override void InitializeParamsValues() { IArgumentCollection argumentInfos = Function.ParameterType; IParameterDataCollection parameters = Function.Parameters; for (int i = 0; i < argumentInfos.Count; i++) { string paramValue = parameters[i].Value; if (parameters[i].ParameterType == ParameterType.Value) { Params[i] = Context.TypeInvoker.CastConstantValue(argumentInfos[i].Type, paramValue); } else { // 如果是变量,则先获取对应的Varaible变量,真正的值在运行时才更新获取 string variableName = ModuleUtils.GetVariableNameFromParamValue(paramValue); IVariable variable = ModuleUtils.GetVaraibleByRawVarName(variableName, StepData); if (null == variable) { Context.LogSession.Print(LogLevel.Error, SequenceIndex, $"Unexist variable '{variableName}' in sequence data."); throw new TestflowDataException(ModuleErrorCode.SequenceDataError, Context.I18N.GetFStr("UnexistVariable", variableName)); } // 将变量的值保存到Parameter中 string varFullName = CoreUtils.GetRuntimeVariableName(Context.SessionId, variable); parameters[i].Value = ModuleUtils.GetFullParameterVariableName(varFullName, parameters[i].Value); Params[i] = null; } } //todo 做同步的时候再添加对返回值的处理,代码参照StepExecutionEntity的InitializeParamsValue }
protected override void InitializeParamsValues() { IArgumentCollection argumentInfos = Function.ParameterType; IParameterDataCollection parameters = Function.Parameters; for (int i = 0; i < argumentInfos.Count; i++) { string paramValue = parameters[i].Value; switch (parameters[i].ParameterType) { case ParameterType.Value: Params[i] = Context.TypeInvoker.CastConstantValue(argumentInfos[i].Type, paramValue); break; case ParameterType.Variable: // 如果是变量,则先获取对应的Varaible变量,真正的值在运行时才更新获取 string variableName = ModuleUtils.GetVariableNameFromParamValue(paramValue); IVariable variable = ModuleUtils.GetVaraibleByRawVarName(variableName, StepData); if (null == variable) { Context.LogSession.Print(LogLevel.Error, Context.SessionId, $"Unexist variable '{variableName}' in sequence data."); throw new TestflowDataException(ModuleErrorCode.SequenceDataError, Context.I18N.GetFStr("UnexistVariable", variableName)); } // 将变量的值保存到Parameter中 string varFullName = CoreUtils.GetRuntimeVariableName(Context.SessionId, variable); parameters[i].Value = ModuleUtils.GetFullParameterVariableName(varFullName, parameters[i].Value); Params[i] = null; break; default: Context.LogSession.Print(LogLevel.Error, Context.SessionId, $"The value of parameter '{argumentInfos[i].Name}' is not configured"); throw new TestflowDataException(ModuleErrorCode.SequenceDataError, Context.I18N.GetStr("InvalidParamVar")); break; } } if (null != Function.ReturnType && CoreUtils.IsValidVaraible(Function.Return)) { // 如果是变量,则先获取对应的Varaible变量,真正的值在运行时才更新获取 string variableName = ModuleUtils.GetVariableNameFromParamValue(Function.Return); IVariable variable = ModuleUtils.GetVaraibleByRawVarName(variableName, StepData); if (null == variable) { Context.LogSession.Print(LogLevel.Error, SequenceIndex, $"Unexist variable '{variableName}' in sequence data."); throw new TestflowDataException(ModuleErrorCode.SequenceDataError, Context.I18N.GetFStr("UnexistVariable", variableName)); } ReturnVar = CoreUtils.GetRuntimeVariableName(Context.SessionId, variable); } CommonStepDataCheck(InstanceVar); }
public static string GetVariableFullName(string variableName, ISequenceStep step, int session) { while (step.Parent is ISequenceStep) { step = (ISequenceStep)step.Parent; } ISequence sequence = (ISequence)step.Parent; IVariable variable = sequence.Variables.FirstOrDefault(item => item.Name.Equals(variableName)); if (null != variable) { return(CoreUtils.GetRuntimeVariableName(session, variable)); } ISequenceGroup sequenceGroup = (ISequenceGroup)sequence.Parent; variable = sequenceGroup.Variables.First(item => item.Name.Equals(variableName)); return(CoreUtils.GetRuntimeVariableName(session, variable)); }
public void AddWatchVariable(int session, IVariable variable) { string variableName = CoreUtils.GetRuntimeVariableName(session, variable); if (!_watchVariables.ContainsKey(session)) { _watchVariables.Add(session, new List <string>(Constants.DefaultRuntimeSize)); } if (!_watchVariables[session].Contains(variableName)) { _watchVariables[session].Add(variableName); } RuntimeState runtimeState = _globalInfo.StateMachine.State; if (runtimeState == RuntimeState.Running || runtimeState == RuntimeState.Blocked || runtimeState == RuntimeState.DebugBlocked) { SendRefreshWatchMessage(session); } }
private void AddVariables(IVariableCollection variables, bool addToSyncSet) { int sessionId = _context.SessionId; foreach (IVariable variable in variables) { string variableName = CoreUtils.GetRuntimeVariableName(sessionId, variable); object value = null; // 如果变量已匹配类型并且配置的值有效,则初始化变量值。如果是值类型但是未配置值则获取默认值 if (variable.VariableType != VariableType.Undefined && null != variable.Type) { value = CoreUtils.IsValidVaraibleValue(variable) ? _context.TypeInvoker.CastConstantValue(variable.Type, variable.Value) : _context.Convertor.GetDefaultValue(variable.Type); } this._variables.Add(variableName, value); // 如果变量的OI报告级别配置为trace则添加变量到监控数据中 // 如果变量OI报告级别为最终结果或者报告级别不为None,则添加变量到返回数据 if (variable.OIRecordLevel == RecordLevel.FullTrace || variable.ReportRecordLevel == RecordLevel.FullTrace) { _fullTraceVariables.Add(variableName); _context.ReturnVariables.Add(variableName); } else if (variable.OIRecordLevel == RecordLevel.Trace || variable.ReportRecordLevel == RecordLevel.Trace) { _context.TraceVariables.Add(variableName); _context.ReturnVariables.Add(variableName); } else if (variable.OIRecordLevel == RecordLevel.FinalResult || variable.ReportRecordLevel != RecordLevel.None) { _context.ReturnVariables.Add(variableName); } if (addToSyncSet) { _syncVariables.Add(variableName); } } }
public void RemoveWatchVariable(int session, IVariable variable) { string variableName = CoreUtils.GetRuntimeVariableName(session, variable); if (!_watchVariables.ContainsKey(session)) { return; } if (_watchVariables[session].Contains(variableName)) { _watchVariables[session].Remove(variableName); if (0 == _watchVariables[session].Count) { _watchVariables.Remove(session); } } RuntimeState runtimeState = _globalInfo.StateMachine.State; if (runtimeState == RuntimeState.Running || runtimeState == RuntimeState.Blocked || runtimeState == RuntimeState.DebugBlocked) { SendRefreshWatchMessage(session); } }