Exemple #1
0
        /// <summary>
        /// Validates the app config section by ensuring required values are present
        /// </summary>
        /// <param name="configSection">The config section to be validated</param>
        /// <param name="configValidation">A list of strings containing the requried field names</param>
        public static void Validate(ConfigSection configSection, ConfigValidation configValidation)
        {
            if (configValidation == null)
            {
                throw new MaqsConfigException("The value passed in for configValidation (required fields in a config) is null");
            }
            var configSectionPassed = GetSection(configSection);

            List <string> exceptions = new List <string>();

            foreach (var requiredField in configValidation.RequiredFields)
            {
                if (!configSectionPassed.ContainsKey(requiredField))
                {
                    exceptions.Add("Key missing " + requiredField);
                }
            }

            if (exceptions.Count > 0)
            {
                StringBuilder message = new StringBuilder();
                foreach (var mess in exceptions)
                {
                    message.AppendLine(mess);
                }
                throw new MaqsConfigException(message.ToString());
            }
        }
Exemple #2
0
        /// <summary>
        /// Validates the app config section by ensuring required values are present
        /// </summary>
        /// <param name="configSection">The config section to be validated</param>
        /// <param name="configValidation">A list of strings containing the requried field names</param>
        public static void Validate(ConfigSection configSection, ConfigValidation configValidation)
        {
            // Don't run the validation if the user has decided to skip the validation
            if (GetGeneralValue("SkipConfigValidation").Equals("Yes", StringComparison.CurrentCultureIgnoreCase))
            {
                return;
            }

            if (configValidation == null)
            {
                throw new MaqsConfigException("The value passed in for configValidation (required fields in a config) is null");
            }
            var configSectionPassed = GetSectionDictionary(configSection);

            List <string> exceptions = new List <string>();

            // Check if we have any required fields
            if (configValidation.RequiredFields != null && configValidation.RequiredFields.Count > 0)
            {
                foreach (var requiredField in configValidation.RequiredFields)
                {
                    if (!configSectionPassed.ContainsKey(requiredField))
                    {
                        exceptions.Add($"Key missing: {requiredField}");
                    }
                }
            }

            // Check if we have any one of required fields
            if (configValidation.RequiredOneOfFields != null && configValidation.RequiredOneOfFields.Count > 0 && !configValidation.RequiredOneOfFields.Any(x => configSectionPassed.ContainsKey(x)))
            {
                // We have one of fields and didn't find any of them
                exceptions.Add($"Need at least one of the following keys: {string.Join(", ", configValidation.RequiredOneOfFields)}");
            }

            if (exceptions.Count > 0)
            {
                StringBuilder message = new StringBuilder();
                foreach (var exception in exceptions)
                {
                    message.AppendLine(exception);
                }

                message.AppendLine("*This check can be skipped by setting the 'SkipConfigValidation' configuration value to 'Yes'.");
                throw new MaqsConfigException(message.ToString());
            }
        }
Exemple #3
0
        /// <summary>
        /// Validates the app config section by ensuring required values are present
        /// </summary>
        /// <param name="configSection">The config section to be validated</param>
        /// <param name="configValidation">A list of strings containing the requried field names</param>
        public static void Validate(ConfigSection configSection, ConfigValidation configValidation)
        {
            // Don't run the validation if the user has decided to skip the validation
            if (GetGeneralValue("SkipConfigValidation").Equals("Yes", StringComparison.CurrentCultureIgnoreCase))
            {
                return;
            }

            if (configValidation == null)
            {
                throw new MaqsConfigException("The value passed in for configValidation (required fields in a config) is null");
            }
            var configSectionPassed = GetSection(configSection);

            List <string> exceptions = new List <string>();

            foreach (var requiredField in configValidation.RequiredFields)
            {
                if (!configSectionPassed.ContainsKey(requiredField))
                {
                    exceptions.Add("Key missing " + requiredField);
                }
            }

            if (exceptions.Count > 0)
            {
                StringBuilder message = new StringBuilder();
                foreach (var mess in exceptions)
                {
                    message.AppendLine(mess);
                }

                message.AppendLine("*This check can be skipped by setting the 'SkipConfigValidation' configuration value to 'Yes'.");
                throw new MaqsConfigException(message.ToString());
            }
        }