コード例 #1
0
        private static void GetParameters(Type analyzerType, RuleDetail ruleDetail)
        {
            var typeToGetParametersFrom = analyzerType;
            var templateInterface       = analyzerType.GetInterfaces()
                                          .FirstOrDefault(type => type.IsGenericType &&
                                                          type.GetGenericTypeDefinition() == typeof(IRuleTemplate <>));

            if (templateInterface != null)
            {
                typeToGetParametersFrom = templateInterface.GetGenericArguments().First();
            }

            var parameters = typeToGetParametersFrom.GetProperties()
                             .Select(p => p.GetCustomAttributes <RuleParameterAttribute>().SingleOrDefault());

            foreach (var ruleParameter in parameters
                     .Where(attribute => attribute != null))
            {
                ruleDetail.Parameters.Add(
                    new RuleParameter
                {
                    DefaultValue = ruleParameter.DefaultValue,
                    Description  = ruleParameter.Description,
                    Key          = ruleParameter.Key,
                    Type         = ruleParameter.Type.ToSonarQubeString()
                });
            }
        }
コード例 #2
0
 public ActionResult ZhangADD(RuleDetailS te)
 {
     try
     {
         if (ef.RuleDetails.Any(x => x.BookID == ef.TextBooks.FirstOrDefault(a => a.BookName == te.BookIDName && a.Shan == false).BookID&& x.QuestionCount == te.QuestionCount && x.QuestionLevel == te.QuestionLevel && x.Shan == false && x.RuleID == ef.PaperRules.FirstOrDefault(b => b.RuleName == te.RuleIDName && b.Shan == false).RuleID))
         {
             return(Content("已经存在了,请重新添加"));
         }
         else
         {
             RuleDetail ta = new RuleDetail()
             {
                 BookID        = ef.TextBooks.FirstOrDefault(x => x.BookName == te.BookIDName).BookID,
                 RuleID        = ef.PaperRules.FirstOrDefault(x => x.RuleName == te.RuleIDName).RuleID,
                 QuestionCount = te.QuestionCount,
                 QuestionLevel = te.QuestionLevel
             };
             ef.Entry(ta).State = EntityState.Added;
             if (ef.SaveChanges() > 0)
             {
                 return(Content("添加成功"));
             }
             else
             {
                 return(Content("添加失败"));
             }
         }
     }
     catch (Exception ex)
     {
         return(Content(ex.ToString()));
     }
 }
コード例 #3
0
        public RuleDetail GetActiveDisableFor(bool isFutureBooking, DateTime pickupDate, Func <string> pickupZoneGetterFunc, Func <string> dropOffZoneGetterFunc, string market, Position pickupPoint)
        {
            var rules = new RuleDetail[0];

            if (market.HasValue() && _serverSettings.ServerData.ValidateAdminRulesForExternalMarket)
            {
                // External market with admin defined rules validation
                rules = _ruleDao.GetActiveDisableRule(isFutureBooking)
                        .Where(rule => rule.Market == market)
                        .ToArray();
            }
            else if (!market.HasValue())
            {
                // Home market rules validation
                rules = _ruleDao.GetActiveDisableRule(isFutureBooking)
                        .Where(rule => !rule.Market.HasValue())
                        .ToArray();
            }

            if (rules.Any())
            {
                rules = FilterRulesByZone(rules, pickupZoneGetterFunc(), dropOffZoneGetterFunc(), pickupPoint);
            }

            return(GetMatching(rules, pickupDate));
        }
コード例 #4
0
        public void ConvertCsharpLinks()
        {
            // Arrange
            var ruleDetail = new RuleDetail
            {
                Description = @"<p>Some description here...</p>
<h2>Noncompliant Code Example</h2>
<pre>
if (str == null &amp;&amp; str.length() == 0) {
  System.out.println(""String is empty"");
}
</pre>
<p>Some text here; use Rule {rule:csharpsquid:S2259} instead.</p>
<p>Some more text here; use rule {rule:csharpsquid:S2259} instead.</p>
<p>Other text here; use {rule:csharpsquid:S2259} instead.</p>",
            };

            // Act
            var result = RuleImplementationMeta.Convert(ruleDetail, "arbitrary-version", AnalyzerLanguage.CSharp);

            var expected = @"<p>Some description here...</p>
<h2>Noncompliant Code Example</h2>
<pre>
if (str == null &amp;&amp; str.length() == 0) {
  System.out.println(""String is empty"");
}
</pre>
<p>Some text here; use <a class=""rule-link"" href=""#version=arbitrary-version&ruleId=S2259"">Rule S2259</a> instead.</p>
<p>Some more text here; use <a class=""rule-link"" href=""#version=arbitrary-version&ruleId=S2259"">Rule S2259</a> instead.</p>
<p>Other text here; use <a class=""rule-link"" href=""#version=arbitrary-version&ruleId=S2259"">Rule S2259</a> instead.</p>";

            // Assert
            result.Description.Should().Be(expected);
        }
