public static TAttribute GetAttribute <TAttribute>(this InternalCommands command)
        {
            MemberInfo member    = typeof(InternalCommands).GetMember(command.ToString()).FirstOrDefault();
            object     attribute = member?.GetCustomAttributes(typeof(TAttribute), false)?.FirstOrDefault();

            return((TAttribute)attribute);
        }
Esempio n. 2
0
        public void UpdateHelpHints(string command)
        {
            FlowDocumentHelp.Blocks.Clear();
            string commandHelpHints = null;
            Array  commands         = Enum.GetValues(typeof(InternalCommands));

            if (InternalCommands.GoogleTranslate.GetAttribute <CommandNameAttribute>().Commands[0].CompareTo(command) != 0)
            {
                for (int index = 0; index < commands.Length; index++)
                {
                    InternalCommands iCommand    = (InternalCommands)commands.GetValue(index);
                    string           description = iCommand.GetAttribute <CommandDescriptionAttribute>()?.Description;
                    string           name        = iCommand.GetAttribute <CommandNameAttribute>()?.Commands.FirstOrDefault();
                    string           usage       = iCommand.GetAttribute <CommandUsageAttribute>()?.Usage;
                    if (!string.IsNullOrEmpty(description) && !string.IsNullOrEmpty(name))
                    {
                        string tabs = "\t";
                        if (name.Length < 8)
                        {
                            tabs += "\t";
                        }
                        string commandHelpHint = null;
                        if ((index < commands.Length) && (index < commands.Length - 1))
                        {
                            commandHelpHint = string.Format("<Bold>{0}</Bold>{1}{2}<LineBreak/>", name, tabs, description);
                            if (!string.IsNullOrEmpty(usage))
                            {
                                commandHelpHint += string.Format("\t<Span Foreground=\"Gray\">{0}</Span><LineBreak/><LineBreak/>", usage);
                            }
                        }
                        else
                        {
                            commandHelpHint = string.Format("<Bold>{0}</Bold>{1}{2}", name, tabs, description);
                            if (!string.IsNullOrEmpty(usage))
                            {
                                commandHelpHint += string.Format("<LineBreak/>\t<Span Foreground=\"Gray\">{0}</Span>", usage);
                            }
                        }
                        if (name.StartsWith(command) && !string.IsNullOrEmpty(command))
                        {
                            commandHelpHint = "<Span Foreground=\"Yellow\">" + commandHelpHint + "</Span>";
                        }
                        commandHelpHints += commandHelpHint;
                    }
                }
            }
            else
            {
                commandHelpHints = InternalCommands.GoogleTranslate.GetAttribute <CommandUsageAttribute>()?.Usage;
            }
            string    docSource = string.Format("<Paragraph xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\" xml:space=\"preserve\">{0}</Paragraph>", commandHelpHints);
            Paragraph obj       = (Paragraph)XamlReader.Parse(docSource);

            FlowDocumentHelp.Blocks.Add(obj);
        }
Esempio n. 3
0
        public static string Run(string command)
        {
            string output = "Sorry... I can't figure out what you want me to do!";
            var    parsed = command.Split(' ');
            var    cmd    = parsed.First().Trim().ToLowerInvariant();
            var    args   = command.Substring(cmd.Length);

            if (RestrictedCommands.Contains(cmd))
            {
                return($"The '{cmd}' command is restricted.");
            }
            if (InternalCommands.Contains(cmd))
            {
                output = RunInternalCommand(cmd, args);
            }
            else
            {
                output = RunExternalCommand(cmd, args) ?? output;
            }

            return(output);
        }
        public static bool ContainsParameter(this InternalCommands command, string parameter)
        {
            CommandParametersAttribute attribute = GetAttribute <CommandParametersAttribute>(command);

            return(attribute != null?attribute.Parameters.Contains(parameter) : false);
        }
Esempio n. 5
0
 public static bool ContainsCommand(this InternalCommands command)
 {
     return(false);
 }