Пример #1
0
        //---------------------------------------------------------------------------------------------

        public void FillFromDataRow(DataRow row)
        {
            foreach (PropertyInfo pInfo in this.GetType().GetProperties())
            {
                ParameterAttribute attrParam = (ParameterAttribute)this.GetAttribute(pInfo, typeof(ParameterAttribute));

                if (attrParam != null)
                {
                    Usages defaultUsage = Usages.Add | Usages.Load | Usages.Save;

                    UsageAttribute usage = (UsageAttribute)this.GetAttribute(pInfo, typeof(UsageAttribute));
                    if (usage != null)
                    {
                        defaultUsage = usage.Usage;
                    }

                    if ((defaultUsage & Usages.Load) == Usages.Load)
                    {
                        object value = (row.Table.Columns.Contains(attrParam.Name)) ? Utils.DBNullToNull(row[attrParam.Name]) : null;

                        if (pInfo.PropertyType.GetInterface("Caleb.Library.CAL.ICalBusiness") != null)
                        {
                            ICalBusiness business = (ICalBusiness)pInfo.GetValue(this, null);
                            business.ID = CalBusiness.ToID(value);
                        }
                        else
                        {
                            pInfo.SetValue(this, value, null);
                        }
                    }
                }
            }
        }
Пример #2
0
        protected MemberInfoUsage[] GetMembers()
        {
            // Return cached members
            if (members != null)
            {
                return(members);
            }

            // Cache members
            ArrayList memberList = new ArrayList();

            // TODO: Parse base class first to get /v and /h shown first
            BindingFlags flags = BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public;

            foreach (MemberInfo info in GetType().GetMembers(flags))
            {
                // Only doing fields and properties
                if ((info.MemberType != MemberTypes.Field) && (info.MemberType != MemberTypes.Property))
                {
                    continue;
                }

                // Skip variables w/o usage
                object[]       attribs = info.GetCustomAttributes(typeof(UsageAttribute), true);
                UsageAttribute usage   = (UsageAttribute)(attribs.Length != 0 ? attribs[0] : null);
                if (usage is NoUsageAttribute)
                {
                    continue;
                }

                // Default settings with no attribute
                if (usage == null)
                {
                    PropertyInfo prop  = info as PropertyInfo;
                    FieldInfo    field = info as FieldInfo;
                    Debug.Assert((prop != null) || (field != null));

                    // If the type is bool, it's probably just a flag
                    if (((prop != null) && (prop.PropertyType == typeof(bool))) ||
                        ((field != null) && (field.FieldType == typeof(bool))))
                    {
                        usage = new FlagUsageAttribute(info.Name);
                    }
                    // If the type is not a bool, it probably also have a value
                    else
                    {
                        usage = new ValueUsageAttribute(info.Name);
                    }
                }

                memberList.Add(new MemberInfoUsage(info, usage));
            }

            members = (MemberInfoUsage[])memberList.ToArray(typeof(MemberInfoUsage));
            return(members);
        }
Пример #3
0
        //---------------------------------------------------------------------------------------------

        public DataRow FillToDataRow(DataRow row)
        {
            foreach (PropertyInfo pInfo in this.GetType().GetProperties())
            {
                ParameterAttribute attrParam = (ParameterAttribute)this.GetAttribute(pInfo, typeof(ParameterAttribute));
                if (attrParam != null)
                {
                    Usages         defaultUsage = Usages.Add | Usages.Save | Usages.Load;
                    UsageAttribute usage        = (UsageAttribute)this.GetAttribute(pInfo, typeof(UsageAttribute));
                    if (usage != null)
                    {
                        defaultUsage = usage.Usage;
                    }
                    if ((defaultUsage & Usages.Add) == Usages.Add)
                    {
                        bool isBusiness        = pInfo.PropertyType.GetInterface("Caleb.Library.CAL.ICalBusiness") != null;
                        Type type              = pInfo.PropertyType;
                        bool isGenericNullable = pInfo.PropertyType.IsGenericType && pInfo.PropertyType.GetGenericTypeDefinition() == typeof(Nullable <>);
                        type = isGenericNullable ? Nullable.GetUnderlyingType(pInfo.PropertyType) : pInfo.PropertyType;
                        if (isBusiness)
                        {
                            type = typeof(Int32);
                        }
                        if (!row.Table.Columns.Contains(attrParam.Name))
                        {
                            row.Table.Columns.Add(attrParam.Name, type);
                        }
                        if (isBusiness)
                        {
                            ICalBusiness business = (ICalBusiness)pInfo.GetValue(this, null);
                            row[attrParam.Name] = Utils.ToDBDataNullValue(business.ID);
                        }
                        else
                        {
                            row[attrParam.Name] = Utils.ToDBDataNullValue(pInfo.GetValue(this, null));
                        }
                    }
                }
            }
            return(row);
        }