コード例 #5
0
        private static RuleDetail GetRuleDetail(RuleAttribute rule, Type analyzerType, AnalyzerLanguage language)
        {
            var resources = new ResourceManager("SonarAnalyzer.RspecStrings", analyzerType.Assembly);

            var ruleDetail = new RuleDetail
            {
                Key                  = rule.Key,
                Title                = resources.GetString($"{rule.Key}_Title"),
                Severity             = resources.GetString($"{rule.Key}_Severity"),
                IsActivatedByDefault = bool.Parse(resources.GetString($"{rule.Key}_IsActivatedByDefault")),
                Description          = GetResourceHtml(rule, language)
            };

            ruleDetail.Tags.AddRange(resources.GetString($"{rule.Key}_Tags").Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries));

            var remediation     = resources.GetString($"{rule.Key}_Remediation");
            var remediationCost = resources.GetString($"{rule.Key}_RemediationCost");

            ruleDetail.SqaleDescriptor = GetSqaleDescriptor(remediation, remediationCost);

            GetParameters(analyzerType, ruleDetail);
            GetCodeFixNames(analyzerType, ruleDetail);

            return(ruleDetail);
        }
コード例 #6
0
        public string Updashow(int grade, PaperRuleS te)
        {
            int             suan          = ef.Questions.Where(x => x.BookID == ef.TextBooks.FirstOrDefault(a => a.GradeID == grade && x.Shan == false).BookID&& x.Shan == false).ToList().Count;
            List <TextBook> TextBookCount = ef.TextBooks.Where(x => x.GradeID == grade && x.Shan == false).ToList();
            int             Ping          = 50 % TextBookCount.Count;
            bool            flage         = true;
            int             sum           = 0;

            for (int i = 0; i < TextBookCount.Count; i++)
            {
                int BookIDa = TextBookCount[i].BookID;
                int jie     = ef.Questions.Where(x => x.BookID == BookIDa && x.Shan == false).ToList().Count;
                sum += jie;
                if (sum < 50)
                {
                    flage = false;
                }
            }
            if (flage)
            {
                Teacher   tea = Session["User"] as Teacher;
                PaperRule ta  = new PaperRule()
                {
                    GradeID    = grade,
                    CreateTime = DateTime.Now,
                    RuleName   = te.RuleName,
                    CreatorID  = tea.TeacherID,
                    Shan       = false,
                    RuleID     = te.RuleID
                };
                ef.Entry(ta).State = EntityState.Modified;
                ef.SaveChanges();
                List <RuleDetail> List = ef.RuleDetails.Where(x => x.RuleID == ta.RuleID).ToList();
                for (int i = 0; i < List.Count; i++)
                {
                    ef.RuleDetails.Remove(List[i]);
                    ef.SaveChanges();
                }
                Grade           gr  = ef.Grades.FirstOrDefault(x => x.GradeID == ta.GradeID);
                List <TextBook> li  = ef.TextBooks.Where(x => x.GradeID == gr.GradeID).ToList();
                int             chu = 50 % li.Count;
                for (int i = 0; i < li.Count; i++)
                {
                    RuleDetail Ru = new RuleDetail();
                    Ru.RuleID          = ta.RuleID;
                    Ru.BookID          = li[i].BookID;
                    Ru.QuestionCount   = i == 0 ? ((50 - chu) / li.Count) + chu : (50 - chu) / li.Count;
                    Ru.QuestionLevel   = 1;
                    Ru.Shan            = false;
                    ef.Entry(Ru).State = EntityState.Added;
                    ef.SaveChanges();
                }
                return("增加成功");
            }
            else
            {
                return("题数量不够,不能进行抽题");
            }
        }
