コード例 #1
0
        public static ValidationResults Validate(Activity toValidate, ValidationSettings settings)
        {
            if (toValidate == null)
            {
                throw FxTrace.Exception.ArgumentNull(nameof(toValidate));
            }

            if (settings == null)
            {
                throw FxTrace.Exception.ArgumentNull(nameof(settings));
            }

            if (toValidate.HasBeenAssociatedWithAnInstance)
            {
                throw FxTrace.Exception.AsError(new InvalidOperationException(SR.RootActivityAlreadyAssociatedWithInstance(toValidate.DisplayName)));
            }

            if (settings.PrepareForRuntime && (settings.SingleLevel || settings.SkipValidatingRootConfiguration || settings.OnlyUseAdditionalConstraints))
            {
                throw FxTrace.Exception.Argument(nameof(settings), SR.InvalidPrepareForRuntimeValidationSettings);
            }

            InternalActivityValidationServices validator = new InternalActivityValidationServices(settings, toValidate);

            return(validator.InternalValidate());
        }
 public static ProcessActivityTreeOptions GetValidationOptions(ValidationSettings settings)
 {
     if (settings.SingleLevel)
     {
         return SingleLevelValidationOptions;
     }
     return ValidationOptions;
 }
コード例 #3
0
 public ValidationResults Validate(ValidationSettings settings)
 {
     if (this.workflowService != null)
     {
         return this.workflowService.Validate(settings);
     }
     else
     {
         return ActivityValidationServices.Validate(this.activity, settings);
     }
 }
        public static ValidationResults Validate(Activity toValidate, ValidationSettings settings)
        {
            if (toValidate == null)
            {
                throw FxTrace.Exception.ArgumentNull("toValidate");
            }
            if (settings == null)
            {
                throw FxTrace.Exception.ArgumentNull("settings");
            }
            if (toValidate.HasBeenAssociatedWithAnInstance)
            {
                throw FxTrace.Exception.AsError(new InvalidOperationException(System.Activities.SR.RootActivityAlreadyAssociatedWithInstance(toValidate.DisplayName)));
            }
            InternalActivityValidationServices services = new InternalActivityValidationServices(settings, toValidate);

            return(services.InternalValidate());
        }
コード例 #5
0
ファイル: Program.cs プロジェクト: tian1ll1/WPF_Examples
        static void Main()
        {
            Sequence wf = new Sequence
            {
                Activities =
                {
                    new If
                    {
                        Condition = true
                    },
                    new Pick
                    {
                        Branches =
                        {
                            new PickBranch
                            {
                                Trigger = new WriteLine
                                {
                                    Text = "When this completes..."
                                },
                                Action = new WriteLine
                                {
                                    Text = "... do this."
                                }
                            }
                        }
                    }
                }
            };

            // ValidationSettings enables the host to customize the behavior of ActivityValidationServices.Validate.
            ValidationSettings validationSettings = new ValidationSettings
            {
                // AdditionalConstraints enables the host to add specific validation logic (a constraint) to a specify type of activity in the Workflow.
                AdditionalConstraints =
                    {
                        {typeof(If), new List<Constraint> {ConstraintsLibrary.ConstraintError_IfShouldHaveThenOrElse()}},
                        {typeof(Pick), new List<Constraint> {ConstraintsLibrary.ConstraintWarning_PickHasOneBranch()}}
                    }
            };

            ValidationResults results = ActivityValidationServices.Validate(wf, validationSettings);
            PrintResults(results);
        }