Пример #4
0
        public static void SendCommandUsage(Mobile player, string command)
        {
            string       message;
            CommandEntry entry = CommandSystem.Entries[command];

            if (null != entry)
            {
                MethodInfo mi = entry.Handler.Method;

                object[] attrs = mi.GetCustomAttributes(typeof(UsageAttribute), false);

                UsageAttribute usage = attrs.Length > 0 ? attrs[0] as UsageAttribute : null;

                message = "Format: " + (null == usage ? " - no usage" : usage.Usage);
            }
            else
            {
                message = command + " - unknown command";
            }

            player.SendMessage(kRedHue, message);
        }
Пример #5
0
        public static void FillTable()
        {
            List <CommandEntry> commands = new List <CommandEntry>(CommandSystem.Entries.Values);
            List <CommandInfo>  list     = new List <CommandInfo>();

            commands.Sort();
            commands.Reverse();
            Docs.Clean(commands);

            for (int i = 0; i < commands.Count; ++i)
            {
                CommandEntry e = commands[i];

                MethodInfo mi = e.Handler.Method;

                object[] attrs = mi.GetCustomAttributes(typeof(UsageAttribute), false);

                if (attrs.Length == 0)
                {
                    continue;
                }

                UsageAttribute usage = attrs[0] as UsageAttribute;

                attrs = mi.GetCustomAttributes(typeof(DescriptionAttribute), false);

                if (attrs.Length == 0)
                {
                    continue;
                }

                DescriptionAttribute desc = attrs[0] as DescriptionAttribute;

                if (usage == null || desc == null)
                {
                    continue;
                }

                attrs = mi.GetCustomAttributes(typeof(AliasesAttribute), false);

                AliasesAttribute aliases = (attrs.Length == 0 ? null : attrs[0] as AliasesAttribute);

                string descString = desc.Description.Replace("<", "(").Replace(">", ")");

                if (aliases == null)
                {
                    list.Add(new CommandInfo(e.AccessLevel, e.Command, null, usage.Usage, descString));
                }
                else
                {
                    list.Add(new CommandInfo(e.AccessLevel, e.Command, aliases.Aliases, usage.Usage, descString));

                    for (int j = 0; j < aliases.Aliases.Length; j++)
                    {
                        string[] newAliases = new string[aliases.Aliases.Length];

                        aliases.Aliases.CopyTo(newAliases, 0);

                        newAliases[j] = e.Command;

                        list.Add(new CommandInfo(e.AccessLevel, aliases.Aliases[j], newAliases, usage.Usage, descString));
                    }
                }
            }

            for (int i = 0; i < TargetCommands.AllCommands.Count; ++i)
            {
                BaseCommand command = TargetCommands.AllCommands[i];

                string usage = command.Usage;
                string desc  = command.Description;

                if (usage == null || desc == null)
                {
                    continue;
                }

                string[] cmds    = command.Commands;
                string   cmd     = cmds[0];
                string[] aliases = new string[cmds.Length - 1];

                for (int j = 0; j < aliases.Length; ++j)
                {
                    aliases[j] = cmds[j + 1];
                }

                desc = desc.Replace("<", "(").Replace(">", ")");

                if (command.Supports != CommandSupport.Single)
                {
                    StringBuilder sb = new StringBuilder(50 + desc.Length);

                    sb.Append("Modifiers: ");

                    if ((command.Supports & CommandSupport.Global) != 0)
                    {
                        sb.Append("<i>Global</i>, ");
                    }

                    if ((command.Supports & CommandSupport.Online) != 0)
                    {
                        sb.Append("<i>Online</i>, ");
                    }

                    if ((command.Supports & CommandSupport.Region) != 0)
                    {
                        sb.Append("<i>Region</i>, ");
                    }

                    if ((command.Supports & CommandSupport.Contained) != 0)
                    {
                        sb.Append("<i>Contained</i>, ");
                    }

                    if ((command.Supports & CommandSupport.Multi) != 0)
                    {
                        sb.Append("<i>Multi</i>, ");
                    }

                    if ((command.Supports & CommandSupport.Area) != 0)
                    {
                        sb.Append("<i>Area</i>, ");
                    }

                    if ((command.Supports & CommandSupport.Self) != 0)
                    {
                        sb.Append("<i>Self</i>, ");
                    }

                    sb.Remove(sb.Length - 2, 2);
                    sb.Append("<br>");
                    sb.Append(desc);

                    desc = sb.ToString();
                }

                list.Add(new CommandInfo(command.AccessLevel, cmd, aliases, usage, desc));

                for (int j = 0; j < aliases.Length; j++)
                {
                    string[] newAliases = new string[aliases.Length];

                    aliases.CopyTo(newAliases, 0);

                    newAliases[j] = cmd;

                    list.Add(new CommandInfo(command.AccessLevel, aliases[j], newAliases, usage, desc));
                }
            }

            List <BaseCommandImplementor> commandImpls = BaseCommandImplementor.Implementors;

            for (int i = 0; i < commandImpls.Count; ++i)
            {
                BaseCommandImplementor command = commandImpls[i];

                string usage = command.Usage;
                string desc  = command.Description;

                if (usage == null || desc == null)
                {
                    continue;
                }

                string[] cmds    = command.Accessors;
                string   cmd     = cmds[0];
                string[] aliases = new string[cmds.Length - 1];

                for (int j = 0; j < aliases.Length; ++j)
                {
                    aliases[j] = cmds[j + 1];
                }

                desc = desc.Replace("<", ")").Replace(">", ")");

                list.Add(new CommandInfo(command.AccessLevel, cmd, aliases, usage, desc));

                for (int j = 0; j < aliases.Length; j++)
                {
                    string[] newAliases = new string[aliases.Length];

                    aliases.CopyTo(newAliases, 0);

                    newAliases[j] = cmd;

                    list.Add(new CommandInfo(command.AccessLevel, aliases[j], newAliases, usage, desc));
                }
            }

            list.Sort(new CommandInfoSorter());

            m_SortedHelpInfo = list;

            foreach (CommandInfo c in m_SortedHelpInfo)
            {
                if (!m_HelpInfos.ContainsKey(c.Name.ToLower()))
                {
                    m_HelpInfos.Add(c.Name.ToLower(), c);
                }
            }
        }