コード例 #7
0
 private static void GetTags(Type analyzerType, RuleDetail ruleDetail)
 {
     var tags = analyzerType.GetCustomAttributes<TagsAttribute>().FirstOrDefault();
     if (tags != null)
     {
         ruleDetail.Tags.AddRange(tags.Tags);
     }
 }
コード例 #8
0
 private bool IsDayMatch(RuleDetail rule, DateTime date)
 {
     if (rule.Type == (decimal)RuleType.Date)
     {
         return(date >= rule.ActiveFrom && date < rule.ActiveTo);
     }
     return(false);
 }
コード例 #9
0
        private static void GetTags(Type analyzerType, RuleDetail ruleDetail)
        {
            var tags = analyzerType.GetCustomAttributes <TagsAttribute>().FirstOrDefault();

            if (tags != null)
            {
                ruleDetail.Tags.AddRange(tags.Tags);
            }
        }
コード例 #10
0
ファイル: RuleDescription.cs プロジェクト: andwi/sonarlint-vs
 public static RuleDescription Convert(RuleDetail detail, string productVersion)
 {
     return(new RuleDescription
     {
         Key = detail.Key,
         Title = detail.Title,
         Description = AddLinksBetweenRulesToDescription(detail.Description, productVersion),
         Tags = detail.Tags
     });
 }
コード例 #11
0
        private static void GetCodeFixNames(Type analyzerType, RuleDetail ruleDetail)
        {
            var codeFixProvider = GetCodeFixProviderType(analyzerType);

            if (codeFixProvider == null)
            {
                return;
            }

            var titles = GetCodeFixTitles(codeFixProvider);

            ruleDetail.CodeFixTitles.AddRange(titles);
        }
コード例 #12
0
 public static RuleImplementationMeta Convert(RuleDetail detail, string productVersion, AnalyzerLanguage language)
 {
     return new RuleImplementationMeta
     {
         Id = detail.Key,
         Language = language.GetFriendlyName(),
         Severity = detail.Severity,
         Title = detail.Title,
         Description = GetParameterDescription(detail.Parameters) +
             AddLinksBetweenRulesToDescription(detail.Description, productVersion) +
             GetCodeFixDescription(detail),
         Tags = detail.Tags
     };
 }
コード例 #13
0
 public static RuleImplementationMeta Convert(RuleDetail detail, string productVersion, AnalyzerLanguage language)
 {
     return(new RuleImplementationMeta
     {
         Id = detail.Key,
         Language = language.GetFriendlyName(),
         Severity = detail.Severity,
         Title = detail.Title,
         Description = GetParameterDescription(detail.Parameters) +
                       AddLinksBetweenRulesToDescription(detail.Description, productVersion) +
                       GetCodeFixDescription(detail),
         Tags = detail.Tags
     });
 }
コード例 #14
0
        private static string GetCodeFixDescription(RuleDetail detail)
        {
            if (!detail.CodeFixTitles.Any())
            {
                return(string.Empty);
            }

            const string listItemPattern = "<li>{0}</li>";
            const string codeFixPattern  = "<h2>Code Fixes</h2><ul>{0}</ul>";

            return
                (string.Format(codeFixPattern,
                               string.Join("", detail.CodeFixTitles.Select(title => string.Format(listItemPattern, title)))));
        }
コード例 #15
0
        private static void GetParameters(Type analyzerType, RuleDetail ruleDetail)
        {
            var parameters = analyzerType.GetProperties()
                             .Select(p => p.GetCustomAttributes <RuleParameterAttribute>().SingleOrDefault());

            foreach (var ruleParameter in parameters
                     .Where(attribute => attribute != null))
            {
                ruleDetail.Parameters.Add(
                    new RuleParameter
                {
                    DefaultValue = ruleParameter.DefaultValue,
                    Description  = ruleParameter.Description,
                    Key          = ruleParameter.Key,
                    Type         = ruleParameter.Type.ToSonarQubeString()
                });
            }
        }