コード例 #6
0
ファイル: Program.cs プロジェクト: tian1ll1/WPF_Examples
        static void Main(string[] args)
        {
            //Create a WF with configuration errors
            Sequence wf = new Sequence()
            {
                Activities =
                {
                    new Sequence
                    {
                        DisplayName = "Sequence1"
                    },
                    new If
                    {
                        DisplayName = "If",
                        Condition = new InArgument<bool>(true)
                    },
                    new Switch<bool>
                    {
                        DisplayName = "Switch1",
                        Expression = new InArgument<bool>(true),
                        Default = new WriteLine()
                    },
                    new ForEach<int>
                    {
                        DisplayName = "ForEach2",
                        Values = new InArgument<IEnumerable<int>>((env) => new int[] { 1, 2, 3 })
                    },
                    new Parallel
                    {
                        DisplayName = "Parallel1"
                    },
                    new ParallelForEach<int>
                    {
                        DisplayName = "ParallelForEach1",
                        Values = new InArgument<IEnumerable<int>>((env) => new int[] { 1, 2, 3 })
                    },
                    new Pick
                    {
                        DisplayName = "Pick1",
                        Branches =
                        {
                            new PickBranch
                            {
                                Action = new WriteLine()
                            }
                        }
                    },
                    new Pick
                    {
                        DisplayName = "Pick2"
                    },
                    new WriteLine
                    {
                        DisplayName = "Wr"
                    }
                }
            };

            //Create an instance of Validation Settings.
            ValidationSettings settings = new ValidationSettings()
            {
                //Create value pairs constraints and activity types. We are providing a list of constraints that you want to apply on a specify activity type
                AdditionalConstraints =
                {
                    {typeof(Activity), new List<Constraint> {ConstraintLibrary.ActivityDisplayNameIsNotSetWarning()}},
                    {typeof(ForEach<int>), new List<Constraint> {ConstraintLibrary.ForEachPropertyMustBeSetError<int>()}},
                    {typeof(WriteLine), new List<Constraint> {ConstraintLibrary.WriteLineHasNoTextWarning()}},
                    {typeof(Pick), new List<Constraint> {ConstraintLibrary.PickHasNoBranchesWarning(), ConstraintLibrary.PickHasOneBranchWarning()}},
                    {typeof(Parallel), new List<Constraint> {ConstraintLibrary.ParallelHasNoBranchesWarning()}},
                    {typeof(Switch<bool>), new List<Constraint> {ConstraintLibrary.SwitchHasDefaultButNoCasesWarning<bool>(), ConstraintLibrary.SwitchHasNoCasesOrDefaultWarning<bool>()}},
                    {typeof(If), new List<Constraint> {ConstraintLibrary.IfShouldHaveThenOrElseError()}},
                    {typeof(Sequence), new List<Constraint> {ConstraintLibrary.SequenceIsEmptyWarning()}}
                }
            };

            //Call the Validate method with the workflow you want to validate, and the settings you want to use.
            ValidationResults results = ActivityValidationServices.Validate(wf, settings);
            //Print the validation errors and warning that were generated my ActivityValidationServices.Validate.
            PrintResults(results);
        }
コード例 #7
0
 internal InternalActivityValidationServices(ValidationSettings settings, Activity toValidate)
 {
     this.settings       = settings;
     this.rootToValidate = toValidate;
     this.environment    = settings.Environment;
 }
コード例 #8
0
ファイル: WorkflowValidation.cs プロジェクト: 40a/PowerShell
        private void ValidateWorkflowInternal(Activity workflow, string runtimeAssembly, PSWorkflowValidationResults validationResults)
        {
            Tracer.WriteMessage(Facility + "Validating a workflow.");
            _structuredTracer.WorkflowValidationStarted(Guid.Empty);

            ValidationSettings validationSettings = new ValidationSettings
            {
                AdditionalConstraints =
                    {                             
                        { typeof(Activity), new List<Constraint> { ValidateActivitiesConstraint(runtimeAssembly, validationResults)} }
                    }
            };

            try
            {
                validationResults.Results = ActivityValidationServices.Validate(workflow, validationSettings);
            }
            catch (Exception e)
            {
                Tracer.TraceException(e);
                ValidationException exception = new ValidationException(Resources.ErrorWhileValidatingWorkflow, e);
                throw exception;
            }

            _structuredTracer.WorkflowValidationFinished(Guid.Empty);

        }
コード例 #9
0
 public static ProcessActivityTreeOptions GetValidationOptions(ValidationSettings settings)
 {
     ProcessActivityTreeOptions result = null;
     if (settings.SkipValidatingRootConfiguration && settings.SingleLevel)
     {
         result = ProcessActivityTreeOptions.SingleLevelSkipRootConfigurationValidationOptions;
     }
     else if (settings.SkipValidatingRootConfiguration)
     {
         result = ProcessActivityTreeOptions.SkipRootConfigurationValidationOptions;
     }
     else if (settings.SingleLevel)
     {
         result = ProcessActivityTreeOptions.SingleLevelValidationOptions;
     }
     else if (settings.PrepareForRuntime)
     {
         Fx.Assert(!settings.SkipValidatingRootConfiguration && !settings.SingleLevel && !settings.OnlyUseAdditionalConstraints, "PrepareForRuntime cannot be set at the same time any of the three is set.");
         result = ProcessActivityTreeOptions.ValidationAndPrepareForRuntimeOptions;
     }
     else
     {
         result = ProcessActivityTreeOptions.ValidationOptions;
     }
     if (settings.CancellationToken == CancellationToken.None)
     {
         return result;
     }
     else
     {
         return AttachCancellationToken(result, settings.CancellationToken);
     }
 }
 internal InternalActivityValidationServices(ValidationSettings settings, Activity toValidate)
 {
     this.settings = settings;
     this.rootToValidate = toValidate;
 }
 public static ValidationResults Validate(Activity toValidate, ValidationSettings settings)
 {
     if (toValidate == null)
     {
         throw FxTrace.Exception.ArgumentNull("toValidate");
     }
     if (settings == null)
     {
         throw FxTrace.Exception.ArgumentNull("settings");
     }
     if (toValidate.HasBeenAssociatedWithAnInstance)
     {
         throw FxTrace.Exception.AsError(new InvalidOperationException(System.Activities.SR.RootActivityAlreadyAssociatedWithInstance(toValidate.DisplayName)));
     }
     InternalActivityValidationServices services = new InternalActivityValidationServices(settings, toValidate);
     return services.InternalValidate();
 }
