public void Example3() { var objects = new[] { new { MachineName = "ctxtest01", Ip = "10.0.0.10", Ports = new[] { 80, 8080, 9090 }, Comments = "" }, new { MachineName = "ctxtest02", Ip = "10.0.0.11", Ports = new[] { 5432 }, Comments = @"This bad boy hosts our database and a couple of internal jobs." } }; var hints = new Hints { MaxTableWidth = 80 }; var formatter = new TableFormatter(hints); var text = formatter.FormatObjects(objects); Console.WriteLine(text); /* * * ==================================================================================== | MachineName | Ip | Ports | Comments | | ==================================================================================== | ctxtest01 | 10.0.0.10 | 80 | | | | | 8080 | | | | | 9090 | | | ==================================================================================== | ctxtest02 | 10.0.0.11 | 5432 | This bad boy hosts our database and a couple | | | | | of internal jobs. | | ==================================================================================== | */ }
public async Task <string> GetTopByProperties( [FromQuery] string city = "amsterdam", [FromQuery] int limit = 10, [FromQuery] string[]?extras = null) { extras ??= new string[0]; // We are fetching a lot of duplicate entries because the second query // (properties with garden) will return a subset of objects already available in the // initial query. However, becuase the property entity does not contain info whether // it has a garden or not, we need to make fetch them separately (instead of doing // client side filtering) // Since fetching this from Funda requires walking over all the available data, we // cache the results based on `city` and `extras`. We don't cache based on `limit` // because we need to fetch all the properties anyway regardless of client requested // limit. var cacheKey = (city, extras); if (!cache.TryGetValue(cacheKey, out List <Agent> agents)) { agents = await repository.ListTopAgentsByProperties(city, extras); var cacheEntryOptions = new MemoryCacheEntryOptions() .SetAbsoluteExpiration(TimeSpan.FromDays(1)); cache.Set(cacheKey, agents, cacheEntryOptions); } var tableFormatter = new TableFormatter(); return(tableFormatter.FormatObjects(agents.Take(limit))); }
public void CanFormatAsTableWithTwoColumns() { var tableFormatter = new TableFormatter(); var text = tableFormatter.FormatObjects(new[] { new { FirstColumn = "r1", SecondColumn = "hej" }, new { FirstColumn = "r2", SecondColumn = "hej" }, new { FirstColumn = "r3", SecondColumn = "hej" }, new { FirstColumn = "r4", SecondColumn = "hej" } }); Console.WriteLine(text); const string expected = @" +-------------+--------------+ | FirstColumn | SecondColumn | +-------------+--------------+ | r1 | hej | +-------------+--------------+ | r2 | hej | +-------------+--------------+ | r3 | hej | +-------------+--------------+ | r4 | hej | +-------------+--------------+ "; Assert.That(text.Normalized(), Is.EqualTo(expected.Normalized())); }
public void CanCollapseTable() { var objects = new[] { new { Id = "whatever01", Value = "jigeojgieojw" }, new { Id = "whatever02", Value = "huiehguiw" }, new { Id = "whatever03", Value = "nvnjkdnjkdsjkvds" }, new { Id = "whatever04", Value = "fjeiufhweui" } }; var formatter = new TableFormatter(new Hints { CollapseVerticallyWhenSingleLine = true }); var text = formatter.FormatObjects(objects); Console.WriteLine(text); Assert.That(text.Normalized(), Is.EqualTo(@" +------------+------------------+ | Id | Value | +------------+------------------+ | whatever01 | jigeojgieojw | | whatever02 | huiehguiw | | whatever03 | nvnjkdnjkdsjkvds | | whatever04 | fjeiufhweui | +------------+------------------+ ".Normalized())); }
public void DoesNotCollapseWhenCellHasMoreLines() { var objects = new[] { new { Id = "whatever01", Value = "jigeojgieojw" }, new { Id = "whatever02", Value = @"huiehguiw ruined the party!" }, }; var formatter = new TableFormatter(new Hints { CollapseVerticallyWhenSingleLine = true }); var text = formatter.FormatObjects(objects); Console.WriteLine(text); Assert.That(text.Normalized(), Is.EqualTo(@" +------------+-------------------+ | Id | Value | +------------+-------------------+ | whatever01 | jigeojgieojw | +------------+-------------------+ | whatever02 | huiehguiw | | | ruined the party! | +------------+-------------------+ ".Normalized())); }
public void Example3_WithoutHint() { var objects = new[] { new { MachineName = "ctxtest01", Ip = "10.0.0.10", Ports = new[] { 80, 8080, 9090 }, Comments = "" }, new { MachineName = "ctxtest02", Ip = "10.0.0.11", Ports = new[] { 5432 }, Comments = @"This bad boy hosts our database and a couple of internal jobs." } }; var formatter = new TableFormatter(); var text = formatter.FormatObjects(objects); Console.WriteLine(text); /* * +----------------------------------------------------------------+-----------+-------------+-------+ | Comments | Ip | MachineName | Ports | +----------------------------------------------------------------+-----------+-------------+-------+ | | 10.0.0.10 | ctxtest01 | 80 | | | | | 8080 | | | | | 9090 | +----------------------------------------------------------------+-----------+-------------+-------+ | This bad boy hosts our database and a couple of internal jobs. | 10.0.0.11 | ctxtest02 | 5432 | +----------------------------------------------------------------+-----------+-------------+-------+ | */ }
public void CanFormatAsTableWithCellWithMultipleLines() { var tableFormatter = new TableFormatter(); var text = tableFormatter.FormatObjects(new[] { new { FirstColumn = @"This is the first line This is the second line And this is the third and last line" } }); Console.WriteLine(text); const string expected = @" +-------------------------------------+ | FirstColumn | +-------------------------------------+ | This is the first line | | This is the second line | | And this is the third and last line | +-------------------------------------+ "; Assert.That(text.Normalized(), Is.EqualTo(expected.Normalized())); }
public void CanFormatAsTableWithThreeColumns() { var tableFormatter = new TableFormatter(); var objects = new[] { new { FirstColumn = "r1", SecondColumn = "hej", ThirdColumn = "hej igen" }, new { FirstColumn = "r2", SecondColumn = "hej", ThirdColumn = "hej igen" }, }; var text = tableFormatter.FormatObjects(objects); Console.WriteLine(text); const string expected = @" +-------------+--------------+-------------+ | FirstColumn | SecondColumn | ThirdColumn | +-------------+--------------+-------------+ | r1 | hej | hej igen | +-------------+--------------+-------------+ | r2 | hej | hej igen | +-------------+--------------+-------------+ "; Assert.That(text.Normalized(), Is.EqualTo(expected.Normalized())); }
/// <summary> /// Renders a string that displays data from the properties of the given <paramref name="rows"/> /// in tabular form /// </summary> public static string ToTable(this IEnumerable rows) { if (rows == null) { throw new ArgumentNullException(nameof(rows)); } return(TableFormatter.FormatObjects(rows)); }
public static void DumpDirectoryContentsToConsole(this DirectoryInfo directoryInfo) { var files = directoryInfo.GetFiles() .Select(file => new { FilePath = file, Length = file.Length, Size = file.Length.FormatAsHumanReadableSize() }) .ToList(); Console.WriteLine($@"Listing directory {directoryInfo.FullName}: {DirectoryFormatter.FormatObjects(files)} "); }
public ConsoleWriter() { ReceiveAny(msg => { System.Threading.Thread.Sleep(250); var serializedObject = _tf.FormatObjects(new[] { msg }); var isError = serializedObject.Contains("broken"); var output = isError ? Console.Error : Console.Out; output.WriteLine(msg.GetType().Name); output.WriteLine(serializedObject); }); }
public void Example1() { var tableFormatter = new TableFormatter(); var objects = new[] { new { FirstColumn = "r1", SecondColumn = "hej", ThirdColumn = "hej igen" }, new { FirstColumn = "r2", SecondColumn = "hej", ThirdColumn = "hej igen" }, }; var text = tableFormatter.FormatObjects(objects); Console.WriteLine(text); }
public void CanFormatAsTableWithCellWiderThanColumnLabel() { var tableFormatter = new TableFormatter(); var text = tableFormatter.FormatObjects(new[] { new { FirstColumn = "This is a fairly long text" } }); Console.WriteLine(text); const string expected = @" +----------------------------+ | FirstColumn | +----------------------------+ | This is a fairly long text | +----------------------------+ "; Assert.That(text.Normalized(), Is.EqualTo(expected.Normalized())); }
public void PrintExamples() { var formatter = new TableFormatter(new Hints { CollapseVerticallyWhenSingleLine = true }); var positions = Enumerable.Range(0, 10) .SelectMany(fileNumber => Enumerable.Range(0, 100).Select(bytePosition => new{ fileNumber, bytePosition })) .Select(a => new KafkaesquePosition(a.fileNumber, a.bytePosition)) .Select(p => { var position = p.ToPosition("topic", 0); var roundtrippedKafkaesquePosition = position.ToKafkaesquePosition(); return(new { KafkaesquePosition = p, Position = position, RoundtrippedKafkaesquePosition = roundtrippedKafkaesquePosition }); }); Console.WriteLine(formatter.FormatObjects(positions)); }
public void SimplePaddingTest_TwoColumns() { var tableFormatter = new TableFormatter(); var objects = new[] { new { A = "A", B = "B" } }; var text = tableFormatter.FormatObjects(objects); Console.WriteLine(text); const string expected = @" +---+---+ | A | B | +---+---+ | A | B | +---+---+ "; Assert.That(text.Normalized(), Is.EqualTo(expected.Normalized())); }
protected void PrintTable(IEnumerable objects) { Console.WriteLine(Formatter.FormatObjects(objects)); }
public void CrearTxt(string ventas) { var numeroVentas = ventas.Split(','); VentaMinorista ventaInDB = new VentaMinorista(); VentaMinoristaReporte reporteTemp = new VentaMinoristaReporte(); List <VentaMinoristaReporte> ventaReporte = new List <VentaMinoristaReporte>(); foreach (var item in numeroVentas) { if (item != string.Empty) { ventaInDB = ventaMinoristaBL.GetVentaMinoristaByNumeroVenta(int.Parse(item)); //Guardamos los datos necesarios para el reporte reporteTemp = new VentaMinoristaReporte(); reporteTemp.ID = ventaInDB.ID; reporteTemp.Fecha = ventaInDB.Fecha.Date.ToString("dd/MM/yyyy"); reporteTemp.Local = ventaInDB.Local; reporteTemp.Importe_Informe_Z = String.Format("{0:c}", ventaInDB.ImporteInformeZ); reporteTemp.IVA = Constants.IVA; reporteTemp.Importe_IVA = String.Format("{0:c}", ventaInDB.ImporteIva); reporteTemp.Factura_N = ventaInDB.NumFactura; reporteTemp.Tipo_Factura = ventaInDB.TipoFactura; reporteTemp.Primer_Numero_Tic = ventaInDB.PrimerNumeroTicket; reporteTemp.Ultimo_Numero_Tic = ventaInDB.UltimoNumeroTicket; ventaReporte.Add(reporteTemp); } } using (StringWriter sw = new StringWriter()) { using (HtmlTextWriter hw = new HtmlTextWriter(sw)) { StringBuilder sb = new StringBuilder(); var tableFormatter = new TableFormatter(); //List<VentaMinoristaReporte> listaModif = new List<VentaMinoristaReporte>(); //foreach (var venta in ventaReporte) //{ // var obj = new VentaMinoristaReporte() // { // ID = venta.ID, // Fecha = venta.Fecha.Date, // Local = venta.Local, // Importe_Informe_Z = venta.Importe_Informe_Z, // IVA = venta.IVA, // Importe_IVA = venta.Importe_IVA, // Factura_N = venta.Factura_N, // Tipo_Factura = venta.Tipo_Factura, // Primer_Numero_Tic = venta.Primer_Numero_Tic, // Ultimo_Numero_Tic = venta.Ultimo_Numero_Tic // }; // listaModif.Add(obj); //} sb.Append(tableFormatter.FormatObjects(ventaReporte)); //Export HTML String as PDF. StringReader sr = new StringReader(sb.ToString()); string fecha = string.Format("{0}{1}{2}", DateTime.Now.Date.Day, DateTime.Now.Date.Month, DateTime.Now.Date.Year); HttpContext.Current.Response.ContentType = "text/plain"; HttpContext.Current.Response.AddHeader("content-disposition", "attachment;filename=ReporteVenta_" + fecha + ".txt"); HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache); HttpContext.Current.Response.Write(sb.ToString()); HttpContext.Current.Response.End(); } } }
static void PrintStats(ProfileLog log) { var formatter = new TableFormatter(); Console.WriteLine(); Console.WriteLine(); var frames = log.Frames.Skip(2).Where(f => f.Calls.Length != 0); var frameTimes = frames.Where(f => f.RawTime > 0).Select(f => f.RawTime).ToArray(); Array.Sort(frameTimes); var avgFrameMs = frameTimes.Average() / 1000.0; var medianFrameMs = frameTimes.Median() / 1000.0; var percentile90 = frameTimes.Take((int)(frameTimes.Length * 0.90)).Average() / 1000.0; var toppercentile90 = frameTimes.Skip((int)(frameTimes.Length * 0.90)).Average() / 1000.0; var top1percent = frameTimes.Skip((int)(frameTimes.Length * 0.99)).Average() / 1000.0; Console.WriteLine($"FrameTime Avg: {avgFrameMs:F3} Median: {medianFrameMs:F3} top 10%: {toppercentile90:F3}\n"); var gcframes = frames.Select(f => (f.MainThread?.GCTime ?? 0) * 10.0 / 1000.0).ToList(); var maxFrameStep = gcframes.OrderByDescending(t => t).ToList(); if (log.WaitForGCJobId != -1) { PrintNode(log.NodeStatsLookup[log.WaitForGCJobId], "WaitForGC"); var gcTimesFull = log.GetNodeTimes(log.WaitForGCJobId); Array.Sort(gcTimesFull); var gcTimes = gcTimesFull.SkipWhile(t => t == 0).ToArray(); var gcMedian = gcTimes.Median() * 10 / 1000.0; var gcVariance = gcTimes.Variance() * 10 / 1000.0; var gc90avg = gcTimes.Skip((int)(gcTimes.Length * 0.90)).Average() * 10 / 1000.0; var gc99avg = gcTimes.Skip((int)(gcTimes.Length * 0.99)).Average() * 10 / 1000.0; } if (log.WaitForGPUId != -1) { PrintNode(log.NodeStatsLookup[log.WaitForGPUId], "WaitForGPU"); } var top15 = log.NodeStats. OrderByDescending(n => n.AvgExclusiveTime). Take(15). Select(n => new { Name = n.Name, AvgTime = n.AvgExclusiveTime, PeakAvg = n.MaxAvgExclusiveTime, TotalTime = n.TotalExclusiveTime, Calls = n.CallCount, }); Console.Write(formatter.FormatObjects(top15)); }
public async Task Search( [Summary("The user whose infractions are to be displayed.")] IGuildUser subject) { var infractions = await _moderationService.SearchInfractionsAsync( new InfractionSearchCriteria { GuildId = subject.GuildId, SubjectId = subject.Id, IsDeleted = false }, new[] { new SortingCriteria { PropertyName = "CreateAction.Created", Direction = SortDirection.Descending } }); if (infractions.Count == 0) { await ReplyAsync(Format.Code("No infractions")); return; } var hints = new Hints { MaxTableWidth = 100 }; var formatter = new TableFormatter(hints); var tableText = formatter.FormatObjects(infractions.Select(infraction => new { Id = infraction.Id, Created = infraction.CreateAction.Created.ToUniversalTime().ToString("yyyy MMM dd HH:mm"), Type = infraction.Type.ToString(), Subject = infraction.Subject.Username, Creator = infraction.CreateAction.CreatedBy.DisplayName, State = (infraction.RescindAction != null) ? "Rescinded" : (infraction.Expires != null) ? "Will Expire" : "Active", Reason = infraction.Reason })); var replyBuilder = new StringBuilder(); foreach (var line in tableText.Split("\r\n")) { if ((replyBuilder.Length + line.Length) > 1998) { await ReplyAsync(Format.Code(replyBuilder.ToString())); replyBuilder.Clear(); } replyBuilder.AppendLine(line); } if (replyBuilder.Length > 0) { await ReplyAsync(Format.Code(replyBuilder.ToString())); } }
public void CrearTxtCompra(string compra) { var numeroCompra = compra.Split(','); Compra compraInDB = new Compra(); CompraReporte reporteTemp = new CompraReporte(); List <CompraReporte> compraReporte = new List <CompraReporte>(); foreach (var item in numeroCompra) { if (item != string.Empty) { compraInDB = compraBL.GetCompraByNumeroCompra(int.Parse(item)); //Guardamos los datos necesarios para el reporte reporteTemp = new CompraReporte(); reporteTemp.ID = compraInDB.NumeroCompra; reporteTemp.Nombre = compraInDB.Proveedor.Nombre; reporteTemp.Cuit = compraInDB.Proveedor.Cuit; reporteTemp.Iibb = compraInDB.Proveedor.Iibb; reporteTemp.Fecha = compraInDB.Fecha.Date.ToString("dd/MM/yyyy"); reporteTemp.TipoFactura = compraInDB.TipoFactura; reporteTemp.Factura = compraInDB.Factura; reporteTemp.SumaTotal = String.Format("{0:c}", compraInDB.SumaTotal); reporteTemp.DescuentoPorc = compraInDB.DescuentoPorc; reporteTemp.Descuento = String.Format("{0:c}", compraInDB.Descuento); reporteTemp.Subtotal = String.Format("{0:c}", compraInDB.Subtotal); reporteTemp.Iva = compraInDB.Iva; reporteTemp.ImporteIva = String.Format("{0:c}", compraInDB.ImporteIva); reporteTemp.ImporteIibbbsas = String.Format("{0:c}", compraInDB.ImporteIibbbsas); reporteTemp.ImporteIibbcaba = String.Format("{0:c}", compraInDB.ImporteIibbcaba); reporteTemp.ImportePercIva = String.Format("{0:c}", compraInDB.ImportePercIva); reporteTemp.Clasificacion = compraInDB.Clasificacion.Nombre; reporteTemp.Total = String.Format("{0:c}", compraInDB.Total); compraReporte.Add(reporteTemp); } } using (StringWriter sw = new StringWriter()) { using (HtmlTextWriter hw = new HtmlTextWriter(sw)) { StringBuilder sb = new StringBuilder(); var tableFormatter = new TableFormatter(); sb.Append(tableFormatter.FormatObjects(compraReporte)); //Export HTML String as PDF. StringReader sr = new StringReader(sb.ToString()); string fecha = string.Format("{0}{1}{2}", DateTime.Now.Date.Day, DateTime.Now.Date.Month, DateTime.Now.Date.Year); HttpContext.Current.Response.ContentType = "text/plain"; HttpContext.Current.Response.AddHeader("content-disposition", "attachment;filename=ReporteCompra_" + fecha + ".txt"); HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache); HttpContext.Current.Response.Write(sb.ToString()); HttpContext.Current.Response.End(); } } }