Ejemplo n.º 1
0
 public static string RenderInfoFacts(this IEnumerable <InfoFact> infofacts, int number,
                                      bool takeSummary        = true, bool shuffle = false,
                                      string delimiterBetween = " ",
                                      string lineFormat       = "{0}", bool html = false)
 {
     return(InfoFact.RenderInfoFacts(infofacts.ToArray(), number, takeSummary, shuffle, delimiterBetween, lineFormat, html));
 }
Ejemplo n.º 2
0
        public static string RenderInfoFacts(InfoFact[] infofacts, int number,
                                             bool takeSummary        = true, bool shuffle = false,
                                             string delimiterBetween = " ",
                                             string lineFormat       = "{0}", bool html = false)
        {
            if ((infofacts?.Count() ?? 0) == 0)
            {
                return(string.Empty);
            }

            IEnumerable <InfoFact> infof = infofacts
                                           .Where(m => m.Level != ImportanceLevel.Summary)
                                           .OrderByDescending(o => o.Level).ToArray();
            InfoFact summaryIf = infofacts.FirstOrDefault(m => m.Level == ImportanceLevel.Summary);

            var taken = new List <InfoFact>();

            if (takeSummary && summaryIf != null)
            {
                taken.Add(summaryIf);
            }


            if (taken.Count < number)
            {
                if (shuffle && taken.Count() > 1)
                {
                    taken.AddRange(infof.Shuffle().Take(number - taken.Count));
                }
                else
                {
                    taken.AddRange(infof.Take(number - taken.Count));
                }
            }

            bool useStringF = lineFormat.Contains("{0}");

            if (taken.Count == 0)
            {
                return("");
            }
            else
            {
                return(taken
                       .Select(t => useStringF ? string.Format(lineFormat, t.Render(html)) : t.Render(html))
                       .Aggregate((f, s) => f + delimiterBetween + s));
            }
        }