Example #1
0
        protected override Task <DataTable> ExecuteAsyncWithResult(AsyncCodeActivityContext context, CancellationToken cancellationToken)
        {
            IEnumerable <KeyValuePair <Rectangle, string> > positions = this.Positions.Get(context);
            string         input         = this.InputString.Get(context);
            ITableOptions  tableOptions  = this.GetTableOptions();
            IFormatOptions formatOptions = this.GetFormatOptions(context);

            return(Task.Factory.StartNew <DataTable>(delegate
            {
                TableFormatter tableFormatter = new TableFormatter();
                if (positions == null)
                {
                    return tableFormatter.Format(input, formatOptions, tableOptions);
                }
                return tableFormatter.Format(positions, tableOptions);
            }));
        }
Example #2
0
        public static IEnumerable <string> Tablize(IEnumerable objs, Type type, params string[] columeOptions)
        {
            var info = GetOrRegister(type);

            // TODO: TypeRegister can cache a TableFormatter. But need to make a base non-generic TableFormatter
            Func <TypeInfo, string> getHeader = _ => columeOptions.FirstOrDefault(opt => opt.StartsWith(_.Name)) ?? _.Name;
            var formatter = new TableFormatter <object>()
                            .SetHeaders(info.Select(getHeader).ToArray())
                            .SetColumns(info.Select(_ => _.Getter).ToArray());

            return(formatter.Format(objs.OfType <object>()));
        }
        private static void Main()
        {
            // ************ Configuration ***************
            const string apiKey = "ac1b0b1572524640a0ecc54de453ea9f";

            FundaApi.RateLimiter.Set(100, TimeSpan.FromMinutes(1));
            // ********** End configuration *************

            using var cancelTokenSource = new CancellationTokenSource();

            var funda = new FundaApi(apiKey);

            var makelaarTop10 = funda.ForSale(QueryAmsterdam, cancelTokenSource.Token)
                                .GroupBy(o => o.MakelaarId)
                                .Select(m => new MakelaarAggregateResult()
            {
                AantalObjecten  = m.Count(),
                Makelaar        = m.First().MakelaarNaam,
                Koopprijs       = m.Sum(_ => _.Koopprijs),
                Woonoppervlakte = m.Sum(_ => _.Woonoppervlakte)
            })
                                .OrderByDescending(_ => _.AantalObjecten)
                                .Take(10);

            Console.WriteLine("Top 10 realtors in Amsterdam selling properties");
            Console.WriteLine("---------------------------");
            Console.WriteLine(TableFormatter.Format(makelaarTop10));

            var makelaarTuinTop10 = funda.ForSale(QueryAmsterdamGarden, cancelTokenSource.Token)
                                    .GroupBy(o => o.MakelaarId)
                                    .Select(m => new MakelaarAggregateResult()
            {
                AantalObjecten  = m.Count(),
                Makelaar        = m.First().MakelaarNaam,
                Koopprijs       = m.Sum(_ => _.Koopprijs),
                Woonoppervlakte = m.Sum(_ => _.Woonoppervlakte)
            })
                                    .OrderByDescending(_ => _.AantalObjecten)
                                    .Take(10);

            Console.WriteLine("Top 10 realtors in Amsterdam selling properties with a garden");
            Console.WriteLine("---------------------------");
            Console.WriteLine(TableFormatter.Format(makelaarTuinTop10));
        }