コード例 #16
0
        private static RuleDetail GetRuleDetail(Type analyzerType, AnalyzerLanguage language)
        {
            var rule = analyzerType.GetCustomAttributes <RuleAttribute>().Single();

            var ruleDetail = new RuleDetail
            {
                Key                  = rule.Key,
                Title                = rule.Title,
                Severity             = rule.Severity.ToString(),
                IsActivatedByDefault = rule.IsActivatedByDefault,
                Description          = GetResourceHtml(rule, language)
            };

            GetParameters(analyzerType, ruleDetail);
            GetTags(analyzerType, ruleDetail);
            GetSqale(analyzerType, ruleDetail);
            GetCodeFixNames(analyzerType, ruleDetail);

            return(ruleDetail);
        }
コード例 #17
0
        private static RuleDetail GetRuleDetail(Type analyzerType)
        {
            var rule = analyzerType.GetCustomAttributes <RuleAttribute>().Single();

            var ruleDetail = new RuleDetail
            {
                Key                  = rule.Key,
                Title                = rule.Title,
                Severity             = rule.Severity.ToString().ToUpper(CultureInfo.InvariantCulture),
                IsActivatedByDefault = rule.IsActivatedByDefault,
                Description          = GetResourceHtml(analyzerType, rule),
                IsTemplate           = RuleFinder.IsRuleTemplate(analyzerType)
            };

            GetParameters(analyzerType, ruleDetail);
            GetTags(analyzerType, ruleDetail);
            GetSqale(analyzerType, ruleDetail);

            return(ruleDetail);
        }
コード例 #18
0
        private static RuleDetail GetRuleDetail(Type analyzerType)
        {
            var rule = analyzerType.GetCustomAttributes <RuleAttribute>().Single();

            var ruleDetail = new RuleDetail
            {
                Key                  = rule.Key,
                Title                = rule.Title,
                Severity             = rule.Severity.ToString(),
                IdeSeverity          = (int)rule.Severity.ToDiagnosticSeverity(),
                IsActivatedByDefault = rule.IsActivatedByDefault,
                Description          = "Full HTML description"
            };

            GetParameters(analyzerType, ruleDetail);
            GetTags(analyzerType, ruleDetail);
            GetSqale(analyzerType, ruleDetail);

            return(ruleDetail);
        }
コード例 #19
0
        private static RuleDetail GetRuleDetail(Type analyzerType, AnalyzerLanguage language)
        {
            var rule = analyzerType.GetCustomAttributes<RuleAttribute>().Single();

            var ruleDetail = new RuleDetail
            {
                Key = rule.Key,
                Title = rule.Title,
                Severity = rule.Severity.ToString(),
                IsActivatedByDefault = rule.IsActivatedByDefault,
                Description = GetResourceHtml(rule, language)
            };

            GetParameters(analyzerType, ruleDetail);
            GetTags(analyzerType, ruleDetail);
            GetSqale(analyzerType, ruleDetail);
            GetCodeFixNames(analyzerType, ruleDetail);

            return ruleDetail;
        }
コード例 #20
0
        private static RuleDetail GetRuleDetail(Type analyzerType)
        {
            var rule = analyzerType.GetCustomAttributes<RuleAttribute>().Single();

            var ruleDetail = new RuleDetail
            {
                Key = rule.Key,
                Title = rule.Title,
                Severity = rule.Severity.ToString(),
                IdeSeverity = (int)rule.Severity.ToDiagnosticSeverity(),
                IsActivatedByDefault = rule.IsActivatedByDefault,
                Description = "Full HTML description"
            };

            GetParameters(analyzerType, ruleDetail);
            GetTags(analyzerType, ruleDetail);
            GetSqale(analyzerType, ruleDetail);

            return ruleDetail;
        }
コード例 #21
0
        public ActionResult Update(RuleDetailS te)
        {
            RuleDetail ta = new RuleDetail()
            {
                BookID        = ef.TextBooks.FirstOrDefault(x => x.BookName == te.BookIDName && x.Shan == false).BookID,
                DetailID      = te.DetailID,
                QuestionCount = te.QuestionCount,
                QuestionLevel = te.QuestionLevel,
                RuleID        = ef.PaperRules.FirstOrDefault(x => x.RuleName == te.RuleIDName && x.Shan == false).RuleID,
            };

            ef.Entry(ta).State = EntityState.Modified;
            if (ef.SaveChanges() > 0)
            {
                return(Content("成功"));
            }
            else
            {
                return(Content("失败"));
            }
        }
