本文整理汇总了C#中System.Workflow.Activities.Rules.RuleValidation类的典型用法代码示例。如果您正苦于以下问题:C# RuleValidation类的具体用法?C# RuleValidation怎么用?C# RuleValidation使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RuleValidation类属于System.Workflow.Activities.Rules命名空间,在下文中一共展示了RuleValidation类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Evaluate
// Methods
public override bool Evaluate (Activity activity, IServiceProvider provider)
{
Activity parent = activity;
RuleDefinitions definitions = null;
while (parent != null) {
definitions = (RuleDefinitions) parent.GetValue (RuleDefinitions.RuleDefinitionsProperty);
if (definitions != null)
break;
parent = parent.Parent;
}
if (definitions == null) {
Console.WriteLine ("No definition");
return false;
}
//Console.WriteLine ("Definition {0} at {1}", definitions, parent);
RuleValidation validation = new RuleValidation (activity.GetType (), null);
RuleExecution execution = new RuleExecution (validation, parent);
RuleCondition condition = definitions.Conditions [ConditionName];
//Console.WriteLine ("Condition {0}", condition);
return condition.Evaluate (execution);
}
示例2: Execute
protected override ActivityExecutionStatus Execute(ActivityExecutionContext context)
{
if (context == null)
{
throw new ArgumentNullException("context");
}
ExternalRuleSetService.ExternalRuleSetService ruleSetService = context.GetService<ExternalRuleSetService.ExternalRuleSetService>();
if (ruleSetService != null)
{
RuleSet ruleSet = ruleSetService.GetRuleSet(new RuleSetInfo(this.RuleSetName, this.MajorVersion, this.MinorVersion));
if (ruleSet != null)
{
Activity targetActivity = this.GetRootWorkflow(this.Parent);
RuleValidation validation = new RuleValidation(targetActivity.GetType(), null);
RuleExecution execution = new RuleExecution(validation, targetActivity, context);
ruleSet.Execute(execution);
}
}
else
{
throw new InvalidOperationException("A RuleSetService must be configured on the host to use the PolicyFromService activity.");
}
return ActivityExecutionStatus.Closed;
}
示例3: Validate
internal override RuleExpressionInfo Validate(CodeExpression expression, RuleValidation validation, bool isWritten)
{
RuleExpressionInfo info;
bool flag;
CodeDirectionExpression expression2 = (CodeDirectionExpression) expression;
if (isWritten)
{
ValidationError item = new ValidationError(string.Format(CultureInfo.CurrentCulture, Messages.CannotWriteToExpression, new object[] { typeof(CodeDirectionExpression).ToString() }), 0x17a);
item.UserData["ErrorObject"] = expression2;
validation.Errors.Add(item);
return null;
}
if (expression2.Expression == null)
{
ValidationError error2 = new ValidationError(Messages.NullDirectionTarget, 0x53d);
error2.UserData["ErrorObject"] = expression2;
validation.Errors.Add(error2);
return null;
}
if (expression2.Expression is CodeTypeReferenceExpression)
{
ValidationError error = new ValidationError(string.Format(CultureInfo.CurrentCulture, Messages.CodeExpressionNotHandled, new object[] { expression2.Expression.GetType().FullName }), 0x548);
error.UserData["ErrorObject"] = expression2.Expression;
validation.AddError(error);
return null;
}
if (expression2.Direction == FieldDirection.Ref)
{
flag = true;
if (RuleExpressionWalker.Validate(validation, expression2.Expression, false) == null)
{
return null;
}
info = RuleExpressionWalker.Validate(validation, expression2.Expression, true);
}
else if (expression2.Direction == FieldDirection.Out)
{
flag = true;
info = RuleExpressionWalker.Validate(validation, expression2.Expression, true);
}
else
{
flag = false;
info = RuleExpressionWalker.Validate(validation, expression2.Expression, false);
}
if (info == null)
{
return null;
}
Type expressionType = info.ExpressionType;
if (expressionType == null)
{
return null;
}
if (((expressionType != typeof(NullLiteral)) && flag) && !expressionType.IsByRef)
{
expressionType = expressionType.MakeByRefType();
}
return new RuleExpressionInfo(expressionType);
}
示例4: Validate
internal override bool Validate(RuleValidation validation, MemberInfo member, Type contextType, ParameterInfo[] parameters)
{
Stack<MemberInfo> methodStack = new Stack<MemberInfo>();
methodStack.Push(member);
bool flag = this.ValidateInvokeAttribute(validation, member, contextType, methodStack);
methodStack.Pop();
return flag;
}
示例5: Validate
internal override bool Validate(RuleValidation validation)
{
bool flag = false;
RuleExpressionInfo info = null;
if (this.assignStatement.Left == null)
{
ValidationError item = new ValidationError(Messages.NullAssignLeft, 0x541);
item.UserData["ErrorObject"] = this.assignStatement;
validation.Errors.Add(item);
}
else
{
info = validation.ExpressionInfo(this.assignStatement.Left);
if (info == null)
{
info = RuleExpressionWalker.Validate(validation, this.assignStatement.Left, true);
}
}
RuleExpressionInfo info2 = null;
if (this.assignStatement.Right == null)
{
ValidationError error2 = new ValidationError(Messages.NullAssignRight, 0x543);
error2.UserData["ErrorObject"] = this.assignStatement;
validation.Errors.Add(error2);
}
else
{
info2 = RuleExpressionWalker.Validate(validation, this.assignStatement.Right, false);
}
if ((info == null) || (info2 == null))
{
return flag;
}
Type expressionType = info2.ExpressionType;
Type lhsType = info.ExpressionType;
if (lhsType == typeof(NullLiteral))
{
ValidationError error3 = new ValidationError(Messages.NullAssignLeft, 0x542);
error3.UserData["ErrorObject"] = this.assignStatement;
validation.Errors.Add(error3);
return false;
}
if (lhsType != expressionType)
{
ValidationError error = null;
if (!RuleValidation.TypesAreAssignable(expressionType, lhsType, this.assignStatement.Right, out error))
{
if (error == null)
{
error = new ValidationError(string.Format(CultureInfo.CurrentCulture, Messages.AssignNotAllowed, new object[] { RuleDecompiler.DecompileType(expressionType), RuleDecompiler.DecompileType(lhsType) }), 0x545);
}
error.UserData["ErrorObject"] = this.assignStatement;
validation.Errors.Add(error);
return flag;
}
}
return true;
}
示例6: GetSideEffects
public override ICollection<string> GetSideEffects(RuleValidation validation)
{
RuleAnalysis analysis = new RuleAnalysis(validation, true);
if (this.codeDomStatement != null)
{
CodeDomStatementWalker.AnalyzeUsage(analysis, this.codeDomStatement);
}
return analysis.GetSymbols();
}
示例7: GetDependencies
public override ICollection<string> GetDependencies(RuleValidation validation)
{
RuleAnalysis analysis = new RuleAnalysis(validation, false);
if (this._expression != null)
{
RuleExpressionWalker.AnalyzeUsage(analysis, this._expression, true, false, null);
}
return analysis.GetSymbols();
}
示例8: ValidateInvokeAttribute
private bool ValidateInvokeAttribute(RuleValidation validation, MemberInfo member, Type contextType, Stack<MemberInfo> methodStack)
{
ValidationError error;
if (string.IsNullOrEmpty(this.methodInvoked))
{
error = new ValidationError(string.Format(CultureInfo.CurrentCulture, Messages.AttributeMethodNotFound, new object[] { member.Name, base.GetType().Name, Messages.NullValue }), 0x56b, true);
error.UserData["ErrorObject"] = this;
validation.AddError(error);
return false;
}
bool flag = true;
MemberInfo[] infoArray = contextType.GetMember(this.methodInvoked, MemberTypes.Property | MemberTypes.Method, BindingFlags.FlattenHierarchy | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance);
if ((infoArray == null) || (infoArray.Length == 0))
{
error = new ValidationError(string.Format(CultureInfo.CurrentCulture, Messages.AttributeMethodNotFound, new object[] { member.Name, base.GetType().Name, this.methodInvoked }), 0x56b, true);
error.UserData["ErrorObject"] = this;
validation.AddError(error);
return false;
}
for (int i = 0; i < infoArray.Length; i++)
{
MemberInfo item = infoArray[i];
if (!methodStack.Contains(item))
{
methodStack.Push(item);
object[] customAttributes = item.GetCustomAttributes(typeof(RuleAttribute), true);
if ((customAttributes != null) && (customAttributes.Length != 0))
{
foreach (RuleAttribute attribute in customAttributes)
{
RuleReadWriteAttribute attribute2 = attribute as RuleReadWriteAttribute;
if (attribute2 != null)
{
if (attribute2.Target == RuleAttributeTarget.Parameter)
{
error = new ValidationError(string.Format(CultureInfo.CurrentCulture, Messages.InvokeAttrRefersToParameterAttribute, new object[] { item.Name }), 0x1a5, true);
error.UserData["ErrorObject"] = this;
validation.AddError(error);
flag = false;
}
else
{
attribute2.Validate(validation, item, contextType, null);
}
}
else
{
((RuleInvokeAttribute) attribute).ValidateInvokeAttribute(validation, item, contextType, methodStack);
}
}
}
methodStack.Pop();
}
}
return flag;
}
示例9: Validate
internal override RuleExpressionInfo Validate(CodeExpression expression, RuleValidation validation, bool isWritten)
{
if (isWritten)
{
ValidationError item = new ValidationError(string.Format(CultureInfo.CurrentCulture, Messages.CannotWriteToExpression, new object[] { typeof(CodeThisReferenceExpression).ToString() }), 0x17a);
item.UserData["ErrorObject"] = expression;
validation.Errors.Add(item);
return null;
}
return new RuleExpressionInfo(validation.ThisType);
}
示例10: Validate
internal override RuleExpressionInfo Validate(CodeExpression expression, RuleValidation validation, bool isWritten)
{
if (isWritten)
{
ValidationError item = new ValidationError(string.Format(CultureInfo.CurrentCulture, Messages.CannotWriteToExpression, new object[] { typeof(CodePrimitiveExpression).ToString() }), 0x17a);
item.UserData["ErrorObject"] = expression;
validation.Errors.Add(item);
return null;
}
CodePrimitiveExpression expression2 = (CodePrimitiveExpression) expression;
return new RuleExpressionInfo((expression2.Value != null) ? expression2.Value.GetType() : typeof(NullLiteral));
}
示例11: RuleConditionDialog
public RuleConditionDialog(System.Type activityType, ITypeProvider typeProvider, CodeExpression expression)
{
this.ruleExpressionCondition = new RuleExpressionCondition();
if (activityType == null)
{
throw new ArgumentNullException("activityType");
}
this.InitializeComponent();
RuleValidation validation = new RuleValidation(activityType, typeProvider);
this.ruleParser = new Parser(validation);
this.InitializeDialog(expression);
}
示例12: Validate
internal override RuleExpressionInfo Validate(CodeExpression expression, RuleValidation validation, bool isWritten)
{
if (isWritten)
{
string message = string.Format(CultureInfo.CurrentCulture, Messages.CannotWriteToExpression, typeof(CodeThisReferenceExpression).ToString());
ValidationError error = new ValidationError(message, ErrorNumbers.Error_InvalidAssignTarget);
error.UserData[RuleUserDataKeys.ErrorObject] = expression;
validation.Errors.Add(error);
return null;
}
return new RuleExpressionInfo(validation.ThisType);
}
示例13: RuleEngine
internal RuleEngine(RuleSet ruleSet, RuleValidation validation, ActivityExecutionContext executionContext)
{
if (!ruleSet.Validate(validation))
{
throw new RuleSetValidationException(string.Format(CultureInfo.CurrentCulture, Messages.RuleSetValidationFailed, new object[] { ruleSet.name }), validation.Errors);
}
this.name = ruleSet.Name;
this.validation = validation;
Tracer tracer = null;
if (WorkflowActivityTrace.Rules.Switch.ShouldTrace(TraceEventType.Information))
{
tracer = new Tracer(ruleSet.Name, executionContext);
}
this.analyzedRules = Executor.Preprocess(ruleSet.ChainingBehavior, ruleSet.Rules, validation, tracer);
}
示例14: Validate
public override bool Validate(RuleValidation validator)
{
if (validator == null)
{
throw new ArgumentNullException("validator");
}
if (this.codeDomStatement == null)
{
ValidationError error = new ValidationError(Messages.NullStatement, 0x53d);
error.UserData["ErrorObject"] = this;
validator.AddError(error);
return false;
}
return CodeDomStatementWalker.Validate(validator, this.codeDomStatement);
}
示例15: RuleExecution
public RuleExecution(RuleValidation validation, object thisObject)
{
if (validation == null)
{
throw new ArgumentNullException("validation");
}
if (thisObject == null)
{
throw new ArgumentNullException("thisObject");
}
if (validation.ThisType != thisObject.GetType())
{
throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Messages.ValidationMismatch, new object[] { RuleDecompiler.DecompileType(validation.ThisType), RuleDecompiler.DecompileType(thisObject.GetType()) }));
}
this.validation = validation;
this.activity = thisObject as System.Workflow.ComponentModel.Activity;
this.thisObject = thisObject;
this.thisLiteralResult = new RuleLiteralResult(thisObject);
}