public ValidationOutcomeProcessor(
            IValidationStorageService validationStorageService,
            IPackageValidationEnqueuer validationEnqueuer,
            IStatusProcessor <T> validatedPackageProcessor,
            IValidationFileService packageFileService,
            IOptionsSnapshot <ValidationConfiguration> validationConfigurationAccessor,
            IMessageService <T> messageService,
            ITelemetryService telemetryService,
            ILogger <ValidationOutcomeProcessor <T> > logger)
        {
            _validationStorageService = validationStorageService ?? throw new ArgumentNullException(nameof(validationStorageService));
            _validationEnqueuer       = validationEnqueuer ?? throw new ArgumentNullException(nameof(validationEnqueuer));
            _packageStateProcessor    = validatedPackageProcessor ?? throw new ArgumentNullException(nameof(validatedPackageProcessor));
            _packageFileService       = packageFileService ?? throw new ArgumentNullException(nameof(packageFileService));
            if (validationConfigurationAccessor == null)
            {
                throw new ArgumentNullException(nameof(validationConfigurationAccessor));
            }
            _validationConfiguration = validationConfigurationAccessor.Value
                                       ?? throw new ArgumentException($"The {nameof(validationConfigurationAccessor)}.Value property cannot be null",
                                                                      nameof(validationConfigurationAccessor));
            _messageService   = messageService ?? throw new ArgumentNullException(nameof(messageService));
            _telemetryService = telemetryService ?? throw new ArgumentNullException(nameof(telemetryService));
            _logger           = logger ?? throw new ArgumentNullException(nameof(logger));

            _validationConfigurationsByName = _validationConfiguration.Validations.ToDictionary(v => v.Name);
        }
        public ConfigurationValidator(IOptionsSnapshot <ValidationConfiguration> optionsAccessor)
        {
            if (optionsAccessor == null)
            {
                throw new ArgumentNullException(nameof(optionsAccessor));
            }

            _configuration = optionsAccessor.Value ?? throw new ArgumentException("Value property cannot be null", nameof(optionsAccessor));
        }
        private static void CheckPrerequisitesLoops(ValidationConfiguration configuration)
        {
            var validations = configuration.Validations.ToDictionary(v => v.Name);

            var globalVisitedValidations = new HashSet <string>();

            foreach (var validationName in validations.Keys)
            {
                ValidationDepthFirstSearch(validationName, new HashSet <string>(), globalVisitedValidations, validations);
            }
        }
        private static void CheckUnknownPrerequisites(ValidationConfiguration configuration)
        {
            var declaredValidations = new HashSet <string>(configuration.Validations.Select(v => v.Name));
            var prerequisites       = new HashSet <string>(configuration.Validations.Select(v => v.RequiredValidations).SelectMany(p => p));

            prerequisites.ExceptWith(declaredValidations);
            if (prerequisites.Any())
            {
                throw new ConfigurationErrorsException($"Unknown validations set as prerequisites: {string.Join(", ", prerequisites)}");
            }
        }
Esempio n. 5
0
 public ValidationSetProvider(
     IValidationStorageService validationStorageService,
     IOptionsSnapshot <ValidationConfiguration> validationConfigurationAccessor,
     ILogger <ValidationSetProvider> logger)
 {
     _validationStorageService = validationStorageService ?? throw new ArgumentNullException(nameof(validationStorageService));
     if (validationConfigurationAccessor == null)
     {
         throw new ArgumentNullException(nameof(validationConfigurationAccessor));
     }
     _validationConfiguration = validationConfigurationAccessor.Value ?? throw new ArgumentException($"The Value property cannot be null", nameof(validationConfigurationAccessor));
     _logger = logger ?? throw new ArgumentNullException(nameof(logger));
 }
        private static void CheckDuplicateValidations(ValidationConfiguration configuration)
        {
            var duplicateValidations = configuration.Validations
                                       .Select(v => v.Name)
                                       .GroupBy(n => n)
                                       .Where(g => g.Count() > 1)
                                       .ToList();

            if (duplicateValidations.Any())
            {
                throw new ConfigurationErrorsException($"Duplicate validations: {string.Join(", ", duplicateValidations.Select(d => d.Key))}");
            }
        }
        private static void CheckPropertyValues(ValidationConfiguration configuration)
        {
            foreach (var validationConfigurationItem in configuration.Validations)
            {
                if (string.IsNullOrWhiteSpace(validationConfigurationItem.Name))
                {
                    throw new ConfigurationErrorsException("Validation name cannot be empty");
                }

                if (validationConfigurationItem.FailAfter == TimeSpan.Zero)
                {
                    throw new ConfigurationErrorsException($"failAfter timeout must be set for validation {validationConfigurationItem.Name}");
                }
            }
        }
 public ValidationSetProcessor(
     IValidatorProvider validatorProvider,
     IValidationStorageService validationStorageService,
     IOptionsSnapshot <ValidationConfiguration> validationConfigurationAccessor,
     IValidationPackageFileService packageFileService,
     ITelemetryService telemetryService,
     ILogger <ValidationSetProcessor> logger)
 {
     _validatorProvider        = validatorProvider ?? throw new ArgumentNullException(nameof(validatorProvider));
     _validationStorageService = validationStorageService ?? throw new ArgumentNullException(nameof(validationStorageService));
     if (validationConfigurationAccessor == null)
     {
         throw new ArgumentNullException(nameof(validationConfigurationAccessor));
     }
     _validationConfiguration = validationConfigurationAccessor.Value ?? throw new ArgumentException($"The Value property cannot be null", nameof(validationConfigurationAccessor));
     _packageFileService      = packageFileService ?? throw new ArgumentNullException(nameof(packageFileService));
     _telemetryService        = telemetryService ?? throw new ArgumentNullException(nameof(telemetryService));
     _logger = logger ?? throw new ArgumentNullException(nameof(logger));
 }