コード例 #22
0
        private static void GetSqale(Type analyzerType, RuleDetail ruleDetail)
        {
            var sqaleRemediation = analyzerType.GetCustomAttributes <SqaleRemediationAttribute>().FirstOrDefault();

            if (sqaleRemediation == null || sqaleRemediation is NoSqaleRemediationAttribute)
            {
                ruleDetail.SqaleDescriptor = null;
                return;
            }

            var sqaleSubCharacteristic = analyzerType.GetCustomAttributes <SqaleSubCharacteristicAttribute>().First();
            var sqaleDescriptor        = new SqaleDescriptor
            {
                SubCharacteristic = sqaleSubCharacteristic.SubCharacteristic.ToSonarQubeString()
            };
            var constantRemediation = sqaleRemediation as SqaleConstantRemediationAttribute;

            if (constantRemediation == null)
            {
                ruleDetail.SqaleDescriptor = sqaleDescriptor;
                return;
            }

            sqaleDescriptor.Remediation.Properties.AddRange(new[]
            {
                new SqaleRemediationProperty
                {
                    Key  = SqaleRemediationProperty.RemediationFunctionKey,
                    Text = SqaleRemediationProperty.ConstantRemediationFunctionValue
                },
                new SqaleRemediationProperty
                {
                    Key   = SqaleRemediationProperty.OffsetKey,
                    Value = constantRemediation.Value,
                    Text  = string.Empty
                }
            });

            ruleDetail.SqaleDescriptor = sqaleDescriptor;
        }
コード例 #23
0
        private static void GetSqale(Type analyzerType, RuleDetail ruleDetail)
        {
            var sqaleRemediation = analyzerType.GetCustomAttributes<SqaleRemediationAttribute>().FirstOrDefault();

            if (sqaleRemediation == null || sqaleRemediation is NoSqaleRemediationAttribute)
            {
                ruleDetail.SqaleDescriptor = null;
                return;
            }

            var sqaleSubCharacteristic = analyzerType.GetCustomAttributes<SqaleSubCharacteristicAttribute>().First();
            var sqaleDescriptor = new SqaleDescriptor
            {
                SubCharacteristic = sqaleSubCharacteristic.SubCharacteristic.ToSonarQubeString()
            };
            var constantRemediation = sqaleRemediation as SqaleConstantRemediationAttribute;
            if (constantRemediation == null)
            {
                ruleDetail.SqaleDescriptor = sqaleDescriptor;
                return;
            }

            sqaleDescriptor.Remediation.Properties.AddRange(new[]
            {
                new SqaleRemediationProperty
                {
                    Key = SqaleRemediationProperty.RemediationFunctionKey,
                    Text = SqaleRemediationProperty.ConstantRemediationFunctionValue
                },
                new SqaleRemediationProperty
                {
                    Key = SqaleRemediationProperty.OffsetKey,
                    Value = constantRemediation.Value,
                    Text = string.Empty
                }
            });

            ruleDetail.SqaleDescriptor = sqaleDescriptor;
        }
コード例 #24
0
        private bool IsRecurringMatch(RuleDetail rule, DateTime date)
        {
            if (rule.Type == (int)RuleType.Recurring)
            {
                // Represents the candidate date day of the week value in the DayOfTheWeek enum
                var dayOfTheWeek = 1 << (int)date.DayOfWeek;

                if (rule.StartTime != null &&
                    rule.EndTime != null)
                {
                    var dayOffset = 0;
                    if (rule.StartTime.Value.Date != rule.EndTime.Value.Date)
                    {
                        // end time is on the next day
                        dayOffset = 1;
                    }

                    var startTime =
                        DateTime.MinValue.AddHours(rule.StartTime.Value.Hour).AddMinutes(rule.StartTime.Value.Minute);
                    var endTime =
                        DateTime.MinValue.AddDays(dayOffset).AddHours(rule.EndTime.Value.Hour).AddMinutes(rule.EndTime.Value.Minute);
                    var time = DateTime.MinValue.AddHours(date.Hour).AddMinutes(date.Minute);

                    // Determine if the candidate date is between start time and end time
                    var isInRange = time >= startTime && time < endTime;

                    if (isInRange)
                    {
                        // Now determine if the day of the week is correct
                        if (startTime.Date == time.Date)
                        {
                            // The candidate date is the same day defined for the rule
                            return((rule.DaysOfTheWeek & dayOfTheWeek) == dayOfTheWeek);
                        }
                    }
                }
            }
            return(false);
        }
