/// <summary> /// 在作用域下执行 /// </summary> /// <param name="instanceType">实例类型</param> /// <param name="instance">The instance.</param> /// <param name="scope">执行代码作用区间</param> public override bool InvokeInScope(Type instanceType, object instance, ModuleRunScope scope = null) { PropertyInfo pInfo = instanceType.GetProperty(Name, BindingFlags.Public | BindingFlags.Instance); if (pInfo == null) { throw new System.Configuration.ConfigurationErrorsException("属性[" + Name + "]在类型(" + instanceType.FullName + ")中未找到,请确保系统配置正确!"); } else { object targetVal = Value; //if (string.IsNullOrEmpty(Value)) //{ //} int idx = Value.IndexOf('$'); if (idx != -1) { if (Value[idx + 1] != '$') { string str = "\\$([a-zA-z_][a-zA-z_0-9]*)"; string varName = Regex.Match(Value, str).Groups[1].Value; targetVal = scope.GetVaraible(varName); } } pInfo.SetValue(instance, targetVal, null); } return(false); }
/// <summary> /// 当前条件是否通过 /// </summary> /// <param name="scope">作用域</param> /// <returns> /// <c>true</c> if the specified scope is passed; otherwise, <c>false</c>. /// </returns> public virtual bool IsPassed(ModuleRunScope scope) { if (ExpressionLeft != null && ExpressionRight != null) { string result = ExpressionLeft.Invoke(scope); string resultRight = ExpressionRight.Invoke(scope); if (!string.IsNullOrEmpty(BooleanCompareDelegate)) { return(ConditionalElement.GetBooleanDelegate(BooleanCompareDelegate)(result, resultRight)); } else { return(string.Equals(result, resultRight, ComparisonMode)); } } object boolKey = scope.GetVaraible(Key); if (boolKey == null) { return(false); } else { return(Convert.ToBoolean(boolKey)); } }
/// <summary> /// 当前条件是否通过 /// </summary> /// <param name="scope">作用域</param> /// <returns></returns> /// <exception cref="NotImplementedException"></exception> public bool IsPassed(ModuleRunScope scope) { object cmp = scope.GetVaraible(ScopeInstanceKey); if (cmp == null) { throw new System.Configuration.ConfigurationErrorsException("作用域变量[" + ScopeInstanceKey + "]未找到,请确保系统配置正确!"); } Type cmpType = TypeCache.GetRuntimeType(CompareType); return(cmp.GetType().Equals(cmpType)); }
/// <summary> /// 在作用域下执行 /// </summary> /// <param name="instanceType">实例类型</param> /// <param name="instance">The instance.</param> /// <param name="scope">执行代码作用区间</param> /// <returns>是否中途中止进行</returns> public override bool InvokeInScope(Type instanceType, object instance, ModuleRunScope scope = null) { object enumeratorObj = scope.GetVaraible(ScopeIEnumerableInstance); if (enumeratorObj == null) { throw new System.Configuration.ConfigurationErrorsException("作用域变量[" + ScopeIEnumerableInstance + "]未找到,请确保系统配置正确!"); } Type objType = enumeratorObj.GetType(); System.Collections.IEnumerator enumerator = null; if (objType.IsArray) { Array arr = enumeratorObj as Array; enumerator = arr.GetEnumerator(); } else { MethodInfo mInfo = objType.GetMethod("GetEnumerator", BindingFlags.InvokeMethod | BindingFlags.Instance); if (mInfo == null) { throw new System.Configuration.ConfigurationErrorsException("作用域变量[" + ScopeIEnumerableInstance + "]没有实现GetEnumerator()的方法,不是一个可枚举的实例类型,请确保系统配置正确!"); } enumerator = mInfo.Invoke(enumeratorObj, null) as System.Collections.IEnumerator; } if (enumerator == null) { throw new System.Configuration.ConfigurationErrorsException("系统传参错误,作用域变量[" + ScopeIEnumerableInstance + "]不是一个可枚举的实例类型,请确保系统配置正确!"); } bool stopInvoke = false; using (ModuleRunScope nScope = new ModuleRunScope(scope)) { while (enumerator.MoveNext()) { nScope.StepSwap = enumerator.Current; if (Match.CanRunInScope(nScope)) { bool exit = InvokeStepsInScope(instanceType, instance, nScope, base.Steps); if (exit) { stopInvoke = true; break; } } } } return(stopInvoke); }
/// <summary> /// 当前条件是否通过 /// </summary> /// <param name="scope">作用域</param> /// <returns> /// <c>true</c> if the specified scope is passed; otherwise, <c>false</c>. /// </returns> public virtual bool IsPassed(ModuleRunScope scope) { if (Expression != null) { bool result = Expression.Invoke(scope); return(result); } object boolKey = scope.GetVaraible(Key); if (boolKey == null) { return(false); } else { return(Convert.ToBoolean(boolKey)); } }
public object GetVaraible(string varName) { //键值特殊处理$ TODO if (varName == "$StepSwap") { return(StepSwap); } if (VarDict.ContainsKey(varName)) { return(VarDict[varName]); } else { if (Parent == null) { return(null); } return(Parent.GetVaraible(varName)); } }