Esempio n. 9
0
 public ValidationOutcomeProcessor(
     ICorePackageService galleryPackageService,
     ICorePackageFileService packageFileService,
     IPackageValidationEnqueuer validationEnqueuer,
     IOptionsSnapshot <ValidationConfiguration> validationConfigurationAccessor,
     ILogger <ValidationOutcomeProcessor> logger)
 {
     _galleryPackageService = galleryPackageService ?? throw new ArgumentNullException(nameof(galleryPackageService));
     _packageFileService    = packageFileService ?? throw new ArgumentNullException(nameof(packageFileService));
     _validationEnqueuer    = validationEnqueuer ?? throw new ArgumentNullException(nameof(validationEnqueuer));
     if (validationConfigurationAccessor == null)
     {
         throw new ArgumentNullException(nameof(validationConfigurationAccessor));
     }
     _validationConfiguration = validationConfigurationAccessor.Value
                                ?? throw new ArgumentException($"The {nameof(validationConfigurationAccessor)}.Value property cannot be null",
                                                               nameof(validationConfigurationAccessor));
     _logger = logger ?? throw new ArgumentNullException(nameof(logger));
 }
Esempio n. 10
0
        public BaseValidationMessageHandler(
            IOptionsSnapshot <ValidationConfiguration> validationConfigsAccessor,
            IEntityService <TEntity> entityService,
            IValidationSetProvider <TEntity> validationSetProvider,
            IValidationSetProcessor validationSetProcessor,
            IValidationOutcomeProcessor <TEntity> validationOutcomeProcessor,
            ILeaseService leaseService,
            IPackageValidationEnqueuer validationEnqueuer,
            IFeatureFlagService featureFlagService,
            ITelemetryService telemetryService,
            ILogger logger)
        {
            if (validationConfigsAccessor == null)
            {
                throw new ArgumentNullException(nameof(validationConfigsAccessor));
            }

            if (validationConfigsAccessor.Value == null)
            {
                throw new ArgumentException(
                          $"The {nameof(IOptionsSnapshot<ValidationConfiguration>)}.{nameof(IOptionsSnapshot<ValidationConfiguration>.Value)} property cannot be null",
                          nameof(validationConfigsAccessor));
            }

            if (validationConfigsAccessor.Value.MissingPackageRetryCount < 1)
            {
                throw new ArgumentOutOfRangeException(
                          nameof(validationConfigsAccessor),
                          $"{nameof(ValidationConfiguration)}.{nameof(ValidationConfiguration.MissingPackageRetryCount)} must be at least 1");
            }

            _configs                    = validationConfigsAccessor.Value;
            _entityService              = entityService ?? throw new ArgumentNullException(nameof(entityService));
            _validationSetProvider      = validationSetProvider ?? throw new ArgumentNullException(nameof(validationSetProvider));
            _validationSetProcessor     = validationSetProcessor ?? throw new ArgumentNullException(nameof(validationSetProcessor));
            _validationOutcomeProcessor = validationOutcomeProcessor ?? throw new ArgumentNullException(nameof(validationOutcomeProcessor));
            _leaseService               = leaseService ?? throw new ArgumentNullException(nameof(leaseService));
            _validationEnqueuer         = validationEnqueuer ?? throw new ArgumentNullException(nameof(leaseService));
            _featureFlagService         = featureFlagService ?? throw new ArgumentNullException(nameof(featureFlagService));
            _telemetryService           = telemetryService ?? throw new ArgumentNullException(nameof(telemetryService));
            _logger = logger ?? throw new ArgumentNullException(nameof(logger));
        }
Esempio n. 11
0
        public ValidationMessageHandler(
            IOptionsSnapshot <ValidationConfiguration> validationConfigsAccessor,
            ICorePackageService galleryPackageService,
            IValidationSetProvider validationSetProvider,
            IValidationSetProcessor validationSetProcessor,
            IValidationOutcomeProcessor validationOutcomeProcessor,
            ITelemetryService telemetryService,
            ILogger <ValidationMessageHandler> logger)
        {
            if (validationConfigsAccessor == null)
            {
                throw new ArgumentNullException(nameof(validationConfigsAccessor));
            }

            if (validationConfigsAccessor.Value == null)
            {
                throw new ArgumentException(
                          $"The {nameof(IOptionsSnapshot<ValidationConfiguration>)}.{nameof(IOptionsSnapshot<ValidationConfiguration>.Value)} property cannot be null",
                          nameof(validationConfigsAccessor));
            }

            if (validationConfigsAccessor.Value.MissingPackageRetryCount < 1)
            {
                throw new ArgumentOutOfRangeException(
                          nameof(validationConfigsAccessor),
                          $"{nameof(ValidationConfiguration)}.{nameof(ValidationConfiguration.MissingPackageRetryCount)} must be at least 1");
            }

            _configs = validationConfigsAccessor.Value;
            _galleryPackageService      = galleryPackageService ?? throw new ArgumentNullException(nameof(galleryPackageService));
            _validationSetProvider      = validationSetProvider ?? throw new ArgumentNullException(nameof(validationSetProvider));
            _validationSetProcessor     = validationSetProcessor ?? throw new ArgumentNullException(nameof(validationSetProcessor));
            _validationOutcomeProcessor = validationOutcomeProcessor ?? throw new ArgumentNullException(nameof(validationOutcomeProcessor));
            _telemetryService           = telemetryService ?? throw new ArgumentNullException(nameof(telemetryService));
            _logger = logger ?? throw new ArgumentNullException(nameof(logger));
        }