コード例 #12
0
 internal InternalActivityValidationServices(ValidationSettings settings, Activity toValidate)
 {
     this.settings       = settings;
     this.rootToValidate = toValidate;
 }
コード例 #13
0
        internal ValidationService(EditingContext context, TaskDispatcher validationTaskDispatcher)
        {
            Fx.Assert(validationTaskDispatcher != null, "validationTaskDispatcher cannot be null.");
            this.validationTaskDispatcher = validationTaskDispatcher;
            this.context = context;
            this.settings = new ValidationSettings { SkipValidatingRootConfiguration = true };
            this.context.Services.Subscribe<ModelService>(new SubscribeServiceCallback<ModelService>(OnModelServiceAvailable));
            this.context.Services.Subscribe<ModelSearchService>(new SubscribeServiceCallback<ModelSearchService>(OnModelSearchServiceAvailable));
            this.context.Services.Subscribe<ObjectReferenceService>(new SubscribeServiceCallback<ObjectReferenceService>(OnObjectReferenceServiceAvailable));
            this.context.Services.Subscribe<ModelTreeManager>(new SubscribeServiceCallback<ModelTreeManager>(OnModelTreeManagerAvailable));
            this.context.Services.Subscribe<IValidationErrorService>(new SubscribeServiceCallback<IValidationErrorService>(OnErrorServiceAvailable));
            this.context.Services.Subscribe<AttachedPropertiesService>(new SubscribeServiceCallback<AttachedPropertiesService>(OnAttachedPropertiesServiceAvailable));
            AssemblyName currentAssemblyName = Assembly.GetExecutingAssembly().GetName();
            StringBuilder validationKeyPath = new StringBuilder(90);
            validationKeyPath.Append(ValidationRegKeyInitialPath);
            validationKeyPath.AppendFormat("{0}{1}{2}", "v", currentAssemblyName.Version.ToString(), "\\");
            validationKeyPath.Append(currentAssemblyName.Name);

            RegistryKey validationRegistryKey = Registry.CurrentUser.OpenSubKey(validationKeyPath.ToString());
            if (validationRegistryKey != null)
            {
                object value = validationRegistryKey.GetValue(ValidationRegKeyName);

                this.isValidationDisabled = (value != null && string.Equals("1", value.ToString()));

                validationRegistryKey.Close();
            }
        }
コード例 #14
0
ファイル: PSWorkflowValidator.cs プロジェクト: nickchal/pash
		private void ValidateWorkflowInternal(Activity workflow, string runtimeAssembly, PSWorkflowValidationResults validationResults)
		{
			PSWorkflowValidator.Tracer.WriteMessage(string.Concat(PSWorkflowValidator.Facility, "Validating a workflow."));
			PSWorkflowValidator._structuredTracer.WorkflowValidationStarted(Guid.Empty);
			ValidationSettings validationSetting = new ValidationSettings();
			List<Constraint> constraints = new List<Constraint>();
			constraints.Add(this.ValidateActivitiesConstraint(runtimeAssembly, validationResults));
			validationSetting.AdditionalConstraints.Add(typeof(Activity), constraints);
			ValidationSettings validationSetting1 = validationSetting;
			try
			{
				validationResults.Results = ActivityValidationServices.Validate(workflow, validationSetting1);
			}
			catch (Exception exception1)
			{
				Exception exception = exception1;
				PSWorkflowValidator.Tracer.TraceException(exception);
				new ValidationException(Resources.ErrorWhileValidatingWorkflow, exception);
				throw exception;
			}
			PSWorkflowValidator._structuredTracer.WorkflowValidationFinished(Guid.Empty);
		}