コード例 #1
0
 internal static void Validate(this ISupportValidation validating, string subject)
 {
     try
     {
         validating.Validate();
     }
     catch (Exception exception)
     {
         if (exception.IsFatal())
         {
             throw;
         }
         throw new BindingException(string.Format("{0} is not valid: {1}.", subject, exception.Message), exception);
     }
 }
コード例 #2
0
        internal static void Validate(this ISupportValidation validating, string subject)
        {
            try
            {
                validating.Validate();
            }
            catch (Exception exception) when(!exception.IsFatal())
            {
                var message = $"{subject} is not valid: {exception.Message}";

                if (!message.EndsWith("."))
                {
                    message += ".";
                }
                throw new BindingException(message, exception);
            }
        }
コード例 #3
0
        private void BeginValidation()
        {
            ThreadStart beginValidation = delegate
            {
                while (true)
                {
                    // Wait if there is no work to do
                    this.queueResetEvent.WaitOne();

                    ISupportValidation obj = null;
                    lock (this.validationQueue)
                    {
                        if (this.validationQueue.Count == 0)
                        {
                            this.Status = ValidationStatus.Ready;
                            this.queueResetEvent.Reset();
                            continue;
                        }
                        else
                        {
                            obj = this.validationQueue[0];
                            this.validationQueue.RemoveAt(0);
                        }
                    }

                    lock (this.validationResults)
                    {
                        // Try to get the validation results (they may have been removed by a different
                        // thread calling RemoveObject)
                        HashCollection <ValidationResult> oldValidationResults;
                        if (this.validationResults.TryGetValue(obj, out oldValidationResults))
                        {
                            HashCollection <ValidationResult> newValidationResults = new HashCollection <ValidationResult> ();
                            foreach (ValidationResult validationResult in obj.Validate())
                            {
                                if (!newValidationResults.Contains(validationResult))
                                {
                                    newValidationResults.Add(validationResult);
                                }
                            }

                            foreach (ValidationResult validationResult in new List <ValidationResult> (oldValidationResults))
                            {
                                if (!newValidationResults.Contains(validationResult))
                                {
                                    oldValidationResults.Remove(validationResult);
                                    ValidationResult   currentValidationResult = validationResult;
                                    SendOrPostCallback raiseRemovedEvent       = delegate
                                    {
                                        this.RaiseValidationResultRemovedEvent(currentValidationResult);
                                    };
                                    this.asyncOperation.Post(raiseRemovedEvent, null);
                                }
                            }

                            foreach (ValidationResult validationResult in newValidationResults)
                            {
                                if (!oldValidationResults.Contains(validationResult))
                                {
                                    oldValidationResults.Add(validationResult);
                                    ValidationResult   currentValidationResult = validationResult;
                                    SendOrPostCallback raiseAddedEvent         = delegate
                                    {
                                        this.RaiseValidationResultAddedEvent(currentValidationResult);
                                    };
                                    this.asyncOperation.Post(raiseAddedEvent, null);
                                }
                            }
                        }
                    }
                }
            };

            Thread thread = new Thread(beginValidation);

            thread.Name         = "Validation Manager";
            thread.IsBackground = true;
            thread.Priority     = ThreadPriority.BelowNormal;
            thread.Start();
        }