コード例 #1
0
        /// <summary>
        /// Retrieves an empty set of rules used for reporting.
        /// </summary>
        /// <param name="connection">A schematic connection.</param>
        /// <param name="level">The level used for reporting.</param>
        /// <returns>An empty set of rules.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="connection"/> is <c>null</c>.</exception>
        /// <exception cref="ArgumentException"><paramref name="level"/> does not have a valid enum value.</exception>
        public IEnumerable <IRule> GetRules(ISchematicConnection connection, RuleLevel level)
        {
            if (connection == null)
            {
                throw new ArgumentNullException(nameof(connection));
            }
            if (!level.IsValid())
            {
                throw new ArgumentException($"The { nameof(RuleLevel) } provided must be a valid enum.", nameof(level));
            }

            return(Array.Empty <IRule>());
        }
コード例 #2
0
        /// <summary>
        /// Retrieves the rules used to analyze database objects.
        /// </summary>
        /// <param name="connection">A schematic connection.</param>
        /// <param name="level">The level used for reporting.</param>
        /// <returns>Rules used for analyzing database objects.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="connection"/> is <c>null</c>.</exception>
        /// <exception cref="ArgumentException"><paramref name="level"/> does not have a valid enum value.</exception>
        public IEnumerable <IRule> GetRules(ISchematicConnection connection, RuleLevel level)
        {
            if (connection == null)
            {
                throw new ArgumentNullException(nameof(connection));
            }
            if (!level.IsValid())
            {
                throw new ArgumentException($"The { nameof(RuleLevel) } provided must be a valid enum.", nameof(level));
            }

            return(RuleProviders
                   .SelectMany(rp => rp.GetRules(connection, level))
                   .ToList());
        }
コード例 #3
0
        /// <summary>
        /// Retrieves the set of rules used to analyze database objects for reporting.
        /// </summary>
        /// <param name="connection">A schematic connection.</param>
        /// <param name="level">The level used for reporting.</param>
        /// <returns>Rules used for analyzing database objects.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="connection"/> is <c>null</c>.</exception>
        /// <exception cref="ArgumentException"><paramref name="level"/> does not have a valid enum value.</exception>
        public IEnumerable <IRule> GetRules(ISchematicConnection connection, RuleLevel level)
        {
            if (connection == null)
            {
                throw new ArgumentNullException(nameof(connection));
            }
            if (!level.IsValid())
            {
                throw new ArgumentException($"The { nameof(RuleLevel) } provided must be a valid enum.", nameof(level));
            }

            var ruleProvider = new RuleProviderBuilder()
                               .AddRuleProvider <DefaultHtmlRuleProvider>()
                               .AddRuleProvider <PluginProvider>()
                               .Build();

            return(ruleProvider.GetRules(connection, level));
        }
コード例 #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Rule"/> class.
        /// </summary>
        /// <param name="id">A unique identifier for the rule.</param>
        /// <param name="title">A descriptive title.</param>
        /// <param name="level">The reporting level.</param>
        /// <exception cref="ArgumentNullException"><paramref name="id"/> or <paramref name="title"/> is <c>null</c>, empty or whitespace.</exception>
        /// <exception cref="ArgumentException"><paramref name="level"/> is an invalid value.</exception>
        protected Rule(string id, string title, RuleLevel level)
        {
            if (id.IsNullOrWhiteSpace())
            {
                throw new ArgumentNullException(nameof(id));
            }
            if (title.IsNullOrWhiteSpace())
            {
                throw new ArgumentNullException(nameof(title));
            }
            if (!level.IsValid())
            {
                throw new ArgumentException($"The { nameof(RuleLevel) } provided must be a valid enum.", nameof(level));
            }

            Id    = id;
            Level = level;
            Title = title;
        }
