コード例 #1
0
ファイル: RuleEventArgs.cs プロジェクト: chenxx08/ifc-dotnet
		/// <summary>
		/// Constructor. Copies the data from a RuleAttribute.
		/// </summary>
		/// <param name="attribute"></param>
		/// <param name="evaluatedObj"></param>
		public RuleEventArgs(RuleAttribute attribute, object evaluatedObj){
			if(attribute != null){
				this._name = attribute.Name;
				this._description = attribute.Description;
			}
			this._evaluatedObj = evaluatedObj;
		}
コード例 #2
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,
                Type                 = resources.GetString($"{rule.Key}_Type"),
                Title                = resources.GetString($"{rule.Key}_Title"),
                Severity             = resources.GetString($"{rule.Key}_Severity"),
                IsActivatedByDefault = bool.Parse(resources.GetString($"{rule.Key}_IsActivatedByDefault")),
                Description          = GetResourceHtml(rule, language),
                Remediation          = ToSonarQubeRemediationFunction(resources.GetString($"{rule.Key}_Remediation")),
                RemediationCost      = resources.GetString($"{rule.Key}_RemediationCost")
            };

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

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

            return(ruleDetail);
        }
コード例 #3
0
        public void AddMessage(string message, Trade trade, RuleAttribute attribute = null, RewardRule rule = null)
        {
            if (trade != null)
            {
                TradeMessage tradeMessage = new TradeMessage
                {
                    TradeId = trade.Id,
                    Message = message,
                };
                if (attribute != null)
                {
                    tradeMessage.RuleId   = attribute.Id;
                    tradeMessage.RuleName = attribute.Name;
                    tradeMessage.Type     = Resolve <IRuleModuleService>().GetRuleType(attribute.Id)?.FullName;
                }
                if (rule != null)
                {
                    tradeMessage.ConfigId = rule.Id;
                    tradeMessage.RuleName = rule.Base?.Name;
                }

                Resolve <ITradeMessageService>().Add(tradeMessage);
            }
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: trabasbaenjir/microsoft
        static void Main(string[] args)
        {
            XmlDocument   doc            = new XmlDocument();
            XmlElement    projectElement = doc.CreateElement("ProjectSchemaDefinitions", xmlns);
            List <string> categories     = new List <string>();

            doc.AppendChild(projectElement);

            // These attributes are probably common to all property schemas in Visual Studio.
            projectElement.SetAttribute("xmlns", "clr-namespace:Microsoft.Build.Framework.XamlTypes;assembly=Microsoft.Build.Framework");
            projectElement.SetAttribute("xmlns:x", "http://schemas.microsoft.com/winfx/2006/xaml");
            projectElement.SetAttribute("xmlns:sys", "clr-namespace:System;assembly=mscorlib");
            projectElement.SetAttribute("xmlns:transformCallback", "Microsoft.Cpp.Dev10.ConvertPropertyCallback");

            XmlElement ruleElement = (XmlElement)projectElement.AppendChild(doc.CreateElement("Rule", xmlns));

            ruleElement.AppendChild(doc.CreateComment("This file is generated! Modify with caution!"));

            RuleAttribute ruleAttr = (RuleAttribute)Attribute.GetCustomAttribute(typeof(Clang), typeof(RuleAttribute));

            if (ruleAttr == null)
            {
                throw new InvalidOperationException("Class requires Rule attribute!");
            }

            PropsToXmlAttr(doc, ruleAttr, ruleElement);

            DataSourceAttribute dataAttr = (DataSourceAttribute)Attribute.GetCustomAttribute(typeof(Clang), typeof(DataSourceAttribute));

            if (dataAttr == null)
            {
                throw new InvalidOperationException("Class requires DataSource attribute!");
            }

            AttrToSubElem(doc, dataAttr, ruleElement, "DataSource");

            XmlElement catsElement = (XmlElement)ruleElement.AppendChild(doc.CreateElement("Rule.Categories", xmlns));

            PropertyCategoryAttribute[] allAttributes = (PropertyCategoryAttribute[])Attribute.GetCustomAttributes(typeof(Clang), typeof(PropertyCategoryAttribute));
            allAttributes = allAttributes.OrderBy(x => x.Order).ToArray();
            Dictionary <string, PropertyCategoryAttribute> categoryMap = allAttributes.ToDictionary(x => x.Name);

            MemberInfo[] members = typeof(Clang).GetMembers(BindingFlags.Public | BindingFlags.DeclaredOnly | BindingFlags.Instance);

            foreach (PropertyCategoryAttribute catAttr in allAttributes)
            {
                XmlElement catElement = (XmlElement)catsElement.AppendChild(doc.CreateElement("Category", xmlns));

                PropsToXmlAttr(doc, catAttr, catElement);
            }

            foreach (MemberInfo member in members)
            {
                PropertyPageAttribute[] attrs = (PropertyPageAttribute[])Attribute.GetCustomAttributes(member, typeof(PropertyPageAttribute));

                foreach (PropertyPageAttribute attr in attrs)
                {
                    Console.WriteLine("Member name: {0}", member.Name);

                    if (attr.Category != null && attr.Category != "")
                    {
                        PropertyCategoryAttribute req;
                        if (!categoryMap.TryGetValue(attr.Category, out req))
                        {
                            Console.WriteLine("Category not found: {0}", attr.Category);
                        }
                    }
                }

                XmlElement curElement = null;

                switch (member.MemberType)
                {
                case MemberTypes.Property:
                    PropertyInfo          pInfo    = (PropertyInfo)member;
                    PropertyPageAttribute propAttr = (PropertyPageAttribute)Attribute.GetCustomAttribute(member, typeof(PropertyPageAttribute));

                    // Untracked parameter.
                    if (propAttr == null)
                    {
                        continue;
                    }

                    if (pInfo.PropertyType.IsSubclassOf(typeof(Enum)))
                    {
                        Console.WriteLine("Warning: Enumerations are invalid types because VisualStudio isn't that smart. You'll have to make it a string and back it with an enum.");
                        continue;
                    }
                    else if (pInfo.PropertyType.IsAssignableFrom(typeof(ITaskItem[])))
                    {
                        curElement = (XmlElement)ruleElement.AppendChild(doc.CreateElement("StringListProperty", xmlns));
                        PropsToXmlAttr(doc, propAttr, curElement).SetAttribute("Name", member.Name);
                    }
                    else if (pInfo.PropertyType.IsAssignableFrom(typeof(String)))
                    {
                        EnumeratedValueAttribute enumAttr = (EnumeratedValueAttribute)Attribute.GetCustomAttribute(member, typeof(EnumeratedValueAttribute));

                        if (enumAttr != null)
                        {
                            curElement = (XmlElement)ruleElement.AppendChild(doc.CreateElement("EnumProperty", xmlns));
                            PropsToXmlAttr(doc, propAttr, curElement).SetAttribute("Name", member.Name);

                            int foundAttr = 0;

                            FieldInfo[] fields = enumAttr.Enumeration.GetFields(BindingFlags.Public | BindingFlags.Static);
                            foreach (FieldInfo field in fields)
                            {
                                FieldAttribute attr = (FieldAttribute)field.GetCustomAttribute(typeof(FieldAttribute));
                                if (attr != null)
                                {
                                    foundAttr++;
                                    PropsToXmlAttr(doc, attr, (XmlElement)curElement.AppendChild(doc.CreateElement("EnumValue", xmlns))).SetAttribute("Name", field.Name);
                                }
                            }

                            if (foundAttr > 0 && foundAttr != fields.Length)
                            {
                                Console.WriteLine("Not all fields in {0} have attributes", pInfo.Name);
                            }
                        }
                        else
                        {
                            curElement = (XmlElement)ruleElement.AppendChild(doc.CreateElement("StringProperty", xmlns));
                            PropsToXmlAttr(doc, propAttr, curElement).SetAttribute("Name", member.Name);
                        }
                    }
                    else if (pInfo.PropertyType.IsAssignableFrom(typeof(String[])))
                    {
                        curElement = (XmlElement)ruleElement.AppendChild(doc.CreateElement("StringListProperty", xmlns));
                        PropsToXmlAttr(doc, propAttr, curElement).SetAttribute("Name", member.Name);
                    }
                    else if (pInfo.PropertyType.IsAssignableFrom(typeof(Boolean)))
                    {
                        curElement = (XmlElement)ruleElement.AppendChild(doc.CreateElement("BoolProperty", xmlns));
                        PropsToXmlAttr(doc, propAttr, curElement).SetAttribute("Name", member.Name);
                    }
                    else if (pInfo.PropertyType.IsAssignableFrom(typeof(int)))
                    {
                        curElement = (XmlElement)ruleElement.AppendChild(doc.CreateElement("IntProperty", xmlns));
                        PropsToXmlAttr(doc, propAttr, curElement).SetAttribute("Name", member.Name);
                    }
                    break;

                // Fields are not exposed, only property accessors.
                case MemberTypes.Field:
                    break;

                default:
                    break;
                }

                if (curElement != null)
                {
                    DataSourceAttribute dataSrcAttr = (DataSourceAttribute)Attribute.GetCustomAttribute(member, typeof(DataSourceAttribute));
                    if (dataSrcAttr != null)
                    {
                        AttrToSubElem(doc, dataSrcAttr, curElement, "DataSource");
                    }
                }
            }

            IEnumerable <Attribute> additionalAttrs = Attribute.GetCustomAttributes(typeof(Clang), typeof(ItemTypeAttribute));

            additionalAttrs = additionalAttrs.Concat(Attribute.GetCustomAttributes(typeof(Clang), typeof(FileExtensionAttribute)));
            additionalAttrs = additionalAttrs.Concat(Attribute.GetCustomAttributes(typeof(Clang), typeof(ContentTypeAttribute)));

            foreach (Attribute additionalAttr in additionalAttrs)
            {
                string attrName = additionalAttr.GetType().Name;
                attrName = attrName.Substring(0, attrName.Length - "Attribute".Length);
                // So lollers. C# is great.
                PropsToXmlAttr(doc, additionalAttr, (XmlElement)projectElement.AppendChild(doc.CreateElement(attrName, xmlns)));
            }

            FileStream        fs          = new FileStream(@"..\..\sbclang.xml", FileMode.Create);
            XmlWriterSettings xmlSettings = new XmlWriterSettings();

            xmlSettings.NewLineOnAttributes = true;
            xmlSettings.Indent            = true;
            xmlSettings.NamespaceHandling = NamespaceHandling.OmitDuplicates;
            XmlWriter writer = XmlWriter.Create(fs, xmlSettings);

            doc.Save(writer);

            Console.WriteLine("All done! Press any key to exit.");
            Console.ReadKey();
        }
コード例 #5
0
		public void BindToGrammar() {
			RuleAttribute ruleAttribute = new RuleAttribute("<Negate Exp> ::= '-' <Value>");
			Assert.NotNull(ruleAttribute.Bind(grammar));
		}