Ejemplo n.º 1
0
        private void procAssembly(Assembly asm)
        {
            foreach (Object ca in asm.GetCustomAttributes(typeof(ConflictRuleAttribute), true))
            {
                ConflictRuleAttribute cae = (ConflictRuleAttribute)ca;

                string resname;
                if ("*".Equals(cae.Resource))
                {
                    resname = "*";
                }
                else
                {
                    short        ord;
                    ResourceType rt = BookKeeper.getResourceType(cae.Resource, out ord);
                    if (rt == ResourceType.Custom)
                    {
                        resname = cae.Resource.ToLower();
                    }
                    else if (rt == ResourceType.ArgumentEntry && ord > -1)
                    {
                        resname = BookKeeper.resourceTypeAsString(rt) + ord;
                    }
                    else
                    {
                        resname = BookKeeper.resourceTypeAsString(rt);
                    }
                }

                bool add = true;
                foreach (ConflictRule cr in rules)
                {
                    if (cr.Constraint == cae.Constraint && cr.Resource.Equals(resname) && cr.Pattern.Equals(cae.Pattern))
                    {
                        add = false;
                        break;
                    }
                }
                if (add)
                {
                    try
                    {
                        ConflictRule cr = new ConflictRule(cae.Pattern, resname, cae.Constraint, cae.Message);
                        rules.Add(cr);
                    }
                    catch (Exception e)
                    {
#if DEBUG
                        Console.Error.WriteLine("<ResourceValidator> Unable to create conflict rule with pattern {0} for resource {1}", cae.Pattern, resname);
                        Console.Error.WriteLine("<ResourceValidator> " + e.Message);
                        Console.Error.WriteLine("<ResourceValidator> " + e.StackTrace);
#endif
                    }
                }
            }
        }