Exemple #1
0
        public async void RunValidation()
        {
            if (!this.Enabled)
            {
                return;
            }

            if (Interlocked.Increment(ref _validationRequests) == 1)
            {
                while (Volatile.Read(ref _validationRequests) > 0)
                {
                    Volatile.Write(ref _validationRequests, 1);
                    var results = new Queue <ValidationIndicatorEvent>();
                    State = ValidationState.Validating;
                    var superClassResult = new ValidationIndicatorEvent();
                    await Task.Run(() => OnPerformValidation(superClassResult));

                    results.Enqueue(superClassResult);
                    if (PerformValidation != null)
                    {
                        foreach (var handler in PerformValidation.GetInvocationList())
                        {
                            var handlerEventArgs = new ValidationIndicatorEvent();
                            await Task.Run(() => handler.DynamicInvoke(this, handlerEventArgs));

                            results.Enqueue(handlerEventArgs);
                        }
                    }

                    // Only show result on last validation cycle
                    if (Interlocked.Decrement(ref _validationRequests) == 0)
                    {
                        var valid = results.All(r => r.ValidationResult == true);
                        State = valid ? ValidationState.Valid : ValidationState.Error;
                        _validationMessage = results.Where(r => r.ValidationResult == valid).Select(r => r.ValidationMessage).ToParagraphCase();
                    }
                }
            }
        }
Exemple #2
0
 protected virtual void OnPerformValidation(ValidationIndicatorEvent @event)
 {
 }