protected override void UpdateListViewItem(object ruleObject, ListViewItem listViewItem) { bool flag; RuleSet set = ruleObject as RuleSet; ValidationManager serviceProvider = new ValidationManager(base.Activity.Site); ITypeProvider service = (ITypeProvider)serviceProvider.GetService(typeof(ITypeProvider)); RuleValidation validation = new RuleValidation(base.Activity, service, false); using (WorkflowCompilationContext.CreateScope(serviceProvider)) { flag = set.Validate(validation); } listViewItem.Tag = set; listViewItem.Text = set.Name; string text = flag ? Messages.Yes : Messages.No; if (listViewItem.SubItems.Count == 1) { listViewItem.SubItems.Add(text); } else { listViewItem.SubItems[1].Text = text; } }
protected override void UpdateListViewItem(object ruleObject, ListViewItem listViewItem) { RuleSet ruleSet = ruleObject as RuleSet; ValidationManager manager = new ValidationManager(this.Activity.Site); ITypeProvider typeProvider = (ITypeProvider)manager.GetService(typeof(ITypeProvider)); RuleValidation validation = new RuleValidation(this.Activity, typeProvider, false); bool valid; using (WorkflowCompilationContext.CreateScope(manager)) { valid = ruleSet.Validate(validation); } listViewItem.Tag = ruleSet; listViewItem.Text = ruleSet.Name; string validText = valid ? Messages.Yes : Messages.No; if (listViewItem.SubItems.Count == 1) { listViewItem.SubItems.Add(validText); } else { listViewItem.SubItems[1].Text = validText; } }
internal void ValidateDefinition(Activity root, bool isNewType, ITypeProvider typeProvider) { if (this.validateOnCreate) { ValidationErrorCollection errors = new ValidationErrorCollection(); if (typeProvider == null) { typeProvider = WorkflowRuntime.CreateTypeProvider(root); } if (!isNewType) { if (!string.IsNullOrEmpty(root.GetValue(WorkflowMarkupSerializer.XClassProperty) as string)) { errors.Add(new ValidationError(ExecutionStringManager.XomlWorkflowHasClassName, 0x61c)); } Queue queue = new Queue(); queue.Enqueue(root); while (queue.Count > 0) { Activity activity = queue.Dequeue() as Activity; if (activity.GetValue(WorkflowMarkupSerializer.XCodeProperty) != null) { errors.Add(new ValidationError(ExecutionStringManager.XomlWorkflowHasCode, 0x61d)); } CompositeActivity activity2 = activity as CompositeActivity; if (activity2 != null) { foreach (Activity activity3 in activity2.EnabledActivities) { queue.Enqueue(activity3); } } } } ServiceContainer serviceProvider = new ServiceContainer(); serviceProvider.AddService(typeof(ITypeProvider), typeProvider); ValidationManager manager = new ValidationManager(serviceProvider); using (WorkflowCompilationContext.CreateScope(manager)) { foreach (Validator validator in manager.GetValidators(root.GetType())) { foreach (ValidationError error in validator.Validate(manager, root)) { if (!error.UserData.Contains(typeof(Activity))) { error.UserData[typeof(Activity)] = root; } errors.Add(error); } } } if (errors.HasErrors) { throw new WorkflowValidationFailedException(ExecutionStringManager.WorkflowValidationFailure, errors); } } }
public ValidationErrorCollection Validate() { ValidationErrorCollection errors; TypeProvider serviceInstance = CreateTypeProvider(this.originalRootActivity); ServiceContainer serviceProvider = new ServiceContainer(); serviceProvider.AddService(typeof(ITypeProvider), serviceInstance); ValidationManager manager = new ValidationManager(serviceProvider); using (WorkflowCompilationContext.CreateScope(manager)) { errors = ValidationHelpers.ValidateObject(manager, this.clonedRootActivity); } return(XomlCompilerHelper.MorphIntoFriendlyValidationErrors(errors)); }
public override ValidationErrorCollection Validate(ValidationManager manager, object obj) { ValidationErrorCollection validationErrors = base.Validate(manager, obj); RuleSetReference ruleSetReference = obj as RuleSetReference; if (ruleSetReference == null) { string message = string.Format(CultureInfo.CurrentCulture, Messages.UnexpectedArgumentType, typeof(RuleSetReference).FullName, "obj"); throw new ArgumentException(message, "obj"); } Activity activity = manager.Context[typeof(Activity)] as Activity; if (activity == null) { string message = string.Format(CultureInfo.CurrentCulture, Messages.ContextStackItemMissing, typeof(Activity).Name); throw new InvalidOperationException(message); } PropertyValidationContext validationContext = manager.Context[typeof(PropertyValidationContext)] as PropertyValidationContext; if (validationContext == null) { string message = string.Format(CultureInfo.CurrentCulture, Messages.ContextStackItemMissing, typeof(PropertyValidationContext).Name); throw new InvalidOperationException(message); } if (!string.IsNullOrEmpty(ruleSetReference.RuleSetName)) { RuleDefinitions rules = null; RuleSetCollection ruleSetCollection = null; CompositeActivity declaringActivity = Helpers.GetDeclaringActivity(activity); if (declaringActivity == null) { declaringActivity = Helpers.GetRootActivity(activity) as CompositeActivity; } if (activity.Site != null) { rules = ConditionHelper.Load_Rules_DT(activity.Site, declaringActivity); } else { rules = ConditionHelper.Load_Rules_RT(declaringActivity); } if (rules != null) { ruleSetCollection = rules.RuleSets; } if (ruleSetCollection == null || !ruleSetCollection.Contains(ruleSetReference.RuleSetName)) { string message = string.Format(CultureInfo.CurrentCulture, Messages.RuleSetNotFound, ruleSetReference.RuleSetName); ValidationError validationError = new ValidationError(message, ErrorNumbers.Error_RuleSetNotFound); validationError.PropertyName = GetFullPropertyName(manager) + "." + "RuleSetName"; validationErrors.Add(validationError); } else { RuleSet actualRuleSet = ruleSetCollection[ruleSetReference.RuleSetName]; ITypeProvider typeProvider = (ITypeProvider)manager.GetService(typeof(ITypeProvider)); IDisposable localContextScope = (WorkflowCompilationContext.Current == null ? WorkflowCompilationContext.CreateScope(manager) : null); try { RuleValidation validation = new RuleValidation(activity, typeProvider, WorkflowCompilationContext.Current.CheckTypes); actualRuleSet.Validate(validation); ValidationErrorCollection actualRuleSetErrors = validation.Errors; if (actualRuleSetErrors.Count > 0) { string expressionPropertyName = GetFullPropertyName(manager); string genericErrorMsg = string.Format(CultureInfo.CurrentCulture, Messages.InvalidRuleSetExpression, expressionPropertyName); int errorNumber = ErrorNumbers.Error_InvalidRuleSetExpression; if (activity.Site != null) { foreach (ValidationError actualError in actualRuleSetErrors) { ValidationError validationError = new ValidationError(actualError.ErrorText, errorNumber); validationError.PropertyName = expressionPropertyName + "." + "RuleSet Definition"; validationErrors.Add(validationError); } } else { foreach (ValidationError actualError in actualRuleSetErrors) { ValidationError validationError = new ValidationError(genericErrorMsg + " " + actualError.ErrorText, errorNumber); validationError.PropertyName = expressionPropertyName; validationErrors.Add(validationError); } } } // } finally { if (localContextScope != null) { localContextScope.Dispose(); } } } } else { string message = string.Format(CultureInfo.CurrentCulture, Messages.InvalidRuleSetName, "RuleSetReference"); ValidationError validationError = new ValidationError(message, ErrorNumbers.Error_InvalidRuleSetName); validationError.PropertyName = GetFullPropertyName(manager) + "." + "RuleSetName"; validationErrors.Add(validationError); } return(validationErrors); }
public override ValidationErrorCollection Validate(ValidationManager manager, object obj) { if (manager == null) { throw new ArgumentNullException("manager"); } if (manager.Context == null) { throw new InvalidOperationException(Messages.ContextStackMissing); } ValidationErrorCollection errors = base.Validate(manager, obj); RuleConditionReference reference = obj as RuleConditionReference; if (reference == null) { throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Messages.UnexpectedArgumentType, new object[] { typeof(RuleConditionReference).FullName, "obj" }), "obj"); } Activity activity = manager.Context[typeof(Activity)] as Activity; if (activity == null) { throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Messages.ContextStackItemMissing, new object[] { typeof(Activity).Name })); } if (!(manager.Context[typeof(PropertyValidationContext)] is PropertyValidationContext)) { throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Messages.ContextStackItemMissing, new object[] { typeof(PropertyValidationContext).Name })); } if (!string.IsNullOrEmpty(reference.ConditionName)) { RuleDefinitions definitions = null; RuleConditionCollection conditions = null; CompositeActivity declaringActivity = Helpers.GetDeclaringActivity(activity); if (declaringActivity == null) { declaringActivity = Helpers.GetRootActivity(activity) as CompositeActivity; } if (activity.Site != null) { definitions = ConditionHelper.Load_Rules_DT(activity.Site, declaringActivity); } else { definitions = ConditionHelper.Load_Rules_RT(declaringActivity); } if (definitions != null) { conditions = definitions.Conditions; } if ((conditions == null) || !conditions.Contains(reference.ConditionName)) { ValidationError error = new ValidationError(string.Format(CultureInfo.CurrentCulture, Messages.ConditionNotFound, new object[] { reference.ConditionName }), 0x53e) { PropertyName = base.GetFullPropertyName(manager) + ".ConditionName" }; errors.Add(error); return(errors); } RuleCondition condition = conditions[reference.ConditionName]; ITypeProvider service = (ITypeProvider)manager.GetService(typeof(ITypeProvider)); using ((WorkflowCompilationContext.Current == null) ? WorkflowCompilationContext.CreateScope(manager) : null) { RuleValidation validation = new RuleValidation(activity, service, WorkflowCompilationContext.Current.CheckTypes); condition.Validate(validation); ValidationErrorCollection errors2 = validation.Errors; if (errors2.Count > 0) { string fullPropertyName = base.GetFullPropertyName(manager); string errorText = string.Format(CultureInfo.CurrentCulture, Messages.InvalidConditionExpression, new object[] { fullPropertyName }); int errorNumber = 0x558; if (activity.Site != null) { ValidationError error2 = new ValidationError(errorText, errorNumber) { PropertyName = fullPropertyName + ".Expression" }; errors.Add(error2); } else { foreach (ValidationError error3 in errors2) { ValidationError error4 = new ValidationError(errorText + " " + error3.ErrorText, errorNumber) { PropertyName = fullPropertyName + ".Expression" }; errors.Add(error4); } } } foreach (RuleCondition condition2 in conditions) { if ((condition2.Name == reference.ConditionName) && (condition2 != condition)) { ValidationError error5 = new ValidationError(string.Format(CultureInfo.CurrentCulture, Messages.DuplicateConditions, new object[] { reference.ConditionName }), 0x53f) { PropertyName = base.GetFullPropertyName(manager) + ".ConditionName" }; errors.Add(error5); } } return(errors); } } ValidationError item = new ValidationError(string.Format(CultureInfo.CurrentCulture, Messages.InvalidConditionName, new object[] { "ConditionName" }), 0x540) { PropertyName = base.GetFullPropertyName(manager) + ".ConditionName" }; errors.Add(item); return(errors); }
internal void ValidateDefinition(Activity root, bool isNewType, ITypeProvider typeProvider) { if (!this.validateOnCreate) { return; } ValidationErrorCollection errors = new ValidationErrorCollection(); // For validation purposes, create a type provider in the type case if the // host did not push one. if (typeProvider == null) { typeProvider = WorkflowRuntime.CreateTypeProvider(root); } // Validate that we are purely XAML. if (!isNewType) { if (!string.IsNullOrEmpty(root.GetValue(WorkflowMarkupSerializer.XClassProperty) as string)) { errors.Add(new ValidationError(ExecutionStringManager.XomlWorkflowHasClassName, ErrorNumbers.Error_XomlWorkflowHasClassName)); } Queue compositeActivities = new Queue(); compositeActivities.Enqueue(root); while (compositeActivities.Count > 0) { Activity activity = compositeActivities.Dequeue() as Activity; if (activity.GetValue(WorkflowMarkupSerializer.XCodeProperty) != null) { errors.Add(new ValidationError(ExecutionStringManager.XomlWorkflowHasCode, ErrorNumbers.Error_XomlWorkflowHasCode)); } CompositeActivity compositeActivity = activity as CompositeActivity; if (compositeActivity != null) { foreach (Activity childActivity in compositeActivity.EnabledActivities) { compositeActivities.Enqueue(childActivity); } } } } ServiceContainer serviceContainer = new ServiceContainer(); serviceContainer.AddService(typeof(ITypeProvider), typeProvider); ValidationManager validationManager = new ValidationManager(serviceContainer); using (WorkflowCompilationContext.CreateScope(validationManager)) { foreach (Validator validator in validationManager.GetValidators(root.GetType())) { foreach (ValidationError error in validator.Validate(validationManager, root)) { if (!error.UserData.Contains(typeof(Activity))) { error.UserData[typeof(Activity)] = root; } errors.Add(error); } } } if (errors.HasErrors) { throw new WorkflowValidationFailedException(ExecutionStringManager.WorkflowValidationFailure, errors); } }
public override ValidationErrorCollection Validate(ValidationManager manager, object obj) { ValidationErrorCollection errors = base.Validate(manager, obj); RuleSetReference reference = obj as RuleSetReference; if (reference == null) { throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Messages.UnexpectedArgumentType, new object[] { typeof(RuleSetReference).FullName, "obj" }), "obj"); } Activity activity = manager.Context[typeof(Activity)] as Activity; if (activity == null) { throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Messages.ContextStackItemMissing, new object[] { typeof(Activity).Name })); } if (!(manager.Context[typeof(PropertyValidationContext)] is PropertyValidationContext)) { throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Messages.ContextStackItemMissing, new object[] { typeof(PropertyValidationContext).Name })); } if (!string.IsNullOrEmpty(reference.RuleSetName)) { RuleDefinitions definitions = null; RuleSetCollection ruleSets = null; CompositeActivity declaringActivity = Helpers.GetDeclaringActivity(activity); if (declaringActivity == null) { declaringActivity = Helpers.GetRootActivity(activity) as CompositeActivity; } if (activity.Site != null) { definitions = ConditionHelper.Load_Rules_DT(activity.Site, declaringActivity); } else { definitions = ConditionHelper.Load_Rules_RT(declaringActivity); } if (definitions != null) { ruleSets = definitions.RuleSets; } if ((ruleSets == null) || !ruleSets.Contains(reference.RuleSetName)) { ValidationError error = new ValidationError(string.Format(CultureInfo.CurrentCulture, Messages.RuleSetNotFound, new object[] { reference.RuleSetName }), 0x576) { PropertyName = base.GetFullPropertyName(manager) + ".RuleSetName" }; errors.Add(error); return(errors); } RuleSet set = ruleSets[reference.RuleSetName]; ITypeProvider service = (ITypeProvider)manager.GetService(typeof(ITypeProvider)); using ((WorkflowCompilationContext.Current == null) ? WorkflowCompilationContext.CreateScope(manager) : null) { RuleValidation validation = new RuleValidation(activity, service, WorkflowCompilationContext.Current.CheckTypes); set.Validate(validation); ValidationErrorCollection errors2 = validation.Errors; if (errors2.Count > 0) { string fullPropertyName = base.GetFullPropertyName(manager); string str6 = string.Format(CultureInfo.CurrentCulture, Messages.InvalidRuleSetExpression, new object[] { fullPropertyName }); int errorNumber = 0x577; if (activity.Site != null) { foreach (ValidationError error2 in errors2) { ValidationError error3 = new ValidationError(error2.ErrorText, errorNumber) { PropertyName = fullPropertyName + ".RuleSet Definition" }; errors.Add(error3); } return(errors); } foreach (ValidationError error4 in errors2) { ValidationError error5 = new ValidationError(str6 + " " + error4.ErrorText, errorNumber) { PropertyName = fullPropertyName }; errors.Add(error5); } } return(errors); } } ValidationError item = new ValidationError(string.Format(CultureInfo.CurrentCulture, Messages.InvalidRuleSetName, new object[] { "RuleSetReference" }), 0x578) { PropertyName = base.GetFullPropertyName(manager) + ".RuleSetName" }; errors.Add(item); return(errors); }