コード例 #25
0
        public UCRuleInfo(RuleDetail ruledetail)
        {
            InitializeComponent();
            //复制对象选择,顺数标准段,倒数标准段
            foreach (Control item in flp_duixiangxuanze.Controls)
            {
                if (ruledetail.duixiangxuanze.Contains(item.Text))
                {
                    (item as CheckBox).Checked = true;
                }
            }
            tb_shunshu.Text = ruledetail._shunshu.ToString();
            tb_daoshu.Text  = ruledetail._daoshu.ToString();
            //赋值文本特征
            tb_wenbentezheng.Text = ruledetail.wenbentezheng;
            //赋值文本特征结果
            tb_zidingyijieguo.Text = ruledetail._zidingyivalue;
            foreach (Control item in flp_juzhi.Controls)
            {
                if (item is CheckBox && ruledetail.fuzhi.Contains(item.Text))
                {
                    (item as CheckBox).Checked = true;
                }
            }
            //赋值类型
            cbb_fuzhileixing.Text = ruledetail.fuzhileixing;
            //赋值覆盖范围
            foreach (Control control in flp_fugaifanwei.Controls)
            {
                if (ruledetail.fuzhifanwei.Contains(control.Text))
                {
                    (control as CheckBox).Checked = true;
                }
            }
            //赋值解析表横,列名称

            rb_liemingcheng.Checked  = ruledetail._liemingcheng;
            rb_hengmingcheng.Checked = !ruledetail._liemingcheng;
        }
コード例 #26
0
 public static RuleDescription Convert(RuleDetail detail, string productVersion, AnalyzerLanguage language)
 {
     return new RuleDescription
     {
         Key = detail.Key,
         Data = new Dictionary<string, RuleMetaData>
         {
             {
                 language.ToString(),
                 new RuleMetaData
                 {
                     Title = detail.Title,
                     Description =
                         GetParameterDescription(detail.Parameters) +
                         AddLinksBetweenRulesToDescription(detail.Description, productVersion) +
                         GetCodeFixDescription(detail),
                     Tags = detail.Tags,
                     Severity = detail.Severity,
                     IdeSeverity = detail.IdeSeverity
                 }
             }
         }
     };
 }
コード例 #27
0
 public static RuleDescription Convert(RuleDetail detail, string productVersion, AnalyzerLanguage language)
 {
     return(new RuleDescription
     {
         Key = detail.Key,
         Data = new Dictionary <string, RuleMetaData>
         {
             {
                 language.ToString(),
                 new RuleMetaData
                 {
                     Title = detail.Title,
                     Description =
                         GetParameterDescription(detail.Parameters) +
                         AddLinksBetweenRulesToDescription(detail.Description, productVersion) +
                         GetCodeFixDescription(detail),
                     Tags = detail.Tags,
                     Severity = detail.Severity,
                     IdeSeverity = detail.IdeSeverity
                 }
             }
         }
     });
 }
コード例 #28
0
        private static void GetParameters(Type analyzerType, RuleDetail ruleDetail)
        {
            var typeToGetParametersFrom = analyzerType;
            var templateInterface = analyzerType.GetInterfaces()
                .FirstOrDefault(type => type.IsGenericType &&
                                        type.GetGenericTypeDefinition() == typeof (IRuleTemplate<>));

            if (templateInterface != null)
            {
                typeToGetParametersFrom = templateInterface.GetGenericArguments().First();
            }

            var parameters = typeToGetParametersFrom.GetProperties()
                .Select(p => p.GetCustomAttributes<RuleParameterAttribute>().SingleOrDefault());

            foreach (var ruleParameter in parameters
                .Where(attribute => attribute != null))
            {
                ruleDetail.Parameters.Add(
                    new RuleParameter
                    {
                        DefaultValue = ruleParameter.DefaultValue,
                        Description = ruleParameter.Description,
                        Key = ruleParameter.Key,
                        Type = ruleParameter.Type.ToSonarQubeString()
                    });
            }
        }
