private void PrintListType(List <int> ColumnsMaxLengths) { EliteConsole.PrintInfo(Spacer); for (int i = 0; i < Columns.Count; i++) { EliteConsole.PrintInfo(Columns[i]); EliteConsole.PrintInfo(new String(' ', ColumnsMaxLengths[i] - Columns[i].Length + 1)); } EliteConsole.PrintInfoLine(); EliteConsole.PrintInfo(Spacer); for (int i = 0; i < Columns.Count; i++) { EliteConsole.PrintInfo(new String('-', Columns[i].Length)); EliteConsole.PrintInfo(new String(' ', ColumnsMaxLengths[i] - Columns[i].Length + 1)); } EliteConsole.PrintInfoLine(); foreach (List <string> row in Rows) { EliteConsole.PrintInfo(Spacer); for (int i = 0; i < row.Count; i++) { EliteConsole.PrintInfo(row[i]); EliteConsole.PrintInfo(new String(' ', ColumnsMaxLengths[i] - row[i].Length + 1)); } EliteConsole.PrintInfoLine(); } }
private void PrintParameterType(List <int> ColumnsMaxLengths) { EliteConsole.PrintInfo(Spacer); EliteConsole.PrintHighlightLine(this.Title); EliteConsole.PrintInfo(Spacer); EliteConsole.PrintInfoLine(new String('=', ColumnsMaxLengths.Sum() + Columns.Count - 1)); foreach (List <string> row in Rows) { EliteConsole.PrintInfo(Spacer); for (int i = 0; i < row.Count; i++) { EliteConsole.PrintInfo(row[i]); EliteConsole.PrintInfo(new String(' ', ColumnsMaxLengths[i] - row[i].Length + 1)); } EliteConsole.PrintInfoLine(); } }
public bool PrintEvent(EventModel theEvent, string Context = "*") { lock (_EventLock) { if (ContextMatches(theEvent, Context)) { EliteConsole.PrintInfoLine(); switch (theEvent.Level) { case EventLevel.Highlight: EliteConsole.PrintFormattedHighlightLine(theEvent.MessageHeader); break; case EventLevel.Info: EliteConsole.PrintFormattedInfoLine(theEvent.MessageHeader); break; case EventLevel.Warning: EliteConsole.PrintFormattedWarningLine(theEvent.MessageHeader); break; case EventLevel.Error: EliteConsole.PrintFormattedErrorLine(theEvent.MessageHeader); break; default: EliteConsole.PrintFormattedInfoLine(theEvent.MessageHeader); break; } if (!string.IsNullOrWhiteSpace(theEvent.MessageBody)) { EliteConsole.PrintInfoLine(theEvent.MessageBody); } return(true); } return(false); } }
public void Print() { // Ensure enough columns for given rows if (Rows.Count > 0) { while (Rows.Select(R => R.Count).Max() > Columns.Count) { Columns.Add(""); } // Shortens overly lengthy fields this.ShortenFields(); } // Calculate max Column Lengths List <int> ColumnsMaxLengths = Columns.Select(C => 0).ToList(); for (int i = 0; i < Rows.Count; i++) { for (int j = 0; j < Rows[i].Count; j++) { ColumnsMaxLengths[j] = Math.Max(ColumnsMaxLengths[j], Rows[i][j].Length); } } bool empty = !(ColumnsMaxLengths.Max() > 0); for (int i = 0; i < ColumnsMaxLengths.Count; i++) { // Remove empty columns, if it is not a completely empty menu if (ColumnsMaxLengths[i] == 0 && !empty) { Rows.ForEach(R => R.RemoveAt(i)); Columns.RemoveAt(i); ColumnsMaxLengths.RemoveAt(i); i--; } else { // Column name is the max, if longer than all the column's fields ColumnsMaxLengths[i] = Math.Max(ColumnsMaxLengths[i], Columns[i].Length); } } EliteConsole.PrintInfoLine(); EliteConsole.PrintInfoLine(); switch (this.MenuType) { case EliteConsoleMenuType.Menu: PrintMenuType(ColumnsMaxLengths); break; case EliteConsoleMenuType.Parameter: PrintParameterType(ColumnsMaxLengths); break; case EliteConsoleMenuType.List: PrintListType(ColumnsMaxLengths); break; } if (this.PrintEndBuffer) { EliteConsole.PrintInfoLine(); EliteConsole.PrintInfoLine(); } }
static void Main(string[] args) { CommandLineApplication app = new CommandLineApplication(); app.HelpOption("-? | -h | --help"); var UserNameOption = app.Option( "-u | --username <USERNAME>", "The UserName to login to the Covenant API.", CommandOptionType.SingleValue ); var PasswordOption = app.Option( "-p | --password <PASSWORD>", "The Password to login to the Covenant API.", CommandOptionType.SingleValue ); var HashOption = app.Option( "-h | --hash <HASH>", "The Covenant API certificate hash to trust.", CommandOptionType.SingleValue ); var ComputerNameOption = app.Option( "-c | --computername <COMPUTERNAME>", "The ComputerName (IPAddress or Hostname) to bind the Covenant API to.", CommandOptionType.SingleValue ); app.OnExecute(() => { string username = UserNameOption.Value(); string password = PasswordOption.Value(); string computername = ComputerNameOption.Value(); string hash = HashOption.Value(); try { if (!ComputerNameOption.HasValue()) { EliteConsole.PrintHighlight("Covenant ComputerName: "); computername = EliteConsole.Read(); } EliteConsole.PrintFormattedHighlightLine("Connecting to Covenant..."); Elite elite = new Elite(new Uri("https://" + computername + ":7443")); bool connected = elite.Connect(); if (!connected) { EliteConsole.PrintFormattedErrorLine("Could not connect to Covenant at: " + computername); if (computername.ToLower() == "localhost" || computername == "127.0.0.1") { EliteConsole.PrintFormattedErrorLine("Are you using Docker? Elite cannot connect over the loopback address while using Docker, because Covenant is not running within the Elite docker container."); } return(-1); } if (!UserNameOption.HasValue()) { EliteConsole.PrintHighlight("Username: "******"Password: "******"Covenant CertHash (Empty to trust all): "); hash = EliteConsole.Read(); } EliteConsole.PrintFormattedHighlightLine("Logging in to Covenant..."); bool login = elite.Login(username, password, hash); if (login) { elite.Launch(); elite.CancelEventPoller.Cancel(); } else { EliteConsole.PrintFormattedErrorLine("Covenant login failed. Check your username and password again."); EliteConsole.PrintFormattedErrorLine("Incorrect password for user: "******"SocketException") { EliteConsole.PrintFormattedErrorLine("Could not connect to Covenant at: " + computername); if (computername.ToLower() == "localhost" || computername == "127.0.0.1") { EliteConsole.PrintFormattedErrorLine("Are you using Docker? Elite cannot connect over the loopback address while using Docker, because Covenant is not running within the Elite docker container."); } return(-1); } catch (HttpRequestException e) when(e.InnerException.GetType().Name == "AuthenticationException") { EliteConsole.PrintFormattedErrorLine("Covenant certificate does not match: " + hash); return(-2); } catch (HttpRequestException) { EliteConsole.PrintFormattedErrorLine("Covenant login failed. Check your username and password again."); EliteConsole.PrintFormattedErrorLine("Incorrect password for user: "******"Unknown Exception Occured: " + e.Message + Environment.NewLine + e.StackTrace); return(-4); } return(0); }); app.Execute(args); }