using System.Collections.Generic; using System.Linq; using FluentValidation.Results; using NzbDrone.Common.Extensions; namespace NzbDrone.Core.Validation { public class NzbDroneValidationResult : ValidationResult { public NzbDroneValidationResult() { Failures = new List(); Errors = new List(); Warnings = new List(); } public NzbDroneValidationResult(ValidationResult validationResult) : this(validationResult.Errors) { } public NzbDroneValidationResult(IEnumerable failures) { var errors = new List(); var warnings = new List(); foreach (var failureBase in failures) { var failure = failureBase as NzbDroneValidationFailure; if (failure == null) { failure = new NzbDroneValidationFailure(failureBase); } if (failure.IsWarning) { warnings.Add(failure); } else { errors.Add(failure); } } Failures = errors.Concat(warnings).ToList(); Errors = errors; errors.ForEach(base.Errors.Add); Warnings = warnings; } public IList Failures { get; private set; } public new IList Errors { get; private set; } public IList Warnings { get; private set; } public virtual bool HasWarnings { get { return Warnings.Any(); } } public override bool IsValid { get { return Errors.Empty(); } } } }