コード例 #29
0
        private static void GetCodeFixNames(Type analyzerType, RuleDetail ruleDetail)
        {
            var codeFixProvider = GetCodeFixProviderType(analyzerType);
            if (codeFixProvider == null)
            {
                return;
            }

            var titles = GetCodeFixTitles(codeFixProvider);

            ruleDetail.CodeFixTitles.AddRange(titles);
        }
コード例 #30
0
        private static string GetCodeFixDescription(RuleDetail detail)
        {
            if (!detail.CodeFixTitles.Any())
            {
                return string.Empty;
            }

            const string listItemPattern = "<li>{0}</li>";
            const string codeFixPattern = "<h2>Code Fixes</h2><ul>{0}</ul>";

            return
                string.Format(codeFixPattern,
                    string.Join("", detail.CodeFixTitles.Select(title => string.Format(listItemPattern, title))));
        }
コード例 #31
0
        private static void GetParameters(Type analyzerType, RuleDetail ruleDetail)
        {
            var parameters = analyzerType.GetProperties()
                .Select(p => p.GetCustomAttributes<RuleParameterAttribute>().SingleOrDefault());

            foreach (var ruleParameter in parameters
                .Where(attribute => attribute != null))
            {
                ruleDetail.Parameters.Add(
                    new RuleParameter
                    {
                        DefaultValue = ruleParameter.DefaultValue,
                        Description = ruleParameter.Description,
                        Key = ruleParameter.Key,
                        Type = ruleParameter.Type.ToSonarQubeString()
                    });
            }
        }
コード例 #32
0
        /// <summary>
        /// 点击保存按钮时触发的事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_baocun_Click(object sender, EventArgs e)
        {
            //获得名称
            string guizemingcheng = tb_guizemingcheng.Text;
            //获得规则说明
            string guizeshuoming = tb_shuoming.Text;
            //获得规则详情集合,循环获得panel_wenbentezheng中所有的control,转换成ucruleinfo,获得信息
            JiexiGuize jiexiguize = new JiexiGuize();

            foreach (UserControl uc in panel_wenbentezheng.Controls)
            {
                var        myuc = uc as UCRuleInfo;
                RuleDetail ri   = new RuleDetail();

                ri._shunshu = myuc.tb_shunshu.Text.Trim().Equals(string.Empty)?0: Convert.ToInt32(myuc.tb_shunshu.Text);
                ri._daoshu  = myuc.tb_daoshu.Text.Trim().Equals(string.Empty) ? 0 : Convert.ToInt32(myuc.tb_daoshu.Text);
                //获得对象选择,myuc.flp_duixiangxuanze中checked=true的text
                foreach (Control item in myuc.flp_duixiangxuanze.Controls)
                {
                    if (item is CheckBox && (item as CheckBox).Checked)
                    {
                        ri.duixiangxuanze.Add(item.Text);
                    }
                }
                //获得文本特征
                ri.wenbentezheng = myuc.tb_wenbentezheng.Text;
                //获得文本特征结果
                ri._zidingyivalue = myuc.tb_zidingyijieguo.Text;
                foreach (Control item in myuc.flp_juzhi.Controls)
                {
                    if (item is CheckBox && (item as CheckBox).Checked)
                    {
                        ri.fuzhi.Add(item.Text);
                    }
                }
                //获得赋值类型
                ri.fuzhileixing = myuc.cbb_fuzhileixing.Text;
                //获得赋值覆盖范围
                foreach (Control mycontrol in myuc.flp_fugaifanwei.Controls)
                {
                    if ((mycontrol as CheckBox).Checked)
                    {
                        ri.fuzhifanwei.Add(mycontrol.Text);
                    }
                }
                //获得横.列名称
                ri._liemingcheng = myuc.rb_liemingcheng.Checked;
                jiexiguize.ruleinfo.Add(ri);
            }
            //将解析规则转为json格式
            string json = JsonConvert.SerializeObject(jiexiguize, Formatting.None);

            //在保存之前先删除
            DeleteRule(guizemingcheng);
            //保存规则
            bool b = SaveRule(guizemingcheng, guizeshuoming, json);

            if (b)
            {
                this.DialogResult = DialogResult.OK;
            }
            else
            {
                MessageBox.Show($"规则 {guizemingcheng} 保存失败!");
            }
        }