public string ToCsv() { var stringBuilder = new StringBuilder(); if (Items.Count == 0) { return(""); } var s = ""; var filteredPropertyNames = FilterProperties(); foreach (var property in filteredPropertyNames) { var headerName = property.Name; if (ColumnNameOverrides.ContainsKey(property.Name)) { headerName = ColumnNameOverrides[property.Name]; } s += $"{headerName.ToCsv()},"; } s = s.Remove(s.Length - 1); stringBuilder.AppendLine(s); foreach (var row in Items) { s = (from property in filteredPropertyNames select GetValue(row, property)).Aggregate("", (current, value) => current + $"{value.ToCsv()},"); s = s.Remove(s.Length - 1); stringBuilder.AppendLine(s); } return(stringBuilder.ToString()); }
public string ToHtml() { var stringBuilder = new StringBuilder(); if (Items.Count == 0) { return(""); } stringBuilder.AppendLine("<table style=\"border-collapse: collapse; width: 100%;\">"); stringBuilder.AppendLine("<tr>"); var filteredPropertyNames = FilterProperties(); foreach (var property in filteredPropertyNames) { var headerName = property.Name; if (ColumnNameOverrides.ContainsKey(property.Name)) { headerName = ColumnNameOverrides[property.Name]; } stringBuilder.AppendLine( $"<th style=\"text-align: center; background-color: #04163d; color: white;padding: 4px;border: 1px solid #dddddd; font-family:monospace; font-size: 14px;\">{headerName.ToHtml()}</th>"); } stringBuilder.AppendLine("</tr>"); var rowNumber = 1; for (var index = 0; index < Items.Count; index++) { var row = Items[index]; stringBuilder.AppendLine("<tr>"); foreach (var property in filteredPropertyNames) { var color = rowNumber % 2 == 0 ? "#f2f2f2" : "white"; var value = property.Name == Options.KeyName ? ObjectToString(Keys[index]) : GetValue(row, property); stringBuilder.AppendLine( $"<td style=\"text-align: right; color: black; background-color: {color};padding: 4px;border: 1px solid #dddddd; font-family:monospace; font-size: 14px;\">{value.ToHtml()}</td>"); } rowNumber++; stringBuilder.AppendLine("</tr>"); } stringBuilder.AppendLine("</table>"); return(stringBuilder.ToString()); }
public string ToCsv() { var stringBuilder = new StringBuilder(); if (Items.Count == 0) { return(""); } var s = ""; var filteredPropertyNames = FilterProperties(); foreach (var property in filteredPropertyNames) { var headerName = property.Name; if (ColumnNameOverrides.ContainsKey(property.Name)) { headerName = ColumnNameOverrides[property.Name]; } s += $"{headerName.ToCsv()},"; } s = s.Remove(s.Length - 1); stringBuilder.AppendLine(s); for (var i = 0; i < Items.Count; i++) { var row = Items[i]; s = ""; foreach (var t in filteredPropertyNames) { if (t.Name == Options.KeyName) { var keyValueParsed = ObjectToString(Keys[i]); s += $"{keyValueParsed.ToCsv()},"; } else { var property = t; var s1 = GetValue(row, property); s += $"{s1.ToCsv()},"; } } s = s.Remove(s.Length - 1); stringBuilder.AppendLine(s); } return(stringBuilder.ToString()); }
private static PetaPoco.Sql BuildWhereCondition(PetaPoco.Sql sql, WorkUnitQueryParameter parameter) { string format = "[{0}] {1} @0"; if (parameter.Column.Equals(WorkUnitRowColumn.Assigned) || parameter.Column.Equals(WorkUnitRowColumn.Finished)) { format = "datetime([{0}]) {1} datetime(@0)"; } sql = sql.Append(String.Format(CultureInfo.InvariantCulture, format, ColumnNameOverrides.ContainsKey(parameter.Column) ? ColumnNameOverrides[parameter.Column] : parameter.Column.ToString(), parameter.GetOperatorString()), parameter.Value); return(sql); }
public string ToMarkDown() { if (Items.Count == 0) { return(""); } var stringBuilder = new StringBuilder(); var s = "|"; var filteredPropertyNames = FilterProperties(); foreach (var property in filteredPropertyNames) { var headerName = property.Name; if (ColumnNameOverrides.ContainsKey(property.Name)) { headerName = ColumnNameOverrides[property.Name]; } var length = MaxWidth[property.Name] - headerName.Length; s += $" {headerName.ToValidOutput()}{new string(' ', length)} |"; } stringBuilder.AppendLine(s); s = "|"; foreach (var property in filteredPropertyNames) { var columnSeparator = $" {new string('-', MaxWidth[property.Name])} |"; if (ColumnTextJustification.ContainsKey(property.Name)) { switch (ColumnTextJustification[property.Name]) { case TextJustification.Centered: columnSeparator = columnSeparator.Replace("- ", ": "); columnSeparator = columnSeparator.Replace(" -", " :"); break; case TextJustification.Right: columnSeparator = columnSeparator.Replace("- ", ": "); break; case TextJustification.Left: columnSeparator = columnSeparator.Replace(" -", " :"); break; case TextJustification.Justified: break; default: throw new ArgumentOutOfRangeException(); } } s += columnSeparator; } stringBuilder.AppendLine(s); for (var i = 0; i < Items.Count; i++) { var row = Items[i]; s = "|"; foreach (var property in filteredPropertyNames) { if (property.Name == Options.KeyName) { var keyValueParsed = ObjectToString(Keys[i]); var length = MaxWidth[property.Name] - keyValueParsed.Length; s += $" {keyValueParsed.ToValidOutput()}{new string(' ', length)} |"; } else { var value = GetValue(row, property); var length = MaxWidth[property.Name] - value.Length; s += $" {value.ToValidOutput()}{new string(' ', length)} |"; } } stringBuilder.AppendLine(s); } stringBuilder.AppendLine(); return(stringBuilder.ToString()); }
public override string ToString() { if (Items.Count == 0) { return(""); } var s = "|"; var stringBuilder = new StringBuilder(); var filteredPropertyNames = FilterProperties(); foreach (var property in filteredPropertyNames) { var headerName = property.Name; if (ColumnNameOverrides.ContainsKey(property.Name)) { headerName = ColumnNameOverrides[property.Name]; } var length = MaxWidth[property.Name] - headerName.Length; var totalLength = $"{new string(' ', length)}{headerName.ToValidOutput()}".Length; var remaining = totalLength - $"{new string(' ', length / 2)}{headerName.ToValidOutput()}".Length; s += $" {new string(' ', length / 2)}{headerName.ToValidOutput()}{new string(' ', remaining)} |"; } stringBuilder.AppendLine(s); s = filteredPropertyNames.Aggregate("|", (current, name) => current + $" {new string('-', MaxWidth[name.Name])} |"); stringBuilder.AppendLine(s); for (var index = 0; index < Items.Count; index++) { var row = Items[index]; stringBuilder.Append("|"); foreach (var property in filteredPropertyNames) { if (property.Name == Options.KeyName) { var keyValueParsed = ObjectToString(Keys[index]); var lengthParsed = MaxWidth[property.Name] - keyValueParsed.Length; if (ColumnTextJustification.ContainsKey(property.Name)) { switch (ColumnTextJustification[property.Name]) { case TextJustification.Centered: var totalLength = $"{new string(' ', lengthParsed)}{keyValueParsed.ToValidOutput()}" .Length; var remaining = totalLength - $"{new string(' ', lengthParsed / 2)}{keyValueParsed.ToValidOutput()}".Length; stringBuilder.Append(' '); stringBuilder.Append($"{new string(' ', lengthParsed / 2)}{keyValueParsed.ToValidOutput()}{new string(' ', remaining)}"); stringBuilder.Append(" |"); break; case TextJustification.Right: stringBuilder.Append(' '); stringBuilder.Append($"{new string(' ', lengthParsed)}{keyValueParsed.ToValidOutput()}"); stringBuilder.Append(" |"); break; case TextJustification.Left: stringBuilder.Append(' '); stringBuilder.Append($"{keyValueParsed.ToValidOutput()}{new string(' ', lengthParsed)}"); stringBuilder.Append(" |"); break; case TextJustification.Justified: stringBuilder.Append(' '); stringBuilder.Append($"{keyValueParsed.ToValidOutput()}{new string(' ', lengthParsed)}"); stringBuilder.Append(" |"); break; default: throw new ArgumentOutOfRangeException(); } } else { stringBuilder.Append(' '); stringBuilder.Append($"{keyValueParsed.ToValidOutput()}{new string(' ', lengthParsed)}"); stringBuilder.Append(" |"); } } else { var value = GetValue(row, property); var length = MaxWidth[property.Name] - value.Length; if (ColumnTextJustification.ContainsKey(property.Name)) { switch (ColumnTextJustification[property.Name]) { case TextJustification.Centered: var totalLength = $"{new string(' ', length)}{value.ToValidOutput()}".Length; var remaining = totalLength - $"{new string(' ', length / 2)}{value.ToValidOutput()}".Length; stringBuilder.Append(' '); stringBuilder.Append($"{new string(' ', length / 2)}{value.ToValidOutput()}{new string(' ', remaining)}"); stringBuilder.Append(" |"); break; case TextJustification.Right: stringBuilder.Append(' '); stringBuilder.Append($"{new string(' ', length)}{value.ToValidOutput()}"); stringBuilder.Append(" |"); break; case TextJustification.Left: stringBuilder.Append(' '); stringBuilder.Append($"{value.ToValidOutput()}{new string(' ', length)}"); stringBuilder.Append(" |"); break; case TextJustification.Justified: stringBuilder.Append(' '); stringBuilder.Append($"{value.ToValidOutput()}{new string(' ', length)}"); stringBuilder.Append(" |"); break; default: throw new ArgumentOutOfRangeException(); } } else { stringBuilder.Append(' '); stringBuilder.Append($"{value.ToValidOutput()}{new string(' ', length)}"); stringBuilder.Append(" |"); } } } stringBuilder.Append(Environment.NewLine); } stringBuilder.AppendLine(); return(stringBuilder.ToString()); }
public string ToHtml() { var stringBuilder = new StringBuilder(); if (Items.Count == 0) { return(""); } stringBuilder.AppendLine("<table style=\"border-collapse: collapse; width: 100%;\">"); stringBuilder.AppendLine("<tr>"); var filteredPropertyNames = FilterProperties(); foreach (var property in filteredPropertyNames) { var headerName = property.Name; if (ColumnNameOverrides.ContainsKey(property.Name)) { headerName = ColumnNameOverrides[property.Name]; } stringBuilder.AppendLine( $"<th style=\"text-align: center; background-color: #04163d; color: white;padding: 4px;border: 1px solid #dddddd; font-family:monospace; font-size: 14px;\">{headerName.ToHtml()}</th>"); } stringBuilder.AppendLine("</tr>"); var rowNumber = 1; foreach (var row in Items) { stringBuilder.AppendLine("<tr>"); foreach (var property in filteredPropertyNames) { var value = GetValue(row, property); var color = rowNumber % 2 == 0 ? "#f2f2f2" : "white"; if (Operation != null && Operation.ContainsKey(property.Name)) { foreach (var item in Operation[property.Name]) { switch (item.Type) { case HighlightType.Decimal: try { var parsed = decimal.Parse(value.Trim()); foreach (var num in item.DecimalValue) { switch (item.Operation) { case HighlightOperation.Differences when decimal.Compare(Math.Round(parsed, Options.NumberDecimals), Math.Round(num, Options.NumberDecimals)) != 0: color = "#f9f948"; break; case HighlightOperation.Differences: color = "#f9f948"; break; case HighlightOperation.Equality: { if (decimal.Compare(Math.Round(parsed, Options.NumberDecimals), Math.Round(num, Options.NumberDecimals)) == 0) { color = "#f9f948"; } break; } default: throw new ArgumentOutOfRangeException( $"Unrecognized operation {item.Operation}"); } } } catch { // do nothing } break; case HighlightType.String: try { foreach (var str in item.StringValue) { switch (item.Operation) { case HighlightOperation.Differences when value.Trim() != str: color = "#f9f948"; break; case HighlightOperation.Differences: color = "#f9f948"; break; case HighlightOperation.Equality: { if (value.Trim() == str) { color = "#f9f948"; } break; } default: throw new ArgumentOutOfRangeException( $"Unrecognized operation {item.Operation}"); } } } catch { // do nothing } break; default: throw new ArgumentOutOfRangeException($"Unrecognized type {item.Type}"); } } } stringBuilder.AppendLine( $"<td style=\"text-align: right; color: black; background-color: {color};padding: 4px;border: 1px solid #dddddd; font-family:monospace; font-size: 14px;\">{value.ToHtml()}</td>"); } rowNumber++; stringBuilder.AppendLine("</tr>"); } stringBuilder.AppendLine("</table>"); return(stringBuilder.ToString()); }
public string ToSpecFlowString() { if (Items.Count == 0) { return(string.Empty); } var s = "|"; var sb = new StringBuilder(); var filteredPropertyNames = FilterProperties(); foreach (var property in filteredPropertyNames) { var headerName = property.Name; if (ColumnNameOverrides.ContainsKey(property.Name)) { headerName = ColumnNameOverrides[property.Name]; } var length = MaxWidth[property.Name] - headerName.Length; var header = headerName.ToValidOutput(); var totalLength = $"{new string(' ', length)}{header}".Length; var remaining = totalLength - $"{new string(' ', length / 2)}{header}".Length; s += $" {new string(' ', length / 2)}{header}{new string(' ', remaining)} |"; } sb.AppendLine(s); foreach (var row in Items) { sb.Append('|'); foreach (var property in filteredPropertyNames) { var value = GetValue(row, property); var length = MaxWidth[property.Name] - value.Length; var output = value.ToValidOutput(); if (ColumnTextJustification.ContainsKey(property.Name)) { switch (ColumnTextJustification[property.Name]) { case TextJustification.Centered: var totalLength = $"{new string(' ', length)}{output}".Length; var remaining = totalLength - $"{new string(' ', length / 2)}{output}".Length; sb.Append(' '); sb.Append($"{new string(' ', length / 2)}{output}{new string(' ', remaining)}"); sb.Append(" |"); break; case TextJustification.Right: sb.Append(' '); sb.Append($"{new string(' ', length)}{output}"); sb.Append(" |"); break; case TextJustification.Left: sb.Append(' '); sb.Append($"{output}{new string(' ', length)}"); sb.Append(" |"); break; case TextJustification.Justified: sb.Append(' '); sb.Append($"{output}{new string(' ', length)}"); sb.Append(" |"); break; default: throw new ArgumentOutOfRangeException(); } } else { sb.Append(' '); sb.Append($"{output}{new string(' ', length)}"); sb.Append(" |"); } } sb.Append(Environment.NewLine); } sb.AppendLine(""); return(sb.ToString()); }
public void ToConsole() { if (Items.Count == 0) { return; } var s = "|"; var filteredPropertyNames = FilterProperties(); foreach (var property in filteredPropertyNames) { var headerName = property.Name; if (ColumnNameOverrides.ContainsKey(property.Name)) { headerName = ColumnNameOverrides[property.Name]; } var length = MaxWidth[property.Name] - headerName.Length; var header = headerName.ToValidOutput(); var totalLength = $"{new string(' ', length)}{header}".Length; var remaining = totalLength - $"{new string(' ', length / 2)}{header}".Length; s += $" {new string(' ', length / 2)}{header}{new string(' ', remaining)} |"; } Console.WriteLine(s); s = filteredPropertyNames.Aggregate("|", (current, name) => current + $" {new string('-', MaxWidth[name.Name])} |"); Console.WriteLine(s); foreach (var row in Items) { Console.Write("|"); foreach (var property in filteredPropertyNames) { var value = GetValue(row, property); var length = MaxWidth[property.Name] - value.Length; var output = value.ToValidOutput(); if (ColumnTextJustification.ContainsKey(property.Name)) { switch (ColumnTextJustification[property.Name]) { case TextJustification.Centered: var totalLength = $"{new string(' ', length)}{output}".Length; var remaining = totalLength - $"{new string(' ', length / 2)}{output}".Length; ConsoleRender($"{new string(' ', length / 2)}{output}{new string(' ', remaining)}", property.Name); break; case TextJustification.Right: ConsoleRender($"{new string(' ', length)}{output}", property.Name); break; case TextJustification.Left: ConsoleRender($"{output}{new string(' ', length)}", property.Name); break; case TextJustification.Justified: ConsoleRender($"{output}{new string(' ', length)}", property.Name); break; default: throw new ArgumentOutOfRangeException(); } } else { ConsoleRender($"{output}{new string(' ', length)}", property.Name); } } Console.Write(Environment.NewLine); } Console.WriteLine(); }