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); } }
public ParseCommands(DragonChat chat) { _chat = chat; adminCommands = new AdminCommands(chat); userCommands = new UserCommands(chat); defaultCommands = new DefaultCommands(chat); }
/// <summary>Download the update package.</summary> public void Download() { Package _package = new Package(_packagePath.ToString()); _state = UpdateState.Downloading; DefaultCommands.Download(_package.Download, _packageDownloadPath); }
/// <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; } }
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); } } } }
/// <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()); }
/// <summary>Extract the update package.</summary> public void Extract() { DefaultCommands.Extract(_packageDownloadPath, _downloadPath); }
static ChatManager() { root = DefaultCommands.GetCommands(); }