コード例 #1
0
        /// <summary>
        /// Analysis is quite simple - the table's name is examined and if it ends with "View" then a problem
        /// is created
        /// </summary>
        /// <param name="ruleExecutionContext"></param>
        /// <returns></returns>
        public override IList <SqlRuleProblem> Analyze(SqlRuleExecutionContext ruleExecutionContext)
        {
            List <SqlRuleProblem> problems = new List <SqlRuleProblem>();
            TSqlObject            table    = ruleExecutionContext.ModelElement;

            if (table != null)
            {
                if (NameEndsInView(table.Name))
                {
                    // DisplayServices is a useful helper service for formatting names
                    DisplayServices displayServices = ruleExecutionContext.SchemaModel.DisplayServices;
                    string          formattedName   = displayServices.GetElementName(table, ElementNameStyle.FullyQualifiedName);

                    string problemDescription = string.Format(NameEndingInViewMsgFormat,
                                                              formattedName);
                    SqlRuleProblem problem = new SqlRuleProblem(problemDescription, table);
                    problems.Add(problem);
                }
            }

            return(problems);
        }
コード例 #2
0
        private string DumpProblemsToString(IEnumerable <SqlRuleProblem> problems)
        {
            DisplayServices       displayServices = this.ModelForAnalysis.DisplayServices;
            List <SqlRuleProblem> problemList     = new List <SqlRuleProblem>(problems);

            SortProblemsByFileName(problemList);

            StringBuilder sb = new StringBuilder();

            foreach (SqlRuleProblem problem in problemList)
            {
                this.AppendOneProblemItem(sb, "Problem description", problem.Description);
                this.AppendOneProblemItem(sb, "FullID", problem.RuleId);
                this.AppendOneProblemItem(sb, "Severity", problem.Severity.ToString());
                this.AppendOneProblemItem(sb, "Model element", displayServices.GetElementName(problem.ModelElement, ElementNameStyle.FullyQualifiedName));

                string fileName = null;
                if (problem.SourceName != null)
                {
                    FileInfo fileInfo = new FileInfo(problem.SourceName);
                    fileName = fileInfo.Name;
                }
                else
                {
                    fileName = string.Empty;
                }

                this.AppendOneProblemItem(sb, "Script file", fileName);
                this.AppendOneProblemItem(sb, "Start line", problem.StartLine.ToString());
                this.AppendOneProblemItem(sb, "Start column", problem.StartColumn.ToString());

                sb.Append("========end of problem========\r\n\r\n");
            }

            return(sb.ToString());
        }