public override void WritePacket()
        {
            var root = DefaultCommands.GetCommands();
            HashSet <CommandNode> nodes = new HashSet <CommandNode>();
            HashSet <CommandNode> Work  = new HashSet <CommandNode>()
            {
                root
            };

            while (Work.Count != 0)
            {
                foreach (var v in Work.ToArray())
                {
                    nodes.Add(v);
                    Work.Remove(v);
                    foreach (var v2 in v.CommandNodes)
                    {
                        if (v2.GetType() != typeof(FunctionCommandNode))
                        {
                            Work.Add(v2);
                        }
                    }
                }
            }
            var array = nodes.Reverse().ToArray();

            Write((VarInt)array.Length);
            foreach (var v in array)
            {
                WriteNode(v, array);
            }
            var rootI = Array.IndexOf(array, array.First(x => x.GetType() == typeof(RootCommandNode)));

            Write((VarInt)rootI);
        }
        /// <summary>
        /// Constructs a command-line interpreter from the objects and/or System.Types provided.
        /// </summary>
        public CommandInterpreter(DefaultCommands defaultCmds, params object[] handlers)
        {
            _head     = null;
            _prompt   = "> ";
            _commands = new Dictionary <string, ICommand>(StringComparer.OrdinalIgnoreCase);
            _options  = new Dictionary <string, IOption>(StringComparer.OrdinalIgnoreCase);
            _filters  = new List <ICommandFilter>();
            _fnNextCh = GetNextCharacter;

            //defaults to { Redirect, then Pipe, then everything else }
            _filterPrecedence = "<|*";

            _buildInCommands = new BuiltInCommands(
                Command.Make(this, this.GetType().GetMethod("Get")),
                Command.Make(this, this.GetType().GetMethod("Set", new Type[] { typeof(string), typeof(object), typeof(bool) })),
                Command.Make(this, this.GetType().GetMethod("Help", new Type[] { typeof(string), typeof(bool) })),
                Option.Make(this, this.GetType().GetProperty("ErrorLevel")),
                Option.Make(this, this.GetType().GetProperty("Prompt"))
                );

            _buildInCommands.Add(this, defaultCmds);

            foreach (object o in handlers)
            {
                AddHandler(o);
            }
        }
示例#3
0
        public ParseCommands(DragonChat chat)
        {
            _chat = chat;

            adminCommands   = new AdminCommands(chat);
            userCommands    = new UserCommands(chat);
            defaultCommands = new DefaultCommands(chat);
        }
示例#4
0
        /// <summary>Download the update package.</summary>
        public void Download()
        {
            Package _package = new Package(_packagePath.ToString());

            _state = UpdateState.Downloading;

            DefaultCommands.Download(_package.Download, _packageDownloadPath);
        }
示例#5
0
文件: Host.cs 项目: vercas/vCommands
        /// <summary>
        /// Registers a default set of commands to the host.
        /// </summary>
        public void RegisterDefaultCommands(bool includeManual = true, bool includeMath = true, bool shortHelp = false)
        {
            ShortHelp = shortHelp;

            DefaultCommands.Register(this, includeManual, includeMath, shortHelp);

            if (includeManual)
            {
                DefaultManuals.Register(Library, ManualDrivers);
            }
        }
 private void UpdateControl()
 {
     switch (ToolbarMode)
     {
         default:
         case ListToolbarMode.Default:
             ShowCategory(DefaultCommands.Split(','));
             break;
         case ListToolbarMode.Cancel:
             ShowCategory("cancel");
             break;
         case ListToolbarMode.CancelDelete:
             ShowCategory("cancel", "delete");
             break;
     }
 }
示例#7
0
 public void Add(CommandInterpreter ci, DefaultCommands cmds)
 {
     foreach (DefaultCommands key in Enum.GetValues(typeof(DefaultCommands)))
     {
         IDisplayInfo item;
         if (key == (key & cmds) && _contents.TryGetValue(key, out item))
         {
             if (item is ICommandFilter)
             {
                 ci.AddFilter(item as ICommandFilter);
             }
             else if (item is ICommand)
             {
                 ci.AddCommand(item as ICommand);
             }
             else if (item is IOption)
             {
                 ci.AddOption(item as IOption);
             }
         }
     }
 }
示例#8
0
        /// <summary>Checks for updates.</summary>
        public void CheckForUpdate()
        {
            if (_working)
            {
                throw new InvalidOperationException("Another update process is already in progress.");
            }
            else if (_packagePath == null)
            {
                throw new InvalidOperationException("The source must be set before checking for updates.");
            }
            else if (!NetworkManager.IsURLFormatted(_packagePath.ToString()))
            {
                throw new UriFormatException("The source uri is not well formatted.");
            }
            else if (!NetworkManager.SourceExists(_packagePath.ToString()))
            {
                throw new FileNotFoundException("The remote source file is not found.");
            }
            else if (string.IsNullOrWhiteSpace(_downloadPath))
            {
                throw new NoNullAllowedException("The path is null or whitespace.");
            }

            if (_state != UpdateState.NotChecked)
            {
                throw new InvalidOperationException("Already checked for updates.");
            }

            if (UpdateRequired())
            {
                _state = UpdateState.Outdated;
            }
            else
            {
                _state = UpdateState.Updated;
            }

            DefaultCommands.Check(_executablePath, _packagePath.ToString());
        }
示例#9
0
 /// <summary>Extract the update package.</summary>
 public void Extract()
 {
     DefaultCommands.Extract(_packageDownloadPath, _downloadPath);
 }
示例#10
0
 static ChatManager()
 {
     root = DefaultCommands.GetCommands();
 }