Пример #6
0
        private static void ShowCommandInfo(KonsoleCommandEntry e, CategoryAttribute cat)
        {
            try
            {
                MethodInfo mi = e.Handler.Method;

                object[] attrs = mi.GetCustomAttributes(typeof(CategoryAttribute), false);

                CategoryAttribute category;
                if (attrs.Length == 0)
                {
                    category = new CategoryAttribute("[General]");
                }
                else
                {
                    category = attrs[0] as CategoryAttribute;
                }

                if (cat != null && category.Category != cat.Category)
                {
                    return;
                }

                attrs = mi.GetCustomAttributes(typeof(UsageAttribute), false);

                if (attrs.Length == 0)
                {
                    return;
                }

                UsageAttribute usage = attrs[0] as UsageAttribute;

                attrs = mi.GetCustomAttributes(typeof(DescriptionAttribute), false);

                if (attrs.Length == 0)
                {
                    return;
                }

                DescriptionAttribute desc = attrs[0] as DescriptionAttribute;

                if (usage == null || desc == null)
                {
                    return;
                }

                attrs = mi.GetCustomAttributes(typeof(AliasesAttribute), false);

                AliasesAttribute aliases = (attrs.Length == 0 ? null : attrs[0] as AliasesAttribute);

                string alias = "";
                if (aliases != null)
                {
                    string[] v = aliases.Aliases;

                    for (int i = 0; i < v.Length; ++i)
                    {
                        if (i != 0)
                        {
                            alias = alias + ", ";
                        }

                        alias = alias + v[i];
                    }
                }

                string strInfo = usage.Usage + "\t" + desc.Description + "\t" + alias;
                Console.WriteLine("| " + strInfo);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error retrieving method information: " + ex.Message);
            }
        }
Пример #7
0
        public static string GetUsage(this Command command)
        {
            UsageAttribute usage = (UsageAttribute)command.CustomAttributes.FirstOrDefault(a => a.GetType() == typeof(UsageAttribute));

            return(usage != null ? usage.Value : "");
        }
 public MemberInfoUsage(MemberInfo info, UsageAttribute usage)
 {
     this.info = info;
     this.usage = usage;
 }
Пример #9
0
 public MemberInfoUsage(MemberInfo info, UsageAttribute usage)
 {
     this.info  = info;
     this.usage = usage;
 }