コード例 #5
0
        /// <summary>
        /// Dynamically retrieves the rules used to analyze database objects. Searches the currently executing directory to obtain other rules.
        /// </summary>
        /// <param name="connection">A schematic connection.</param>
        /// <param name="level">The level used for reporting.</param>
        /// <returns>Rules used for analyzing database objects.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="connection"/> is <c>null</c>.</exception>
        /// <exception cref="ArgumentException"><paramref name="level"/> is not a valid enum value.</exception>
        public IEnumerable <IRule> GetRules(ISchematicConnection connection, RuleLevel level)
        {
            if (connection == null)
            {
                throw new ArgumentNullException(nameof(connection));
            }
            if (!level.IsValid())
            {
                throw new ArgumentException($"The { nameof(RuleLevel) } provided must be a valid enum.", nameof(level));
            }

            var dialectType = connection.Dialect.GetType();

            return(LoadPluginAssemblies()
                   .SelectMany(a => LoadRequiredTypes(a, dialectType))
                   .Select(t => Array.Find(t.GetConstructors(), c => c.IsPublic && c.GetParameters().Length == 0))
                   .SelectMany(c => GetRules(c, connection, level))
                   .ToList());
        }
コード例 #6
0
        /// <summary>
        /// Retrieves the default set of rules used to analyze database objects.
        /// </summary>
        /// <param name="connection">A schematic connection.</param>
        /// <param name="level">The level used for reporting.</param>
        /// <returns>Rules used for analyzing database objects.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="connection"/> is <c>null</c>.</exception>
        /// <exception cref="ArgumentException"><paramref name="level"/> does not have a valid enum value.</exception>
        public IEnumerable <IRule> GetRules(ISchematicConnection connection, RuleLevel level)
        {
            if (connection == null)
            {
                throw new ArgumentNullException(nameof(connection));
            }
            if (!level.IsValid())
            {
                throw new ArgumentException($"The { nameof(RuleLevel) } provided must be a valid enum.", nameof(level));
            }

            return(new IRule[]
            {
                new CandidateKeyMissingRule(level),
                new ColumnWithNullDefaultValueRule(level),
                new ColumnWithNumericSuffix(level),
                new DisabledObjectsRule(level),
                new ForeignKeyColumnTypeMismatchRule(level),
                new ForeignKeyIndexRule(level),
                new ForeignKeyIsPrimaryKeyRule(level),
                new ForeignKeyMissingRule(level),
                new ForeignKeyRelationshipCycleRule(level),
                new InvalidViewDefinitionRule(connection, level),
                new NoIndexesPresentOnTableRule(level),
                new NoNonNullableColumnsPresentRule(level),
                new NoSurrogatePrimaryKeyRule(level),
                new NoValueForNullableColumnRule(connection, level),
                new OnlyOneColumnPresentRule(level),
                new OrphanedTableRule(level),
                new PrimaryKeyColumnNotFirstColumnRule(level),
                new PrimaryKeyNotIntegerRule(level),
                new RedundantIndexesRule(level),
                new ReservedKeywordNameRule(connection.Dialect, level),
                new TooManyColumnsRule(level),
                new UniqueIndexWithNullableColumnsRule(level),
                new WhitespaceNameRule(level)
            });
        }
コード例 #7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RuleMessage"/> class.
        /// </summary>
        /// <param name="ruleId">The rule identifier.</param>
        /// <param name="title">The rule title.</param>
        /// <param name="level">The warning/reporting level.</param>
        /// <param name="message">A descriptive message that informs about the potential issue that was discovered.</param>
        /// <exception cref="ArgumentNullException"><paramref name="ruleId"/> or <paramref name="title"/> or <paramref name="message"/> are <c>null</c>, empty or whitespace.</exception>
        /// <exception cref="ArgumentException">The given rule reporting level was not a valid value.</exception>
        public RuleMessage(string ruleId, string title, RuleLevel level, string message)
        {
            if (ruleId.IsNullOrWhiteSpace())
            {
                throw new ArgumentNullException(nameof(ruleId));
            }
            if (title.IsNullOrWhiteSpace())
            {
                throw new ArgumentNullException(nameof(title));
            }
            if (!level.IsValid())
            {
                throw new ArgumentException($"The { nameof(RuleLevel) } provided must be a valid enum.", nameof(level));
            }
            if (message.IsNullOrWhiteSpace())
            {
                throw new ArgumentNullException(nameof(message));
            }

            RuleId  = ruleId;
            Title   = title;
            Level   = level;
            Message = message;
        }