public void ExecuteCommand(List <string> args, TTY io, UUID limitedToScene) { Action <List <string>, TTY, UUID> del; if (args.Count == 0) { return; } else if (args[0] == "help") { if (args.Count == 1) { var commands = new StringBuilder("Command list:\n"); SortedDictionary <string, Action <List <string>, TTY, UUID> > sorted = new SortedDictionary <string, Action <List <string>, TTY, UUID> >(Commands); foreach (string cmd in sorted.Keys) { commands.AppendFormat("{0}\n", cmd); } io.Write(commands.ToString()); return; } else { try { del = Commands[args[1]]; args.RemoveAt(1); } catch (Exception) { io.WriteFormatted("Invalid command '{0}' for help", args[1]); return; } } } else { try { del = Commands[args[0]]; } catch (Exception) { io.WriteFormatted("Invalid command '{0}'", args[0]); return; } } try { del(args, io, limitedToScene); } catch (Exception e) { io.WriteFormatted("Command execution error {0}: {1}", e.GetType().ToString(), e.ToString()); } }
private static void ShowPackageDetails(List <string> args, CmdIO.TTY io, UUID limitedToScene) { PackageDescription desc; if (limitedToScene != UUID.Zero) { io.Write("Not supported from limited console"); } else if (args[0] == "help" || args.Count < 3) { io.Write("show package <pkgname> - Show package details"); } else if (CoreUpdater.Instance.TryGetPackageDetails(args[2], out desc)) { var sb = new StringBuilder(); sb.AppendFormat("Package {0}\n", desc.Name); sb.Append("---------------------------------------------------------\n"); sb.AppendFormat("License: {0}\n", desc.License); sb.AppendFormat("Description:\n{0}\n", desc.Description); if (CoreUpdater.Instance.TryGetInstalledPackageDetails(args[2], out desc)) { sb.AppendFormat("Installed Version: {0}\n", desc.Version); } if (CoreUpdater.Instance.TryGetAvailablePackageDetails(args[2], out desc)) { sb.AppendFormat("Available Feed Version: {0}\n", desc.Version); } io.Write(sb.ToString()); } else { io.WriteFormatted("Package {0} not found.\n", args[2]); } }
private void RemoveCachedDnsCommand(List <string> args, CmdIO.TTY io, UUID limitedToScene) { if (args[0] == "help" || args.Count < 3) { io.Write("delete cacheddns <host>\nRemoves a DNS cache entry"); } else { if (DnsNameCache.RemoveCachedDnsEntry(args[2])) { io.WriteFormatted("DNS Entry {0} removed", args[2]); } else { io.WriteFormatted("DNS Entry {0} not found", args[2]); } } }
public void Command_Handler(List <string> args, TTY io, UUID limitedToScene) { Action <List <string>, TTY, UUID> del; if (args.Count < 3) { if (args[0] == "help") { var commands = new StringBuilder(m_Command + " command list:\n"); var sorted = new SortedDictionary <string, Action <List <string>, TTY, UUID> >(m_Dict); foreach (string cmd in sorted.Keys) { commands.AppendFormat("{0} {1}\n", m_Command, cmd); } io.Write(commands.ToString()); } else { io.Write("Invalid " + m_Command + " command"); } return; } try { del = m_Dict[args[2]]; } catch (Exception) { io.WriteFormatted("Unsupported {1} command '{0}'", args[1], m_Command); return; } try { del(args, io, limitedToScene); } catch (Exception e) { io.WriteFormatted("Command execution error {0}: {1}", e.GetType().ToString(), e.ToString()); } }
private static void UninstallPackageCommand(List <string> args, CmdIO.TTY io, UUID limitedToScene) { if (limitedToScene != UUID.Zero) { io.Write("Not supported from limited console"); } else if (args.Count < 2 || args[0] == "help") { io.Write("uninstall <package> - Uninstalls a package"); } else if (!CoreUpdater.Instance.InstalledPackages.ContainsKey(args[1])) { io.WriteFormatted("Package {0} is not installed.", args[1]); } else { CoreUpdater.Instance.UninstallPackage(args[1]); } }
private static void ShowThreadCountCommand(List <string> args, CmdIO.TTY io, UUID limitedToScene) { if (args[0] == "help") { io.Write("Show current thread count"); } else { int maxWorkerThreads; int maxCompletionThreads; int availWorkerThreads; int availCompletionThreads; ThreadPool.GetMaxThreads(out maxWorkerThreads, out maxCompletionThreads); ThreadPool.GetAvailableThreads(out availWorkerThreads, out availCompletionThreads); io.WriteFormatted("Threads: {0}\n\nSystem Threadpool:\nActive worker threads: {1} of {2}\nActive completion port threads: {3} of {4}", Process.GetCurrentProcess().Threads.Count, maxWorkerThreads - availWorkerThreads, maxWorkerThreads, maxCompletionThreads - availCompletionThreads, maxCompletionThreads); } }
private static void ShowMemoryCommand(List <string> args, CmdIO.TTY io, UUID limitedToScene) { if (args[0] == "help") { io.Write("Shows current memory usage by simulator"); } else { Process p = Process.GetCurrentProcess(); FormattedListBuilder b = new FormattedListBuilder(); const long MB_DIV = 1048576; b.AddColumn("", 20); b.AddColumn("Current (MB)", 15); b.AddColumn("Peak (MB)", 15); b.AddHeader(); b.AddSeparator(); b.AddData("GC Heap", (GC.GetTotalMemory(false) + MB_DIV - 1) / MB_DIV, ""); b.AddData("Process memory", (p.WorkingSet64 + MB_DIV - 1) / MB_DIV, (p.PeakWorkingSet64 + MB_DIV - 1) / MB_DIV); io.WriteFormatted(b.ToString()); } }